52 )
throw (AlphabetException, Exception)
55 if (model->getAlphabet()->getAlphabetType() != rootFreqs->getAlphabet()->getAlphabetType())
56 throw AlphabetMismatchException(
"SubstitutionModelSetTools::createHomogeneousModelSet()", model->getAlphabet(), rootFreqs->getAlphabet());
57 if (dynamic_cast<MixedSubstitutionModel*>(model) != NULL)
58 throw Exception(
"createHomogeneousModelSet non yet programmed for mixture models.");
64 vector<int> ids = tree->getNodesId();
65 int rootId = tree->getRootId();
67 for (
unsigned int i = 0; i < ids.size(); i++)
75 ids.erase(ids.begin() + pos);
85 const vector<string>& globalParameterNames
86 )
throw (AlphabetException, Exception)
89 if (rootFreqs && model->getAlphabet()->getAlphabetType() != rootFreqs->getAlphabet()->getAlphabetType())
90 throw AlphabetMismatchException(
"SubstitutionModelSetTools::createNonHomogeneousModelSet()", model->getAlphabet(), rootFreqs->getAlphabet());
91 ParameterList globalParameters, branchParameters;
92 globalParameters = model->getParameters();
94 vector<string> globalParameterNames2;
99 for (i = 0; i < globalParameterNames.size(); i++)
101 if (globalParameterNames[i].find(
"*") != string::npos)
103 for (j = 0; j < globalParameters.size(); j++)
105 StringTokenizer stj(globalParameterNames[i],
"*",
true,
false);
107 string parn = globalParameters[j].getName();
109 string g = stj.nextToken();
114 while (flag && stj.hasMoreToken())
117 pos2 = parn.find(g, pos1);
118 if (pos2 == string::npos)
123 pos1 = pos2 + g.length();
126 ((g.length() == 0) || (pos1 == parn.length()) || (parn.rfind(g) == parn.length() - g.length())))
127 globalParameterNames2.push_back(parn);
130 else if (!globalParameters.hasParameter(globalParameterNames[i]))
131 throw Exception(
"SubstitutionModelSetTools::createNonHomogeneousModelSet. Parameter '" + globalParameterNames[i] +
"' is not valid.");
133 globalParameterNames2.push_back(globalParameterNames[i]);
137 for (i = globalParameters.size(); i > 0; i--)
139 if (find(globalParameterNames2.begin(), globalParameterNames2.end(), globalParameters[i - 1].getName()) == globalParameterNames2.end())
142 branchParameters.addParameter(globalParameters[i - 1]);
143 globalParameters.deleteParameter(i - 1);
153 for (i = branchParameters.size(); i > 0; i--)
155 if (branchParameters[i - 1].getName().find(
"relproba") != string::npos)
157 globalParameters.addParameter(branchParameters[i - 1]);
158 branchParameters.deleteParameter(i - 1);
169 vector<int> ids = tree->getNodesId();
170 int rootId = tree->getRootId();
172 for (i = 0; i < ids.size(); i++)
174 if (ids[i] == rootId)
181 ids.erase(ids.begin() +
static_cast<ptrdiff_t
>(pos));
182 for (i = 0; i < ids.size(); i++)
184 modelSet->
addModel(dynamic_cast<SubstitutionModel*>(model->clone()), vector<int>(1, ids[i]));
188 for (i=0; i < globalParameters.size(); i++)
190 string pname=globalParameters[i].getName();
192 for (
size_t nn = 1; nn < ids.size(); nn++)
193 modelSet->aliasParameters(pname+
"_1",pname+
"_"+TextTools::toString(nn+1));
203 for (i = 0; i < nbm; i++)
206 for (j = 0; j < ids.size(); j++)
Substitution models manager for non-homogeneous / non-reversible models of evolution.
Interface for all substitution models.
void computeHyperNodesProbabilities()
void setRootFrequencies(FrequenciesSet *rootFreqs)
Sets a given FrequenciesSet for root frequencies.
Interface for phylogenetic tree objects.
Parametrize a set of state frequencies.
void addModel(SubstitutionModel *model, const std::vector< int > &nodesId)
Add a new model to the set, and set relationships with nodes and params.
void addToHyperNode(size_t nM, const Vint &vnS, int nH=-1)
Substitution models manager for Mixed Substitution Models. This class inherits from SubstitutionModel...
virtual size_t getNumberOfModels() const =0
Interface for Substitution models, defined as a mixture of "simple" substitution models.