There can be only one (filename convention)
[mussa.git] / alg / test / test_sequence.cpp
1 #include <boost/test/auto_unit_test.hpp>
2
3 #include "alg/sequence.hpp"
4 #include "mussa_exceptions.hpp"
5
6 //! when we try to load a missing file, do we get an error?
7 BOOST_AUTO_TEST_CASE( sequence_load_exception )
8 {
9   Sequence s;
10   // there should be errors when we try to load something that doesn't exist
11   BOOST_CHECK_THROW( s.load_fasta("alkejralk", 1, 0, 0), mussa_load_error);
12   BOOST_CHECK_THROW( s.load_annot("alkejralk", 0, 0), mussa_load_error);
13 }
14
15 //! Do simple operations work correctly?
16 BOOST_AUTO_TEST_CASE( sequence_filter )
17 {
18   Sequence s1("AATTGGCC");
19   BOOST_CHECK_EQUAL(s1.get_seq(), "AATTGGCC");
20
21   Sequence s2("aattggcc");
22   BOOST_CHECK_EQUAL(s2.get_seq(), "AATTGGCC");
23   BOOST_CHECK_EQUAL(s2.rev_comp(), "GGCCAATT");
24   BOOST_CHECK_EQUAL(s2.size(), s2.get_seq().size());
25   BOOST_CHECK_EQUAL(s2.c_seq(), s2.get_seq().c_str());
26
27   Sequence s3("asdfg");
28   BOOST_CHECK_EQUAL(s3.get_seq(), "ANNNG");
29   BOOST_CHECK_EQUAL(s3.subseq(0,2), "AN");
30
31   s3.set_filtered_sequence("AAGGCCTT", 0, 2); 
32   BOOST_CHECK_EQUAL(s3.get_seq(), "AA");
33   s3.set_filtered_sequence("AAGGCCTT", 2, 2);
34   BOOST_CHECK_EQUAL( s3.get_seq(), "GG");
35   s3.set_filtered_sequence("AAGGCCTT", 4);
36   BOOST_CHECK_EQUAL( s3.get_seq(), "CCTT");
37   
38   s3.clear();
39   BOOST_CHECK_EQUAL(s3.get_seq(), "");
40
41   s3.set_seq("AAGGFF");
42   BOOST_CHECK_EQUAL(s3.get_seq(), "AAGGNN");
43 }
44
45 //! Can we load data from a file
46 BOOST_AUTO_TEST_CASE( sequence_load )
47 {
48   Sequence s;
49   s.load_fasta("examples/seq/human_mck_pro.fa");
50   BOOST_CHECK_EQUAL(s.subseq(0, 5), "GGATC"); // first few chars of fasta file
51   BOOST_CHECK_EQUAL(s.get_header(), "gi|180579|gb|M21487.1|HUMCKMM1 Human "
52                                     "muscle creatine kinase gene (CKMM), "
53                                     "5' flank");
54 }
55
56 BOOST_AUTO_TEST_CASE ( sequence_empty )
57 {
58   Sequence s;
59   BOOST_CHECK_EQUAL( s.empty(), true );
60   s = "AAAGGG";
61   BOOST_CHECK_EQUAL( s.empty(), false );
62 }
63
64 BOOST_AUTO_TEST_CASE ( sequence_iterators )
65 {
66   std::string seq_string = "AAGGCCTTNNTATA";
67   Sequence s(seq_string);
68   const Sequence cs(s);
69   std::string::size_type count = 0;
70
71   std::string::iterator str_itor;
72   Sequence::iterator s_itor;
73   Sequence::const_iterator cs_itor;
74
75   for( str_itor = seq_string.begin(),
76        s_itor   = s.begin(),
77        cs_itor  = cs.begin();
78        str_itor != seq_string.end() and
79        s_itor   != s.end() and
80        cs_itor  != cs.end();
81        ++str_itor, ++s_itor, ++cs_itor, ++count)
82   {
83     BOOST_CHECK_EQUAL ( *str_itor, *s_itor );
84     BOOST_CHECK_EQUAL ( *s_itor, *cs_itor );
85     BOOST_CHECK_EQUAL ( *cs_itor, *str_itor );
86   }
87   BOOST_CHECK_EQUAL( seq_string.size(), count );
88   BOOST_CHECK_EQUAL( s.size(), count );
89   BOOST_CHECK_EQUAL( cs.size(), count );
90 }