X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=blobdiff_plain;f=alg%2Ftest%2Ftest_seq_span.cpp;h=9e22f3cb3f93fed3425d9a6106c6c12c8660dddb;hp=9b98f2133d64ba0507d9881e9c75435232f0c0ad;hb=HEAD;hpb=7d4fbcb6060a60a8ea25ca1303fcaaaf8574f24a diff --git a/alg/test/test_seq_span.cpp b/alg/test/test_seq_span.cpp index 9b98f21..9e22f3c 100644 --- a/alg/test/test_seq_span.cpp +++ b/alg/test/test_seq_span.cpp @@ -1,5 +1,6 @@ -#define BOOST_AUTO_TEST_MAIN -#include +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE test_seq_span +#include #include "seq_span.hpp" #include "mussa_exceptions.hpp" @@ -12,6 +13,49 @@ BOOST_AUTO_TEST_CASE( seqspan_from_string ) SeqSpanRef span1(new SeqSpan(str1)); BOOST_CHECK_EQUAL(span1->length(), str1.length()); BOOST_CHECK_EQUAL(span1->sequence(), str1); + BOOST_CHECK_EQUAL(span1->strand(), SeqSpan::PlusStrand); +} + +BOOST_AUTO_TEST_CASE( seqspan_from_string_with_alphabet ) +{ + std::string str1("AAGGCCUU"); + SeqSpanRef span1(new SeqSpan(str1, reduced_rna_alphabet)); + BOOST_CHECK_EQUAL(span1->length(), str1.length()); + BOOST_CHECK_EQUAL(span1->sequence(), str1); + BOOST_CHECK_EQUAL(span1->get_alphabet(), Alphabet::reduced_rna_alphabet()); +} + +BOOST_AUTO_TEST_CASE( seqspan_from_string_with_alphabet_and_plusstrand ) +{ + std::string str1("AAGGCCUU"); + SeqSpanRef span1(new SeqSpan(str1, reduced_rna_alphabet, SeqSpan::PlusStrand)); + BOOST_CHECK_EQUAL(span1->length(), str1.length()); + BOOST_CHECK_EQUAL(span1->sequence(), str1); + BOOST_CHECK_EQUAL(span1->get_alphabet(), Alphabet::reduced_rna_alphabet()); + BOOST_CHECK_EQUAL(span1->strand(), SeqSpan::PlusStrand); +} + +BOOST_AUTO_TEST_CASE( seqspan_from_string_with_alphabet_and_singlestrand ) +{ + std::string str1("AAAAGCT"); + SeqSpanRef span1(new SeqSpan(str1, reduced_dna_alphabet, SeqSpan::SingleStrand)); + BOOST_CHECK_EQUAL(span1->length(), str1.length()); + BOOST_CHECK_EQUAL(span1->sequence(), str1); + BOOST_CHECK_EQUAL(span1->get_alphabet(), Alphabet::reduced_dna_alphabet()); + // we always store strands as Plus + BOOST_CHECK_EQUAL(span1->strand(), SeqSpan::SingleStrand); + BOOST_CHECK_EQUAL(span1->sequence(), "AAAAGCT"); + BOOST_CHECK_THROW(span1->subseq(0,2,SeqSpan::OppositeStrand), sequence_invalid_strand); +} + +BOOST_AUTO_TEST_CASE( seqspan_from_string_with_invalidstrand ) +{ + std::string s("AAAAGCT"); + BOOST_CHECK_THROW(SeqSpan(s, reduced_dna_alphabet, SeqSpan::UnknownStrand), sequence_invalid_strand); + BOOST_CHECK_THROW(SeqSpan(s, reduced_dna_alphabet, SeqSpan::BothStrand), sequence_invalid_strand); + BOOST_CHECK_THROW(SeqSpan(s, reduced_dna_alphabet, SeqSpan::SameStrand), sequence_invalid_strand); + BOOST_CHECK_THROW(SeqSpan(s, reduced_dna_alphabet, SeqSpan::OppositeStrand), sequence_invalid_strand); + BOOST_CHECK_THROW(SeqSpan(s, reduced_dna_alphabet, SeqSpan::BothStrand), sequence_invalid_strand); } BOOST_AUTO_TEST_CASE( seqspan_from_seqspan ) @@ -30,6 +74,23 @@ BOOST_AUTO_TEST_CASE( seqspan_from_seqspan ) BOOST_CHECK_EQUAL(span3->sequence(), str1); } +BOOST_AUTO_TEST_CASE( seqspan_copy ) +{ + SeqSpanRef span1(new SeqSpan("AAAAGGGG")); + SeqSpanRef span2 = span1->subseq(0,4); + SeqSpanRef span2ref(span2); + SeqSpanRef span2copy(new SeqSpan(span2)); + + BOOST_CHECK_EQUAL(span2->start(), 0); + BOOST_CHECK_EQUAL(span2ref->start(), 0); + BOOST_CHECK_EQUAL(span2copy->start(), 0); + + span2->setStart(2); + BOOST_CHECK_EQUAL(span2->start(), 2); + BOOST_CHECK_EQUAL(span2ref->start(), 2); + BOOST_CHECK_EQUAL(span2copy->start(), 0); +} + BOOST_AUTO_TEST_CASE( seqspan_equality ) { std::string str1("AAGGCCTT"); @@ -47,6 +108,25 @@ BOOST_AUTO_TEST_CASE( seqspan_equality ) BOOST_CHECK_EQUAL(SeqSpan::isFamily(*span2, *span3), false); } +BOOST_AUTO_TEST_CASE( seqspan_parents ) +{ + std::string str1("AAGGCCTT"); + std::string str2("AACCGGTT"); + SeqSpanRef s1(new SeqSpan(str1)); + SeqSpanRef s1_1 = s1->subseq(2,4); + SeqSpanRef s2(new SeqSpan(str2)); + SeqSpanRef s2_1 = s2->subseq(0,2); + + BOOST_CHECK_EQUAL(s1, s1_1->parent()); + BOOST_CHECK_EQUAL(s2, s2_1->parent()); + BOOST_CHECK(s1 != s2_1->parent()); + BOOST_CHECK(s2 != s1_1->parent()); + + SeqSpanRef s2_copy = s2; + + BOOST_CHECK_EQUAL(s2_copy, s2_1->parent()); +} + BOOST_AUTO_TEST_CASE( seqspan_find_first_not_of ) { std::string str1("AAAAT"); @@ -69,6 +149,13 @@ BOOST_AUTO_TEST_CASE( seqspan_at ) BOOST_CHECK_EQUAL( str1[2], seq2->at(0) ); BOOST_CHECK_EQUAL( (*seq1)[0], seq1->at(0) ); BOOST_CHECK_EQUAL( (*seq1)[2], (*seq2)[0] ); + + SeqSpanRef seq3 = seq1->subseq(0, 4, SeqSpan::OppositeStrand); + BOOST_CHECK_EQUAL( seq3->at(0), 'C'); + BOOST_CHECK_EQUAL( seq3->at(1), 'C'); + BOOST_CHECK_EQUAL( seq3->at(2), 'T'); + BOOST_CHECK_EQUAL( seq3->at(3), 'T'); + } BOOST_AUTO_TEST_CASE( seqspan_data ) @@ -102,6 +189,21 @@ BOOST_AUTO_TEST_CASE( seqspan_begin_end ) } } +BOOST_AUTO_TEST_CASE( seqspan_subseq_reverse_begin_end ) +{ + std::string str1("AAAACCTT"); + std::string str1rc("AAGGTTTT"); + SeqSpanRef seq1(new SeqSpan(str1)); + SeqSpanRef seq2(new SeqSpan(seq1, 0, SeqSpan::npos, SeqSpan::OppositeStrand )); + + + std::string::const_iterator str1rc_i = str1rc.begin(); + SeqSpan::const_iterator seq2_i = seq2->begin(); + for(; not ((str1rc_i == str1rc.end()) or (seq2_i == seq2->end())); ++str1rc_i, ++seq2_i) { + BOOST_CHECK_EQUAL( *str1rc_i, *seq2_i ); + } +} + BOOST_AUTO_TEST_CASE( seqspan_rbegin_rend ) { std::string str1("AAGGCCTT"); @@ -223,6 +325,28 @@ BOOST_AUTO_TEST_CASE( seqspan_global_mutable_start_stop ) BOOST_CHECK_EQUAL( s3->size(), 1); } +BOOST_AUTO_TEST_CASE( seqspan_global_mutable_start_stop_minus_strand ) +{ + std::string seq_string("AAAAGCTA"); + SeqSpanRef s1(new SeqSpan(seq_string)); + + SeqSpanRef s2 = s1->subseq(2,3, SeqSpan::MinusStrand); + BOOST_CHECK_EQUAL( s2->start(), 2); + BOOST_CHECK_EQUAL( s2->stop(), 2+3); + BOOST_CHECK_EQUAL( s2->size(), 3); + BOOST_CHECK_EQUAL( s2->sequence(), "CTT"); + + SeqSpanRef s3 = s2->subseq(1,2, SeqSpan::SameStrand); + BOOST_CHECK_EQUAL(s3->sequence(), "TT"); + + // Could also argue that it should be CT + // if you assume that the locations are all relative to the global sequence + // and are then reverse complemented + + s2->setStart(1); + BOOST_CHECK_EQUAL( s2->sequence(), "CTTT"); +} + BOOST_AUTO_TEST_CASE( seqspan_parent_mutable_start_stop ) { std::string seq_string("AAGGCCTT"); @@ -280,4 +404,38 @@ BOOST_AUTO_TEST_CASE( seqspan_stop_past_end ) s3->setStop(8); BOOST_CHECK_EQUAL( s3->size(), 4); -} \ No newline at end of file +} + +BOOST_AUTO_TEST_CASE( seqspan_strand_sameother ) +{ + SeqSpanRef seq1(new SeqSpan("AAAAAGGGGG")); + BOOST_CHECK_EQUAL(seq1->strand(), SeqSpan::PlusStrand); + + SeqSpanRef seq2 = seq1->subseq(0,4,SeqSpan::SameStrand); + BOOST_CHECK_EQUAL(seq2->sequence(), "AAAA"); + BOOST_CHECK_EQUAL(seq2->strand(), SeqSpan::PlusStrand); + SeqSpanRef seq3 = seq1->subseq(0,4,SeqSpan::OppositeStrand); + BOOST_CHECK_EQUAL(seq3->sequence(), "TTTT"); + BOOST_CHECK_EQUAL(seq3->strand(), SeqSpan::MinusStrand); + + // opposite of a plus strand should be minus + SeqSpanRef seq4 = seq2->subseq(0,4,SeqSpan::OppositeStrand); + BOOST_CHECK_EQUAL(seq4->sequence(), "TTTT"); + BOOST_CHECK_EQUAL(seq4->strand(), SeqSpan::MinusStrand); + // opposite of a minus strand should be plus + SeqSpanRef seq5 = seq3->subseq(0,4,SeqSpan::OppositeStrand); + BOOST_CHECK_EQUAL(seq5->sequence(), "AAAA"); + BOOST_CHECK_EQUAL(seq5->strand(), SeqSpan::PlusStrand); +} + +BOOST_AUTO_TEST_CASE( seqspan_strand_plusminus ) +{ + SeqSpanRef seq1(new SeqSpan("AAAAAGGGGG")); + BOOST_CHECK_EQUAL(seq1->strand(), SeqSpan::PlusStrand); + + SeqSpanRef seq2 = seq1->subseq(0,4,SeqSpan::PlusStrand); + BOOST_CHECK_EQUAL(seq2->sequence(), "AAAA"); + SeqSpanRef seq3 = seq1->subseq(0,4,SeqSpan::MinusStrand); + BOOST_CHECK_EQUAL(seq3->sequence(), "TTTT"); +} +