+#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
BOOST_CHECK_EQUAL(s.get_sequence(), std::string() );
}
+BOOST_AUTO_TEST_CASE( sequence_from_string )
+{
+ std::string str1("AAAT");
+ Sequence seq1(str1);
+ BOOST_CHECK_EQUAL(seq1.get_sequence(), str1);
+}
+
+BOOST_AUTO_TEST_CASE( sequence_find_first_not_of )
+{
+ std::string str1("AAAAT");
+ Sequence seq1(str1);
+ BOOST_CHECK_EQUAL(seq1.find_first_not_of("A"), str1.find_first_not_of("A"));
+
+ std::string str2("AATTGGCC");
+ Sequence seq2(str2);
+ BOOST_CHECK_EQUAL(seq2.find_first_not_of("qwer"), str2.find_first_not_of("qwer"));
+}
+
//! when we try to load a missing file, do we get an error?
BOOST_AUTO_TEST_CASE( sequence_load_exception )
{
"5' flank");
}
+BOOST_AUTO_TEST_CASE( sequence_load_fasta_error )
+{
+ fs::path seq_path(fs::path(EXAMPLE_DIR, fs::native)/"seq");
+ seq_path /= "broken.fa";
+ bool exception_thrown = false;
+ std::string exception_filename;
+ Sequence s;
+ try {
+ s.load_fasta(seq_path);
+ } catch(sequence_invalid_load_error e) {
+ exception_thrown = true;
+ size_t native_string_size = seq_path.native_file_string().size();
+ std:string estr(e.what());
+ BOOST_REQUIRE(estr.size() > native_string_size);
+ std::copy(estr.begin(), estr.begin()+native_string_size,
+ std::back_inserter(exception_filename));
+ }
+ BOOST_CHECK_EQUAL(exception_thrown, true);
+ BOOST_CHECK_EQUAL(seq_path.native_file_string(), exception_filename);
+}
+
+BOOST_AUTO_TEST_CASE( sequence_load_annot_error )
+{
+ fs::path seq_path(fs::path(EXAMPLE_DIR, fs::native)/"seq");
+ seq_path /= "mouse_mck_pro.fa";
+ fs::path annot_path(fs::path(EXAMPLE_DIR, fs::native));
+ annot_path /= "broken.annot";
+ bool exception_thrown = false;
+ Sequence s;
+ s.load_fasta(seq_path);
+
+ std::string exception_filename;
+ try {
+ s.load_annot(annot_path, 0, 0);
+ } catch(annotation_load_error e) {
+ exception_thrown = true;
+ std:string estr(e.what());
+ size_t native_string_size = annot_path.native_file_string().size();
+ BOOST_REQUIRE(estr.size() > native_string_size);
+ std::copy(estr.begin(), estr.begin()+native_string_size,
+ std::back_inserter(exception_filename));
+ }
+ BOOST_CHECK_EQUAL(exception_thrown, true);
+ BOOST_CHECK_EQUAL(annot_path.native_file_string(), exception_filename);
+}
+
BOOST_AUTO_TEST_CASE( sequence_load_dna_reduced )
{
std::string reduced_dna_fasta_string(">foo\nAAGGCCTTNN\n");
*/
}
+BOOST_AUTO_TEST_CASE( sequence_motif_subseq)
+{
+ // when searching for a motif on a subsequence we should
+ // only search the subsequence ticket:199
+ string aaaa("AAAA");
+ string cccc("CCCC");
+ Sequence s1("AAAANCCCC", Sequence::reduced_dna_alphabet);
+
+ // this shouldn't show up
+ s1.add_motif(cccc);
+ BOOST_CHECK_EQUAL( s1.motifs().size(), 1 );
+
+ s1.add_motif(aaaa);
+ BOOST_CHECK_EQUAL( s1.motifs().size(), 2 );
+
+ Sequence subseq1 = s1.subseq(4,5);
+ BOOST_CHECK_EQUAL(subseq1.motifs().size(), 2);
+ subseq1.clear_motifs();
+ BOOST_CHECK_EQUAL(subseq1.motifs().size(), 0);
+ // this is outside of our subsequence, and so shouldn't be found
+ subseq1.add_motif(aaaa);
+ BOOST_CHECK_EQUAL( subseq1.motifs().size(), 0 );
+
+ subseq1.add_motif(cccc);
+ BOOST_CHECK_EQUAL( subseq1.motifs().size(), 1);
+ std::list<motif>::const_iterator motif_i = subseq1.motifs().begin();
+ BOOST_REQUIRE(motif_i != subseq1.motifs().end());
+ BOOST_CHECK_EQUAL(motif_i->begin, 1);
+ BOOST_CHECK_EQUAL(motif_i->end, 5);
+}
+
BOOST_AUTO_TEST_CASE( annot_test )
{
annot a(0, 10, "test", "thing");
BOOST_CHECK_EQUAL(seq1_loaded, seq1);
BOOST_CHECK_EQUAL(seq2_loaded, seq2);
// test if our pointers are the same
- BOOST_CHECK_EQUAL(seq1_loaded.c_str(), seq2_loaded.c_str());
+ BOOST_CHECK_EQUAL(seq1_loaded.data(), seq2_loaded.data());
}