<commit_before>require 'bio'
require 'bettersam'
require 'csv'
require 'forwardable'
require 'inline'

module Transrate

  class Assembly

    include Enumerable
    extend Forwardable
    def_delegators :@assembly, :each, :<<, :size, :length

    attr_accessor :ublast_db
    attr_accessor :orfs_ublast_db
    attr_accessor :protein
    attr_reader :assembly
    attr_reader :has_run

    # number of bases in the assembly
    attr_writer :n_bases

    # assembly filename
    attr_accessor :file

    # assembly n50
    attr_reader :n50

    # Return a new Assembly.
    #
    # - +:file+ - path to the assembly FASTA file
    def initialize file
      @file = file
      @assembly = []
      @n_bases = 0
      Bio::FastaFormat.open(file).each do |entry|
        @n_bases += entry.length
        @assembly << entry
      end
    end

    # Return a new Assembly object by loading sequences
    # from the FASTA-format +:file+
    def self.stats_from20_fasta file
      a = Assembly.new file
      a.basic_stats
    end

    def run threads=8
      stats = self.basic_stats threads
      stats.each_pair do |key, value|
        ivar = "@#{key.gsub(/\ /, '_')}".to_sym
        attr_ivar = "#{key.gsub(/\ /, '_')}".to_sym
        # creates accessors for the variables in stats
        singleton_class.class_eval { attr_accessor attr_ivar }
        self.instance_variable_set(ivar, value)
      end
      @has_run = true
    end

    # Return a hash of statistics about this assembly. Stats are
    # calculated in parallel by splitting the assembly into
    # equal-sized bins and calling Assembly#basic_bin_stat on each
    # bin in a separate thread.
    
    def basic_stats threads=8
      
      # create a work queue to process contigs in parallel
      queue = Queue.new
      
      # split the contigs into equal sized bins, one bin per thread
      binsize = (@assembly.size / threads.to_f).ceil
      # Transrate.log.info("Processing #{@assembly.size} contigs in #{threads} bins")
      @assembly.each_slice(binsize) do |bin|
        queue << bin
      end<commit_msg>Incline C version of orf_length, uncomment logger<commit_after>require 'bio'
require 'bettersam'
require 'csv'
require 'forwardable'
require 'inline'

module Transrate

  class Assembly

    include Enumerable
    extend Forwardable
    def_delegators :@assembly, :each, :<<, :size, :length

    attr_accessor :ublast_db
    attr_accessor :orfs_ublast_db
    attr_accessor :protein
    attr_reader :assembly
    attr_reader :has_run

    # number of bases in the assembly
    attr_writer :n_bases

    # assembly filename
    attr_accessor :file

    # assembly n50
    attr_reader :n50

    # Return a new Assembly.
    #
    # - +:file+ - path to the assembly FASTA file
    def initialize file
      @file = file
      @assembly = []
      @n_bases = 0
      Bio::FastaFormat.open(file).each do |entry|
        @n_bases += entry.length
        @assembly << entry
      end
    end

    # Return a new Assembly object by loading sequences
    # from the FASTA-format +:file+
    def self.stats_from20_fasta file
      a = Assembly.new file
      a.basic_stats
    end

    def run threads=8
      stats = self.basic_stats threads
      stats.each_pair do |key, value|
        ivar = "@#{key.gsub(/\ /, '_')}".to_sym
        attr_ivar = "#{key.gsub(/\ /, '_')}".to_sym
        # creates accessors for the variables in stats
        singleton_class.class_eval { attr_accessor attr_ivar }
        self.instance_variable_set(ivar, value)
      end
      @has_run = true
    end

    # Return a hash of statistics about this assembly. Stats are
    # calculated in parallel by splitting the assembly into
    # equal-sized bins and calling Assembly#basic_bin_stat on each
    # bin in a separate thread.
    
    def basic_stats threads=8
      
      # create a work queue to process contigs in parallel
      queue = Queue.new
      
      # split the contigs into equal sized bins, one bin per thread
      binsize = (@assembly.size / threads.to_f).ceil
      Transrate.log.info("Processing #{@assembly.size} contigs in #{threads} bins")
      @assembly.each_slice(binsize) do |bin|
        queue << bin
      end
{'fraction_non_alphanumeric': 0.0825381679389313, 'fraction_numerical': 0.004293893129770993, 'mean_word_length': 2.5, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, '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': '6855161', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1263, 'n_words': 403}