test paircomp::NwayComparison
[mussa.git] / alg / test / test_paircomp.cpp
1 #define BOOST_AUTO_TEST_MAIN
2 #include <boost/test/auto_unit_test.hpp>
3 #include <boost/filesystem/path.hpp>
4 namespace fs = boost::filesystem;
5
6 #include <string>
7 #include <iostream>
8
9 #include "alg/sequence.hpp"
10 #include "paircomp.hh"
11 #include "Match.hh"
12
13 using namespace std;
14
15 BOOST_AUTO_TEST_CASE( simple_nxn_comparison )
16 {
17   std::string s(10, 'A');
18   Sequence s1(s);
19   Sequence s2(s);
20   
21   paircomp::ImmutableComparison *cmp;
22   // Make sure we called the string constructor correctly
23   BOOST_REQUIRE_EQUAL( s1.size(), 10 );
24   BOOST_REQUIRE_EQUAL( s2.size(), 10 );
25   cmp = paircomp::simple_nxn_comparison<Sequence>(s1, s2, 10, 0.10);
26   
27   BOOST_CHECK_EQUAL( cmp->is_empty(), false);
28   const paircomp::_MatchContainer *matches = cmp->get_matches(0);
29   BOOST_REQUIRE( matches != 0);
30   BOOST_CHECK_EQUAL( matches->num, 1 );
31 }
32
33 BOOST_AUTO_TEST_CASE( simple_nxn_comparison_mixed_case )
34 {
35   Sequence s1("AtGGcT");
36   Sequence s2("aTggCt");
37   
38   paircomp::ImmutableComparison *cmp;
39   // Make sure we called the string constructor correctly
40   BOOST_REQUIRE_EQUAL( s1.size(), 6 );
41   BOOST_REQUIRE_EQUAL( s2.size(), 6 );
42   cmp = paircomp::simple_nxn_comparison<Sequence>(s1, s2, 6, 1.0);
43   
44   BOOST_CHECK_EQUAL( cmp->is_empty(), false);
45   const paircomp::_MatchContainer *matches = cmp->get_matches(0);
46   BOOST_REQUIRE( matches != 0);
47   BOOST_CHECK_EQUAL( matches->num, 1 );
48   paircomp::Match *m = &(matches->block[ 0 ]);
49   BOOST_CHECK_EQUAL( m->get_top_pos(), 0 );
50   BOOST_CHECK_EQUAL( m->get_bot_pos(), 0 );
51   BOOST_CHECK_EQUAL( m->get_length(), 6 );
52 }
53
54 //! there should be no matches
55 BOOST_AUTO_TEST_CASE( paircomp_3way_null )
56 {
57   Sequence s0("AAAANNNN");
58   Sequence s1("GGGGNNNN");
59   Sequence s2("TTTTNNNN");
60
61   paircomp::NwayComparison<Sequence> cmp(4, 0.75);
62   cmp.add_sequence(s0);
63   cmp.add_sequence(s1);
64   cmp.add_sequence(s2);
65   BOOST_CHECK_EQUAL( cmp.size(), cmp.n_sequences() );
66   BOOST_CHECK_EQUAL( cmp.size(), 3 );
67   std::vector<paircomp::NwayPath> paths = cmp.filter();
68   
69   BOOST_CHECK_EQUAL( paths.size(), 0 );
70 }
71
72 //! there should be no matches
73 BOOST_AUTO_TEST_CASE( paircomp_3way_one_match )
74 {
75   Sequence s0("AAAANNNN");
76   Sequence s1("AAAAGGGG");
77   Sequence s2("NNNNTTTT");
78
79   paircomp::NwayComparison<Sequence> nway(4, 1.0);
80   nway.add_sequence(s0);
81   nway.add_sequence(s1);
82   nway.add_sequence(s2);
83   std::vector<paircomp::NwayPath> paths = nway.filter();
84
85   // check the comparisons hidden within the nway to make sure they still make sense  
86   paircomp::ImmutableComparison *cmp_0_1 = nway.get_comparison(0,1);
87   const paircomp::_MatchContainer *matches = cmp_0_1->get_matches(0);
88   BOOST_REQUIRE( matches != 0 ); 
89   BOOST_CHECK_EQUAL( matches->num, 1 );
90   BOOST_CHECK_EQUAL( matches->block[0].get_top_pos(), 0 );
91   BOOST_CHECK_EQUAL( matches->block[0].get_bot_pos(), 0 );
92
93   BOOST_REQUIRE_EQUAL( paths.size(), 1 );
94   std::stringstream result;
95   result << paths;
96   BOOST_CHECK_EQUAL( result.str(), "[[0(+), 0(-), 4(+)]]");
97   
98   BOOST_CHECK_EQUAL( paths[0][0].pos, 0 );
99   BOOST_CHECK_EQUAL( paths[0][0].orient, 1 );
100
101   BOOST_CHECK_EQUAL( paths[0][1].pos, 0 );
102   BOOST_CHECK_EQUAL( paths[0][1].orient, -1 );
103
104   BOOST_CHECK_EQUAL( paths[0][2].pos, 4 );
105   BOOST_CHECK_EQUAL( paths[0][2].orient, 1 );
106 }