1 #include <boost/test/auto_unit_test.hpp>
2 #include <boost/filesystem/path.hpp>
3 #include <boost/filesystem/operations.hpp>
4 namespace fs=boost::filesystem;
9 #include "alg/sequence.hpp"
10 #include "mussa_exceptions.hpp"
14 //! when we try to load a missing file, do we get an error?
15 BOOST_AUTO_TEST_CASE( sequence_load_exception )
18 // there should be errors when we try to load something that doesn't exist
19 BOOST_CHECK_THROW( s.load_fasta("alkejralk", 1, 0, 0), mussa_load_error);
20 BOOST_CHECK_THROW( s.load_annot("alkejralk", 0, 0), mussa_load_error);
23 //! Do simple operations work correctly?
24 BOOST_AUTO_TEST_CASE( sequence_filter )
26 Sequence s1("AATTGGCC");
27 BOOST_CHECK_EQUAL(s1.get_seq(), "AATTGGCC");
29 Sequence s2("aattggcc");
30 BOOST_CHECK_EQUAL(s2.get_seq(), "AATTGGCC");
31 BOOST_CHECK_EQUAL(s2.rev_comp(), "GGCCAATT");
32 BOOST_CHECK_EQUAL(s2.size(), s2.get_seq().size());
33 BOOST_CHECK_EQUAL(s2.c_seq(), s2.get_seq().c_str());
36 BOOST_CHECK_EQUAL(s3.get_seq(), "ANNNG");
37 BOOST_CHECK_EQUAL(s3.subseq(0,2), "AN");
39 s3.set_filtered_sequence("AAGGCCTT", 0, 2);
40 BOOST_CHECK_EQUAL(s3.get_seq(), "AA");
41 s3.set_filtered_sequence("AAGGCCTT", 2, 2);
42 BOOST_CHECK_EQUAL( s3.get_seq(), "GG");
43 s3.set_filtered_sequence("AAGGCCTT", 4);
44 BOOST_CHECK_EQUAL( s3.get_seq(), "CCTT");
47 BOOST_CHECK_EQUAL(s3.get_seq(), "");
50 BOOST_CHECK_EQUAL(s3.get_seq(), "AAGGNN");
53 //! Can we load data from a file
54 BOOST_AUTO_TEST_CASE( sequence_load )
56 fs::path seq_path(fs::path(EXAMPLE_DIR)/ "seq" );
57 seq_path /= "human_mck_pro.fa";
59 s.load_fasta(seq_path);
60 BOOST_CHECK_EQUAL(s.subseq(0, 5), "GGATC"); // first few chars of fasta file
61 BOOST_CHECK_EQUAL(s.get_header(), "gi|180579|gb|M21487.1|HUMCKMM1 Human "
62 "muscle creatine kinase gene (CKMM), "
66 BOOST_AUTO_TEST_CASE ( sequence_empty )
69 BOOST_CHECK_EQUAL( s.empty(), true );
71 BOOST_CHECK_EQUAL( s.empty(), false );
74 BOOST_AUTO_TEST_CASE ( sequence_iterators )
76 std::string seq_string = "AAGGCCTTNNTATA";
77 Sequence s(seq_string);
79 std::string::size_type count = 0;
81 std::string::iterator str_itor;
82 Sequence::iterator s_itor;
83 Sequence::const_iterator cs_itor;
85 for( str_itor = seq_string.begin(),
88 str_itor != seq_string.end() and
91 ++str_itor, ++s_itor, ++cs_itor, ++count)
93 BOOST_CHECK_EQUAL ( *str_itor, *s_itor );
94 BOOST_CHECK_EQUAL ( *s_itor, *cs_itor );
95 BOOST_CHECK_EQUAL ( *cs_itor, *str_itor );
97 BOOST_CHECK_EQUAL( seq_string.size(), count );
98 BOOST_CHECK_EQUAL( s.size(), count );
99 BOOST_CHECK_EQUAL( cs.size(), count );
102 BOOST_AUTO_TEST_CASE( sequence_motifs )
105 string bogus("AATTGGAA");
106 Sequence s1("AAAAGGGGCCCCTTTT");
108 list<motif>::const_iterator motif_i = s1.motifs().begin();
109 list<motif>::const_iterator motif_end = s1.motifs().end();
111 // do our iterators work?
112 BOOST_CHECK( motif_i == s1.motifs().begin() );
113 BOOST_CHECK( motif_end == s1.motifs().end() );
114 BOOST_CHECK( motif_i == motif_end );
118 BOOST_CHECK( s1.motifs().begin() == s1.motifs().end() );
120 BOOST_CHECK( s1.motifs().begin() != s1.motifs().end() );
121 BOOST_CHECK_EQUAL( s1.motifs().size(), 2 );
123 for(motif_i = s1.motifs().begin();
124 motif_i != s1.motifs().end();
127 BOOST_CHECK_EQUAL( motif_i->type, "motif" );
128 BOOST_CHECK_EQUAL( motif_i->name, m);
129 BOOST_CHECK_EQUAL( motif_i->sequence, m);
133 BOOST_CHECK( s1.motifs().begin() == s1.motifs().end() );
136 BOOST_AUTO_TEST_CASE( annot_test )
138 annot a(0, 10, "test", "thing");
140 BOOST_CHECK_EQUAL( a.start, 0 );
141 BOOST_CHECK_EQUAL( a.end, 10 );
142 BOOST_CHECK_EQUAL( a.type, "test" );
143 BOOST_CHECK_EQUAL( a.name, "thing" );
145 motif m(10, "AAGGCC");
146 BOOST_CHECK_EQUAL( m.start, 10 );
147 BOOST_CHECK_EQUAL( m.type, "motif" );
148 BOOST_CHECK_EQUAL( m.name, "AAGGCC" );
149 BOOST_CHECK_EQUAL( m.end, 10+6 );