42 #include "../Model/SubstitutionModel.h" 43 #include "../Model/Protein/Coala.h" 44 #include "../Model/FrequenciesSet/MvaFrequenciesSet.h" 45 #include "../Likelihood/TreeLikelihood.h" 46 #include "../Mapping/LaplaceSubstitutionCount.h" 47 #include "../Mapping/UniformizationSubstitutionCount.h" 48 #include "../Mapping/DecompositionSubstitutionCount.h" 49 #include "../Mapping/NaiveSubstitutionCount.h" 50 #include "../Mapping/OneJumpSubstitutionCount.h" 51 #include "../OptimizationTools.h" 53 #include "../Io/Newick.h" 54 #include "../Io/NexusIoTree.h" 55 #include "../Io/Nhx.h" 56 #include "../Io/BppOSubstitutionModelFormat.h" 57 #include "../Io/BppOFrequenciesSetFormat.h" 58 #include "../Io/BppORateDistributionFormat.h" 61 #include <Bpp/Io/BppODiscreteDistributionFormat.h> 62 #include <Bpp/Io/BppOParametrizableFormat.h> 63 #include <Bpp/Io/FileTools.h> 64 #include <Bpp/Text/TextTools.h> 65 #include <Bpp/App/ApplicationTools.h> 66 #include <Bpp/Text/StringTokenizer.h> 67 #include <Bpp/Text/KeyvalTools.h> 68 #include <Bpp/Numeric/AutoParameter.h> 69 #include <Bpp/Numeric/Prob/DirichletDiscreteDistribution.h> 70 #include <Bpp/Numeric/Function/DownhillSimplexMethod.h> 71 #include <Bpp/Numeric/Function/PowellMultiDimensions.h> 74 #include <Bpp/Seq/Alphabet/AlphabetTools.h> 75 #include <Bpp/Seq/Container/SequenceContainerTools.h> 76 #include <Bpp/Seq/App/SequenceApplicationTools.h> 97 map<string, string>& params,
100 bool suffixIsOptional,
102 int warn)
throw (Exception)
104 string format = ApplicationTools::getStringParameter(prefix +
"tree.format", params,
"Newick", suffix, suffixIsOptional, warn);
105 string treeFilePath = ApplicationTools::getAFilePath(prefix +
"tree.file", params,
true,
true, suffix, suffixIsOptional,
"none", warn);
108 if (format ==
"Newick")
109 treeReader =
new Newick(
true);
110 else if (format ==
"Nexus")
112 else if (format ==
"NHX")
113 treeReader =
new Nhx();
115 throw Exception(
"Unknow format for tree reading: " + format);
116 Tree* tree = treeReader->
read(treeFilePath);
120 ApplicationTools::displayResult(
"Tree file", treeFilePath);
127 map<string, string>& params,
128 const string& prefix,
129 const string& suffix,
130 bool suffixIsOptional,
132 int warn)
throw (Exception)
134 string format = ApplicationTools::getStringParameter(prefix +
"trees.format", params,
"Newick", suffix, suffixIsOptional, warn);
135 string treeFilePath = ApplicationTools::getAFilePath(prefix +
"trees.file", params,
true,
true, suffix, suffixIsOptional,
"none", warn);
138 if (format ==
"Newick")
139 treeReader =
new Newick(
true);
140 else if (format ==
"Nexus")
142 else if (format ==
"NHX")
143 treeReader =
new Nhx();
145 throw Exception(
"Unknow format for tree reading: " + format);
147 treeReader->
read(treeFilePath, trees);
152 ApplicationTools::displayResult(
"Tree file", treeFilePath);
153 ApplicationTools::displayResult(
"Number of trees in file", trees.size());
166 const Alphabet* alphabet,
167 const GeneticCode* gCode,
168 const SiteContainer* data,
169 std::map<std::string, std::string>& params,
170 const string& suffix,
171 bool suffixIsOptional,
173 int warn)
throw (Exception)
176 string modelDescription;
177 const CodonAlphabet* ca =
dynamic_cast<const CodonAlphabet*
>(alphabet);
179 modelDescription = ApplicationTools::getStringParameter(
"model", params,
"CodonRate(model=JC69)", suffix, suffixIsOptional, warn);
181 throw Exception(
"PhylogeneticsApplicationTools::getSubstitutionModel(): a GeneticCode instance is required for instanciating a codon model.");
183 }
else if (AlphabetTools::isWordAlphabet(alphabet))
184 modelDescription = ApplicationTools::getStringParameter(
"model", params,
"Word(model=JC69)", suffix, suffixIsOptional, warn);
186 modelDescription = ApplicationTools::getStringParameter(
"model", params,
"JC69", suffix, suffixIsOptional, warn);
196 std::map<std::string, std::string>& unparsedParameterValues,
198 const SiteContainer* data,
199 std::map<std::string, double>& existingParams,
200 std::map<std::string, std::string>& sharedParams,
201 bool verbose)
throw (Exception)
203 string initFreqs = ApplicationTools::getStringParameter(model.getNamespace() +
"initFreqs", unparsedParameterValues,
"",
"",
true,
false);
206 ApplicationTools::displayResult(
"Frequencies Initialization for model", (initFreqs ==
"") ?
"None" : initFreqs);
210 if (initFreqs ==
"observed")
213 throw Exception(
"Missing data for observed frequencies");
214 unsigned int psi = ApplicationTools::getParameter<unsigned int>(model.getNamespace() +
"initFreqs.observedPseudoCount", unparsedParameterValues, 0);
215 model.setFreqFromData(*data, psi);
217 else if (initFreqs.substr(0, 6) ==
"values")
220 map<int, double> frequencies;
222 string rf = initFreqs.substr(6);
223 StringTokenizer strtok(rf.substr(1, rf.length() - 2),
",");
225 while (strtok.hasMoreToken())
226 frequencies[i++] = TextTools::toDouble(strtok.nextToken());
227 model.setFreq(frequencies);
230 throw Exception(
"Unknown initFreqs argument");
235 ParameterList pl = model.getIndependentParameters();
236 for (
size_t i = 0; i < pl.size(); ++i)
238 AutoParameter ap(pl[i]);
239 ap.setMessageHandler(ApplicationTools::warning);
240 pl.setParameter(i, ap);
243 for (
size_t i = 0; i < pl.size(); ++i)
245 const string pName = pl[i].getName();
246 size_t posp = model.getParameterNameWithoutNamespace(pName).rfind(
".");
248 bool test1 = (initFreqs ==
"");
249 bool test2 = (model.getParameterNameWithoutNamespace(pName).substr(posp + 1, 5) !=
"theta");
250 bool test3 = (unparsedParameterValues.find(pName) != unparsedParameterValues.end());
251 if (test1 || test2 || test3)
253 if (!test1 && !test2 && test3)
254 ApplicationTools::displayWarning(
"Warning, initFreqs argument is set and a value is set for parameter " + pName);
255 value = ApplicationTools::getStringParameter(pName, unparsedParameterValues, TextTools::toString(pl[i].getValue()));
256 if (value.rfind(
"_")!=string::npos)
258 if (existingParams.find(value) != existingParams.end())
260 pl[i].setValue(existingParams[value]);
261 sharedParams[pl[i].getName()+
"_"+TextTools::toString(modelNumber)]=value;
264 throw Exception(
"Error, unknown parameter " + value);
267 pl[i].setValue(TextTools::toDouble(value));
270 existingParams[pName+
"_"+TextTools::toString(modelNumber)] = pl[i].getValue();
273 ApplicationTools::displayResult(
"Parameter found", pName + +
"_"+TextTools::toString(modelNumber) +
"=" + TextTools::toString(pl[i].getValue()));
276 model.matchParametersValues(pl);
287 const Alphabet* alphabet,
288 const GeneticCode* gCode,
289 const SiteContainer* data,
290 std::map<std::string, std::string>& params,
291 const std::vector<double>& rateFreqs,
292 const std::string& suffix,
293 bool suffixIsOptional,
295 int warn)
throw (Exception)
297 string freqDescription = ApplicationTools::getStringParameter(
"nonhomogeneous.root_freq", params,
"Full(init=observed)", suffix, suffixIsOptional, warn);
298 if (freqDescription ==
"None")
304 FrequenciesSet* freq = getFrequenciesSet(alphabet, gCode, freqDescription, data, rateFreqs, verbose, warn + 1);
306 ApplicationTools::displayResult(
"Root frequencies ", freq->
getName());
314 const Alphabet* alphabet,
315 const GeneticCode* gCode,
316 const std::string& freqDescription,
317 const SiteContainer* data,
318 const std::vector<double>& rateFreqs,
320 int warn)
throw (Exception)
322 map<string, string> unparsedParameterValues;
324 if (AlphabetTools::isCodonAlphabet(alphabet)) {
326 throw Exception(
"PhylogeneticsApplicationTools::getFrequenciesSet(): a GeneticCode instance is required for instanciating a codon frequencies set.");
329 auto_ptr<FrequenciesSet> pFS(bIO.
read(alphabet, freqDescription, data,
true));
332 if (rateFreqs.size() > 0)
337 return pFS.release();
347 const Alphabet* alphabet,
348 const GeneticCode* gCode,
349 const SiteContainer* data,
350 std::map<std::string, std::string>& params,
351 const std::string& suffix,
352 bool suffixIsOptional,
356 if (!ApplicationTools::parameterExists(
"nonhomogeneous.number_of_models", params))
357 throw Exception(
"A value is needed for this parameter: nonhomogeneous.number_of_models .");
358 size_t nbModels = ApplicationTools::getParameter<size_t>(
"nonhomogeneous.number_of_models", params, 1, suffix, suffixIsOptional, warn);
360 throw Exception(
"The number of models can't be 0 !");
363 for (
size_t i = 0; nomix &(i < nbModels); i++)
365 string prefix =
"model" + TextTools::toString(i + 1);
367 modelDesc = ApplicationTools::getStringParameter(prefix, params,
"", suffix, suffixIsOptional, warn);
369 if (modelDesc.find(
"Mixed") != string::npos)
375 setSubstitutionModelSet(*modelSet1, alphabet, gCode, data, params, suffix, suffixIsOptional, verbose, warn);
380 completeMixedSubstitutionModelSet(*dynamic_cast<MixedSubstitutionModelSet*>(modelSet), alphabet, data, params, suffix, suffixIsOptional, verbose);
383 modelSet = modelSet1;
392 const Alphabet* alphabet,
393 const GeneticCode* gCode,
394 const SiteContainer* data,
395 map<string, string>& params,
396 const string& suffix,
397 bool suffixIsOptional,
402 if (!ApplicationTools::parameterExists(
"nonhomogeneous.number_of_models", params))
403 throw Exception(
"You must specify this parameter: 'nonhomogeneous.number_of_models'.");
404 size_t nbModels = ApplicationTools::getParameter<size_t>(
"nonhomogeneous.number_of_models", params, 1, suffix, suffixIsOptional, warn);
406 throw Exception(
"The number of models can't be 0 !");
409 ApplicationTools::displayResult(
"Number of distinct models", TextTools::toString(nbModels));
416 vector<double> rateFreqs;
418 if (AlphabetTools::isCodonAlphabet(alphabet)) {
420 throw Exception(
"PhylogeneticsApplicationTools::setSubstitutionModelSet(): a GeneticCode instance is required for instanciating a codon model.");
422 tmpDesc = ApplicationTools::getStringParameter(
"model1", params,
"CodonRate(model=JC69)", suffix, suffixIsOptional, warn);
423 }
else if (AlphabetTools::isWordAlphabet(alphabet))
424 tmpDesc = ApplicationTools::getStringParameter(
"model1", params,
"Word(model=JC69)", suffix, suffixIsOptional, warn);
426 tmpDesc = ApplicationTools::getStringParameter(
"model1", params,
"JC69", suffix, suffixIsOptional, warn);
428 auto_ptr<SubstitutionModel> tmp(bIO.
read(alphabet, tmpDesc, data,
false));
431 if (tmp->getNumberOfStates() != alphabet->getSize())
434 size_t n =
static_cast<size_t>(tmp->getNumberOfStates() / alphabet->getSize());
435 rateFreqs = vector<double>(n, 1. /
static_cast<double>(n));
441 bool stationarity = ApplicationTools::getBooleanParameter(
"nonhomogeneous.stationarity", params,
false,
"",
true, warn);
445 rootFrequencies = getRootFrequenciesSet(alphabet, gCode, data, params, rateFreqs, suffix, suffixIsOptional, verbose);
446 stationarity = !rootFrequencies;
447 string freqDescription = ApplicationTools::getStringParameter(
"nonhomogeneous.root_freq", params,
"", suffix, suffixIsOptional, warn);
448 if (freqDescription.substr(0, 10) ==
"MVAprotein")
450 if (dynamic_cast<Coala*>(tmp.get()))
451 dynamic_cast<MvaFrequenciesSet*
>(rootFrequencies)->initSet(dynamic_cast<CoalaCore*>(tmp.get()));
453 throw Exception(
"The MVAprotein frequencies set at the root can only be used if a Coala model is used on branches.");
456 ApplicationTools::displayBooleanResult(
"Stationarity assumed", stationarity);
466 map<string, double> existingParameters;
468 for (
size_t i = 0; i < nbModels; i++)
470 string prefix =
"model" + TextTools::toString(i + 1);
472 if (AlphabetTools::isCodonAlphabet(alphabet))
473 modelDesc = ApplicationTools::getStringParameter(prefix, params,
"CodonRate(model=JC69)", suffix, suffixIsOptional, warn);
474 else if (AlphabetTools::isWordAlphabet(alphabet))
475 modelDesc = ApplicationTools::getStringParameter(prefix, params,
"Word(model=JC69)", suffix, suffixIsOptional, warn);
477 modelDesc = ApplicationTools::getStringParameter(prefix, params,
"JC69", suffix, suffixIsOptional, warn);
479 auto_ptr<SubstitutionModel> model(bIO.
read(alphabet, modelDesc, data,
false));
482 map<string, string> sharedParameters;
483 setSubstitutionModelParametersInitialValuesWithAliases(
485 unparsedParameterValues, i+1, data,
486 existingParameters, sharedParameters,
489 vector<int> nodesId = ApplicationTools::getVectorParameter<int>(prefix +
".nodes_id", params,
',',
':', TextTools::toString(i), suffix, suffixIsOptional, warn);
492 ApplicationTools::displayResult(
"Model" + TextTools::toString(i + 1) +
" is associated to", TextTools::toString(nodesId.size()) +
" node(s).");
494 modelSet.
addModel(model.get(), nodesId);
497 map<string, string>::const_iterator it;
498 for (it=sharedParameters.begin(); it!=sharedParameters.end(); it++)
499 modelSet.aliasParameters(it->second, it->first);
505 string aliasDesc = ApplicationTools::getStringParameter(
"nonhomogeneous.alias", params,
"", suffix, suffixIsOptional, warn);
506 StringTokenizer st(aliasDesc,
",");
507 while (st.hasMoreToken())
509 string alias = st.nextToken();
510 string::size_type index = alias.find(
"->");
511 if (index == string::npos)
512 throw Exception(
"PhylogeneticsApplicationTools::getSubstitutionModelSet. Bad alias syntax, should contain `->' symbol: " + alias);
513 string p1 = alias.substr(0, index);
514 string p2 = alias.substr(index + 2);
515 ApplicationTools::displayResult(
"Parameter alias found", p1 +
"->" + p2);
516 modelSet.aliasParameters(p1, p2);
523 const Alphabet* alphabet,
524 const SiteContainer* data,
525 map<string, string>& params,
526 const string& suffix,
527 bool suffixIsOptional,
535 if (!ApplicationTools::parameterExists(
"site.number_of_paths", params))
538 numd = ApplicationTools::getParameter<size_t>(
"site.number_of_paths", params, 1, suffix, suffixIsOptional, warn);
541 ApplicationTools::displayResult(
"Number of distinct paths", TextTools::toString(numd));
543 vector<string> vdesc;
546 string desc = ApplicationTools::getStringParameter(
"site.path" + TextTools::toString(numd), params,
"", suffix, suffixIsOptional, warn);
547 if (desc.size() == 0)
550 vdesc.push_back(desc);
554 if (vdesc.size() == 0)
561 for (vector<string>::iterator it(vdesc.begin()); it != vdesc.end(); it++)
564 StringTokenizer st(*it,
"&");
565 while (st.hasMoreToken())
567 string submodel = st.nextToken();
568 string::size_type indexo = submodel.find(
"[");
569 string::size_type indexf = submodel.find(
"]");
570 if ((indexo == string::npos) | (indexf == string::npos))
571 throw Exception(
"PhylogeneticsApplicationTools::setMixedSubstitutionModelSet. Bad path syntax, should contain `[]' symbols: " + submodel);
572 size_t num = TextTools::to<size_t>(submodel.substr(5, indexo - 5));
573 string p2 = submodel.substr(indexo + 1, indexf - indexo - 1);
577 throw BadIntegerException(
"PhylogeneticsApplicationTools::setMixedSubstitutionModelSet: Wrong model for number", static_cast<int>(num - 1));
584 throw Exception(
"A path should own at least a submodel of each mixed model: " + *it);
587 ApplicationTools::displayResult(
"Site Path", *it);
592 throw Exception(
"All paths must be disjoint.");
596 st = (mixedModelSet.
complete()) ?
"Yes" :
"No";
599 ApplicationTools::displayResult(
"Site Path Completion", st);
604 throw Exception(
"The remaining submodels can not create a complete path.");
616 const std::string& distDescription,
617 std::map<std::string, std::string>& unparsedParameterValues,
621 MultipleDiscreteDistribution* pMDD = 0;
622 map<string, string> args;
623 KeyvalTools::parseProcedure(distDescription, distName, args);
625 if (distName ==
"Dirichlet")
627 if (args.find(
"classes") == args.end())
628 throw Exception(
"Missing argument 'classes' (vector of number of classes) in " + distName
630 if (args.find(
"alphas") == args.end())
631 throw Exception(
"Missing argument 'alphas' (vector of Dirichlet shape parameters) in Dirichlet distribution");
632 vector<double> alphas;
633 vector<size_t> classes;
635 string rf = args[
"alphas"];
636 StringTokenizer strtok(rf.substr(1, rf.length() - 2),
",");
637 while (strtok.hasMoreToken())
638 alphas.push_back(TextTools::toDouble(strtok.nextToken()));
640 rf = args[
"classes"];
641 StringTokenizer strtok2(rf.substr(1, rf.length() - 2),
",");
642 while (strtok2.hasMoreToken())
643 classes.push_back(TextTools::to<size_t>(strtok2.nextToken()));
645 pMDD =
new DirichletDiscreteDistribution(classes, alphas);
646 vector<string> v = pMDD->getParameters().getParameterNames();
648 for (
size_t i = 0; i < v.size(); i++)
650 unparsedParameterValues[v[i]] = TextTools::toString(pMDD->getParameterValue(pMDD->getParameterNameWithoutNamespace(v[i])));
654 throw Exception(
"Unknown multiple distribution name: " + distName);
662 map<string, string>& params,
663 const string& suffix,
664 bool suffixIsOptional,
665 bool verbose)
throw (Exception)
667 string distDescription = ApplicationTools::getStringParameter(
"rate_distribution", params,
"Constant()", suffix, suffixIsOptional);
670 map<string, string> args;
671 KeyvalTools::parseProcedure(distDescription, distName, args);
674 auto_ptr<DiscreteDistribution> rDist(bIO.
read(distDescription,
true));
678 ApplicationTools::displayResult(
"Rate distribution", distName);
679 ApplicationTools::displayResult(
"Number of classes", TextTools::toString(rDist->getNumberOfCategories()));
682 return rDist.release();
694 const ParameterList& parameters,
695 std::map<std::string, std::string>& params,
696 const std::string& suffix,
697 bool suffixIsOptional,
702 string optimization = ApplicationTools::getStringParameter(
"optimization", params,
"FullD(derivatives=Newton)", suffix, suffixIsOptional, warn);
703 if (optimization ==
"None")
706 map<string, string> optArgs;
707 KeyvalTools::parseProcedure(optimization, optName, optArgs);
709 unsigned int optVerbose = ApplicationTools::getParameter<unsigned int>(
"optimization.verbose", params, 2, suffix, suffixIsOptional, warn + 1);
711 string mhPath = ApplicationTools::getAFilePath(
"optimization.message_handler", params,
false,
false, suffix, suffixIsOptional,
"none", warn + 1);
712 OutputStream* messageHandler =
713 (mhPath ==
"none") ? 0 :
714 (mhPath ==
"std") ? ApplicationTools::message :
715 new StlOutputStream(
new ofstream(mhPath.c_str(), ios::out));
717 ApplicationTools::displayResult(
"Message handler", mhPath);
719 string prPath = ApplicationTools::getAFilePath(
"optimization.profiler", params,
false,
false, suffix, suffixIsOptional,
"none", warn + 1);
720 OutputStream* profiler =
721 (prPath ==
"none") ? 0 :
722 (prPath ==
"std") ? ApplicationTools::message :
723 new StlOutputStream(
new ofstream(prPath.c_str(), ios::out));
725 profiler->setPrecision(20);
727 ApplicationTools::displayResult(
"Profiler", prPath);
729 bool scaleFirst = ApplicationTools::getBooleanParameter(
"optimization.scale_first", params,
false, suffix, suffixIsOptional, warn + 1);
734 ApplicationTools::displayMessage(
"Scaling the tree before optimizing each branch length separately.");
735 double tolerance = ApplicationTools::getDoubleParameter(
"optimization.scale_first.tolerance", params, .0001, suffix, suffixIsOptional, warn + 1);
737 ApplicationTools::displayResult(
"Scaling tolerance", TextTools::toString(tolerance));
738 unsigned int nbEvalMax = ApplicationTools::getParameter<unsigned int>(
"optimization.scale_first.max_number_f_eval", params, 1000000, suffix, suffixIsOptional, warn + 1);
740 ApplicationTools::displayResult(
"Scaling max # f eval", TextTools::toString(nbEvalMax));
748 ApplicationTools::displayResult(
"New tree likelihood", -tl->getValue());
752 ParameterList parametersToEstimate = parameters;
753 vector<string> parNames = parametersToEstimate.getParameterNames();
755 if (params.find(
"optimization.ignore_parameter") != params.end())
756 throw Exception(
"optimization.ignore_parameter is deprecated, use optimization.ignore_parameters instead!");
757 string paramListDesc = ApplicationTools::getStringParameter(
"optimization.ignore_parameters", params,
"", suffix, suffixIsOptional, warn + 1);
758 StringTokenizer st(paramListDesc,
",");
759 while (st.hasMoreToken())
763 string param = st.nextToken();
764 if (param ==
"BrLen")
766 vector<string> vs = tl->getBranchLengthsParameters().getParameterNames();
767 parametersToEstimate.deleteParameters(vs);
769 ApplicationTools::displayResult(
"Parameter ignored",
string(
"Branch lengths"));
771 else if (param ==
"Ancient")
775 ApplicationTools::displayWarning(
"The 'Ancient' parameters do not exist in homogeneous models, and will be ignored.");
779 parametersToEstimate.deleteParameters(vs);
782 ApplicationTools::displayResult(
"Parameter ignored",
string(
"Root frequencies"));
784 else if (param ==
"Model")
787 vector<string> vs1 = tl->getSubstitutionModelParameters().getParameterNames();
791 VectorTools::diff(vs1,vs2,vs);
796 parametersToEstimate.deleteParameters(vs);
798 ApplicationTools::displayResult(
"Parameter ignored",
string(
"Model"));
800 else if (param.find(
"*") != string::npos)
802 vector<string> vs=ApplicationTools::matchingParameters(param,parNames);
804 for (vector<string>::iterator it = vs.begin(); it != vs.end(); it++)
806 parametersToEstimate.deleteParameter(*it);
808 ApplicationTools::displayResult(
"Parameter ignored", *it);
813 parametersToEstimate.deleteParameter(param);
815 ApplicationTools::displayResult(
"Parameter ignored", param);
818 catch (ParameterNotFoundException& pnfe)
820 ApplicationTools::displayWarning(
"Parameter '" + pnfe.getParameter() +
"' not found, and so can't be ignored!");
825 vector<string> parToEstNames = parametersToEstimate.getParameterNames();
827 if (params.find(
"optimization.constrain_parameter") != params.end())
828 throw Exception(
"optimization.constrain_parameter is deprecated, use optimization.constrain_parameters instead!");
829 paramListDesc = ApplicationTools::getStringParameter(
"optimization.constrain_parameters", params,
"", suffix, suffixIsOptional, warn + 1);
831 string constraint=
"";
834 StringTokenizer st2(paramListDesc,
",");
835 while (st2.hasMoreToken())
839 pc = st2.nextToken();
840 string::size_type index = pc.find(
"=");
841 if (index == string::npos)
842 throw Exception(
"PhylogeneticsApplicationTools::optimizeParamaters. Bad constrain syntax, should contain `=' symbol: " + pc);
843 param = pc.substr(0, index);
844 constraint = pc.substr(index + 1);
845 IntervalConstraint ic(constraint);
847 vector<string> parNames2;
849 if (param ==
"BrLen")
850 parNames2 = tl->getBranchLengthsParameters().getParameterNames();
851 else if (param ==
"Ancient"){
854 ApplicationTools::displayWarning(
"The 'Ancient' parameters do not exist in homogeneous models, and will be ignored.");
858 ApplicationTools::displayResult(
"Parameter ignored",
string(
"Root frequencies"));
861 else if (param ==
"Model")
863 vector<string> vs1 = tl->getSubstitutionModelParameters().getParameterNames();
867 VectorTools::diff(vs1,vs2,parNames2);
872 else if (param.find(
"*") != string::npos)
873 parNames2=ApplicationTools::matchingParameters(param,parToEstNames);
875 parNames2.push_back(param);
878 for (
size_t i=0; i<parNames2.size(); i++)
880 Parameter& par=parametersToEstimate.getParameter(parNames2[i]);
881 if (par.hasConstraint()){
882 par.setConstraint(ic & (*par.getConstraint()),
true);
883 if (par.getConstraint()->isEmpty())
884 throw Exception(
"Empty interval for parameter " + parNames[i] + par.getConstraint()->getDescription());
887 par.setConstraint(ic.clone(),
true);
890 ApplicationTools::displayResult(
"Parameter constrained " + par.getName(), par.getConstraint()->getDescription());
893 catch (ParameterNotFoundException& pnfe)
895 ApplicationTools::displayWarning(
"Parameter '" + pnfe.getParameter() +
"' not found, and so can't be constrained!");
897 catch (ConstraintException& pnfe)
899 throw Exception(
"Parameter '" + param +
"' does not fit the constraint " + constraint);
907 unsigned int nbEvalMax = ApplicationTools::getParameter<unsigned int>(
"optimization.max_number_f_eval", params, 1000000, suffix, suffixIsOptional, warn + 1);
909 ApplicationTools::displayResult(
"Max # ML evaluations", TextTools::toString(nbEvalMax));
911 double tolerance = ApplicationTools::getDoubleParameter(
"optimization.tolerance", params, .000001, suffix, suffixIsOptional, warn + 1);
913 ApplicationTools::displayResult(
"Tolerance", TextTools::toString(tolerance));
916 auto_ptr<BackupListener> backupListener;
917 string backupFile = ApplicationTools::getAFilePath(
"optimization.backup.file", params,
false,
false, suffix, suffixIsOptional,
"none", warn + 1);
918 if (backupFile !=
"none")
920 ApplicationTools::displayResult(
"Parameters will be backup to", backupFile);
921 backupListener.reset(
new BackupListener(backupFile));
922 if (FileTools::fileExists(backupFile))
924 ApplicationTools::displayMessage(
"A backup file was found! Try to restore parameters from previous run...");
925 ifstream bck(backupFile.c_str(), ios::in);
926 vector<string> lines = FileTools::putStreamIntoVectorOfStrings(bck);
927 double fval = TextTools::toDouble(lines[0].substr(5));
928 ParameterList pl = tl->getParameters();
929 for (
size_t l = 1; l < lines.size(); ++l)
931 if (!TextTools::isEmpty(lines[l]))
933 StringTokenizer stp(lines[l],
"=");
934 if (stp.numberOfRemainingTokens() != 2)
936 cerr <<
"Corrupted backup file!!!" << endl;
937 cerr <<
"at line " << l <<
": " << lines[l] << endl;
939 string pname = stp.nextToken();
940 string pvalue = stp.nextToken();
941 size_t p = pl.whichParameterHasName(pname);
942 pl.setParameter(p, AutoParameter(pl[p]));
943 pl[p].setValue(TextTools::toDouble(pvalue));
947 tl->setParameters(pl);
948 if (abs(tl->getValue() - fval) > 0.000001)
949 throw Exception(
"Incorrect likelihood value after restoring, from backup file. Remove backup file and start from scratch :s");
950 ApplicationTools::displayResult(
"Restoring log-likelihood", -fval);
955 bool optimizeTopo = ApplicationTools::getBooleanParameter(
"optimization.topology", params,
false, suffix, suffixIsOptional, warn + 1);
957 ApplicationTools::displayResult(
"Optimize topology", optimizeTopo ?
"yes" :
"no");
958 string nniMethod = ApplicationTools::getStringParameter(
"optimization.topology.algorithm_nni.method", params,
"phyml", suffix, suffixIsOptional, warn + 1);
960 if (nniMethod ==
"fast")
964 else if (nniMethod ==
"better")
968 else if (nniMethod ==
"phyml")
973 throw Exception(
"Unknown NNI algorithm: '" + nniMethod +
"'.");
976 string order = ApplicationTools::getStringParameter(
"derivatives", optArgs,
"Newton",
"",
true, warn + 1);
977 string optMethodDeriv;
978 if (order ==
"Gradient")
982 else if (order ==
"Newton")
986 else if (order ==
"BFGS")
991 throw Exception(
"Unknown derivatives algorithm: '" + order +
"'.");
993 ApplicationTools::displayResult(
"Optimization method", optName);
995 ApplicationTools::displayResult(
"Algorithm used for derivable parameters", order);
998 bool reparam = ApplicationTools::getBooleanParameter(
"optimization.reparametrization", params,
false, suffix, suffixIsOptional, warn + 1);
1000 ApplicationTools::displayResult(
"Reparametrization", (reparam ?
"yes" :
"no"));
1003 string clock = ApplicationTools::getStringParameter(
"optimization.clock", params,
"None", suffix, suffixIsOptional, warn + 1);
1004 if (clock !=
"None" && clock !=
"Global")
1005 throw Exception(
"Molecular clock option not recognized, should be one of 'Global' or 'None'.");
1006 bool useClock = (clock ==
"Global");
1007 if (useClock && optimizeTopo)
1008 throw Exception(
"PhylogeneticsApplicationTools::optimizeParameters. Cannot optimize topology with a molecular clock.");
1010 ApplicationTools::displayResult(
"Molecular clock", clock);
1013 if ((optName ==
"D-Brent") || (optName ==
"D-BFGS"))
1016 string optMethodModel;
1017 if (optName ==
"D-Brent")
1022 unsigned int nstep = ApplicationTools::getParameter<unsigned int>(
"nstep", optArgs, 1,
"",
true, warn + 1);
1026 bool optNumFirst = ApplicationTools::getBooleanParameter(
"optimization.topology.numfirst", params,
true, suffix, suffixIsOptional, warn + 1);
1027 unsigned int topoNbStep = ApplicationTools::getParameter<unsigned int>(
"optimization.topology.nstep", params, 1, suffix, suffixIsOptional, warn + 1);
1028 double tolBefore = ApplicationTools::getDoubleParameter(
"optimization.topology.tolerance.before", params, 100, suffix, suffixIsOptional, warn + 1);
1029 double tolDuring = ApplicationTools::getDoubleParameter(
"optimization.topology.tolerance.during", params, 100, suffix, suffixIsOptional, warn + 1);
1031 dynamic_cast<NNIHomogeneousTreeLikelihood*>(tl), parametersToEstimate,
1032 optNumFirst, tolBefore, tolDuring, nbEvalMax, topoNbStep, messageHandler, profiler,
1033 reparam, optVerbose, optMethodDeriv, nstep, nniAlgo);
1036 if (verbose && nstep > 1)
1037 ApplicationTools::displayResult(
"# of precision steps", TextTools::toString(nstep));
1038 parametersToEstimate.matchParametersValues(tl->getParameters());
1040 dynamic_cast<DiscreteRatesAcrossSitesTreeLikelihood*>(tl), parametersToEstimate,
1041 backupListener.get(), nstep, tolerance, nbEvalMax, messageHandler, profiler, reparam, optVerbose, optMethodDeriv, optMethodModel);
1043 else if (optName ==
"FullD")
1049 bool optNumFirst = ApplicationTools::getBooleanParameter(
"optimization.topology.numfirst", params,
true, suffix, suffixIsOptional, warn + 1);
1050 unsigned int topoNbStep = ApplicationTools::getParameter<unsigned int>(
"optimization.topology.nstep", params, 1, suffix, suffixIsOptional, warn + 1);
1051 double tolBefore = ApplicationTools::getDoubleParameter(
"optimization.topology.tolerance.before", params, 100, suffix, suffixIsOptional, warn + 1);
1052 double tolDuring = ApplicationTools::getDoubleParameter(
"optimization.topology.tolerance.during", params, 100, suffix, suffixIsOptional, warn + 1);
1054 dynamic_cast<NNIHomogeneousTreeLikelihood*>(tl), parametersToEstimate,
1055 optNumFirst, tolBefore, tolDuring, nbEvalMax, topoNbStep, messageHandler, profiler,
1056 reparam, optVerbose, optMethodDeriv, nniAlgo);
1059 parametersToEstimate.matchParametersValues(tl->getParameters());
1061 dynamic_cast<DiscreteRatesAcrossSitesTreeLikelihood*>(tl), parametersToEstimate,
1062 backupListener.get(), tolerance, nbEvalMax, messageHandler, profiler, reparam, useClock, optVerbose, optMethodDeriv);
1065 throw Exception(
"Unknown optimization method: " + optName);
1067 string finalMethod = ApplicationTools::getStringParameter(
"optimization.final", params,
"none", suffix, suffixIsOptional, warn + 1);
1068 Optimizer* finalOptimizer = 0;
1069 if (finalMethod ==
"none")
1071 else if (finalMethod ==
"simplex")
1073 finalOptimizer =
new DownhillSimplexMethod(tl);
1075 else if (finalMethod ==
"powell")
1077 finalOptimizer =
new PowellMultiDimensions(tl);
1080 throw Exception(
"Unknown final optimization method: " + finalMethod);
1084 parametersToEstimate.matchParametersValues(tl->getParameters());
1086 ApplicationTools::displayResult(
"Final optimization step", finalMethod);
1087 finalOptimizer->setProfiler(profiler);
1088 finalOptimizer->setMessageHandler(messageHandler);
1089 finalOptimizer->setMaximumNumberOfEvaluations(nbEvalMax);
1090 finalOptimizer->getStopCondition()->setTolerance(tolerance);
1091 finalOptimizer->setVerbose(verbose);
1092 finalOptimizer->setConstraintPolicy(AutoParameter::CONSTRAINTS_AUTO);
1093 finalOptimizer->init(parametersToEstimate);
1094 finalOptimizer->optimize();
1095 n += finalOptimizer->getNumberOfEvaluations();
1096 delete finalOptimizer;
1100 ApplicationTools::displayResult(
"Performed", TextTools::toString(n) +
" function evaluations.");
1101 if (backupFile !=
"none")
1103 remove(backupFile.c_str());
1112 const ParameterList& parameters,
1113 map<string, string>& params,
1114 const string& suffix,
1115 bool suffixIsOptional,
1120 string optimization = ApplicationTools::getStringParameter(
"optimization", params,
"FullD(derivatives=Newton)", suffix, suffixIsOptional, warn);
1121 if (optimization ==
"None")
1124 map<string, string> optArgs;
1125 KeyvalTools::parseProcedure(optimization, optName, optArgs);
1127 unsigned int optVerbose = ApplicationTools::getParameter<unsigned int>(
"optimization.verbose", params, 2, suffix, suffixIsOptional, warn + 1);
1129 string mhPath = ApplicationTools::getAFilePath(
"optimization.message_handler", params,
false,
false, suffix, suffixIsOptional,
"none", warn + 1);
1130 OutputStream* messageHandler =
1131 (mhPath ==
"none") ? 0 :
1132 (mhPath ==
"std") ? ApplicationTools::message :
1133 new StlOutputStream(
new ofstream(mhPath.c_str(), ios::out));
1135 ApplicationTools::displayResult(
"Message handler", mhPath);
1137 string prPath = ApplicationTools::getAFilePath(
"optimization.profiler", params,
false,
false, suffix, suffixIsOptional,
"none", warn + 1);
1138 OutputStream* profiler =
1139 (prPath ==
"none") ? 0 :
1140 (prPath ==
"std") ? ApplicationTools::message :
1141 new StlOutputStream(
new ofstream(prPath.c_str(), ios::out));
1143 profiler->setPrecision(20);
1145 ApplicationTools::displayResult(
"Profiler", prPath);
1147 ParameterList parametersToEstimate = parameters;
1150 if (params.find(
"optimization.ignore_parameter") != params.end())
1151 throw Exception(
"optimization.ignore_parameter is deprecated, use optimization.ignore_parameters instead!");
1152 string paramListDesc = ApplicationTools::getStringParameter(
"optimization.ignore_parameters", params,
"", suffix, suffixIsOptional, warn + 1);
1153 StringTokenizer st(paramListDesc,
",");
1154 while (st.hasMoreToken())
1158 string param = st.nextToken();
1159 if (param ==
"BrLen")
1161 vector<string> vs = tl->getBranchLengthsParameters().getParameterNames();
1162 parametersToEstimate.deleteParameters(vs);
1164 ApplicationTools::displayResult(
"Parameter ignored",
string(
"Branch lengths"));
1166 else if (param ==
"Ancient")
1170 ApplicationTools::displayWarning(
"The 'Ancient' parameters do not exist in homogeneous models, and will be ignored.");
1174 parametersToEstimate.deleteParameters(vs);
1177 ApplicationTools::displayResult(
"Parameter ignored",
string(
"Root frequencies"));
1181 parametersToEstimate.deleteParameter(param);
1183 ApplicationTools::displayResult(
"Parameter ignored", param);
1186 catch (ParameterNotFoundException& pnfe)
1188 ApplicationTools::displayError(
"Parameter '" + pnfe.getParameter() +
"' not found, and so can't be ignored!");
1192 unsigned int nbEvalMax = ApplicationTools::getParameter<unsigned int>(
"optimization.max_number_f_eval", params, 1000000, suffix, suffixIsOptional, warn + 1);
1194 ApplicationTools::displayResult(
"Max # ML evaluations", TextTools::toString(nbEvalMax));
1196 double tolerance = ApplicationTools::getDoubleParameter(
"optimization.tolerance", params, .000001, suffix, suffixIsOptional, warn + 1);
1198 ApplicationTools::displayResult(
"Tolerance", TextTools::toString(tolerance));
1200 string order = ApplicationTools::getStringParameter(
"derivatives", optArgs,
"Gradient",
"",
true, warn + 1);
1201 string optMethod, derMethod;
1202 if (order ==
"Gradient")
1206 else if (order ==
"Newton")
1211 throw Exception(
"Option '" + order +
"' is not known for 'optimization.method.derivatives'.");
1213 ApplicationTools::displayResult(
"Optimization method", optName);
1215 ApplicationTools::displayResult(
"Algorithm used for derivable parameters", order);
1218 auto_ptr<BackupListener> backupListener;
1219 string backupFile = ApplicationTools::getAFilePath(
"optimization.backup.file", params,
false,
false, suffix, suffixIsOptional,
"none", warn + 1);
1220 if (backupFile !=
"none")
1222 ApplicationTools::displayResult(
"Parameters will be backup to", backupFile);
1223 backupListener.reset(
new BackupListener(backupFile));
1224 if (FileTools::fileExists(backupFile))
1226 ApplicationTools::displayMessage(
"A backup file was found! Try to restore parameters from previous run...");
1227 ifstream bck(backupFile.c_str(), ios::in);
1228 vector<string> lines = FileTools::putStreamIntoVectorOfStrings(bck);
1229 double fval = TextTools::toDouble(lines[0].substr(5));
1230 ParameterList pl = tl->getParameters();
1231 for (
size_t l = 1; l < lines.size(); ++l)
1233 if (!TextTools::isEmpty(lines[l]))
1235 StringTokenizer stp(lines[l],
"=");
1236 if (stp.numberOfRemainingTokens() != 2)
1238 cerr <<
"Corrupted backup file!!!" << endl;
1239 cerr <<
"at line " << l <<
": " << lines[l] << endl;
1241 string pname = stp.nextToken();
1242 string pvalue = stp.nextToken();
1243 size_t p = pl.whichParameterHasName(pname);
1244 pl.setParameter(p, AutoParameter(pl[p]));
1245 pl[p].setValue(TextTools::toDouble(pvalue));
1249 tl->setParameters(pl);
1250 if (abs(tl->getValue() - fval) > 0.000001)
1251 throw Exception(
"Incorrect likelihood value after restoring, from backup file. Remove backup file and start from scratch :s");
1252 ApplicationTools::displayResult(
"Restoring log-likelihood", -fval);
1257 if (optName ==
"D-Brent")
1260 unsigned int nstep = ApplicationTools::getParameter<unsigned int>(
"nstep", optArgs, 1,
"",
true, warn + 1);
1261 if (verbose && nstep > 1)
1262 ApplicationTools::displayResult(
"# of precision steps", TextTools::toString(nstep));
1265 parametersToEstimate,
1266 backupListener.get(),
1275 else if (optName ==
"FullD")
1280 parametersToEstimate,
1281 backupListener.get(),
1290 throw Exception(
"Unknown optimization method: " + optName);
1292 string finalMethod = ApplicationTools::getStringParameter(
"optimization.final", params,
"none", suffix, suffixIsOptional, warn + 1);
1293 Optimizer* finalOptimizer = 0;
1294 if (finalMethod ==
"none")
1296 else if (finalMethod ==
"simplex")
1298 finalOptimizer =
new DownhillSimplexMethod(tl);
1300 else if (finalMethod ==
"powell")
1302 finalOptimizer =
new PowellMultiDimensions(tl);
1305 throw Exception(
"Unknown final optimization method: " + finalMethod);
1309 parametersToEstimate.matchParametersValues(tl->getParameters());
1310 ApplicationTools::displayResult(
"Final optimization step", finalMethod);
1311 finalOptimizer->setProfiler(profiler);
1312 finalOptimizer->setMessageHandler(messageHandler);
1313 finalOptimizer->setMaximumNumberOfEvaluations(nbEvalMax);
1314 finalOptimizer->getStopCondition()->setTolerance(tolerance);
1315 finalOptimizer->setVerbose(verbose);
1316 finalOptimizer->setConstraintPolicy(AutoParameter::CONSTRAINTS_AUTO);
1317 finalOptimizer->init(parametersToEstimate);
1318 finalOptimizer->optimize();
1319 n += finalOptimizer->getNumberOfEvaluations();
1320 delete finalOptimizer;
1324 ApplicationTools::displayResult(
"Performed", TextTools::toString(n) +
" function evaluations.");
1325 if (backupFile !=
"none")
1327 remove(backupFile.c_str());
1335 for (
size_t i = 0; i < pl.size(); ++i)
1337 const Constraint* constraint = pl[i].getConstraint();
1340 double value = pl[i].getValue();
1341 if (!constraint->isCorrect(value - 1e-6) || !constraint->isCorrect(value + 1e-6))
1343 ApplicationTools::displayWarning(
"This parameter has a value close to the boundary: " + pl[i].getName() +
"(" + TextTools::toString(value) +
").");
1353 map<string, string>& params,
1354 const string& prefix,
1355 const string& suffix,
1356 bool suffixIsOptional,
1359 int warn)
throw (Exception)
1361 string format = ApplicationTools::getStringParameter(prefix +
"tree.format", params,
"Newick", suffix, suffixIsOptional, warn);
1362 string file = ApplicationTools::getAFilePath(prefix +
"tree.file", params,
true,
false, suffix, suffixIsOptional,
"none", warn);
1364 if (format ==
"Newick")
1365 treeWriter =
new Newick();
1366 else if (format ==
"Nexus")
1368 else if (format ==
"NHX")
1369 treeWriter =
new Nhx(
false);
1371 throw Exception(
"Unknown format for tree writing: " + format);
1373 treeWriter->
write(tree, file,
true);
1376 ApplicationTools::displayResult(
"Wrote tree to file ", file);
1382 const vector<Tree*>& trees,
1383 map<string, string>& params,
1384 const string& prefix,
1385 const string& suffix,
1386 bool suffixIsOptional,
1389 int warn)
throw (Exception)
1391 string format = ApplicationTools::getStringParameter(prefix +
"trees.format", params,
"Newick", suffix, suffixIsOptional, warn);
1392 string file = ApplicationTools::getAFilePath(prefix +
"trees.file", params,
true,
false, suffix, suffixIsOptional,
"none", warn);
1394 if (format ==
"Newick")
1395 treeWriter =
new Newick();
1396 else if (format ==
"Nexus")
1398 else if (format ==
"NHX")
1399 treeWriter =
new Nhx();
1401 throw Exception(
"Unknow format for tree writing: " + format);
1403 treeWriter->
write(trees, file,
true);
1406 ApplicationTools::displayResult(
"Wrote trees to file ", file);
1414 map<string, string> globalAliases;
1415 vector<string> writtenNames;
1417 bIO.
write(*model, out, globalAliases, writtenNames);
1425 (out <<
"nonhomogeneous=general").endLine();
1426 (out <<
"nonhomogeneous.number_of_models=" << modelSet->
getNumberOfModels()).endLine();
1429 map< size_t, vector<string> > modelLinks;
1430 map< string, set<size_t> > parameterLinks;
1431 vector<string> writtenNames;
1439 map<string, string> aliases;
1441 ParameterList pl=model->getParameters();
1443 for (
size_t np = 0 ; np< pl.size() ; np++)
1445 string nfrom = modelSet->getFrom(pl[np].getName() +
"_" + TextTools::toString(i + 1));
1447 aliases[pl[np].getName()] = nfrom;
1451 writtenNames.clear();
1452 out.endLine() <<
"model" << (i + 1) <<
"=";
1454 map<string, string>::iterator it;
1455 bIOsm.
write(*model, out, aliases, writtenNames);
1458 out <<
"model" << (i + 1) <<
".nodes_id=" << ids[0];
1459 for (
size_t j = 1; j < ids.size(); ++j)
1461 out <<
"," << ids[j];
1468 (out <<
"# Root frequencies:").endLine();
1469 out <<
"nonhomogeneous.root_freq=";
1479 out <<
"rate_distribution=";
1480 map<string, string> globalAliases;
1481 vector<string> writtenNames;
1484 bIO->
write(*rDist, out, globalAliases, writtenNames);
1494 const Alphabet* alphabet,
1496 map<string, string>& params,
1503 map<string, string> nijtParams;
1504 string nijtText = ApplicationTools::getStringParameter(
"nijt", params,
"Uniformization", suffix,
true, warn);
1505 KeyvalTools::parseProcedure(nijtText, nijtOption, nijtParams);
1507 if (nijtOption ==
"Laplace")
1509 size_t trunc = ApplicationTools::getParameter<size_t>(
"trunc", nijtParams, 10, suffix,
true, warn + 1);
1512 else if (nijtOption ==
"Uniformization")
1514 string weightOption = ApplicationTools::getStringParameter(
"weight", nijtParams,
"None",
"",
true, warn + 1);
1515 AlphabetIndex2* weights = SequenceApplicationTools::getAlphabetIndex2(alphabet, weightOption,
"Substitution weight scheme:");
1518 else if (nijtOption ==
"Decomposition")
1520 string weightOption = ApplicationTools::getStringParameter(
"weight", nijtParams,
"None",
"",
true, warn + 1);
1521 AlphabetIndex2* weights = SequenceApplicationTools::getAlphabetIndex2(alphabet, weightOption,
"Substitution weight scheme:");
1526 throw Exception(
"Decomposition method can only be used with reversible substitution models.");
1528 else if (nijtOption ==
"Naive")
1530 string weightOption = ApplicationTools::getStringParameter(
"weight", nijtParams,
"None",
"",
true, warn + 1);
1531 AlphabetIndex2* weights = SequenceApplicationTools::getAlphabetIndex2(alphabet, weightOption,
"Substitution weight scheme:");
1534 else if (nijtOption ==
"Label")
1538 else if (nijtOption ==
"ProbOneJump")
1544 ApplicationTools::displayError(
"Invalid option '" + nijtOption +
", in 'nijt' parameter.");
1547 ApplicationTools::displayResult(
"Substitution count procedure", nijtOption);
1550 return substitutionCount;
bool hasExclusivePaths() const
Substitution models manager for non-homogeneous / non-reversible models of evolution.
Interface for all substitution models.
void computeHyperNodesProbabilities()
a simple parser for reading trees from a Nexus file.
virtual Vint getSubmodelNumbers(std::string &desc) const =0
static const std::string FAST
Analytical substitution count using the eigen decomposition method.
const SubstitutionModel * getModel(size_t i) const
Get one model from the set knowing its index.
void setRootFrequencies(FrequenciesSet *rootFreqs)
Sets a given FrequenciesSet for root frequencies.
virtual ParameterList getRootFrequenciesParameters() const =0
The so-called 'Nhx - New Hampshire eXtended' parenthetic format.
The TreeLikelihood interface.
HyperNode & getHyperNode(size_t i)
General interface for tree writers.
General interface for tree readers.
The phylogenetic tree class.
Interface for phylogenetic tree objects.
Parametrize a set of state frequencies.
FrequenciesSet to be used with a Markov-modulated substitution model.
void addModel(SubstitutionModel *model, const std::vector< int > &nodesId)
Add a new model to the set, and set relationships with nodes and params.
const FrequenciesSet * getRootFrequenciesSet() const
virtual Tree * read(const std::string &path) const =0
Read a tree from a file.
void clear()
Resets all the information contained in this object.
virtual void read(const std::string &path, std::vector< Tree *> &trees) const =0
Read trees from a file.
Interface for reversible substitution models.
void addToHyperNode(size_t nM, const Vint &vnS, int nH=-1)
The so-called 'newick' parenthetic format.
virtual std::string getName() const =0
Computes the probability that at least one jump occured on a branch, given the initial and final stat...
General interface for tree writers.
virtual void write(const Tree &tree, const std::string &path, bool overwrite) const =0
Write a tree to a file.
Substitution models manager for Mixed Substitution Models. This class inherits from SubstitutionModel...
Interface for likelihood computation with a global clock and rate across sites variation.
General interface for multiple trees readers.
virtual void write(const std::vector< Tree *> &trees, const std::string &path, bool overwrite) const =0
Write trees to a file.
Labelling substitution count.
The SubstitutionsCount interface.
static const std::string BETTER
static const std::string PHYML
Specialization of the TreeLikelihood interface for the branch non-homogeneous and non-stationary mode...
const std::vector< int > & getNodesWithModel(size_t i) const
Get a list of nodes id for which the given model is associated.
size_t getNumberOfModels() const
Naive substitution count.
A frequencies set used to estimate frequencies at the root with the COaLA model. Frequencies at the r...
bool hasMixedSubstitutionModel() const
Laplace estimate of the substitution count.
size_t getNumberOfHyperNodes() const
Interface for Substitution models, defined as a mixture of "simple" substitution models.