lib/transrate/assembly.rb
# Calculate basic statistics in an single thread for a bin
# of contigs.
#
# Basic statistics are:
#
# - N10, N30, N50, N70, N90
# - number of contigs >= 1,000 base pairs long
# - number of contigs >= 10,000 base pairs long
# - length of the shortest contig
# - length of the longest contig
# - number of contigs in the bin
# - mean contig length
# - total number of nucleotides in the bin
# - mean % of contig length covered by the longest ORF
#
# @param [Array] bin An array of Bio::Sequence objects
# representing contigs in the assembly
Calculate basic statistics in an single thread for a bin
of contigs.

Basic statistics are.

N10, N30, N50, N70, N90
number of contigs >= 1,000 base pairs long
number of contigs >= 10,000 base pairs long
length of the shortest contig
length of the longest contig
number of contigs in the bin
mean contig length
total number of nucleotides in the bin
mean % of contig length covered by the longest ORF
Calculate basic statistics in an single thread for a bin of contigs . Basic statistics are . N10 N30 N50 N70 N90 number of contigs > = 1 000 base pairs long number of contigs > = 10 000 base pairs long length of the shortest contig length of the longest contig number of contigs in the bin mean contig length total number of nucleotides in the bin mean % of contig length covered by the longest ORF
def basic_bin_stats bin
      cumulative_length = 0.0
      x = [90, 70, 50, 30, 10]
      x2 = x.clone
      cutoff = x2.pop / 100.0
      res = []
      n_under_200 = 0
      n_over_1k = 0
      n_over_10k = 0
      n_with_orf = 0
      orf_length_sum = 0
      bin.sort_by! { |c| c.seq.length }
      bin.each do |contig|
        if contig.length < 200
          n_under_200 += 1
          next
        end
        n_over_1k += 1 if contig.length > 1_000
        n_over_10k += 1 if contig.length > 10_000
        orf_length = contig.orf_length
        orf_length_sum += orf_length
        n_with_orf += 1 if orf_length > 149
        cumulative_length += contig.length
        if cumulative_length >= @n_bases * cutoff
          res << contig.length
          if x2.empty?
            cutoff = 1
          else
            cutoff = x2.pop / 100.0
          end
        end
      end
      while res.length < x.length do
        res << bin.last.length
      end
      mean = cumulative_length / @assembly.size
      ns = Hash[x.map { |n| "n#{n}" }.zip(res)]
      {
        'n_seqs' => bin.size,
        'smallest' => bin.first.length,
        'largest' => bin.last.length,
        'n_bases' => n_bases,
        'mean_len' => mean,
        'n_under_200' => n_under_200,
        'n_over_1k' => n_over_1k,
        'n_over_10k' => n_over_10k,
        'n_with_orf' => n_with_orf,
        'mean_orf_percent' => 300 * orf_length_sum / (@assembly.size * mean)
      }.merge ns
    end
def basic_bin_stats bin cumulative_length = 0.0 x = [ 90 , 70 , 50 , 30 , 10 ] x2 = x . clone cutoff = x2 . pop / 100.0 res = [ ] n_under_200 = 0 n_over_1k = 0 n_over_10k = 0 n_with_orf = 0 orf_length_sum = 0 bin . sort_by! { | c | c . seq . length } bin . each do | contig | if contig . length < 200 n_under_200 += 1 next end n_over_1k += 1 if contig . length > 1_000 n_over_10k += 1 if contig . length > 10_000 orf_length = contig . orf_length orf_length_sum += orf_length n_with_orf += 1 if orf_length > 149 cumulative_length += contig . length if cumulative_length >= @n_bases * cutoff res << contig . length if x2 . empty? cutoff = 1 else cutoff = x2 . pop / 100.0 end end end while res . length < x . length do res << bin . last . length end mean = cumulative_length / @assembly . size ns = Hash [ x . map { | n | "n#{n}" } . zip ( res ) ] { 'n_seqs' => bin . size , 'smallest' => bin . first . length , 'largest' => bin . last . length , 'n_bases' => n_bases , 'mean_len' => mean , 'n_under_200' => n_under_200 , 'n_over_1k' => n_over_1k , 'n_over_10k' => n_over_10k , 'n_with_orf' => n_with_orf , 'mean_orf_percent' => 300 * orf_length_sum / ( @assembly . size * mean ) } . merge ns end
Calculate basic statistics in an single thread for a bin
of contigs.
Calculate basic statistics in an single thread for a bin of contigs .
# cumulative length is a float so we can divide it # accurately later to get the mean length # we'll calculate Nx for x in [10, 30, 50, 70, 90] # to do this we create a stack of the x values and # pop the first one to set the first cutoff. when # the cutoff is reached we store the nucleotide length and pop # the next value to set the next cutoff. we take a copy # of the Array so we can use the intact original to collect # the results later # sort the contigs in ascending length order # and iterate over them # increment our long contig counters if this # contig is above the thresholds # ignore contigs less than 200 bases, # but record how many there are # add the length of the longest orf to the # running total # only consider orfs that are realistic length # (here we set minimum amino acid length as 50) # increment the cumulative length and check whether the Nx # cutoff has been reached. if it has, store the Nx value and # get the next cutoff # if there aren't enough sequences we might have no value for some # of the Nx. Fill the empty ones in with the longest contig length. # calculate and return the statistics as a hash
bin
<not_specific>
<not_specific>
bin An array of Bio::Sequence objects representing contigs in the assembly
bin An array of Bio :: Sequence objects representing contigs in the assembly