lib/seqtrimnext/classes/extract_stats.rb in seqtrimnext-2.0.51 vs lib/seqtrimnext/classes/extract_stats.rb in seqtrimnext-2.0.52

- old
+ new

@@ -9,24 +9,24 @@ require 'scbi_plot' require "scbi_math" class ExtractStats - def initialize(sequence_reader,params) + def initialize(sequence_readers,params) @sequence_lengths = [] #array of sequences lengths @length_frequency = [] #number of sequences of each size (frequency) @keys={} #found keys @params = params - @use_qual=sequence_reader.with_qual? + @use_qual=sequence_readers.first.with_qual? # @params.get_param('use_qual') @totalnt=0 @qv=[] - @sequence_lengths_stats, @length_frequency_stats, @quality_stats = extract_stats_from_sequences(sequence_reader) + @sequence_lengths_stats, @length_frequency_stats, @quality_stats = extract_stats_from_sequences(sequence_readers) set_params_and_results plot_lengths @@ -35,34 +35,37 @@ print_global_stats end - def extract_stats_from_sequences(sequence_reader) + def extract_stats_from_sequences(sequence_readers) + sequence_readers.each do |sequence_reader| - sequence_reader.each do |name_seq,fasta_seq,qual| - l = fasta_seq.length - @totalnt+=l + sequence_reader.each do |name_seq,fasta_seq,qual| + l = fasta_seq.length - #save all lengths - @sequence_lengths.push l + @totalnt+=l - # add key value - add_key(fasta_seq[0..3].upcase) + #save all lengths + @sequence_lengths.push l - # add fasta length - @length_frequency[fasta_seq.length] = (@length_frequency[fasta_seq.length] || 1 ) + 1 + # add key value + add_key(fasta_seq[0..3].upcase) - #extract qv values - extract_qv_from_sequence(qual) if @use_qual + # add fasta length + @length_frequency[fasta_seq.length] = (@length_frequency[fasta_seq.length] || 1 ) + 1 - # print some progress info - if (sequence_reader.num_seqs % 10000==0) - puts "Calculating stats: #{sequence_reader.num_seqs}" - end + #extract qv values + extract_qv_from_sequence(qual) if @use_qual + # print some progress info + if (sequence_reader.num_seqs % 10000==0) + puts "Calculating stats: #{sequence_reader.num_seqs}" + end + + end end length_stats = ScbiNArray.to_na(@sequence_lengths) length_frequency_stats = ScbiNArray.to_na(@length_frequency.map{|e| e || 0}) quality_stats = ScbiNArray.to_na(@qv) if @use_qual @@ -72,14 +75,14 @@ def plot_lengths ## PLOT RESULTS if !File.exists?('graphs') - Dir.mkdir('graphs') + Dir.mkdir('graphs') end - + x = [] y = [] x =(0..@length_frequency.length-1).collect.to_a y = @length_frequency.map{|e| e || 0} @@ -105,13 +108,13 @@ end def plot_qualities if !File.exists?('graphs') - Dir.mkdir('graphs') + Dir.mkdir('graphs') end minimum_qual_value = @params.get_param('min_quality').to_i - + # get qualities values x=[] y=[] min=[] max=[]