Class: Statistics

Inherits:
Object
  • Object
show all
Defined in:
lib/nugen_barcode_splitter/statistics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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")
    barcodes[i] = line[0]
    i += 1
  end

  @num_reads = Array.new(barcodes.length(),0)
  @num_unmatched = 0
  @total = 0
  @barcodes = 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

#barcodesObject

Returns the value of attribute barcodes.



38
39
40
# File 'lib/nugen_barcode_splitter/statistics.rb', line 38

def barcodes
  @barcodes
end

#num_readsObject

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_unmatchedObject

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

#totalObject

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_sObject



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