4 #include <boost/test/auto_unit_test.hpp>
5 #include <boost/filesystem/operations.hpp>
6 #include <boost/filesystem/path.hpp>
7 namespace fs = boost::filesystem;
10 #include "alg/sequence.hpp"
14 #include "mussa_exceptions.hpp"
16 BOOST_AUTO_TEST_CASE( flp_simple )
20 // when we first setup progress should be equal to -1
21 // aka FLPs::seqcomp_not_running
22 BOOST_CHECK_EQUAL( f.progress(), -1 );
23 f.seqcomp("AAGGTAAGGT", "AAGGTAAGGT", false);
24 // now that we're done we should be equal to not running again.
25 // yeah it'd be nice to make a thread test
26 BOOST_CHECK_EQUAL( f.progress(), -1 );
28 // are the match_locations correct?
29 for (int i=0; i != f.size(); i++)
31 std::list<int> window_locations = f.match_locations(i);
32 std::list<FLPs::match> window_matches = f.matches(i);
33 std::list<int>::iterator loc_i = window_locations.begin();
34 std::list<FLPs::match>::iterator match_i = window_matches.begin();
35 for (; loc_i != window_locations.end(); ++loc_i, ++match_i)
37 // I'm missing pythons easy lists and in operator here.
38 if (i == 0) BOOST_CHECK( *loc_i == 0 || *loc_i == 5);
39 else if (i == 1) BOOST_CHECK( *loc_i == 1 || *loc_i == 6);
40 else if (i == 2) BOOST_CHECK( *loc_i == 2 );
41 else if (i == 3) BOOST_CHECK( *loc_i == 3 );
42 else if (i == 4) BOOST_CHECK( *loc_i == 4 );
43 else if (i == 6) BOOST_CHECK( *loc_i == 5 || *loc_i == 0);
44 BOOST_CHECK_EQUAL( *loc_i, match_i->index );
49 BOOST_AUTO_TEST_CASE( flp_save )
51 std::string seq("AAGGCCTTAAGGCCTT");
56 f1.seqcomp(seq, seq, false);
57 std::string fname("flp_save_this_is_a_horrible_filename_because_"
58 "im_too_lazy_to_write_a_portable_mktmp.flp");
62 boost::filesystem::remove( boost::filesystem::path(fname) );
64 BOOST_CHECK_EQUAL( f1.size(), seq.size()-win_size+1);
65 BOOST_CHECK_EQUAL( f2.size(), seq.size()-win_size+1);
66 BOOST_CHECK_EQUAL( f1.size(), f2.size() );
67 for (int win=0; win < f1.size(); ++win)
69 std::list<FLPs::match> f1_matches = f1.matches(win);
70 std::list<FLPs::match> f2_matches = f2.matches(win);
71 std::list<FLPs::match>::const_iterator f1_match_i = f1_matches.begin();
72 std::list<FLPs::match>::const_iterator f2_match_i = f2_matches.begin();
74 f1_match_i != f1_matches.end() && f2_match_i != f2_matches.end();
75 ++f1_match_i, ++f2_match_i)
77 BOOST_CHECK_EQUAL( *f1_match_i, *f2_match_i);
82 /*! Apparently when we run multiple seqcomps we want to
83 * save all the FLPs generated
85 BOOST_AUTO_TEST_CASE( flp_reverse_compliment )
88 Sequence s1("AAAATTTT");
89 Sequence s2("AACAGGGG");
91 f1.seqcomp(s1, s2, false);
92 f1.seqcomp(s1, s2.rev_comp(), true);
96 f2.seqcomp(s1, s2.rev_comp(), true);
97 f2.seqcomp(s1, s2, false);
99 // The order of doing the reverse compliment search shouldn't matter
100 // when we're using exactly the same sequence
101 BOOST_CHECK_EQUAL( f1.size(), f2.size() );
102 for (int i = 0; i < f1.size(); ++i )
104 BOOST_CHECK_EQUAL( f1.matches(i).size(), f2.matches(i).size() );
105 // FIXME: should we test the individual lists?
109 BOOST_AUTO_TEST_CASE( flp_file_check )
111 fs::path filename = "Thy_micturations_are_to_me_as_plurdled_gabbleblotchits";
113 BOOST_CHECK_THROW( f1.load(filename), mussa_load_error);