move strand into seqspan
[mussa.git] / alg / test / test_seq_span.cpp
index 90e3d00928fa09ee921cd67157d2bae98cac47a3..4989b6cbc8dc37159ed8604da6b71990a8b1e199 100644 (file)
@@ -12,6 +12,7 @@ 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 )
@@ -23,6 +24,39 @@ BOOST_AUTO_TEST_CASE( seqspan_from_string_with_alphabet )
   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 )
 {
   std::string str1("AAGGCCTT");
@@ -78,6 +112,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 ) 
@@ -111,6 +152,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");
@@ -289,4 +345,37 @@ BOOST_AUTO_TEST_CASE( seqspan_stop_past_end )
   
   s3->setStop(8);
   BOOST_CHECK_EQUAL( s3->size(), 4);
+}
+
+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");
 }
\ No newline at end of file