Class: Iroki::Biom
- Inherits:
-
File
- Object
- File
- Iroki::Biom
- Defined in:
- lib/iroki/biom.rb
Instance Attribute Summary collapse
-
#single_group ⇒ Object
Returns the value of attribute single_group.
Instance Method Summary collapse
Instance Attribute Details
#single_group ⇒ Object
Returns the value of attribute single_group.
26 27 28 |
# File 'lib/iroki/biom.rb', line 26 def single_group @single_group end |
Instance Method Details
#parse ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/iroki/biom.rb', line 28 def parse samples = [] counts = [] lineno = -1 first_line_count = -1 self.each_line.with_index do |line, idx| unless line.start_with? "#" lineno += 1 sample, *the_counts = line.chomp.split "\t" abort_if sample.nil? || sample.empty? || sample =~ / +/, "Line #{idx+1} has no sample" the_counts.flatten.each do |count| abort_unless valid_numerical_val?(count), "The value '#{count}' in the " + "biom file might not be valid" end if lineno.zero? first_line_count = the_counts.count else abort_unless first_line_count == the_counts.count, "Line number #{idx+1} (#{line.inspect}) in the " + "biom file has #{the_counts.count} " + "columns when it should have " + "#{first_line_count} columns like the " + "first row does." end samples << sample if the_counts.length == 1 counts << the_counts.first.to_f @single_group = true else counts << the_counts.map(&:to_f) end end end [samples, counts, @single_group] end |