<commit_before># encoding: utf-8
require 'bio'
require 'forwardable'

module Cheripic

  class ContigError < CheripicError; end

  class Contig

    include Enumerable
    extend Forwardable
    delegate [:size, :length] => :@contig
    def_delegator :@contig, :entry_id, :id
    attr_accessor :hm_pos, :ht_pos, :hemi_pos

    def initialize (fasta)
      @contig = fasta
      @contig.data = nil
      @hm_pos = []
      @ht_pos = []
      @hemi_pos = {}
    end

    def hm_num
      self.hm_pos.length
    end

    def ht_num
      self.ht_pos.length
    end

    def hme_score
      hmes_adjust = Options.params.hmes_adjust
      if self.hm_num == 0 and self.ht_num == 0
        0.0
      else
        (self.hm_num + hmes_adjust) / (self.ht_num + hmes_adjust)
      end
    end

    def bfr_score
      bfr_adjust = Options.params.bfr_adjust
      if self.hemi_pos.values.empty?
        bfr_adjust
      else
        geom_mean(self.hemi_pos.values)
      end
    end

    # geometric mean of an array of numbers
    def geom_mean(array)
      return array[0].to_f if array.length == 1
      sum = 0.0
      array.each{ |v| sum += Math.log(v.to_f) }
      sum /= array.size
      Math.exp sum
    end

  end # Contig

end # Cheripic<commit_msg>keeping only id and length info from fasta object to reduce the size of the object and a method to get semi snp number for each contig<commit_after># encoding: utf-8
require 'bio'
require 'forwardable'

module Cheripic

  class ContigError < CheripicError; end

  class Contig

    include Enumerable
    extend Forwardable
    # delegate [:size, :length] => :@contig
    # def_delegator :@contig, :entry_id, :id
    attr_accessor :hm_pos, :ht_pos, :hemi_pos, :id, :length

    def initialize (fasta)
      @id = fasta.entry_id
      @length = fasta.length
      @hm_pos = []
      @ht_pos = []
      @hemi_pos = {}
    end

    def hm_num
      self.hm_pos.length
    end

    def ht_num
      self.ht_pos.length
    end

    def hme_score
      hmes_adjust = Options.params.hmes_adjust
      if self.hm_num == 0 and self.ht_num == 0
        0.0
      else
        (self.hm_num + hmes_adjust) / (self.ht_num + hmes_adjust)
      end
    end

    def hemi_num
      self.hemi_pos.length
    end

    def bfr_score
      if self.hemi_pos.values.empty?
        0.0
      else
        geom_mean(self.hemi_pos.values)
      end
    end

    # geometric mean of an array of numbers
    def geom_mean(array)
      return array[0].to_f if array.length == 1
      sum = 0.0
      array.each{ |v| sum += Math.log(v.to_f) }
      sum /= array.size
      Math.exp sum
    end

  end # Contig

end # Cheripic
{'fraction_non_alphanumeric': 0.088157396897465, 'fraction_numerical': 0.007567158531971245, 'mean_word_length': 2.1069330199764984, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1421982', 'n_tokens_mistral': 972, 'n_tokens_neox': 937, 'n_words': 245}