libsequence  1.9.5
alphabets.cc
Go to the documentation of this file.
1 
4 #include <Sequence/Fasta.hpp>
5 #include <boost/test/unit_test.hpp>
6 #include <algorithm>
7 #include <iterator>
8 BOOST_AUTO_TEST_SUITE(AlphabetTest)
9 
10 BOOST_AUTO_TEST_CASE( check_dna_alphabet )
11 {
12  for ( auto c : {'A','G','C','T'} )
13  {
14  BOOST_REQUIRE( std::distance(Sequence::dna_alphabet.begin(),
15  std::find( Sequence::dna_alphabet.begin(),
16  Sequence::dna_alphabet.end(), c ) ) < 4 );
17  }
18 }
19 
20 BOOST_AUTO_TEST_CASE( check_isDNA_1 )
21 {
22  for (auto c : Sequence::dna_alphabet )
23  {
24  BOOST_REQUIRE( Sequence::isDNA(c) );
25  }
26 }
27 
28 BOOST_AUTO_TEST_CASE( check_isDNA_2 )
29 {
30  Sequence::Fasta f = { "name","ATGCZAGC" }; //Z is a non-DNA character
31  auto itr = std::find_if( f.begin(),f.end(),
32  [](const char & __ch) {
33  return !Sequence::isDNA(__ch);
34  } );
35  BOOST_REQUIRE_EQUAL( std::distance(f.begin(),itr),4 );
36 
37  f.seq.erase( std::remove_if(f.begin(),
38  f.end(),
39  [](const char & __ch) {
40  return !Sequence::isDNA(__ch);
41  }), f.seq.end() );
42  BOOST_REQUIRE_EQUAL(f.seq,"ATGCAGC");
43 }
44 
45 //Test of dna_poly_alphabet
46 BOOST_AUTO_TEST_CASE( dna_poly_alphabet_1 )
47 {
48  BOOST_REQUIRE( std::find( Sequence::dna_poly_alphabet.begin(),
50 }
51 
52 BOOST_AUTO_TEST_CASE( dna_poly_alphabet_2 )
53 {
54  BOOST_CHECK_EQUAL( Sequence::POLYEOS, 8 );
55 }
56 
57 BOOST_AUTO_TEST_CASE( dna_poly_alphabet_3 )
58 {
59  for ( auto c : {'A','C','G','T','N','0','1','-'} )
60  {
61  BOOST_CHECK( std::distance( Sequence::dna_poly_alphabet.begin(),
62  std::find(Sequence::dna_poly_alphabet.begin(),
64  }
65 }
66 
67 BOOST_AUTO_TEST_CASE( dna_poly_alphabet_4 )
68 {
69  for ( auto c : {'a','c','g','t','n','W','K'} )
70  {
71  BOOST_CHECK( std::distance( Sequence::dna_poly_alphabet.begin(),
72  std::find(Sequence::dna_poly_alphabet.begin(),
74  }
75 }
76 
77 BOOST_AUTO_TEST_CASE( dna_poly_alphabet_5 )
78 {
79  for ( auto c : {'a','c','g','t','n','W','K'} )
80  {
81  BOOST_CHECK( std::distance( Sequence::dna_poly_alphabet.begin(),
82  std::find(Sequence::dna_poly_alphabet.begin(),
84  }
85 }
86 BOOST_AUTO_TEST_SUITE_END()
FASTA sequence stream.
Definition: Fasta.hpp:49
bool isDNA(const char &ch)
test if character is part of Sequence::dna_alphabet
Definition: SeqAlphabets.cc:25
const alphabet_t dna_alphabet
Alphabet for DNA sequences Valid DNA characters. Upper-case only. Only - is accepted as gap character...
Definition: SeqAlphabets.cc:8
const alphabet_t::size_type NOTPOLYCHAR
An index from dna_poly_alphabet >= this is not a valid character for variation analysis.
Definition: SeqAlphabets.cc:18
iterator begin()
Definition: Seq.cc:189
iterator end()
Definition: Seq.cc:198
Declaration of Sequence::Fasta streams.
const alphabet_t dna_poly_alphabet
Alphabet for polymorphism (SNP) analysis. 16 characters are used so that we may encode 2 nucleotides ...
Definition: SeqAlphabets.cc:13
const alphabet_t::size_type POLYEOS
The value of terminating an encoded string of SNP data.
Definition: SeqAlphabets.cc:20