From: martinahansen Date: Fri, 8 Mar 2013 10:09:02 +0000 (+0000) Subject: added << method to Seq.rb X-Git-Url: https://git.donarmstrong.com/?p=biopieces.git;a=commitdiff_plain;h=80706855913e8607239241fd2938f47d1fb76799 added << method to Seq.rb git-svn-id: http://biopieces.googlecode.com/svn/trunk@2113 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_ruby/lib/maasha/seq.rb b/code_ruby/lib/maasha/seq.rb index c8cc9f1..cf4b6e6 100644 --- a/code_ruby/lib/maasha/seq.rb +++ b/code_ruby/lib/maasha/seq.rb @@ -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) diff --git a/code_ruby/test/maasha/test_seq.rb b/code_ruby/test/maasha/test_seq.rb index 8ec6f97..4a68d67 100755 --- a/code_ruby/test/maasha/test_seq.rb +++ b/code_ruby/test/maasha/test_seq.rb @@ -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) }