|
bpp-seq
2.1.0
|
00001 // 00002 // File: AbstractAlphabet.h 00003 // Authors: Guillaume Deuchst 00004 // Julien Dutheil 00005 // Sylvain Gaillard 00006 // Created on: Tue Jul 22 2003 00007 // 00008 00009 /* 00010 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004) 00011 00012 This software is a computer program whose purpose is to provide classes 00013 for sequences analysis. 00014 00015 This software is governed by the CeCILL license under French law and 00016 abiding by the rules of distribution of free software. You can use, 00017 modify and/ or redistribute the software under the terms of the CeCILL 00018 license as circulated by CEA, CNRS and INRIA at the following URL 00019 "http://www.cecill.info". 00020 00021 As a counterpart to the access to the source code and rights to copy, 00022 modify and redistribute granted by the license, users are provided only 00023 with a limited warranty and the software's author, the holder of the 00024 economic rights, and the successive licensors have only limited 00025 liability. 00026 00027 In this respect, the user's attention is drawn to the risks associated 00028 with loading, using, modifying and/or developing or reproducing the 00029 software by the user in light of its specific status of free software, 00030 that may mean that it is complicated to manipulate, and that also 00031 therefore means that it is reserved for developers and experienced 00032 professionals having in-depth computer knowledge. Users are therefore 00033 encouraged to load and test the software's suitability as regards their 00034 requirements in conditions enabling the security of their systems and/or 00035 data to be ensured and, more generally, to use and operate it in the 00036 same conditions as regards security. 00037 00038 The fact that you are presently reading this means that you have had 00039 knowledge of the CeCILL license and that you accept its terms. 00040 */ 00041 00042 #ifndef _ABSTRACTALPHABET_H_ 00043 #define _ABSTRACTALPHABET_H_ 00044 00045 #include "Alphabet.h" 00046 #include "AlphabetState.h" 00047 #include <Bpp/Exceptions.h> 00048 00049 // From the STL: 00050 #include <string> 00051 #include <vector> 00052 #include <map> 00053 00054 namespace bpp 00055 { 00056 00067 class AbstractAlphabet: 00068 public Alphabet 00069 { 00070 private: 00071 00075 std::vector<AlphabetState*> alphabet_; 00080 std::map<std::string, size_t> letters_; 00081 std::map<int, size_t> nums_; 00089 void updateMaps_(size_t pos, const AlphabetState& st); 00090 00091 protected: 00099 mutable std::vector<std::string> charList_; 00100 mutable std::vector<int> intList_; 00103 public: 00104 00105 AbstractAlphabet(): alphabet_(), letters_(), nums_(), charList_(), intList_() {} 00106 00107 virtual ~AbstractAlphabet() 00108 { 00109 for (unsigned int i = 0 ; i < alphabet_.size() ; i++) 00110 delete alphabet_[i]; 00111 } 00112 00113 public: 00119 unsigned int getNumberOfChars() const { return static_cast<unsigned int>(alphabet_.size()); } 00120 std::string getName(const std::string& state) const throw (BadCharException); 00121 std::string getName(int state) const throw (BadIntException); 00122 int charToInt(const std::string& state) const throw (BadCharException); 00123 std::string intToChar(int state) const throw (BadIntException); 00124 bool isIntInAlphabet(int state) const; 00125 bool isCharInAlphabet(const std::string& state) const; 00126 std::vector<int> getAlias(int state) const throw (BadIntException); 00127 std::vector<std::string> getAlias(const std::string& state) const throw (BadCharException); 00128 int getGeneric(const std::vector<int>& states) const throw (BadIntException); 00129 std::string getGeneric(const std::vector<std::string>& states) const throw (AlphabetException); 00130 const std::vector<int>& getSupportedInts() const; 00131 const std::vector<std::string>& getSupportedChars() const; 00132 int getGapCharacterCode() const { return -1; } 00133 bool isGap(int state) const { return state == -1; } 00134 bool isGap(const std::string& state) const { return charToInt(state) == -1; } 00150 const AlphabetState& getState(const std::string& letter) const throw (BadCharException); 00160 const AlphabetState& getState(int num) const throw (BadIntException); 00163 protected: 00169 virtual void registerState(const AlphabetState& st); 00176 virtual void setState(size_t pos, const AlphabetState& st) throw (IndexOutOfBoundsException); 00182 void resize(unsigned int size) { alphabet_.resize(size); } 00192 virtual AlphabetState& getStateAt(size_t pos) throw (IndexOutOfBoundsException); 00202 virtual const AlphabetState& getStateAt(size_t pos) const throw (IndexOutOfBoundsException); 00203 00207 void remap() { 00208 for (size_t i = 0 ; i < alphabet_.size() ; i++) { 00209 updateMaps_(i, * alphabet_[i]); 00210 } 00211 } 00212 00213 unsigned int getStateCodingSize() const { return 1; } 00214 00215 }; 00216 00217 } //end of namespace bpp. 00218 00219 #endif // _ABSTRACTALPHABET_H_ 00220