bpp-seq  2.1.0
 All Classes Namespaces Files Functions Variables Friends Pages
AlphabetTools.h
Go to the documentation of this file.
1 //
2 // File: AlphabetTools.h
3 // Created by: Julien Dutheil
4 // Created on: Fri Oct 10 17:27:39 2003
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (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 #ifndef _ALPHABETTOOLS_H_
41 #define _ALPHABETTOOLS_H_
42 
43 #include "DNA.h"
44 #include "RNA.h"
45 #include "ProteicAlphabet.h"
46 #include "DefaultAlphabet.h"
47 #include "CodonAlphabet.h"
48 #include "RNY.h"
49 #include "BinaryAlphabet.h"
51 
52 #include <typeinfo>
53 
54 namespace bpp
55 {
60 {
61 public:
62  static const DNA DNA_ALPHABET;
63  static const RNA RNA_ALPHABET;
66 
67 public:
69  virtual ~AlphabetTools() {}
70 
71 public:
89  static int getType(char state);
90 
99  static bool checkAlphabetCodingSize(const Alphabet& alphabet) throw (AlphabetException);
100 
110  static bool checkAlphabetCodingSize(const Alphabet* alphabet) throw (AlphabetException);
111 
119  static unsigned int getAlphabetCodingSize(const Alphabet& alphabet) throw (AlphabetException);
120 
131  static unsigned int getAlphabetCodingSize(const Alphabet* alphabet) throw (AlphabetException);
132 
137  static bool isNucleicAlphabet(const Alphabet* alphabet) { return alphabetInheritsFrom<NucleicAlphabet>(alphabet); }
138 
143  static bool isDNAAlphabet(const Alphabet* alphabet) { return alphabetInheritsFrom<DNA>(alphabet); }
144 
149  static bool isRNAAlphabet(const Alphabet* alphabet) { return alphabetInheritsFrom<RNA>(alphabet); }
150 
155  static bool isProteicAlphabet(const Alphabet* alphabet) { return alphabetInheritsFrom<ProteicAlphabet>(alphabet); }
156 
161  static bool isCodonAlphabet(const Alphabet* alphabet) { return alphabetInheritsFrom<CodonAlphabet>(alphabet); }
162 
167  static bool isWordAlphabet(const Alphabet* alphabet) { return alphabetInheritsFrom<WordAlphabet>(alphabet); }
168 
173  static bool isRNYAlphabet(const Alphabet* alphabet) { return alphabetInheritsFrom<RNY>(alphabet); }
174 
179  static bool isBinaryAlphabet(const Alphabet* alphabet) { return alphabetInheritsFrom<BinaryAlphabet>(alphabet); }
180 
185  static bool isDefaultAlphabet(const Alphabet* alphabet) { return alphabetInheritsFrom<DefaultAlphabet>(alphabet); }
186 
205  static bool match(const Alphabet* alphabet, int i, int j)
206  {
207  std::vector<int> a = alphabet->getAlias(i);
208  std::vector<int> b = alphabet->getAlias(j);
209  std::vector<int> u = VectorTools::vectorIntersection(a, b);
210  return u.size() > 0;
211  }
212 
213 private:
214  template<class Y>
215  static bool alphabetInheritsFrom(const Alphabet* alphabet)
216  {
217  try
218  {
219  const Y* t = dynamic_cast<const Y*>(alphabet);
220  return t != 0; // Solves strange behavior in new gcc?
221  }
222  catch (std::exception& e)
223  {
224  return false;
225  }
226  }
227 };
228 } // end of namespace bpp.
229 
230 #endif // _ALPHABETTOOLS_H_
231