Class: Bio::KmerMultipleAbundanceHash
- Inherits:
-
Hash
- Object
- Hash
- Bio::KmerMultipleAbundanceHash
- Includes:
- FinishM::Logging
- Defined in:
- lib/kmer_multi_abundance_file.rb
Overview
A class to work with a kmer abundance file format, where the kmer is first, then each abundance after that (no headings, space separated)
Class Method Summary collapse
Instance Method Summary collapse
Methods included from FinishM::Logging
Class Method Details
.parse_from_file(path) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kmer_multi_abundance_file.rb', line 9 def self.parse_from_file(path) obj = self.new kmer_length = nil num_abundances = nil CSV.foreach(path, :col_sep => ' ') do |row| kmer = row[0].upcase abundances = row[1...row.length] kmer_length ||= kmer.length if kmer.length != kmer_length raise "inconsistent length of kmer found in kmer abundance file, in line: #{row.inspect}" end num_abundances ||= abundances.length if num_abundances != abundances.length raise "inconsistent number of abundances found in kmer abundance file, in line: #{row.inspect}" end obj[kmer] = abundances end return obj end |
Instance Method Details
#[](kmer) ⇒ Object
42 43 44 45 46 |
# File 'lib/kmer_multi_abundance_file.rb', line 42 def [](kmer) abundances = super(kmer.upcase) abundances ||= [0]*number_of_abundances return abundances end |
#kmer_length ⇒ Object
30 31 32 33 34 |
# File 'lib/kmer_multi_abundance_file.rb', line 30 def kmer_length each do |kmer, abundances| return kmer.length end end |
#number_of_abundances ⇒ Object
36 37 38 39 40 |
# File 'lib/kmer_multi_abundance_file.rb', line 36 def number_of_abundances each do |kmer, abundances| return abundances.length end end |