]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/test/maasha/test_sam.rb
rewrite of FASTQ internals
[biopieces.git] / code_ruby / test / maasha / test_sam.rb
index 06fcf25975d96ba929d67e2329ac77c5763732e7..e23633041be3285c292395c80f78e50da5fdc5c2 100755 (executable)
@@ -1,4 +1,5 @@
 #!/usr/bin/env ruby
+$:.unshift File.join(File.dirname(__FILE__), '..', '..')
 
 # Copyright (C) 2011 Martin A. Hansen.
 
@@ -25,8 +26,8 @@
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 require 'test/unit'
+require 'test/helper'
 require 'maasha/sam'
-require 'pp'
 require 'stringio'
 
 SAM_DATA =
@@ -46,124 +47,124 @@ class SamTest < Test::Unit::TestCase
     @sam = Sam.new(StringIO.new(SAM_DATA))
   end
 
-  def test_Sam_new_with_missing_version_number_raises
+  test "#new with missing version number raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@HD")) }
   end
 
-  def test_Sam_new_with_bad_version_number_raises
+  test "#new with bad version number raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@HD\tXN:1.3")) }
   end
 
-  def test_Sam_new_with_ok_version_number_returns_correctly
+  test "#new with ok version number returns correctly" do
     sam = Sam.new(StringIO.new("@HD\tVN:1.3"))
     assert_equal(1.3, sam.header[:HD][:VN])
   end
 
-  def test_Sam_new_with_bad_sort_order_raises
+  test "#new with bad sort order raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@HD\tVN:1.3\tSO:fish")) }
   end
 
-  def test_Sam_new_with_ok_sort_order_returns_correctly
+  test "#new with ok sort order returns correctly" do
     %w{unknown unsorted queryname coordinate}.each do |order|
       sam = Sam.new(StringIO.new("@HD\tVN:1.3\tSO:#{order}"))
       assert_equal(order, sam.header[:HD][:SO])
     end
   end
 
-  def test_Sam_new_with_missing_sequence_name_raises
+  test "#new with missing sequence name raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@SQ")) }
   end
 
-  def test_Sam_new_with_bad_sequence_name_raises
+  test "#new with bad sequence name raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@SQ\tSN:")) }
   end
 
-  def test_Sam_new_with_ok_sequence_name_returns_correctly
+  test "#new with ok sequence name returns correctly" do
     sam = Sam.new(StringIO.new("@SQ\tSN:ref\tLN:45"))
     assert_equal({:LN=>45}, sam.header[:SQ][:SN][:ref])
   end
 
-  def test_Sam_new_with_duplicate_sequence_name_raises
+  test "#new with duplicate sequence name raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@SQ\tSN:ref\n@SQ\tSN:ref")) }
   end
 
-  def test_Sam_new_with_missing_sequence_length_raises
+  test "#new with missing sequence length raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@SQ\tSN:ref")) }
   end
 
-  def test_Sam_new_with_bad_sequence_length_raises
+  test "#new with bad sequence length raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@SQ\tSN:scaffold17_1_MH0083\tLN:x")) }
   end
 
-  def test_Sam_new_with_ok_sequence_length_returns_correctly
+  test "#new with ok sequence length returns correctly" do
     sam = Sam.new(StringIO.new("@SQ\tSN:scaffold17_1_MH0083\tLN:995"))
     assert_equal(995, sam.header[:SQ][:SN][:scaffold17_1_MH0083][:LN])
   end
 
-  def test_Sam_new_with_full_SQ_dont_raise
+  test "#new with full SQ dont raise" do
     sam = Sam.new(StringIO.new("@SQ\tSN:ref\tLN:45\tAS:ident\tM5:87e6b2aedf51b1f9c89becfab9267f41\tSP:E.coli\tUR:http://www.biopieces.org"))
     assert_nothing_raised { sam.header }
   end
 
-  def test_Sam_new_with_bad_read_group_identifier_raises
+  test "#new with bad read group identifier raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@RG\tID:")) }
   end
 
-  def test_Sam_new_with_missing_read_group_identifier_raises
+  test "#new with missing read group identifier raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@RG")) }
   end
 
-  def test_Sam_new_with_duplicate_read_group_identifier_raises
+  test "#new with duplicate read group identifier raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@RG\tID:123\n@RG\tID:123")) }
   end
 
-  def test_Sam_new_with_ok_read_group_identifier_dont_raise
+  test "#new with ok read group identifier dont raise" do
     sam = Sam.new(StringIO.new("@RG\tID:123\n@RG\tID:124"))
     assert_nothing_raised { sam.header }
   end
 
-  def test_Sam_new_with_bad_flow_order_raises
+  test "#new with bad flow order raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@RG\tID:123\tFO:3")) }
   end
 
