lib/genomer-plugin-summary/sequences.rb in genomer-plugin-summary-0.0.2 vs lib/genomer-plugin-summary/sequences.rb in genomer-plugin-summary-0.0.3

- old
+ new

@@ -1,9 +1,11 @@ require 'genomer' +require 'genomer-plugin-summary/metrics' require 'terminal-table' class GenomerPluginSummary::Sequences < Genomer::Plugin + include GenomerPluginSummary::Metrics def run sequences = calculate(scaffold) total = total(sequences) @@ -49,26 +51,26 @@ map{|i| hash[i]}. map{|i| i.class == Float ? sprintf('%#.2f',i) : i } end def calculate(scaffold) - total_length = scaffold.map(&:sequence).join.length.to_f + total_length = length(:all,scaffold).to_f + running_length = 0 - length = 0 scaffold.map do |entry| i = nil if entry.entry_type != :unresolved entry_length = entry.sequence.length i = { :sequence => entry.source, - :start => length + 1, - :end => length + entry_length, + :start => running_length + 1, + :end => running_length + entry_length, :size => entry_length, :percent => entry_length / total_length * 100, - :gc => gc_content(entry.sequence) } + :gc => gc(entry) / atgc(entry) * 100 } end - length += entry.sequence.length + running_length += entry.sequence.length i end.compact end def total(seqs) @@ -83,13 +85,8 @@ hash end totals[:gc] /= totals[:size] totals - end - - def gc_content(sequence) - nucleotides = sequence.gsub(/[^ATGCatgc]/,'') - nucleotides.gsub(/[^GCgc]/,'').length.to_f / nucleotides.length * 100 end end