1 #define BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_MODULE test_flp
3 #include <boost/test/auto_unit_test.hpp>
8 #include <boost/filesystem/operations.hpp>
9 #include <boost/filesystem/path.hpp>
10 namespace fs = boost::filesystem;
12 #include "alg/flp.hpp"
13 #include "alg/sequence.hpp"
17 #include "mussa_exceptions.hpp"
19 BOOST_AUTO_TEST_CASE( flp_simple )
23 // when we first setup progress should be equal to -1
24 // aka FLPs::seqcomp_not_running
25 BOOST_CHECK_EQUAL( f.progress(), -1 );
26 f.seqcomp("AAGGTAAGGT", "AAGGTAAGGT", false);
27 // now that we're done we should be equal to not running again.
28 // yeah it'd be nice to make a thread test
29 BOOST_CHECK_EQUAL( f.progress(), -1 );
31 // are the match_locations correct?
32 for (int i=0; i != f.size(); i++)
34 std::list<int> window_locations = f.match_locations(i);
35 std::list<FLPs::match> window_matches = f.matches(i);
36 std::list<int>::iterator loc_i = window_locations.begin();
37 std::list<FLPs::match>::iterator match_i = window_matches.begin();
38 for (; loc_i != window_locations.end(); ++loc_i, ++match_i)
40 // I'm missing pythons easy lists and in operator here.
41 if (i == 0) BOOST_CHECK( *loc_i == 0 || *loc_i == 5);
42 else if (i == 1) BOOST_CHECK( *loc_i == 1 || *loc_i == 6);
43 else if (i == 2) BOOST_CHECK( *loc_i == 2 );
44 else if (i == 3) BOOST_CHECK( *loc_i == 3 );
45 else if (i == 4) BOOST_CHECK( *loc_i == 4 );
46 else if (i == 6) BOOST_CHECK( *loc_i == 5 || *loc_i == 0);
47 BOOST_CHECK_EQUAL( *loc_i, match_i->index );
52 BOOST_AUTO_TEST_CASE( flp_save )
54 std::string seq("AAGGCCTTAAGGCCTT");
59 f1.seqcomp(seq, seq, false);
60 std::string fname("flp_save_this_is_a_horrible_filename_because_"
61 "im_too_lazy_to_write_a_portable_mktmp.flp");
65 boost::filesystem::remove( boost::filesystem::path(fname) );
67 BOOST_CHECK_EQUAL( f1.size(), seq.size()-win_size+1);
68 BOOST_CHECK_EQUAL( f2.size(), seq.size()-win_size+1);
69 BOOST_CHECK_EQUAL( f1.size(), f2.size() );
70 for (int win=0; win < f1.size(); ++win)
72 std::list<FLPs::match> f1_matches = f1.matches(win);
73 std::list<FLPs::match> f2_matches = f2.matches(win);
74 std::list<FLPs::match>::const_iterator f1_match_i = f1_matches.begin();
75 std::list<FLPs::match>::const_iterator f2_match_i = f2_matches.begin();
77 f1_match_i != f1_matches.end() && f2_match_i != f2_matches.end();
78 ++f1_match_i, ++f2_match_i)
80 BOOST_CHECK_EQUAL( *f1_match_i, *f2_match_i);
85 /*! Apparently when we run multiple seqcomps we want to
86 * save all the FLPs generated
88 BOOST_AUTO_TEST_CASE( flp_reverse_compliment )
91 Sequence s1("AAAATTTT");
92 Sequence s2("AACAGGGG");
94 f1.seqcomp(s1, s2, false);
95 f1.seqcomp(s1, s2.rev_comp(), true);
99 f2.seqcomp(s1, s2.rev_comp(), true);
100 f2.seqcomp(s1, s2, false);
102 // The order of doing the reverse compliment search shouldn't matter
103 // when we're using exactly the same sequence
104 BOOST_CHECK_EQUAL( f1.size(), f2.size() );
105 for (int i = 0; i < f1.size(); ++i )
107 BOOST_CHECK_EQUAL( f1.matches(i).size(), f2.matches(i).size() );
108 // FIXME: should we test the individual lists?
112 BOOST_AUTO_TEST_CASE( flp_file_check )
114 fs::path filename = "Thy_micturations_are_to_me_as_plurdled_gabbleblotchits";
116 BOOST_CHECK_THROW( f1.load(filename), mussa_load_error);