libsequence  1.9.5
stateCounter.cc
1 /*
2 
3  Copyright (C) 2003-2009 Kevin Thornton, krthornt[]@[]uci.edu
4 
5  Remove the brackets to email me.
6 
7  This file is part of libsequence.
8 
9  libsequence is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  libsequence is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  long with libsequence. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
25 #include <cctype>
26 
27 namespace Sequence
28 {
57  stateCounter::stateCounter( char gapchar):a(0),g(0),c(0),
58  t(0),zero(0),one(0),gap(0),n(0),ndna(false),_gap(gapchar)
62  {}
63 
64  void stateCounter::operator()(const char &ch)
68  {
69  if (ch == _gap)
70  {
71  ++gap;
72  }
73  else
74  {
75  char _ch = char(toupper(ch));
76  switch(_ch)
77  {
78  case 'A':
79  ++a;
80  break;
81  case 'G':
82  ++g;
83  break;
84  case 'C':
85  ++c;
86  break;
87  case 'T':
88  ++t;
89  break;
90  case '0':
91  ++zero;
92  break;
93  case '1':
94  ++one;
95  break;
96  case 'N':
97  ++n;
98  break;
99  default:
100  ndna = true;
101  break;
102  }
103  }
104  }
105 
106  stateCounter::size_type stateCounter::nStates(void) const
111  {
112  stateCounter::size_type nstates = (a > 0) ? 1 : 0;
113  nstates += (g > 0) ? 1 : 0;
114  nstates += (c > 0) ? 1 : 0;
115  nstates += (t > 0) ? 1 : 0;
116  nstates += (zero > 0) ? 1 : 0;
117  nstates += (one > 0) ? 1 : 0;
118  return nstates;
119  }
120 }
bool operator()(const std::pair< key, value > &l, const std::pair< key, value > &r) const
The namespace in which this library resides.
declaration of Sequence::stateCounter, a class to keep track of nucleotide counts either at a site in...