libsequence  1.9.5
ComparisonsTest.cc
1 
5 #include <boost/test/unit_test.hpp>
6 #include <algorithm>
7 #include <iterator>
8 BOOST_AUTO_TEST_SUITE(ComparisonsTest)
9 
10 BOOST_AUTO_TEST_CASE( notagap ) //Silly!
11 {
12  BOOST_REQUIRE_EQUAL( Sequence::NotAGap('-'), false );
13 }
14 
15 BOOST_AUTO_TEST_CASE( gapped1 )
16 {
17  std::string seq1("ATGATG---ACA");
18 
19  BOOST_REQUIRE_EQUAL( Sequence::Gapped(seq1), true );
20 
21  std::remove(seq1.begin(),seq1.end(),'-');
22 
23  BOOST_REQUIRE_EQUAL( Sequence::Gapped(seq1), false );
24 }
25 
26 BOOST_AUTO_TEST_CASE( gapped2 )
27 {
28  std::string seq1("ATGATG---ACA");
29 
30  auto x = seq1.find('-');
31 
32  BOOST_CHECK_PREDICATE(std::not_equal_to<decltype(x)>(),(x)(std::string::npos));
33 
34  BOOST_REQUIRE_EQUAL( Sequence::Gapped(seq1.begin(),seq1.end()), true );
35  BOOST_REQUIRE_EQUAL( Sequence::Gapped(seq1.begin(),seq1.end(),'x'), false );
36  BOOST_REQUIRE_EQUAL( Sequence::Gapped(seq1.begin(),seq1.begin()+x), false );
37 
38  std::remove(seq1.begin(),seq1.end(),'-');
39 
40  BOOST_REQUIRE_EQUAL( Sequence::Gapped(seq1.begin(),seq1.end()), false );
41 }
42 
43 BOOST_AUTO_TEST_CASE( numdiffs1 )
44 {
45  std::string seq1("ATGATG---ACA"),
46  seq2(seq1);
47 
48  BOOST_REQUIRE_EQUAL( Sequence::NumDiffs(seq1,seq2), 0 );
49 
50  //Replace gap characters with N
51  //Yes, this is done in the most obtuse way possible... :)
52  seq2.replace( seq1.find('-'),
53  std::count(seq1.begin(),seq1.end(),'-'),
54  std::string(std::count(seq1.begin(),seq1.end(),'-'),'N' ).c_str());
55 
56  BOOST_REQUIRE_EQUAL( Sequence::NumDiffs(seq1,seq2), 0 );
57  //Allow missing data to be counted as differences
58  BOOST_REQUIRE_EQUAL( Sequence::NumDiffs(seq1,seq2,false), 3 );
59 }
60 
61 BOOST_AUTO_TEST_CASE( numdiffs2 )
62 {
63  std::string seq1("ATGATG---ACA"),
64  seq2(seq1);
65 
66  seq2.erase(std::remove(seq2.begin(),seq2.end(),'-'),seq2.end());
67 
68  /*
69  With the gaps removed, the two sequences are:
70  ATGATG---ACA
71  ATGATGACA
72 
73  NumDiffs must now return -1
74  */
75  BOOST_REQUIRE_EQUAL( Sequence::NumDiffs(seq1,seq2), -1 );
76 }
77 
78 BOOST_AUTO_TEST_CASE( tstv1 )
79 {
80  //The type casting to int is a hack b/c strongly-type enums are not implicitly-convertible to something printable.
81  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('A','A')), int(Sequence::Mutations::Ts) );
82  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('A','a')), int(Sequence::Mutations::Ts) );
83  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('a','a')), int(Sequence::Mutations::Ts) );
84  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('A','G')), int(Sequence::Mutations::Ts) );
85  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('A','G')), int(Sequence::Mutations::Ts) );
86  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('g','a')), int(Sequence::Mutations::Ts) );
87 
88  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('C','T')), int(Sequence::Mutations::Ts) );
89  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('C','t')), int(Sequence::Mutations::Ts) );
90  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('c','t')), int(Sequence::Mutations::Ts) );
91  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('C','T')), int(Sequence::Mutations::Ts) );
92  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('C','T')), int(Sequence::Mutations::Ts) );
93  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('T','c')), int(Sequence::Mutations::Ts) );
94 
95  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('A','T')), int(Sequence::Mutations::Tv) );
96  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('A','C')), int(Sequence::Mutations::Tv) );
97  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('C','A')), int(Sequence::Mutations::Tv) );
98  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('T','A')), int(Sequence::Mutations::Tv) );
99  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('C','a')), int(Sequence::Mutations::Tv) );
100  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('T','a')), int(Sequence::Mutations::Tv) );
101  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('c','A')), int(Sequence::Mutations::Tv) );
102  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('t','A')), int(Sequence::Mutations::Tv) );
103 
104  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('G','T')), int(Sequence::Mutations::Tv) );
105  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('G','t')), int(Sequence::Mutations::Tv) );
106  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('g','t')), int(Sequence::Mutations::Tv) );
107  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('G','C')), int(Sequence::Mutations::Tv) );
108  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('G','c')), int(Sequence::Mutations::Tv) );
109  BOOST_REQUIRE_EQUAL( int(Sequence::TsTv('T','g')), int(Sequence::Mutations::Tv) );
110 
111  BOOST_REQUIRE_THROW( Sequence::TsTv('G','R'), std::runtime_error );
112  BOOST_REQUIRE_THROW( Sequence::TsTv('G','z'), std::runtime_error );
113 }
114 BOOST_AUTO_TEST_SUITE_END()
Mutations TsTv(const char &i, const char &j)
Definition: Comparisons.cc:35
int NumDiffs(const std::string &seq1, const std::string &seq2, const bool &skip_missing=true, const bool &nucleic_acid=true)
Definition: Comparisons.cc:141
bool NotAGap(const char &c)
Definition: Comparisons.cc:196
delcaration of routines for comparing DNA sequences This file declares a set of functions useful for ...
bool Gapped(const std::string &s)
Definition: Comparisons.cc:184