sample data:
DNA :
This is a string
BaseQuality :
4 4 4 4 4 4 6 7 7 7
Metadata :
Is_read
DNA :
yet another string
BaseQuality :
4 4 4 4 7 7 4 8 4 4 4 4 4
Metadata :
Is_read
SCF_File
.
.
.
I have a method that is using a case statement as follows to separate parts of a longer text file into records using the delimeter "\n\n". And a class that models a data object
def parse_file(myfile)
$/ = "\n\n"
records = []
File.open(myfile) do |f|
f.each_line do |line|
read = Read.new
case line
when /^DNA/
read.dna_data = line.strip
when /^BaseQuality/
read.quality_data =line.strip
when /^Metadata/
read.metadata =line.strip
else
puts "Unrecognized line: #{line}"
end
records.push read
end
end
records
end
class Read
attr_accessor :dna_data,:quality_data,:metadata
end
records.each do |r|
puts r.dna_data
end
dna data contains the 'rightful' string part as well as two nil 'objects'/ irritating nils!
"This is a string"
nil
nil
My problems are the nil strings shown above which are assigned to dna_data when using read.dna_data = line
.
Please how do you get rid of them? How do you avoid them in the first instance. What am i missing? Is my approach 'smelly'? Thank you