bpp-seq  2.2.0
Alphabet.h
Go to the documentation of this file.
1 //
2 // File: Alphabet.h
3 // Created by: Guillaume Deuchst
4 // Julien Dutheil
5 // Created on: Tue Jul 22 2003
6 //
7 
8 /*
9 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
10 
11 This software is a computer program whose purpose is to provide classes
12 for sequences analysis.
13 
14 This software is governed by the CeCILL license under French law and
15 abiding by the rules of distribution of free software. You can use,
16 modify and/ or redistribute the software under the terms of the CeCILL
17 license as circulated by CEA, CNRS and INRIA at the following URL
18 "http://www.cecill.info".
19 
20 As a counterpart to the access to the source code and rights to copy,
21 modify and redistribute granted by the license, users are provided only
22 with a limited warranty and the software's author, the holder of the
23 economic rights, and the successive licensors have only limited
24 liability.
25 
26 In this respect, the user's attention is drawn to the risks associated
27 with loading, using, modifying and/or developing or reproducing the
28 software by the user in light of its specific status of free software,
29 that may mean that it is complicated to manipulate, and that also
30 therefore means that it is reserved for developers and experienced
31 professionals having in-depth computer knowledge. Users are therefore
32 encouraged to load and test the software's suitability as regards their
33 requirements in conditions enabling the security of their systems and/or
34 data to be ensured and, more generally, to use and operate it in the
35 same conditions as regards security.
36 
37 The fact that you are presently reading this means that you have had
38 knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef _ALPHABET_H_
42 #define _ALPHABET_H_
43 
44 #include <string>
45 #include <vector>
46 
47 #include "AlphabetExceptions.h"
48 #include "AlphabetState.h"
49 
50 #include <Bpp/Clonable.h>
51 
101 namespace bpp
102 {
103 
130  class Alphabet:
131  public virtual Clonable
132 {
133  public:
134  Alphabet() {}
135  virtual ~Alphabet() {}
136 
142 #ifndef NO_VIRTUAL_COV
143  Alphabet* clone() const = 0;
144 #endif
145 
148  public:
149 
160  virtual std::string getName(int state) const throw (BadIntException) = 0;
161 
172  virtual std::string getName(const std::string& state) const throw (BadCharException) = 0;
173 
178  virtual int getIntCodeAt(size_t stateIndex) const throw (IndexOutOfBoundsException) = 0;
179 
184  virtual const std::string& getCharCodeAt(size_t stateIndex) const throw (IndexOutOfBoundsException) = 0;
185 
189  virtual size_t getStateIndex(int state) const throw (BadIntException) = 0;
190 
194  virtual size_t getStateIndex(const std::string& state) const throw (BadCharException) = 0;
195 
209  virtual bool isIntInAlphabet(int state) const = 0;
210 
218  virtual bool isCharInAlphabet(const std::string& state) const = 0;
234  virtual const AlphabetState& getStateAt(size_t stateIndex) const throw (IndexOutOfBoundsException) = 0;
235 
245  virtual const AlphabetState& getState(int state) const throw (BadIntException) = 0;
246 
254  virtual const AlphabetState& getState(const std::string& state) const throw (BadCharException) = 0;
255 
271  virtual std::string intToChar(int state) const throw (BadIntException) = 0;
272 
280  virtual int charToInt(const std::string& state) const throw (BadCharException) = 0;
295  virtual size_t getNumberOfStates() const = 0;
296 
303  virtual unsigned int getNumberOfChars() const = 0;
304 
311  virtual unsigned int getNumberOfTypes() const = 0;
312 
319  virtual unsigned int getSize() const = 0;
320 
338  virtual std::vector<int> getAlias(int state) const throw (BadIntException) = 0;
339 
349  virtual std::vector<std::string> getAlias(const std::string& state) const throw (BadCharException) = 0;
350 
361  virtual int getGeneric(const std::vector<int>& states) const throw (BadIntException) = 0;
362 
374  virtual std::string getGeneric(const std::vector<std::string>& states) const throw (AlphabetException) = 0;
375 
383  virtual const std::vector<int>& getSupportedInts() const = 0;
384 
392  virtual const std::vector<std::string>& getSupportedChars() const = 0;
393 
397  virtual int getUnknownCharacterCode() const = 0;
398 
402  virtual int getGapCharacterCode() const = 0;
403 
408  virtual bool isGap(int state) const = 0;
409 
414  virtual bool isGap(const std::string& state) const = 0;
415 
420  virtual bool isUnresolved(int state) const = 0;
421 
426  virtual bool isUnresolved(const std::string& state) const = 0;
427 
439  virtual std::string getAlphabetType() const = 0;
440 
446  virtual unsigned int getStateCodingSize() const = 0;
447 
453  virtual bool equals(const Alphabet& alphabet) const = 0;
454 };
455 
456 } //end of namespace bpp.
457 
458 #endif // _ALPHABET_H_
459 
This is the base class to describe states in an Alphabet.
Definition: AlphabetState.h:54
virtual const std::vector< std::string > & getSupportedChars() const =0
virtual std::string getName(int state) const =0
Get the complete name of a state given its int description.
virtual int charToInt(const std::string &state) const =0
Give the int description of a state given its string description.
An alphabet exception thrown when trying to specify a bad char to the alphabet.
virtual int getGeneric(const std::vector< int > &states) const =0
Get the generic state that match a set of states.
virtual size_t getNumberOfStates() const =0
This is a convenient alias for getNumberOfChars(), returning a size_t instead of unsigned int...
virtual bool isGap(int state) const =0
This alphabet is used to deal NumericAlphabet.
virtual bool isIntInAlphabet(int state) const =0
Tell if a state (specified by its int description) is allowed by the the alphabet.
virtual bool isUnresolved(int state) const =0
virtual const std::vector< int > & getSupportedInts() const =0
virtual unsigned int getSize() const =0
Get the number of resolved states in the alphabet (e.g. return 4 for DNA alphabet). This is the method you&#39;ll need in most cases.
The Alphabet interface.
Definition: Alphabet.h:130
virtual unsigned int getStateCodingSize() const =0
Get the size of the string coding a state.
virtual std::vector< int > getAlias(int state) const =0
Get all resolved states that match a generic state.
virtual int getGapCharacterCode() const =0
virtual bool isCharInAlphabet(const std::string &state) const =0
Tell if a state (specified by its string description) is allowed by the the alphabet.
virtual const std::string & getCharCodeAt(size_t stateIndex) const =0
virtual const AlphabetState & getState(int state) const =0
Get a state given its int description.
Alphabet * clone() const =0
virtual size_t getStateIndex(int state) const =0
virtual unsigned int getNumberOfChars() const =0
Get the number of supported characters in this alphabet, including generic characters (e...
The alphabet exception base class.
virtual int getIntCodeAt(size_t stateIndex) const =0
virtual std::string intToChar(int state) const =0
Give the string description of a state given its int description.
An alphabet exception thrown when trying to specify a bad int to the alphabet.
virtual bool equals(const Alphabet &alphabet) const =0
Comparison of alphabets.
virtual const AlphabetState & getStateAt(size_t stateIndex) const =0
Get a state given its index.
virtual unsigned int getNumberOfTypes() const =0
Get the number of distinct states in alphabet (e.g. return 15 for DNA alphabet). This is the number o...
virtual int getUnknownCharacterCode() const =0
virtual ~Alphabet()
Definition: Alphabet.h:135
virtual std::string getAlphabetType() const =0
Identification method.