-  def test_Sam_new_with_ok_flow_order_dont_raise
+  test "#new with ok flow order dont raise" do
     sam = Sam.new(StringIO.new("@RG\tID:123\tFO:*"))
     assert_nothing_raised { sam.header }
     sam = Sam.new(StringIO.new("@RG\tID:123\tFO:ACMGRSVTWYHKDBN"))
     assert_nothing_raised { sam.header }
   end
 
-  def test_Sam_new_with_bad_platform_raises
+  test "#new with bad platform raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@RG\tID:123\tPL:maersk")) }
   end
 
-  def test_Sam_new_with_ok_platform_dont_raise
+  test "#new with ok platform dont raise" do
     sam = Sam.new(StringIO.new("@RG\tID:123\tPL:ILLUMINA"))
     assert_nothing_raised { sam.header }
   end
 
-  def test_Sam_new_with_bad_program_identifier_raises
+  test "#new with bad program identifier raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@PG\tID:")) }
   end
 
-  def test_Sam_new_with_missing_program_identifier_raises
+  test "#new with missing program identifier raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@PG")) }
   end
 
-  def test_Sam_new_with_duplicate_program_identifier_raises
+  test "#new with duplicate program identifier raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@PG\tID:123\n@PG\tID:123")) }
   end
 
-  def test_Sam_new_with_bad_comment_raises
+  test "#new with bad comment raises" do
     assert_raise(SamError) { Sam.new(StringIO.new("@CO\t")) }
   end 
 
-  def test_Sam_new_with_ok_comment_dont_raise
+  test "#new with ok comment dont raise" do
     sam = Sam.new(StringIO.new("@CO\tfubar"))
     assert_nothing_raised { sam.header }
   end
 
-  def test_Sam_each_with_bad_field_count_raises
+  test "#each with bad field count raises" do
     fields = []
 
     (0 ... 11).each do |i|
@@ -173,22 +174,22 @@ class SamTest < Test::Unit::TestCase
     end
   end
 
