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