X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=code_ruby%2Ftest%2Fmaasha%2Ftest_seq.rb;h=f966a5fa47b2387c74f1c2a785b6f8e49082f1be;hb=124ad80bd42309d1e6ea7d10dcffb86938c29069;hp=a90c565072503641160ea2c7c2e24fded0e0563b;hpb=2dddbfc4c5563421b83cce0e81f2e559ed982bab;p=biopieces.git diff --git a/code_ruby/test/maasha/test_seq.rb b/code_ruby/test/maasha/test_seq.rb index a90c565..f966a5f 100755 --- a/code_ruby/test/maasha/test_seq.rb +++ b/code_ruby/test/maasha/test_seq.rb @@ -9,7 +9,8 @@ class TestSeq < Test::Unit::TestCase @entry = Seq.new end - # def test_Seq# autoremoves whitespace, newlines, and carriage returns + # # autoremoves whitespace, newlines, and carriage returns + # def test_Seq_strip # dna = Seq.new # dna.seq = "A\tT\r\tC\nG " # assert_equal(dna.seq, "ATCG") @@ -277,14 +278,22 @@ class TestSeq < Test::Unit::TestCase end end - def test_Seq_subseq_with_start_lt_0_raises - @entry.seq = "ATCG" - assert_raise(SeqError) { @entry.subseq(-1, 1) } + def test_Seq_shuffle_returns_correctly + orig = "actgactgactgatcgatcgatcgatcgtactg" + @entry.seq = "actgactgactgatcgatcgatcgatcgtactg" + entry_shuf = @entry.shuffle + assert_equal(orig, @entry.seq) + assert_not_equal(@entry.seq, entry_shuf.seq) + end + + def test_Seq_shuffle_bang_returns_correctly + @entry.seq = "actgactgactgatcgatcgatcgatcgtactg" + assert_not_equal(@entry.seq, @entry.shuffle!.seq) end - def test_Seq_subseq_with_length_lt_1_raises + def test_Seq_subseq_with_start_lt_0_raises @entry.seq = "ATCG" - assert_raise(SeqError) { @entry.subseq(0, 0) } + assert_raise(SeqError) { @entry.subseq(-1, 1) } end def test_Seq_subseq_with_start_plus_length_gt_seq_raises @@ -323,11 +332,6 @@ class TestSeq < Test::Unit::TestCase assert_raise(SeqError) { @entry.subseq!(-1, 1) } end - def test_Seq_subseq_bang_with_length_lt_1_raises - @entry.seq = "ATCG" - assert_raise(SeqError) { @entry.subseq!(0, 0) } - end - def test_Seq_subseq_bang_with_start_plus_length_gt_seq_raises @entry.seq = "ATCG" assert_raise(SeqError) { @entry.subseq!(0, 5) } @@ -378,86 +382,6 @@ class TestSeq < Test::Unit::TestCase assert_equal("ATCG", @entry.subseq_rand(4).seq) end - def test_Seq_quality_trim_right_with_missing_seq_raises - @entry.qual = "hhhh" - assert_raise(SeqError) { @entry.quality_trim_right(20) } - end - - def test_Seq_quality_trim_right_with_missing_qual_raises - @entry.seq = "ATCG" - assert_raise(SeqError) { @entry.quality_trim_right(20) } - end - - def test_Seq_quality_trim_right_with_bad_min_raises - @entry.seq = "ATCG" - @entry.qual = "hhhh" - - [-1, 41].each do |min| - assert_raise(SeqError) { @entry.quality_trim_right(min) } - end - end - - def test_Seq_quality_trim_right_with_ok_min_dont_raise - @entry.seq = "ATCG" - @entry.qual = "hhhh" - - [0, 40].each do |min| - assert_nothing_raised { @entry.quality_trim_right(min) } - end - end - - def test_Seq_quality_trim_right_returns_correctly - @entry.seq = "AAAAATCG" - @entry.qual = "hhhhhgfe" - @entry.quality_trim_right(38) - assert_equal("AAAAAT", @entry.seq) - assert_equal("hhhhhg", @entry.qual) - end - - def test_Seq_quality_trim_left_with_missing_seq_raises - @entry.qual = "hhhh" - assert_raise(SeqError) { @entry.quality_trim_left(20) } - end - - def test_Seq_quality_trim_left_with_missing_qual_raises - @entry.seq = "ATCG" - assert_raise(SeqError) { @entry.quality_trim_left(20) } - end - - def test_Seq_quality_trim_left_with_bad_min_raises - @entry.seq = "ATCG" - @entry.qual = "hhhh" - - [-1, 41].each do |min| - assert_raise(SeqError) { @entry.quality_trim_left(min) } - end - end - - def test_Seq_quality_trim_left_with_ok_min_dont_raise - @entry.seq = "ATCG" - @entry.qual = "hhhh" - - [0, 40].each do |min| - assert_nothing_raised { @entry.quality_trim_left(min) } - end - end - - def test_Seq_quality_trim_left_returns_correctly - @entry.seq = "GCTAAAAA" - @entry.qual = "efghhhhh" - @entry.quality_trim_left(38) - assert_equal("TAAAAA", @entry.seq) - assert_equal("ghhhhh", @entry.qual) - end - - def test_Seq_quality_trim_returns_correctly - @entry.seq = "GCTAAAAAGTG" - @entry.qual = "efghhhhhgfe" - @entry.quality_trim(38) - assert_equal("TAAAAAG", @entry.seq) - assert_equal("ghhhhhg", @entry.qual) - end - def test_Seq_indels_remove_without_qual_returns_correctly @entry.seq = "A-T.CG~CG" @entry.qual = nil @@ -578,6 +502,55 @@ class TestSeq < Test::Unit::TestCase assert_equal("-atCG", @entry.mask_seq_soft!(20).seq) end + # qual score detection + + def test_Seq_qual_base33_returns_correctly + # self.qual.match(/[!-:]/) + @entry.qual = '!"#$%&\'()*+,-./0123456789:' + assert_equal(true, @entry.qual_base33? ) + @entry.qual = 32.chr + assert_equal(false, @entry.qual_base33? ) + @entry.qual = 59.chr + assert_equal(false, @entry.qual_base33? ) + end + + def test_Seq_qual_base64_returns_correctly + # self.qual.match(/[K-h]/) + @entry.qual = 'KLMNOPQRSTUVWXYZ[\]^_`abcdefgh' + assert_equal(true, @entry.qual_base64? ) + @entry.qual = 74.chr + assert_equal(false, @entry.qual_base64? ) + @entry.qual = 105.chr + assert_equal(false, @entry.qual_base64? ) + end + + def test_Seq_qual_valid_with_nil_qual_raises + assert_raise(SeqError) { @entry.qual_valid?("illumina1.8") } + end + + def test_Seq_qual_valid_with_bad_encoding_raises + @entry.qual = "abc" + assert_raise(SeqError) { @entry.qual_valid?("foobar") } + end + + def test_Seq_qual_valid_returns_correctly + tests = [["sanger", 0, 93, 33], + ["454", 0, 62, 64], + ["solexa", -5, 62, 64], + ["illumina13", 0, 62, 64], + ["illumina15", 0, 62, 64], + ["illumina18", 0, 93, 33]] + + tests.each do |test| + @entry.qual = (test[1] + test[-1]).chr + (test[2] + test[-1]).chr + assert_equal(true, @entry.qual_valid?(test[0])) + @entry.qual = (test[1] + test[-1] - 1).chr + assert_equal(false, @entry.qual_valid?(test[0])) + @entry.qual = (test[2] + test[-1] + 1).chr + assert_equal(false, @entry.qual_valid?(test[0])) + end + end + # convert sanger to ... def test_Seq_convert_scores_bang_from_sanger_to_sanger_returns_OK @@ -712,6 +685,16 @@ class TestSeq < Test::Unit::TestCase @entry.qual = 'BCDEFGHI' assert_equal('BCDEFGHI', @entry.convert_scores!('illumina18', 'illumina18').qual) end + + def test_Seq_scores_mean_without_qual_raises + @entry.qual = nil + assert_raise(SeqError) { @entry.scores_mean } + end + + def test_Seq_scores_mean_returns_correctly + @entry.qual = '@@hh' + assert_equal(20.0, @entry.scores_mean) + end end __END__