]> git.donarmstrong.com Git - biopieces.git/commitdiff
added << method to Seq.rb
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 8 Mar 2013 10:09:02 +0000 (10:09 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 8 Mar 2013 10:09:02 +0000 (10:09 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@2113 74ccb610-7750-0410-82ae-013aeee3265d

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

index c8cc9f1e9943959c1b3ae1009cce6ba098ef0308..cf4b6e6802883d5447c7bbad7157ae65bc0c95b1 100644 (file)
@@ -420,6 +420,17 @@ class Seq
     self
   end
 
+  # Method to concatenate sequence entries.
+  def <<(entry)
+    raise SeqError, "sequences of different types" unless self.type == entry.type
+    raise SeqError, "qual is missing in one entry" unless self.qual.class == entry.qual.class
+
+    self.seq  << entry.seq
+    self.qual << entry.qual unless entry.qual.nil?
+
+    self
+  end
+
   # Method that returns a subsequence of from a given start position
   # and of a given length.
   def subseq(start, length = self.length - start)
index 8ec6f977cc69f75f9c61f36d29359eb1ca7dbc4a..4a68d67b080b0ed220ae8fb18d7dfed83c1750fa 100755 (executable)
@@ -333,6 +333,46 @@ class TestSeq < Test::Unit::TestCase
     assert_not_equal(@entry.seq, @entry.shuffle!.seq)
   end
 
+  test "#<< with different types raises" do
+    @entry.seq = "atcg"
+    assert_raise(SeqError) { @entry << Seq.new("test", "atcg", "dna") }
+  end
+
+  test "#<< with missing qual in one entry raises" do
+    @entry.seq  = "atcg"
+    @entry.type = "dna"
+    assert_raise(SeqError) { @entry << Seq.new("test", "atcg", "dna", "IIII") }
+    @entry.qual = "IIII"
+    assert_raise(SeqError) { @entry << Seq.new("test", "atcg", "dna") }
+  end
+
+  test "#<< with nil qual in both entries dont raise" do
+    @entry.seq = "atcg"
+    assert_nothing_raised { @entry << Seq.new("test", "atcg") }
+  end
+
+  test "#<< with qual in both entries dont raise" do
+    @entry.seq  = "atcg"
+    @entry.type = "dna"
+    @entry.qual = "IIII"
+    assert_nothing_raised { @entry << Seq.new("test", "atcg", "dna", "IIII") }
+  end
+
+  test "#<< without qual returns correctly" do
+    @entry.seq  = "atcg"
+    @entry <<  Seq.new("test", "ATCG")
+    assert_equal("atcgATCG", @entry.seq)
+  end
+
+  test "#<< with qual returns correctly" do
+    @entry.seq  = "atcg"
+    @entry.type = "dna"
+    @entry.qual = "HHHH"
+    @entry <<  Seq.new("test", "ATCG", "dna", "IIII")
+    assert_equal("atcgATCG", @entry.seq)
+    assert_equal("HHHHIIII", @entry.qual)
+  end
+
   test "#subseq with start < 0 raises" do
     @entry.seq = "ATCG"
     assert_raise(SeqError) { @entry.subseq(-1, 1) }