bpp-seq  2.1.0
 All Classes Namespaces Files Functions Variables Friends Pages
AbstractAlphabet.h
Go to the documentation of this file.
1 //
2 // File: AbstractAlphabet.h
3 // Authors: Guillaume Deuchst
4 // Julien Dutheil
5 // Sylvain Gaillard
6 // Created on: Tue Jul 22 2003
7 //
8 
9 /*
10  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
11 
12  This software is a computer program whose purpose is to provide classes
13  for sequences analysis.
14 
15  This software is governed by the CeCILL license under French law and
16  abiding by the rules of distribution of free software. You can use,
17  modify and/ or redistribute the software under the terms of the CeCILL
18  license as circulated by CEA, CNRS and INRIA at the following URL
19  "http://www.cecill.info".
20 
21  As a counterpart to the access to the source code and rights to copy,
22  modify and redistribute granted by the license, users are provided only
23  with a limited warranty and the software's author, the holder of the
24  economic rights, and the successive licensors have only limited
25  liability.
26 
27  In this respect, the user's attention is drawn to the risks associated
28  with loading, using, modifying and/or developing or reproducing the
29  software by the user in light of its specific status of free software,
30  that may mean that it is complicated to manipulate, and that also
31  therefore means that it is reserved for developers and experienced
32  professionals having in-depth computer knowledge. Users are therefore
33  encouraged to load and test the software's suitability as regards their
34  requirements in conditions enabling the security of their systems and/or
35  data to be ensured and, more generally, to use and operate it in the
36  same conditions as regards security.
37 
38  The fact that you are presently reading this means that you have had
39  knowledge of the CeCILL license and that you accept its terms.
40 */
41 
42 #ifndef _ABSTRACTALPHABET_H_
43 #define _ABSTRACTALPHABET_H_
44 
45 #include "Alphabet.h"
46 #include "AlphabetState.h"
47 #include <Bpp/Exceptions.h>
48 
49 // From the STL:
50 #include <string>
51 #include <vector>
52 #include <map>
53 
54 namespace bpp
55 {
56 
68  public Alphabet
69  {
70  private:
71 
75  std::vector<AlphabetState*> alphabet_;
80  std::map<std::string, size_t> letters_;
81  std::map<int, size_t> nums_;
89  void updateMaps_(size_t pos, const AlphabetState& st);
90 
91  protected:
99  mutable std::vector<std::string> charList_;
100  mutable std::vector<int> intList_;
103  public:
104 
106 
108  {
109  for (unsigned int i = 0 ; i < alphabet_.size() ; i++)
110  delete alphabet_[i];
111  }
112 
113  public:
119  unsigned int getNumberOfChars() const { return static_cast<unsigned int>(alphabet_.size()); }
120  std::string getName(const std::string& state) const throw (BadCharException);
121  std::string getName(int state) const throw (BadIntException);
122  int charToInt(const std::string& state) const throw (BadCharException);
123  std::string intToChar(int state) const throw (BadIntException);
124  bool isIntInAlphabet(int state) const;
125  bool isCharInAlphabet(const std::string& state) const;
126  std::vector<int> getAlias(int state) const throw (BadIntException);
127  std::vector<std::string> getAlias(const std::string& state) const throw (BadCharException);
128  int getGeneric(const std::vector<int>& states) const throw (BadIntException);
129  std::string getGeneric(const std::vector<std::string>& states) const throw (AlphabetException);
130  const std::vector<int>& getSupportedInts() const;
131  const std::vector<std::string>& getSupportedChars() const;
132  int getGapCharacterCode() const { return -1; }
133  bool isGap(int state) const { return state == -1; }
134  bool isGap(const std::string& state) const { return charToInt(state) == -1; }
150  const AlphabetState& getState(const std::string& letter) const throw (BadCharException);
160  const AlphabetState& getState(int num) const throw (BadIntException);
163  protected:
169  virtual void registerState(const AlphabetState& st);
176  virtual void setState(size_t pos, const AlphabetState& st) throw (IndexOutOfBoundsException);
182  void resize(unsigned int size) { alphabet_.resize(size); }
192  virtual AlphabetState& getStateAt(size_t pos) throw (IndexOutOfBoundsException);
202  virtual const AlphabetState& getStateAt(size_t pos) const throw (IndexOutOfBoundsException);
203 
207  void remap() {
208  for (size_t i = 0 ; i < alphabet_.size() ; i++) {
209  updateMaps_(i, * alphabet_[i]);
210  }
211  }
212 
213  unsigned int getStateCodingSize() const { return 1; }
214 
215  };
216 
217 } //end of namespace bpp.
218 
219 #endif // _ABSTRACTALPHABET_H_
220