center on path
[mussa.git] / alg / test / test_glseqbrowser.cpp
1 #include <boost/test/auto_unit_test.hpp>
2 #include <boost/assign/std/vector.hpp>
3 using namespace boost::assign;
4
5 #include <string>
6 #include <list>
7 #include <vector>
8
9 #include "alg/annotation_colors.hpp"
10 #include "alg/glseqbrowser.hpp"
11 #include "alg/sequence.hpp"
12
13 using namespace std;
14
15 BOOST_AUTO_TEST_CASE ( gltracks_connect )
16 {
17   string s0("AAGGCCTT");
18   string s1("TTGGCCAA");
19   string s2("GATTACAA");
20   Sequence seq0(s0);
21   Sequence seq1(s1);
22   Sequence seq2(s2);
23
24   GlSeqBrowser gt;
25   gt.push_sequence(seq0);
26   gt.push_sequence(seq1);
27   gt.push_sequence(seq2);
28
29   // make up some sample data
30   vector<bool> rc;
31   rc += false, false, false;
32   vector<int> path;
33                 path += 1,1,1; gt.link(path, rc, 1);
34   path.clear(); path += 1,1,3; gt.link(path, rc, 1); 
35   path.clear(); path += 2,3,3; gt.link(path, rc, 1); 
36   path.clear(); path += 3,3,3; gt.link(path, rc, 1);
37
38   BOOST_CHECK_EQUAL( gt.path_segments.size(), 2 );
39   GlSeqBrowser::segment_key p(1, 1);
40   GlSeqBrowser::pair_segment_map::iterator psm_i = gt.path_segments[0].find(p);
41   BOOST_CHECK( psm_i != gt.path_segments[0].end() );
42   BOOST_CHECK_EQUAL( psm_i->second.path_ids.size(), 2 );
43
44   gt.clear();
45   BOOST_CHECK_EQUAL( gt.path_segments.size(), 0 );
46 }
47
48 BOOST_AUTO_TEST_CASE( glseqbrowser_center )
49 {
50   string s0("AAGGCCTT");
51   string s1("TTGGCCAA");
52   string s2("GATTACAA");
53   Sequence seq0(s0);
54   Sequence seq1(s1);
55   Sequence seq2(s2);
56   AnnotationColors cm;
57   GlSequence glseq0(seq0, cm);
58   GlSequence glseq1(seq1, cm);
59   GlSequence glseq2(seq2, cm);
60
61   GlSeqBrowser gt;
62   gt.push_sequence(glseq0);
63   gt.push_sequence(glseq1);
64   gt.push_sequence(glseq2);
65
66   vector<int> path;
67   path += 0,3,7; 
68
69   BOOST_CHECK_EQUAL( gt.left(), -gt.border() );
70   BOOST_CHECK_EQUAL( gt.right(), s0.size() + gt.border() );
71
72   gt.centerOnPath(path);
73
74   // I didn't bother to compute how the path should shift things
75   // by the magic number 3, i just ran the test and saw how it failed
76   // and hard coded this in.
77   BOOST_CHECK_EQUAL( gt.left(), -3-gt.border() );
78   BOOST_CHECK_EQUAL( gt.right(), 3 + s0.size() + gt.border() );
79
80   // aparently we end up with a different glsequence in the seqbrowser
81   BOOST_CHECK( glseq1.x() != gt.sequences()[1].x() );
82
83   BOOST_CHECK_EQUAL( gt.sequences()[0].x(), gt.viewportCenter()-path[0] );
84   BOOST_CHECK_EQUAL( gt.sequences()[1].x(), gt.viewportCenter()-path[1] );
85   BOOST_CHECK_EQUAL( gt.sequences()[2].x(), gt.viewportCenter()-path[2] );
86 }