bpp-phyl  2.2.0
SubstitutionModelFactory.cpp
Go to the documentation of this file.
1 //
2 // File: SubstitutionModelFactory.cpp
3 // Created by: Julien Dutheil
4 // Vincent Ranwez
5 // Created on: Fri apr 14 11:11 2006
6 //
7 
8 /*
9 Copyright or © or Copr. Bio++ Development Team, (November 16, 2004, 2005, 2006)
10 
11 This software is a computer program whose purpose is to provide classes
12 for phylogenetic data 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 
43 #include "Protein/JCprot.h"
44 #include "Nucleotide/K80.h"
45 #include "Nucleotide/T92.h"
46 #include "Nucleotide/L95.h"
47 #include "Nucleotide/F84.h"
48 #include "Nucleotide/TN93.h"
49 #include "Nucleotide/HKY85.h"
50 #include "Nucleotide/GTR.h"
51 #include "Nucleotide/SSR.h"
52 #include "Protein/JTT92.h"
53 #include "Protein/DSO78.h"
54 #include "Protein/WAG01.h"
55 #include "Protein/LG08.h"
56 
57 // From bpp-seq:
58 #include <Bpp/Seq/Alphabet/AlphabetTools.h>
59 
60 using namespace bpp;
61 
62 // From the STL:
63 #include <algorithm>
64 
65 using namespace std;
66 
67 const string SubstitutionModelFactory::JUKES_CANTOR = "JC69";
68 const string SubstitutionModelFactory::KIMURA_2P = "K80";
70 const string SubstitutionModelFactory::TAMURA_NEI = "TN93";
73 const string SubstitutionModelFactory::TAMURA = "T92";
74 const string SubstitutionModelFactory::LOBRY = "L95";
75 const string SubstitutionModelFactory::FELSENSTEIN = "F84";
79 const string SubstitutionModelFactory::LE_GASCUEL = "LG08";
80 
81 SubstitutionModel* SubstitutionModelFactory::createModel(const string& modelName) const throw (AlphabetException, Exception)
82 {
83  if (modelName == JUKES_CANTOR)
84  {
85  if (AlphabetTools::isNucleicAlphabet(alphabet_))
86  return new JCnuc(dynamic_cast<const NucleicAlphabet *>(alphabet_));
87  else
88  return new JCprot(dynamic_cast<const ProteicAlphabet *>(alphabet_));
89  }
90  else if(modelName == KIMURA_2P)
91  {
92  try {
93  return new K80(dynamic_cast<const NucleicAlphabet *>(alphabet_));
94  } catch(Exception & e) {
95  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). K80 model requires a nucleotide alphabet.", alphabet_);
96  }
97  }
98  else if(modelName == TAMURA)
99  {
100  try {
101  return new T92(dynamic_cast<const NucleicAlphabet *>(alphabet_));
102  } catch(Exception & e) {
103  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). T92 model requires a nucleotide alphabet.", alphabet_);
104  }
105  }
106  else if(modelName == LOBRY)
107  {
108  try {
109  return new L95(dynamic_cast<const NucleicAlphabet *>(alphabet_));
110  } catch(Exception & e) {
111  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). L95 model requires a nucleotide alphabet.", alphabet_);
112  }
113  }
114  else if(modelName == FELSENSTEIN)
115  {
116  try {
117  return new F84(dynamic_cast<const NucleicAlphabet *>(alphabet_));
118  } catch(Exception & e) {
119  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). T92 model requires a nucleotide alphabet.", alphabet_);
120  }
121  }
122  else if(modelName == TAMURA_NEI)
123  {
124  try {
125  return new TN93(dynamic_cast<const NucleicAlphabet *>(alphabet_));
126  } catch(Exception & e) {
127  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). TN93 model requires a nucleotide alphabet.", alphabet_);
128  }
129  }
130  else if(modelName == HASEGAWA_KISHINO_YANO)
131  {
132  try {
133  return new HKY85(dynamic_cast<const NucleicAlphabet *>(alphabet_));
134  } catch(Exception & e) {
135  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). HKY85 model requires a nucleotide alphabet.", alphabet_);
136  }
137  }
138  else if(modelName == GENERAL_TIME_REVERSIBLE)
139  {
140  try {
141  return new GTR(dynamic_cast<const NucleicAlphabet *>(alphabet_));
142  } catch(Exception & e) {
143  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). GTR model requires a nucleotide alphabet.", alphabet_);
144  }
145  }
146  else if(modelName == STRAND_SYMMETRIC_REVERSIBLE)
147  {
148  try {
149  return new SSR(dynamic_cast<const NucleicAlphabet *>(alphabet_));
150  } catch(Exception & e) {
151  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). SSR model requires a nucleotide alphabet.", alphabet_);
152  }
153  }
154  else if(modelName == JOHN_TAYLOR_THORNTON)
155  {
156  try {
157  return new JTT92(dynamic_cast<const ProteicAlphabet *>(alphabet_));
158  } catch(Exception & e) {
159  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). JTT92 model requires a protein alphabet.", alphabet_);
160  }
161  }
162  else if(modelName == DAYHOFF_SCHWARTZ_ORCUTT)
163  {
164  try {
165  return new DSO78(dynamic_cast<const ProteicAlphabet *>(alphabet_));
166  } catch(Exception & e) {
167  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). DSO78 model requires a protein alphabet.", alphabet_);
168  }
169  }
170  else if(modelName == WHELAN_AND_GOLDMAN)
171  {
172  try {
173  return new WAG01(dynamic_cast<const ProteicAlphabet *>(alphabet_));
174  } catch(Exception & e) {
175  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). WAG01 model requires a protein alphabet.", alphabet_);
176  }
177  }
178  else if(modelName == LE_GASCUEL)
179  {
180  try {
181  return new LG08(dynamic_cast<const ProteicAlphabet *>(alphabet_));
182  } catch(Exception & e) {
183  throw AlphabetException("SubstitutionModelFactory::createInstanceOf(). LE08 model requires a protein alphabet.", alphabet_);
184  }
185  }
186  else throw Exception("SubstitutionModelFactory::createModel(). Unknown model: " + modelName);
187 }
188 
The no-strand bias substitution model for nucleotides, from Lobry 1995. The point of this model is th...
Definition: L95.h:93
Interface for all substitution models.
The Jukes-Cantor substitution model for proteins.
Definition: JCprot.h:134
static const std::string JUKES_CANTOR
The Strand Symmetric Reversible substitution model for nucleotides.
Definition: SSR.h:98
The Whelan and Goldman substitution model for proteins.
Definition: WAG01.h:71
static const std::string KIMURA_2P
STL namespace.
The Le and Gascuel substitution model for proteins.
Definition: LG08.h:64
The Kimura 2-rates substitution model for nucleotides.
Definition: K80.h:150
static const std::string FELSENSTEIN
The Tamura (1992) substitution model for nucleotides.
Definition: T92.h:159
virtual SubstitutionModel * createModel(const std::string &modelName) const
Get a new dynamically created SubstitutionModel object.
The Tamura and Nei (1993) substitution model for nucleotides.
Definition: TN93.h:130
The Hasegawa M, Kishino H and Yano T (1985) substitution model for nucleotides.
Definition: HKY85.h:179
static const std::string LE_GASCUEL
static const std::string HASEGAWA_KISHINO_YANO
The General Time-Reversible substitution model for nucleotides.
Definition: GTR.h:138
The Jones, Taylor and Thornton substitution model for proteins.
Definition: JTT92.h:66
static const std::string DAYHOFF_SCHWARTZ_ORCUTT
static const std::string WHELAN_AND_GOLDMAN
static const std::string JOHN_TAYLOR_THORNTON
static const std::string STRAND_SYMMETRIC_REVERSIBLE
The Jukes-Cantor substitution model for nucleotides.
Definition: JCnuc.h:129
The Felsenstein (1984) substitution model for nucleotides.
Definition: F84.h:178
static const std::string GENERAL_TIME_REVERSIBLE
The Dayhoff, Schwartz and Orcutt substitution model for proteins.
Definition: DSO78.h:66
static const std::string TAMURA_NEI