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
|