]> git.donarmstrong.com Git - biopieces.git/commitdiff
added to_fastq method seq.rb
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 13 Oct 2011 08:51:38 +0000 (08:51 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Thu, 13 Oct 2011 08:51:38 +0000 (08:51 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1558 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/seq.rb
code_ruby/test/maasha/test_seq.rb

index a54da1e81a6d48dd6ee0524e776ee4747f821154..a724339694f27558504f427c31fedcd95167d744 100644 (file)
@@ -182,6 +182,19 @@ class Seq
     ">" + seq_name + $/ + seq + $/
   end
 
+  # Method that given a Seq entry returns a FASTQ entry (a string).
+  def to_fastq
+    raise SeqError, "Missing seq_name" if self.seq_name.nil?
+    raise SeqError, "Missing seq"      if self.seq.nil?
+    raise SeqError, "Missing qual"     if self.qual.nil?
+
+    seq_name = self.seq_name
+    seq      = self.seq
+    qual     = self.qual
+
+    "@" + seq_name + $/ + seq + $/ + "+" + $/ + qual + $/
+  end
+
   # Method that generates a unique key for a
   # DNA sequence and return this key as a Fixnum.
   def to_key
index 7859fbef86a08b5f8802727e37f4243ba960102f..cda1f94045b0752b89deedf75329a7d37803cb94 100755 (executable)
@@ -168,6 +168,13 @@ class TestSeq < Test::Unit::TestCase
     assert_equal(">test\nAT\nCG\n", entry.to_fasta(2))
   end
 
+  def test_Seq_to_fastq_returns_correct_entry
+    @entry.seq_name = 'test'
+    @entry.seq      = 'ATCG'
+    @entry.qual     = 'hhhh'
+    assert_equal("@test\nATCG\n+\nhhhh\n", @entry.to_fastq)
+  end
+
   def test_Seq_to_key_with_bad_residue_raises
     entry = Seq.new("test", "AUCG")
     assert_raise(SeqError) { entry.to_key }