96892618c72bbc9e3791585fbfa6d1fb1931ca7b
[mussa.git] / alg / tsf / trivial_filter.cpp
1 #include "trivial_filter.hpp"
2
3 #include <boost/assign.hpp>
4 using namespace boost::assign;
5
6 #include <iostream>
7
8 TSFLookupTable::TSFLookupTable(int nmer, int length)
9 {
10   generate_dna_pattern(nmer, length);
11 }
12
13 int TSFLookupTable::next(int state, enum nucleotide symbol)
14 {
15 #if 0
16   // dump what row we're looking at
17   std::cout << "[" << state << "]: ";
18   for(int i=0; i != table[state].size(); ++i) {
19     std::cout << table[state][i] << " ";
20   }
21   std::cout << "lookup(" << symbol << ")" << std::endl;
22 #endif
23   return table[state][symbol];
24 }
25
26 void TSFLookupTable::generate_dna_pattern(int nmer, int length)
27 {
28   // currently we can only handle single nucleotides
29   assert (nmer == 1);
30   
31   symbol_vec symbols;
32   symbols += A, T, G, C;
33
34   // add the start state
35   std::vector<int> transitions(8, failed_state);
36   table.push_back(transitions);
37
38   for (symbol_vec::iterator pattern_itor = symbols.begin();
39        pattern_itor != symbols.end();
40        ++pattern_itor)
41   {
42     // update the start state to point at the state we're adding
43     table[0][*pattern_itor] = table.size();
44     
45     // add the counting states
46     for(int i = 0; i != length-nmer; ++ i)
47     {
48       std::vector<int> transitions(8, failed_state);
49       transitions[*pattern_itor] = table.size()+1; //point to next state
50       table.push_back(transitions);
51     }
52
53     // add the accept state
54     std::vector<int> transitions(8, accept_state);
55     transitions[*pattern_itor] = table.size();
56     table.push_back(transitions);
57   }
58 }