bpp-seq  2.2.0
CaseMaskedAlphabet.cpp
Go to the documentation of this file.
1 //
2 // File: CaseMaskedAlphabet.cpp
3 // Created by: Julien Dutheil
4 // Created on: Sun Sep 05 2010
5 //
6 
7 /*
8 Copyright or © or Copr. CNRS, (November 17, 2004)
9 
10 This software is a computer program whose purpose is to provide classes
11 for sequences analysis.
12 
13 This software is governed by the CeCILL license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's author, the holder of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #include "CaseMaskedAlphabet.h"
41 #include <Bpp/Text/TextTools.h>
42 
43 using namespace bpp;
44 
45 //From the STL:
46 #include <vector>
47 #include <iostream>
48 
49 using namespace std;
50 
52  LetterAlphabet(true),
53  nocaseAlphabet_(nocaseAlphabet)
54 {
55  vector<string> chars = nocaseAlphabet_->getSupportedChars();
56  for (size_t i = 0; i < chars.size(); ++i) {
57  AlphabetState* state = nocaseAlphabet_->getState(chars[i]).clone();
58  registerState(state);
59  char c = *chars[i].c_str();
60  if (isalpha(c)) {
61  if (isupper(c)) {
62  registerState(new AlphabetState(state->getNum() + 100, TextTools::toLower(state->getLetter()), string("Masked ") + state->getName()));
63  }
64  }
65  }
66 }
67 
69  throw (BadIntException)
70 {
71  if (!isIntInAlphabet(state))
72  throw BadIntException(state, "CaseMaskedAlphabet::getMaskedEquivalentState. Unsupported state code.");
73  if (state >= 100) return state;
74  else {
75  state += 100;
76  if (!isIntInAlphabet(state))
77  throw BadIntException(state, "CaseMaskedAlphabet::getMaskedEquivalentState. State has masked equivalent.");
78  return state;
79  }
80 }
81 
82 const string CaseMaskedAlphabet::getMaskedEquivalentState(const string& state) const
84 {
85  if (!isCharInAlphabet(state))
86  throw BadCharException(state, "CaseMaskedAlphabet::getMaskedEquivalentState. Unsupported state code.");
87  int code = charToInt(state);
88  if (code >= 100) return state;
89  else {
90  code += 100;
91  if (!isIntInAlphabet(code))
92  throw BadIntException(code, "CaseMaskedAlphabet::getMaskedEquivalentState. State has masked equivalent.");
93  return intToChar(code);
94  }
95 }
96 
97 
This is the base class to describe states in an Alphabet.
Definition: AlphabetState.h:54
An alphabet exception thrown when trying to specify a bad char to the alphabet.
int getNum() const
Get the state&#39;s number.
Definition: AlphabetState.h:83
This alphabet is used to deal NumericAlphabet.
STL namespace.
const std::vector< std::string > & getSupportedChars() const
AlphabetState * clone() const
Definition: AlphabetState.h:76
Specialized partial implementation of Alphabet using single letters.
const AlphabetState & getState(const std::string &letter) const
Get a state by its letter.
const std::string & getName() const
Get the name of the state.
void registerState(AlphabetState *st)
Add a state to the Alphabet.
int getMaskedEquivalentState(int state) const
Get the masked state equivalent to the input one.
const std::string & getLetter() const
Get the letter(s) corresponding to the state.
Definition: AlphabetState.h:99
An alphabet exception thrown when trying to specify a bad int to the alphabet.
const LetterAlphabet * nocaseAlphabet_
CaseMaskedAlphabet(const LetterAlphabet *nocaseAlphabet)