]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/test/maasha/test_sam.rb
fixed alignment descriptors in sam.rb
[biopieces.git] / code_ruby / test / maasha / test_sam.rb
index d02d710942680300290bddd3ac42ef35c249e766..06fcf25975d96ba929d67e2329ac77c5763732e7 100755 (executable)
@@ -355,7 +355,7 @@ class SamTest < Test::Unit::TestCase
       assert_equal("SAM", Sam.to_bp(s)[:REC_TYPE])
       assert_equal("ID00036734", Sam.to_bp(s)[:Q_ID])
       assert_equal("-", Sam.to_bp(s)[:STRAND])
-        assert_equal("gi48994873", Sam.to_bp(s)[:S_ID])
+      assert_equal("gi48994873", Sam.to_bp(s)[:S_ID])
       assert_equal(366089, Sam.to_bp(s)[:S_BEG])
       assert_equal(37, Sam.to_bp(s)[:MAPQ])
       assert_equal("37M1I62M", Sam.to_bp(s)[:CIGAR])
@@ -363,5 +363,45 @@ class SamTest < Test::Unit::TestCase
       assert_equal("37:->T", Sam.to_bp(s)[:ALIGN])
     end
   end
+
+  def test_Sam_to_bp_alignment_descriptor_without_mismatch_or_indel_returns_correctly
+    string = "q_id\t0\ts_id\t1000\t40\t10M\t*\t0\t0\tGTTCCGCTAT\t*\tXT:A:U\tNM:i:0\tX0:i:1\tX1:i:0\tXM:i:0\tXO:i:1\tXG:i:1\tMD:Z:10\n"
+
+    sam = Sam.new(StringIO.new(string))
+
+    sam.each do |s|
+      assert_equal(nil, Sam.to_bp(s)[:ALIGN])
+    end
+  end
+
+  def test_Sam_to_bp_alignment_descriptor_with_mismatches_returns_correctly
+    string = "q_id\t0\ts_id\t1000\t40\t10M\t*\t0\t0\tgTTCCGCTAt\t*\tXT:A:U\tNM:i:2\tX0:i:1\tX1:i:0\tXM:i:0\tXO:i:1\tXG:i:1\tMD:Z:0C8A\n"
+
+    sam = Sam.new(StringIO.new(string))
+
+    sam.each do |s|
+      assert_equal("0:C>g,9:A>t", Sam.to_bp(s)[:ALIGN])
+    end
+  end
+
+  def test_Sam_to_bp_alignment_descriptor_with_insertions_returns_correctly
+    string = "q_id\t0\ts_id\t1000\t40\t1I10M1I\t*\t0\t0\taGTTCCGCTATc\t*\tXT:A:U\tNM:i:2\tX0:i:1\tX1:i:0\tXM:i:0\tXO:i:1\tXG:i:1\tMD:Z:12\n"
+
+    sam = Sam.new(StringIO.new(string))
+
+    sam.each do |s|
+      assert_equal("0:->a,11:->c", Sam.to_bp(s)[:ALIGN])
+    end
+  end
+
+  def test_Sam_to_bp_alignment_descriptor_with_deletions_returns_correctly
+    string = "q_id\t0\ts_id\t1000\t40\t2D10M\t*\t0\t0\tGTTCCGCTAT\t*\tXT:A:U\tNM:i:2\tX0:i:1\tX1:i:0\tXM:i:0\tXO:i:1\tXG:i:1\tMD:Z:^AC10\n"
+
+    sam = Sam.new(StringIO.new(string))
+
+    sam.each do |s|
+      assert_equal("0:A>-,1:C>-", Sam.to_bp(s)[:ALIGN])
+    end
+  end
 end