]> git.donarmstrong.com Git - biopieces.git/commitdiff
added [] og []= to seq.rb
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 11 Mar 2013 06:52:14 +0000 (06:52 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 11 Mar 2013 06:52:14 +0000 (06:52 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@2124 74ccb610-7750-0410-82ae-013aeee3265d

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

index f76466f583af2a18699f3aa4ee40f67fb88e250e..91e79295039e7f8e572efa0ceaf231e8e91c1bd4 100644 (file)
@@ -427,6 +427,25 @@ class Seq
     self
   end
 
+  # Index method for Seq objects.
+  def [](*args)
+    entry = Seq.new
+    entry.seq_name = self.seq_name
+    entry.seq      = self.seq[*args]
+    entry.type     = self.type
+    entry.qual     = self.qual[*args] unless self.qual.nil?
+
+    entry
+  end
+
+  # Index assignment method for Seq objects.
+  def []=(*args, entry)
+    self.seq[*args]  = entry.seq[*args]
+    self.qual[*args] = entry.qual[*args] unless self.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 b3bdd790baa16546e74d655e79dd1ec06f3d57eb..a6a5cd7f8a0d482561b1445cae4a8857cea80700 100755 (executable)
@@ -373,16 +373,48 @@ class TestSeq < Test::Unit::TestCase
     assert_equal("HHHHIIII", @entry.qual)
   end
 
-  test "#[] returns correctly" do
-    @entry.seq  = "atcg"
-    @entry.type = :dna
-    @entry.qual = "FGHI"
+  test "#[] with qual returns correctly" do
+    entry = Seq.new("test", "atcg", :dna, "FGHI")
+
+    e = entry[2]
+
+    assert_equal("test", e.seq_name)
+    assert_equal("c",    e.seq)
+    assert_equal(:dna,   e.type)
+    assert_equal("H",    e.qual)
+    assert_equal("atcg", entry.seq)
+    assert_equal("FGHI", entry.qual)
+  end
+
+  test "#[] without qual returns correctly" do
+    entry = Seq.new("test", "atcg")
+
+    e = entry[2]
 
-    fail
+    assert_equal("test", e.seq_name)
+    assert_equal("c",    e.seq)
+    assert_nil(e.qual)
+    assert_equal("atcg", entry.seq)
   end
 
-  test "[]= returns correctly" do
-    fail
+  test "[]= with qual returns correctly" do
+    entry = Seq.new("test", "atcg", :dna, "FGHI")
+
+    entry[0] = Seq.new("foo", "T", :dna, "I")
+
+    assert_equal("test", entry.seq_name)
+    assert_equal("Ttcg", entry.seq)
+    assert_equal(:dna,   entry.type)
+    assert_equal("IGHI", entry.qual)
+  end
+
+  test "[]= without qual returns correctly" do
+    entry = Seq.new("test", "atcg")
+
+    entry[0] = Seq.new("foo", "T")
+
+    assert_equal("test", entry.seq_name)
+    assert_equal("Ttcg", entry.seq)
   end
 
   test "#subseq with start < 0 raises" do