Class: Statistics
- Inherits:
-
Object
- Object
- Statistics
- Defined in:
- lib/nugen_barcode_splitter/statistics.rb
Instance Attribute Summary collapse
-
#barcodes ⇒ Object
Returns the value of attribute barcodes.
-
#num_reads ⇒ Object
Returns the value of attribute num_reads.
-
#num_unmatched ⇒ Object
Returns the value of attribute num_unmatched.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
-
#initialize(lane_log) ⇒ Statistics
constructor
A new instance of Statistics.
- #to_s ⇒ Object
Constructor Details
#initialize(lane_log) ⇒ Statistics
Returns a new instance of Statistics.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/nugen_barcode_splitter/statistics.rb', line 4 def initialize(lane_log) # getting barcodes: i = 0 @barcodes = [] File.open(lane_log).each do |line| next if line.include?("Id") next if line.empty? break if line.include?("unmatched") line = line.split("\t") [i] = line[0] i += 1 end @num_reads = Array.new(.length(),0) @num_unmatched = 0 @total = 0 @barcodes = File.open(lane_log).each do |line| next if line.include?("Id") next if line.empty? line = line.split("\t") case line[0] when "unmatched" @num_unmatched += line[1].to_i when "total" @total += line[1].to_i else if i = @barcodes.index(line[0]) @num_reads[i]+= line[1].to_i end end end end |
Instance Attribute Details
#barcodes ⇒ Object
Returns the value of attribute barcodes.
38 39 40 |
# File 'lib/nugen_barcode_splitter/statistics.rb', line 38 def @barcodes end |
#num_reads ⇒ Object
Returns the value of attribute num_reads.
38 39 40 |
# File 'lib/nugen_barcode_splitter/statistics.rb', line 38 def num_reads @num_reads end |
#num_unmatched ⇒ Object
Returns the value of attribute num_unmatched.
38 39 40 |
# File 'lib/nugen_barcode_splitter/statistics.rb', line 38 def num_unmatched @num_unmatched end |
#total ⇒ Object
Returns the value of attribute total.
38 39 40 |
# File 'lib/nugen_barcode_splitter/statistics.rb', line 38 def total @total end |
Instance Method Details
#to_s ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nugen_barcode_splitter/statistics.rb', line 40 def to_s str = "Statistics: \nBarcode\t# of reads\n" @barcodes.each_with_index do |code, i| str += "#{code}:\t#{@num_reads[i]} \n" end #percent = (100 / @total.to_f) * @num_unmatched.to_f #percent = (percent.to_f * 100).round / 100.to_f str += "Unmatched:\t#{@num_unmatched}\n" str += "Total:\t#{@total}" str.to_s end |