1 #define BOOST_AUTO_TEST_MAIN
5 #include <boost/test/auto_unit_test.hpp>
6 #include <boost/filesystem/operations.hpp>
7 #include <boost/filesystem/path.hpp>
8 namespace fs = boost::filesystem;
10 #include "alg/flp.hpp"
11 #include "alg/sequence.hpp"
15 #include "mussa_exceptions.hpp"
17 BOOST_AUTO_TEST_CASE( flp_simple )
21 // when we first setup progress should be equal to -1
22 // aka FLPs::seqcomp_not_running
23 BOOST_CHECK_EQUAL( f.progress(), -1 );
24 f.seqcomp("AAGGTAAGGT", "AAGGTAAGGT", false);
25 // now that we're done we should be equal to not running again.
26 // yeah it'd be nice to make a thread test
27 BOOST_CHECK_EQUAL( f.progress(), -1 );
29 // are the match_locations correct?
30 for (int i=0; i != f.size(); i++)
32 std::list<int> window_locations = f.match_locations(i);
33 std::list<FLPs::match> window_matches = f.matches(i);
34 std::list<int>::iterator loc_i = window_locations.begin();
35 std::list<FLPs::match>::iterator match_i = window_matches.begin();
36 for (; loc_i != window_locations.end(); ++loc_i, ++match_i)
38 // I'm missing pythons easy lists and in operator here.
39 if (i == 0) BOOST_CHECK( *loc_i == 0 || *loc_i == 5);
40 else if (i == 1) BOOST_CHECK( *loc_i == 1 || *loc_i == 6);
41 else if (i == 2) BOOST_CHECK( *loc_i == 2 );
42 else if (i == 3) BOOST_CHECK( *loc_i == 3 );
43 else if (i == 4) BOOST_CHECK( *loc_i == 4 );
44 else if (i == 6) BOOST_CHECK( *loc_i == 5 || *loc_i == 0);
45 BOOST_CHECK_EQUAL( *loc_i, match_i->index );
50 BOOST_AUTO_TEST_CASE( flp_save )
52 std::string seq("AAGGCCTTAAGGCCTT");
57 f1.seqcomp(seq, seq, false);
58 std::string fname("flp_save_this_is_a_horrible_filename_because_"
59 "im_too_lazy_to_write_a_portable_mktmp.flp");
63 boost::filesystem::remove( boost::filesystem::path(fname) );
65 BOOST_CHECK_EQUAL( f1.size(), seq.size()-win_size+1);
66 BOOST_CHECK_EQUAL( f2.size(), seq.size()-win_size+1);
67 BOOST_CHECK_EQUAL( f1.size(), f2.size() );
68 for (int win=0; win < f1.size(); ++win)
70 std::list<FLPs::match> f1_matches = f1.matches(win);
71 std::list<FLPs::match> f2_matches = f2.matches(win);
72 std::list<FLPs::match>::const_iterator f1_match_i = f1_matches.begin();
73 std::list<FLPs::match>::const_iterator f2_match_i = f2_matches.begin();
75 f1_match_i != f1_matches.end() && f2_match_i != f2_matches.end();
76 ++f1_match_i, ++f2_match_i)
78 BOOST_CHECK_EQUAL( *f1_match_i, *f2_match_i);
83 /*! Apparently when we run multiple seqcomps we want to
84 * save all the FLPs generated
86 BOOST_AUTO_TEST_CASE( flp_reverse_compliment )
89 Sequence s1("AAAATTTT");
90 Sequence s2("AACAGGGG");
92 f1.seqcomp(s1, s2, false);
93 f1.seqcomp(s1, s2.rev_comp(), true);
97 f2.seqcomp(s1, s2.rev_comp(), true);
98 f2.seqcomp(s1, s2, false);
100 // The order of doing the reverse compliment search shouldn't matter
101 // when we're using exactly the same sequence
102 BOOST_CHECK_EQUAL( f1.size(), f2.size() );
103 for (int i = 0; i < f1.size(); ++i )
105 BOOST_CHECK_EQUAL( f1.matches(i).size(), f2.matches(i).size() );
106 // FIXME: should we test the individual lists?
110 BOOST_AUTO_TEST_CASE( flp_file_check )
112 fs::path filename = "Thy_micturations_are_to_me_as_plurdled_gabbleblotchits";
114 BOOST_CHECK_THROW( f1.load(filename), mussa_load_error);