From: martinahansen Date: Fri, 13 Dec 2013 10:37:23 +0000 (+0000) Subject: changed fasta parse to allow leading empty lines X-Git-Url: https://git.donarmstrong.com/?p=biopieces.git;a=commitdiff_plain;h=164c771704dbc986614e93aed25a6d1fc0e200c7 changed fasta parse to allow leading empty lines git-svn-id: http://biopieces.googlecode.com/svn/trunk@2278 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/lib/maasha/fasta.rb b/code_ruby/lib/maasha/fasta.rb index c9ce43d..971ad54 100644 --- a/code_ruby/lib/maasha/fasta.rb +++ b/code_ruby/lib/maasha/fasta.rb @@ -32,7 +32,11 @@ class Fasta < Filesys # Method to get the next FASTA entry form an ios and return this # as a Seq object. If no entry is found or eof then nil is returned. def get_entry - block = @io.gets($/ + '>') + block = nil + + while block = @io.gets($/ + '>') and block.chomp($/ + '>').empty? + end + return nil if block.nil? block.chomp!($/ + '>') diff --git a/code_ruby/lib/maasha/seq.rb b/code_ruby/lib/maasha/seq.rb index c22ecec..9a8816d 100644 --- a/code_ruby/lib/maasha/seq.rb +++ b/code_ruby/lib/maasha/seq.rb @@ -305,7 +305,7 @@ class Seq seq.chomp! end - ">" + seq_name + $/ + seq + $/ + ">" + seq_name.to_s + $/ + seq + $/ end # Method that given a Seq entry returns a FASTQ entry (a string). diff --git a/code_ruby/test/maasha/test_fasta.rb b/code_ruby/test/maasha/test_fasta.rb index 3924f54..2273eb0 100755 --- a/code_ruby/test/maasha/test_fasta.rb +++ b/code_ruby/test/maasha/test_fasta.rb @@ -72,11 +72,6 @@ class FastaTest < Test::Unit::TestCase assert_raise(FastaError) { fasta.get_entry } end - test "#get_entry with leading newline raises" do - fasta = Fasta.new(StringIO.new("\n>test\nATCG\n")) - assert_raise(FastaError) { fasta.get_entry } - end - # FIXME # test "#get_entry raises on missing > in seq_name" do # fasta = Fasta.new(StringIO.new("test\nATCG\n"))