-  def test_Sam_each_with_ok_field_count_dont_raise
+  test "#each with ok field count dont raise" do
     sam = Sam.new(StringIO.new(SAM_DATA))
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_each_with_bad_qname_raises
+  test "#each with bad qname raises" do
     sam = Sam.new(StringIO.new(" \t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\n"))
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_ok_qname_dont_raise
+  test "#each with ok qname dont raise" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\n"))
     assert_nothing_raised(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_bad_flag_raises
+  test "#each with bad flag raises" do
     sam = Sam.new(StringIO.new("*\t-1\t*\t*\t*\t*\t*\t*\t*\t*\t*\n"))
     assert_raise(SamError) { sam.each }
 
@@ -196,7 +197,7 @@ class SamTest < Test::Unit::TestCase
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_ok_flag_dont_raise
+  test "#each with ok flag dont raise" do
     sam = Sam.new(StringIO.new("*\t0\t*\t*\t*\t*\t*\t*\t*\t*\t*\n"))
     assert_nothing_raised { sam.each }
 
@@ -204,17 +205,17 @@ class SamTest < Test::Unit::TestCase
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_each_with_bad_rname_raises
+  test "#each with bad rname raises" do
     sam = Sam.new(StringIO.new("*\t*\t \t*\t*\t*\t*\t*\t*\t*\t*\n"))
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_ok_rname_dont_raise
+  test "#each with ok rname dont raise" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\n"))
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_each_with_bad_pos_raises
+  test "#each with bad pos raises" do
     sam = Sam.new(StringIO.new("*\t*\t*\t-1\t*\t*\t*\t*\t*\t*\t*\n"))
     assert_raise(SamError) { sam.each }
 
@@ -222,7 +223,7 @@ class SamTest < Test::Unit::TestCase
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_ok_pos_dont_raise
+  test "#each with ok pos dont raise" do
     sam = Sam.new(StringIO.new("*\t*\t*\t0\t*\t*\t*\t*\t*\t*\t*\n"))
     assert_nothing_raised { sam.each }
 
@@ -230,7 +231,7 @@ class SamTest < Test::Unit::TestCase
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_each_with_bad_mapq_raises
+  test "#each with bad mapq raises" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t-1\t*\t*\t*\t*\t*\t*\n"))
     assert_raise(SamError) { sam.each }
 
@@ -238,7 +239,7 @@ class SamTest < Test::Unit::TestCase
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_ok_mapq_dont_raise
+  test "#each with ok mapq dont raise" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t0\t*\t*\t*\t*\t*\t*\n"))
     assert_nothing_raised { sam.each }
 
@@ -246,12 +247,12 @@ class SamTest < Test::Unit::TestCase
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_each_with_bad_rnext_raises
+  test "#each with bad rnext raises" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t \t*\t*\t*\t*\n"))
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_ok_rnext_dont_raise
+  test "#each with ok rnext dont raise" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t*\t*\t*\t*\t*\n"))
     assert_nothing_raised { sam.each }
 
@@ -262,7 +263,7 @@ class SamTest < Test::Unit::TestCase
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_each_with_bad_pnext_raises
+  test "#each with bad pnext raises" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t*\t-1\t*\t*\t*\n"))
     assert_raise(SamError) { sam.each }
 
@@ -270,7 +271,7 @@ class SamTest < Test::Unit::TestCase
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_ok_pnext_dont_raise
+  test "#each with ok pnext dont raise" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t*\t0\t*\t*\t*\n"))
     assert_nothing_raised { sam.each }
 
@@ -278,7 +279,7 @@ class SamTest < Test::Unit::TestCase
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_each_with_bad_tlen_raises
+  test "#each with bad tlen raises" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t*\t*\t-536870912\t*\t*\n"))
     assert_raise(SamError) { sam.each }
 
@@ -286,7 +287,7 @@ class SamTest < Test::Unit::TestCase
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_ok_tlen_dont_raise
+  test "#each with ok tlen dont raise" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t*\t*\t-536870911\t*\t*\n"))
     assert_nothing_raised { sam.each }
 
@@ -294,12 +295,12 @@ class SamTest < Test::Unit::TestCase
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_each_with_bad_seq_raises
+  test "#each with bad seq raises" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t*\t*\t\*\t \t*\n"))
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_ok_seq_dont_raise
+  test "#each with ok seq dont raise" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t*\t*\t\*\t*\t*\n"))
     assert_nothing_raised { sam.each }
 
@@ -307,22 +308,22 @@ class SamTest < Test::Unit::TestCase
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_each_with_bad_qual_raises
+  test "#each with bad qual raises" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t*\t*\t\*\t*\t \n"))
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_ok_qual_dont_raise
+  test "#each with ok qual dont raise" do
     sam = Sam.new(StringIO.new("*\t*\t*\t*\t*\t*\t*\t*\t\*\t*\t@\n"))
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_each_with_rname_missing_from_header_raises
+  test "#each with rname missing from header raises" do
     sam = Sam.new(StringIO.new("@SQ\tSN:ref\tLN:45\n*\t*\tMIS\t*\t*\t*\t*\t*\t\*\t*\t*\n"))
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_rname_present_in_header_dont_raise
+  test "#each with rname present in header dont raise" do
     sam = Sam.new(StringIO.new("@SQ\tSN:ref\tLN:45\n*\t*\tref\t*\t*\t*\t*\t*\t\*\t*\t*\n"))
     assert_nothing_raised { sam.each }
 
@@ -330,12 +331,12 @@ class SamTest < Test::Unit::TestCase
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_each_with_rnext_missing_from_header_raises
+  test "#each with rnext missing from header raises" do
     sam = Sam.new(StringIO.new("@SQ\tSN:ref\tLN:45\n*\t*\t*\t*\t*\t*\tMIS\t*\t\*\t*\t*\n"))
     assert_raise(SamError) { sam.each }
   end
 
-  def test_Sam_each_with_rnext_present_in_header_dont_raise
+  test "#each with rnext present in header dont raise" do
     sam = Sam.new(StringIO.new("@SQ\tSN:ref\tLN:45\n*\t*\t*\t*\t*\t*\t*\t*\t\*\t*\t*\n"))
     assert_nothing_raised { sam.each }
 
@@ -346,7 +347,7 @@ class SamTest < Test::Unit::TestCase
     assert_nothing_raised { sam.each }
   end
 
-  def test_Sam_to_bp_returns_correctly
+  test "#to_bp returns correctly" do
     string = "ID00036734\t0\tgi48994873\t366089\t37\t37M1I62M\t*\t0\t0\tGTTCCGCTATCGGCTGAATTTGATTGCGAGTGAGATATTTTATGCCAGCCAGCCAGACGCAGACGCGCCGAGACAGAACTTAATGGGCCCGCTAACAGCG\t*\tXT:A:U\tNM:i:1\tX0:i:1\tX1:i:0\tXM:i:0\tXO:i:1\tXG:i:1\tMD:Z:99\n"
 
     sam = Sam.new(StringIO.new(string))
@@ -364,7 +365,7 @@ class SamTest < Test::Unit::TestCase
     end
   end
 
-  def test_Sam_to_bp_alignment_descriptor_without_mismatch_or_indel_returns_correctly
+  test "#to_bp alignment descriptor without mismatch or indel returns correctly" do
     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))
@@ -374,7 +375,7 @@ class SamTest < Test::Unit::TestCase
     end
   end
 
-  def test_Sam_to_bp_alignment_descriptor_with_mismatches_returns_correctly
+  test "#to_bp alignment descriptor with mismatches returns correctly" do
     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))
@@ -384,7 +385,7 @@ class SamTest < Test::Unit::TestCase
     end
   end
 
-  def test_Sam_to_bp_alignment_descriptor_with_insertions_returns_correctly
+  test "#to_bp alignment descriptor with insertions returns correctly" do
     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))
@@ -394,7 +395,7 @@ class SamTest < Test::Unit::TestCase
     end
   end
 
-  def test_Sam_to_bp_alignment_descriptor_with_deletions_returns_correctly
+  test "#to_bp alignment descriptor with deletions returns correctly" do
     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))