5#include "../Io/BppOBranchModelFormat.h"
6#include "../Io/BppOFrequencySetFormat.h"
7#include "../Io/BppOMultiTreeReaderFormat.h"
8#include "../Io/BppOMultiTreeWriterFormat.h"
9#include "../Io/BppORateDistributionFormat.h"
10#include "../Io/BppOTreeReaderFormat.h"
11#include "../Io/BppOTreeWriterFormat.h"
12#include "../Io/Newick.h"
13#include "../Io/NexusIoTree.h"
15#include "../Likelihood/AutoCorrelationSequenceEvolution.h"
16#include "../Likelihood/HmmSequenceEvolution.h"
17#include "../Likelihood/MixtureSequenceEvolution.h"
18#include "../Likelihood/NonHomogeneousSubstitutionProcess.h"
19#include "../Likelihood/OneProcessSequenceEvolution.h"
20#include "../Likelihood/ParametrizablePhyloTree.h"
21#include "../Likelihood/PartitionSequenceEvolution.h"
22#include "../Likelihood/PhyloLikelihoods/AlignedPhyloLikelihoodAutoCorrelation.h"
23#include "../Likelihood/PhyloLikelihoods/AutoCorrelationProcessPhyloLikelihood.h"
24#include "../Likelihood/PhyloLikelihoods/PhyloLikelihoodFormula.h"
25#include "../Likelihood/PhyloLikelihoods/AlignedPhyloLikelihoodHmm.h"
26#include "../Likelihood/PhyloLikelihoods/HmmProcessPhyloLikelihood.h"
27#include "../Likelihood/PhyloLikelihoods/AlignedPhyloLikelihoodMixture.h"
28#include "../Likelihood/PhyloLikelihoods/MixtureProcessPhyloLikelihood.h"
29#include "../Likelihood/PhyloLikelihoods/OneProcessSequencePhyloLikelihood.h"
30#include "../Likelihood/PhyloLikelihoods/PartitionProcessPhyloLikelihood.h"
31#include "../Likelihood/PhyloLikelihoods/AlignedPhyloLikelihoodProduct.h"
32#include "../Likelihood/PhyloLikelihoods/SingleDataPhyloLikelihood.h"
33#include "../Likelihood/PhyloLikelihoods/SingleProcessPhyloLikelihood.h"
34#include "../Likelihood/RateAcrossSitesSubstitutionProcess.h"
35#include "../Likelihood/SimpleSubstitutionProcess.h"
36#include "../Likelihood/SubstitutionProcessCollection.h"
37#include "../Likelihood/SubstitutionProcessCollectionMember.h"
38#include "../Mapping/DecompositionSubstitutionCount.h"
39#include "../Mapping/LaplaceSubstitutionCount.h"
40#include "../Mapping/NaiveSubstitutionCount.h"
41#include "../Mapping/OneJumpSubstitutionCount.h"
42#include "../Mapping/UniformizationSubstitutionCount.h"
43#include "../Model/FrequencySet/MvaFrequencySet.h"
44#include "../Model/MixedTransitionModel.h"
45#include "../Model/Protein/Coala.h"
46#include "../Model/SubstitutionModel.h"
47#include "../Model/WrappedModel.h"
48#include "../Model/RateDistribution/ConstantRateDistribution.h"
49#include "../OptimizationTools.h"
50#include "../Tree/PhyloTree.h"
51#include "../Tree/PhyloTreeTools.h"
97unique_ptr<Tree> PhylogeneticsApplicationTools::getTree(
98 const map<string, string>& params,
100 const string& suffix,
101 bool suffixIsOptional,
109 auto iTree = bppoReader.
readITree(format);
115 return iTree->readTree(treeFilePath);
121 const map<string, string>& params,
122 const string& prefix,
123 const string& suffix,
124 bool suffixIsOptional,
138 vector<unique_ptr<Tree>> trees;
139 iTrees->readTrees(treeFilePath, trees);
151 const map<string, string>& params,
152 const map<
size_t, std::shared_ptr<const AlignmentDataInterface>>& mSeq,
153 map<string, string>& unparsedParams,
154 const string& prefix,
155 const string& suffix,
156 bool suffixIsOptional,
162 map<size_t, shared_ptr<PhyloTree>> mTree;
164 for (
size_t nT = 0; nT < vTreesName.size(); nT++)
166 size_t poseq = vTreesName[nT].find(
"=");
168 size_t len = (prefix +
"tree").size();
170 string suff = vTreesName[nT].substr(len, poseq - len);
192 map<string, string> args;
196 if (treeName ==
"user")
200 if (args.find(
"format") != args.end())
201 format = args[
"format"];
211 if (format ==
"Newick")
212 treeReader =
new Newick(
true);
213 else if (format ==
"Nexus")
215 else if (format ==
"NHX")
216 treeReader =
new Nhx();
218 throw Exception(
"Unknown format for tree reading: " + format);
220 vector<unique_ptr<PhyloTree>> trees;
223 if (args.find(
"data") != args.end())
226 if (mSeq.find(seqNum) == mSeq.end())
231 vector<string> names = mSeq.find(seqNum)->second->getSequenceNames();
233 for (
auto& tree:trees)
235 auto nb1 = tree->getNumberOfLeaves();
236 tree->pruneTree(names);
237 auto nb2 = tree->getNumberOfLeaves();
259 nbTree = trees.size();
261 for (
size_t i2 = 0; i2 < trees.size(); i2++)
263 if (mTree.find(i2 + 1) != mTree.end())
269 mTree[i2 + 1] = std::move(trees[i2]);
275 if (trees.size() > 1)
276 throw Exception(
"Error : Several trees for description of " + vTreesName[nT] +
".");
278 if (trees.size() == 1)
280 if (mTree.find(num) != mTree.end())
285 mTree[num] = std::move(trees[0]);
290 else if (treeName ==
"random")
294 if (args.find(
"data") == args.end())
303 if (mSeq.find(seqNum) == mSeq.end())
306 vector<string> names = mSeq.find(seqNum)->second->getSequenceNames();
310 treetemp->setBranchLengths(1.);
314 if (mTree.find(num) != mTree.end())
328 map<string, string> cmdArgs;
334 if (cmdName ==
"Input")
338 if (midPointRootBrLengths ==
"yes")
343 for (
size_t i = 0; i < nbTree; i++)
352 else if (cmdName ==
"Equal")
356 throw Exception(
"Value for branch length must be superior to 0");
360 for (
size_t i = 0; i < nbTree; i++)
362 mTree[i + 1]->setBranchLengths(value);
366 mTree[num]->setBranchLengths(value);
368 else if (cmdName ==
"Clock")
372 for (
size_t i = 0; i < nbTree; i++)
380 else if (cmdName ==
"Grafen")
386 for (
size_t i = 0; i < nbTree; i++)
388 auto tree = mTree[i + 1];
389 if (grafenHeight ==
"input")
397 throw Exception(
"Height must be positive in Grafen's method.");
406 tree->scaleTree(h / nh);
411 auto tree = mTree[num];
412 if (grafenHeight ==
"input")
418 throw Exception(
"Height must be positive in Grafen's method.");
428 tree->scaleTree(h / nh);
432 throw Exception(
"Method '" + initBrLenMethod +
"' unknown for computing branch lengths.");
438 for (
size_t ib = 0; ib < vBrNb.size(); ib++)
440 string apeq = args[vBrNb[ib]];
441 string aveq = vBrNb[ib];
451 size_t posun = apeq.find(
"_");
452 size_t posd = aveq.find(
"_");
466 std::shared_ptr<const Alphabet> alphabet,
467 std::shared_ptr<const GeneticCode> gCode,
468 std::shared_ptr<const AlignmentDataInterface> data,
469 const map<string, string>& params,
470 map<string, string>& unparsedParams,
471 const string& suffix,
472 bool suffixIsOptional,
477 string modelDescription;
478 auto ca = dynamic_pointer_cast<const CodonAlphabet>(alphabet);
483 throw Exception(
"PhylogeneticsApplicationTools::getSubstitutionModel(): a GeneticCode instance is required for instantiating a codon model.");
491 std::map<size_t, std::shared_ptr<const AlignmentDataInterface>> mData;
502 std::shared_ptr<const Alphabet> alphabet,
503 std::shared_ptr<const GeneticCode> gCode,
504 std::shared_ptr<const AlignmentDataInterface> data,
505 const map<string, string>& params,
506 map<string, string>& unparsedParams,
507 const string& suffix,
508 bool suffixIsOptional,
513 string modelDescription;
514 auto ca = dynamic_pointer_cast<const CodonAlphabet>(alphabet);
519 throw Exception(
"PhylogeneticsApplicationTools::getBranchModel(): a GeneticCode instance is required for instantiating a codon model.");
527 std::map<size_t, std::shared_ptr<const AlignmentDataInterface>> mData;
530 auto model = bIO.
readBranchModel(alphabet, modelDescription, mData, 1,
true);
533 unparsedParams.insert(tmpUnparsedParameterValues.begin(), tmpUnparsedParameterValues.end());
541 const map<string, string>& params,
542 const string& suffix,
543 bool suffixIsOptional,
548 map<string, string> paramDist;
550 if (DistFilePath !=
"none")
553 paramDist.insert(params.begin(), params.end());
558 map<size_t, std::shared_ptr<DiscreteDistributionInterface>> mDist;
561 for (
size_t i = 0; i < vratesName.size(); ++i)
563 size_t poseq = vratesName[i].find(
"=");
565 string suff = vratesName[i].substr(17, poseq - 17);
590 if (mDist.size() == 0)
607 std::shared_ptr<const Alphabet> alphabet,
608 std::shared_ptr<const GeneticCode> gCode,
609 const map<
size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
610 const map<string, string>& params,
611 map<string, string>& unparsedParams,
612 const string& suffix,
613 bool suffixIsOptional,
617 if (dynamic_pointer_cast<const CodonAlphabet>(alphabet) && !gCode)
618 throw Exception(
"PhylogeneticsApplicationTools::getBranchModels(): a GeneticCode instance is required for instantiating codon models.");
622 map<string, string> paramModel;
624 if (ModelFilePath !=
"none")
627 paramModel.insert(params.begin(), params.end());
631 vector<size_t> modelsNum;
632 for (
const auto& name : modelsName)
634 size_t poseq = name.find(
"=");
635 if (name.find(
"nodes_id") == string::npos)
637 modelsNum.push_back(TextTools::to<size_t>(name.substr(5, poseq - 5)));
641 map<size_t, std::unique_ptr<BranchModelInterface>> mModel;
646 for (
size_t i = 0; i < modelsNum.size(); ++i)
664 unique_ptr<BranchModelInterface> model;
665 model = bIO.
readBranchModel(alphabet, modelDescription, mData, 0,
true);
669 for (
auto& it : tmpUnparsedParameterValues)
674 mModel[modelsNum[i]] = std::move(model);
686 std::shared_ptr<const Alphabet> alphabet,
687 std::shared_ptr<const GeneticCode> gCode,
688 const string& freqDescription,
689 const std::map<
size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
691 map<string, string>& sharedparams,
692 const vector<double>& rateFreqs,
696 map<string, string> unparsedParameterValues;
701 throw Exception(
"PhylogeneticsApplicationTools::getFrequencySet(): a GeneticCode instance is required for instantiating a codon frequencies set.");
705 auto pFS = bIO.
readFrequencySet(alphabet, freqDescription, mData, nData,
true);
709 sharedparams.insert(unparsedparam.begin(), unparsedparam.end());
712 if (rateFreqs.size() > 0)
714 pFS = std::make_unique<MarkovModulatedFrequencySet>(std::move(pFS), rateFreqs);
722 std::shared_ptr<const Alphabet> alphabet,
723 std::shared_ptr<const GeneticCode> gCode,
724 const std::map<
size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
726 const map<string, string>& params,
727 map<string, string>& sharedparams,
728 const vector<double>& rateFreqs,
729 const string& suffix,
730 bool suffixIsOptional,
735 if (freqDescription ==
"None")
741 map<string, string> unparams;
743 auto freq =
getFrequencySet(alphabet, gCode, freqDescription, mData, nData, unparams, rateFreqs, verbose, warn + 1);
744 freq->setNamespace(
"root." + freq->getNamespace());
746 for (
auto& it : unparams)
748 sharedparams[
"root." + it.first] = it.second;
759 std::shared_ptr<const Alphabet> alphabet,
760 std::shared_ptr<const GeneticCode> gCode,
761 const map<
size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
762 const map<string, string>& params,
763 map<string, string>& sharedparams,
764 const string& suffix,
765 bool suffixIsOptional,
769 if (dynamic_pointer_cast<const CodonAlphabet>(alphabet) && !gCode)
770 throw Exception(
"PhylogeneticsApplicationTools::getRootFrequencySets(): a GeneticCode instance is required for instantiating codon frequencies sets.");
773 map<string, string> paramRF;
775 if (RootFilePath !=
"none")
778 paramRF.insert(params.begin(), params.end());
782 vector<size_t> rfNum;
783 for (
const auto& rfName : vrfName)
785 size_t poseq = rfName.find(
"=");
788 rfNum.push_back(TextTools::to<size_t>(rfName.substr(9, poseq - 9)));
797 map<size_t, std::unique_ptr<FrequencySetInterface>> mFS;
799 for (
size_t i = 0; i < rfNum.size(); ++i)
806 map<string, string> args;
813 if (args.find(
"data") != args.end())
814 nData = TextTools::to<size_t>(args[
"data"]);
816 unique_ptr<FrequencySetInterface> rFS;
820 rFS->setNamespace(
"root." + rFS->getNamespace());
824 for (
auto& it : unparsedparam)
836 mFS[rfNum[i]] = std::move(rFS);
847 const std::map<std::string, std::string>& params,
848 const map<
size_t, std::shared_ptr<BranchModelInterface>>& mModel,
849 const string& suffix,
850 bool suffixIsOptional,
855 map<string, string> paramMP;
857 if (ModelPathsPath !=
"none")
860 paramMP.insert(params.begin(), params.end());
864 map<size_t, std::unique_ptr<ModelPath>> modelPaths;
866 for (
size_t i = 0; i < vmpName.size(); ++i)
868 const auto& name = vmpName[i];
875 num = TextTools::to<size_t>(name.substr(4));
879 throw Exception(
"PhylogeneticsApplicationTools::getModelPaths: bad path number in line " + name);
882 modelPaths[num] = std::make_unique<ModelPath>();
904 auto indexo = submodel.find(
"[");
905 auto indexf = submodel.find(
"]");
906 if ((indexo == string::npos) | (indexf == string::npos))
907 throw Exception(
"PhylogeneticsApplicationTools::getModelPaths. Bad path syntax, should contain `[]' symbols: " + submodel);
909 auto pos = submodel.find(
"model");
910 if (pos == string::npos)
911 throw Exception(
"PhylogeneticsApplicationTools::getModelPaths. Missing identifier 'model' in description: " + submodel);
913 size_t num2 = TextTools::to<size_t>(submodel.substr(pos + 5, indexo - 5 - pos));
914 if (mModel.find(num2) == mModel.end())
915 throw BadIntegerException(
"PhylogeneticsApplicationTools::getModelPaths: Wrong model number",
static_cast<int>(num2));
917 auto pSM = std::dynamic_pointer_cast<MixedTransitionModelInterface>(mModel.at(num2));
919 throw Exception(
"PhylogeneticsApplicationTools::getModelPaths: Model number " +
TextTools::toString(num2) +
" ( " + mModel.at(num2)->getName() +
" ) is not Mixed.");
921 string lp2 = submodel.substr(indexo + 1, indexf - indexo - 1);
931 n2 = TextTools::to<unsigned int>(p2);
932 if (n2 <= 0 || n2 > pSM->getNumberOfModels())
935 submodelNb.push_back(n2 - 1);
939 Vuint submodnb = pSM->getSubmodelNumbers(p2);
940 if (submodelNb.size() == 0)
941 submodelNb = submodnb;
950 modelPaths[num]->setModel(pSM, submodelNb);
951 if (!modelPaths[num]->getLeadModel())
952 modelPaths[num]->setLeadModel(pSM);
955 if (verbose && (i < 10))
964 const std::map<std::string, std::string>& params,
965 const map<
size_t, std::shared_ptr<ModelPath>>& mModelPath,
966 const map<
size_t, std::shared_ptr<BranchModelInterface>>& mModel,
967 const string& suffix,
968 bool suffixIsOptional,
973 map<string, string> paramMS;
975 if (ModelPathsPath !=
"none")
978 paramMS.insert(params.begin(), params.end());
982 map<size_t, std::unique_ptr<ModelScenario>> somp;
984 for (
size_t i = 0; i < vmsName.size(); ++i)
986 const auto& name = vmsName[i];
993 num = TextTools::to<size_t>(name.substr(8));
997 throw Exception(
"PhylogeneticsApplicationTools::getModelScenarios: bad scenario number in line " + name);
1000 somp[num] = std::make_unique<ModelScenario>();
1017 bool complete =
false;
1026 if (path ==
"complete")
1028 else if (path.substr(0, 5) ==
"split")
1030 auto pos = path.find(
"model");
1032 if (pos == string::npos)
1033 throw Exception(
"PhylogeneticsApplicationTools::getModelScenarios. Missing identifier 'model' in scenario description: " + path);
1035 auto poseq = path.find(
"=", pos);
1039 std::vector<std::shared_ptr<MixedTransitionModelInterface>> vpSM;
1043 size_t num2 = TextTools::to<size_t>(dmod);
1045 if (mModel.find(num2) == mModel.end())
1046 throw BadIntegerException(
"PhylogeneticsApplicationTools::getModelScenarios: Wrong model number",
static_cast<int>(num2));
1048 auto pSM = std::dynamic_pointer_cast<MixedTransitionModelInterface>(mModel.at(num2));
1050 throw Exception(
"PhylogeneticsApplicationTools::getModelScenarios: Model number " +
TextTools::toString(num2) +
" ( " + mModel.at(num2)->getName() +
" ) is not Mixed.");
1052 vpSM.push_back(pSM);
1056 vector<vector<uint>> vvnmod;
1057 for (
const auto& pSM:vpSM)
1059 auto nmod = pSM->getNumberOfModels();
1061 vector<vector<uint>> vvnmod2;
1063 if (vvnmod.size() == 0)
1065 for (uint nm = 0; nm < static_cast<unsigned int>(nmod); ++nm)
1067 auto v2 = vector<uint>({nm});
1068 vvnmod2.push_back(v2);
1073 for (
const auto& vnmod:vvnmod)
1075 for (uint nm = 0; nm < static_cast<unsigned int>(nmod); ++nm)
1079 vvnmod2.push_back(v2);
1088 for (
const auto& vn:vvnmod)
1090 auto mp = std::make_shared<ModelPath>();
1092 for (
size_t j = 0; j < vpSM.size(); j++)
1094 mp->setModel(vpSM[j],
Vuint({vn[j]}));
1097 mp->setLeadModel(vpSM[0]);
1098 somp[num]->addModelPath(mp);
1103 numpath = TextTools::to<size_t>(path.substr(4));
1104 if (mModelPath.find(numpath) == mModelPath.end())
1107 somp[num]->addModelPath(mModelPath.at(numpath));
1111 throw BadIntegerException(
"PhylogeneticsApplicationTools::getModelScenarios: Wrong path number",
static_cast<int>(numpath));
1114 if (verbose && (i < 10))
1119 if (somp[num]->getNumberOfModelPaths() == 0)
1120 throw Exception(
"PhylogeneticsApplicationTools::getModelScenarios: 'complete' is not possible on empty scenarios");
1121 somp[num]->complete();
1124 if (somp[num]->getNumberOfModelPaths() == 0)
1125 somp.erase(somp.find(num));
1127 somp[num]->computeModelPathsProbabilities();
1139 std::shared_ptr<const Alphabet> alphabet,
1140 std::shared_ptr<const GeneticCode> gCode,
1141 std::shared_ptr<const AlignmentDataInterface> pData,
1142 const vector< shared_ptr<PhyloTree>>& vTree,
1143 const map<string, string>& params,
1144 const string& suffix,
1145 bool suffixIsOptional,
1151 map<string, string> unparsedParams;
1153 map<size_t, std::shared_ptr<const AlignmentDataInterface>> mData;
1156 map<size_t, std::shared_ptr<PhyloTree>> mTree;
1158 for (
auto it : vTree)
1163 auto mModU =
getBranchModels(alphabet, gCode, mData, params, unparsedParams, suffix, suffixIsOptional, verbose, warn);
1164 auto mMod = uniqueToSharedMap<BranchModelInterface>(mModU);
1166 auto mRootFreqU =
getRootFrequencySets(alphabet, gCode, mData, params, unparsedParams, suffix, suffixIsOptional, verbose, warn);
1167 auto mRootFreq = uniqueToSharedMap<FrequencySetInterface>(mRootFreqU);
1171 auto mPathU =
getModelPaths(params, mMod, suffix, suffixIsOptional, verbose, warn);
1172 auto mPath = uniqueToSharedMap<ModelPath>(mPathU);
1174 auto mScenU =
getModelScenarios(params, mPath, mMod, suffix, suffixIsOptional, verbose, warn);
1175 auto mScen = uniqueToSharedMap<ModelScenario>(mScenU);
1178 mMod, mRootFreq, mDist, mScen,
1179 params, unparsedParams, suffix, suffixIsOptional, verbose, warn);
1182 unique_ptr<AutonomousSubstitutionProcessInterface> ASP;
1184 auto psNum = SPC->getSubstitutionProcessNumbers();
1185 if (psNum.size() == 0)
1186 throw Exception(
"PhylogeneticsApplicationTools::getSubstitutionProcess : missing process in parameters.");
1188 size_t maxps = *max_element(psNum.begin(), psNum.end());
1200 if (vmodnb.size() == 1)
1211 for (
auto nb:vmodnb)
1216 if (!NHSP->isFullySetUp(
false))
1217 throw Exception(
"PhylogeneticsApplicationTools::getSubstitutionProcess: process not fully set up.");
1219 ASP = std::move(NHSP);
1234 const map<string, string>& params,
1238 string procName =
"";
1239 map<string, string> args;
1245 if ((procName !=
"OnePerBranch") && (procName !=
"Homogeneous") && (procName !=
"Nonhomogeneous") && (procName !=
"NonHomogeneous"))
1258 if (args.find(
"tree") == args.end())
1269 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown tree number", (
int)numTree);
1276 if (args.find(
"rate") == args.end())
1290 for (uint i = 1; i <= *std::max_element(vrdn.begin(), vrdn.end()) + 1; i++)
1292 if (std::find(vrdn.begin(), vrdn.end(), i) == vrdn.end())
1298 SubProColl.
addDistribution(std::make_shared<ConstantRateDistribution>(), numRate);
1305 size_t pp = sRate.find(
".");
1307 numRate = TextTools::to<size_t>(sRate.substr(0, pp));
1310 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown rate number", (
int)numRate);
1312 if (pp != string::npos)
1314 size_t numSRate = TextTools::to<size_t>(sRate.substr(pp + 1));
1316 std::make_shared<ConstantDistribution>(
1318 10000 * (numRate + 1) + numSRate);
1320 numRate = 10000 * (numRate + 1) + numSRate;
1327 bool stationarity = (args.find(
"root_freq") == args.end());
1334 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown root frequencies number", (
int)numFreq);
1342 if (args.find(
"scenario") != args.end())
1347 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown scenario number", (
int)numScen);
1359 if (procName ==
"Homogeneous")
1361 if (args.find(
"model") == args.end())
1362 throw Exception(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember. A model number is compulsory.");
1367 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown model number",
static_cast<int>(numModel));
1369 map<size_t, vector<unsigned int>> mModBr;
1371 vector<uint> vNodes;
1377 mModBr[numModel] = vNodes;
1384 if (numRate < 10000)
1404 else if ((procName ==
"Nonhomogeneous") || (procName ==
"NonHomogeneous"))
1407 throw Exception(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : missing tree number for process " +
TextTools::toString(procName));
1409 size_t indModel = 1;
1410 map<size_t, vector<unsigned int>> mModBr;
1416 if (mModBr.find(numModel) != mModBr.end())
1417 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : model number seen twice.", (
int)numModel);
1419 vector<unsigned int> nodesId;
1425 auto tree = SubProColl.
getTree(numTree);
1426 if (descnodes ==
"All")
1428 nodesId = tree->getEdgeIndexes(tree->getSubtreeEdges(tree->getRoot()));
1430 else if (descnodes ==
"Leaves")
1432 nodesId = tree->getNodeIndexes(tree->getLeavesUnderNode(tree->getRoot()));
1434 else if (descnodes ==
"NoLeaves")
1436 auto allIds = tree->getEdgeIndexes(tree->getSubtreeEdges(tree->getRoot()));
1437 auto leavesId = tree->getNodeIndexes(tree->getLeavesUnderNode(tree->getRoot()));
1441 nodesId = ApplicationTools::getVectorParameter<unsigned int>(snodesid, args,
',',
':',
"",
"",
true, warn);
1443 mModBr[numModel] = nodesId;
1451 for (
auto& it : mModBr)
1468 else if (procName ==
"OnePerBranch")
1471 throw Exception(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : missing tree number for process " +
TextTools::toString(procName));
1473 if (args.find(
"model") == args.end())
1474 throw Exception(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember. A model number is compulsory.");
1479 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown model number", (
int)numModel);
1481 vector<string> sharedParameters = ApplicationTools::getVectorParameter<string>(
"shared_parameters", args,
',',
"",
"",
true, 1);
1500 for (
const auto& sP : sharedParameters)
1517 std::shared_ptr<const Alphabet> alphabet,
1518 std::shared_ptr<const GeneticCode> gCode,
1519 const map<
size_t, std::shared_ptr<PhyloTree>>& mTree,
1520 const map<
size_t, std::shared_ptr<BranchModelInterface>>& mMod,
1521 const map<
size_t, std::shared_ptr<FrequencySetInterface>>& mRootFreq,
1522 const map<
size_t, std::shared_ptr<DiscreteDistributionInterface>>& mDist,
1523 const map<
size_t, std::shared_ptr<ModelScenario>>& mScen,
1524 const map<string, string>& params,
1525 map<string, string>& unparsedParams,
1526 const string& suffix,
1527 bool suffixIsOptional,
1531 auto SPC = make_unique<SubstitutionProcessCollection>();
1533 map<string, double> existingParameters;
1538 for (
const auto& itt : mTree)
1542 SPC->addTree(std::make_shared<ParametrizablePhyloTree>(*(itt.second)), itt.first);
1549 for (
const auto& itd : mDist)
1551 SPC->addDistribution(itd.second, itd.first);
1557 for (
const auto& itm : mMod)
1559 SPC->addModel(itm.second, itm.first);
1565 for (
const auto& itr : mRootFreq)
1567 SPC->addFrequencies(itr.second, itr.first);
1573 for (
const auto& itt : mScen)
1575 SPC->addScenario(itt.second, itt.first);
1583 if (vProcName.size() == 0)
1584 throw Exception(
"Missing process in construction of SubstitutionProcessCollection.");
1586 for (
size_t nT = 0; nT < vProcName.size(); nT++)
1588 size_t poseq = vProcName[nT].find(
"=");
1592 string suff = vProcName[nT].substr(len, poseq - len);
1595 num = TextTools::to<size_t>(suff);
1643 for (
const auto& param : params)
1648 SPC->setParameterValue(param.first, v2);
1652 if (SPC->hasParameter(param.first))
1653 unparsedParams[param.first] = param.second;
1657 SPC->aliasParameters(unparsedParams, verbose);
1667 shared_ptr<SubstitutionProcessCollection> SPC,
1668 const map<string, string>& params,
1669 map<string, string>& unparsedParams,
1670 const string& suffix,
1671 bool suffixIsOptional,
1675 map<string, string> paramEvol;
1677 paramEvol.insert(params.begin(), params.end());
1681 vector<size_t> evolsNum;
1682 for (
size_t i = 0; i < evolsName.size(); ++i)
1684 size_t poseq = evolsName[i].find(
"=");
1685 evolsNum.push_back(TextTools::to<size_t>(evolsName[i].substr(7, poseq - 7)));
1688 map<size_t, unique_ptr<SequenceEvolution>> mEvol;
1690 for (
size_t mPi = 0; mPi < evolsNum.size(); ++mPi)
1692 if (SPC->hasSubstitutionProcessNumber(evolsNum[mPi]))
1695 unique_ptr<SequenceEvolution> nEvol;
1697 string evolName =
"";
1698 map<string, string> args;
1711 if (evolName ==
"Simple")
1714 if (!SPC->hasSubstitutionProcessNumber(nproc))
1715 throw BadIntegerException(
"PhylogeneticsApplicationTools::getEvolutions. Unknown process number:", (
int)nproc);
1717 nEvol = make_unique<OneProcessSequenceEvolution>(SPC->getSubstitutionProcess(nproc), nproc);
1727 vector<size_t> vproc;
1733 vproc.push_back(numProc);
1737 if (vproc.size() == 0)
1738 throw BadIntegerException(
"PhylogeneticsApplicationTools::getEvolutions. A process number is compulsory for process", (
int)indProc);
1740 for (
size_t i = 0; i < vproc.size(); ++i)
1742 if (!SPC->hasSubstitutionProcessNumber(vproc[i]))
1743 throw BadIntegerException(
"PhylogeneticsApplicationTools::getEvolutions. Unknown process number:", (
int)vproc[i]);
1746 if (evolName ==
"Partition")
1750 vector<size_t> vMap;
1752 map<size_t, size_t> posProc;
1754 for (
size_t i = 0; i < vproc.size(); ++i)
1758 vector<size_t> procPos = ApplicationTools::getVectorParameter<size_t>(prefix +
".sites", args,
',',
':',
TextTools::toString(i),
"",
true,
true);
1760 for (
size_t j = 0; j < procPos.size(); ++j)
1762 if (posProc.find(procPos[j]) != posProc.end())
1765 posProc[procPos[j]] = vproc[i];
1769 size_t pos = posProc.begin()->first;
1771 while (posProc.find(pos) != posProc.end())
1773 vMap.push_back(posProc[pos]);
1777 if (vMap.size() != posProc.size())
1778 throw Exception(
"Error : there are gaps in the process sites");
1783 auto pMP = make_unique<PartitionSequenceEvolution>(SPC, vMap);
1785 nEvol = std::move(pMP);
1787 else if (evolName ==
"Mixture")
1789 auto pMP = make_unique<MixtureSequenceEvolution>(SPC, vproc);
1794 size_t nbP = pMP->getNumberOfSubstitutionProcess();
1796 vector<double> vprob = ApplicationTools::getVectorParameter<double>(
"probas", args,
',',
"(" +
VectorTools::paste(vector<double>(nbP, 1. / (
double)nbP)) +
")");
1797 if (vprob.size() != 1)
1799 if (vprob.size() != nbP)
1800 throw BadSizeException(
"Wrong size of probas description in Mixture", vprob.size(), nbP);
1802 pMP->setSubProcessProb(si);
1805 nEvol = std::move(pMP);
1807 else if (evolName ==
"HMM")
1809 auto pMP = make_unique<HmmSequenceEvolution>(SPC, vproc);
1814 size_t nbP = pMP->getNumberOfSubstitutionProcess();
1816 string vs =
"(" +
VectorTools::paste(vector<double>(nbP, 1. / (
double)nbP),
",") +
")";
1818 for (
size_t i = 0; i < nbP; ++i)
1820 vvs += (i == 0 ?
"" :
",") + vs;
1824 RowMatrix<double> mat = ApplicationTools::getMatrixParameter<double>(
"probas", args,
',', vvs);
1831 nEvol = std::move(pMP);
1833 else if (evolName ==
"AutoCorr")
1835 auto pMP = make_unique<AutoCorrelationSequenceEvolution>(SPC, vproc);
1837 size_t nbP = pMP->getNumberOfSubstitutionProcess();
1844 vector<double> v = ApplicationTools::getVectorParameter<double>(
"lambdas", args,
',', vs);
1848 for (
size_t i = 0; i < v.size(); ++i)
1853 pMP->matchParametersValues(pl);
1855 nEvol = std::move(pMP);
1858 throw Exception(
"Unknown Process description : " + evolName);
1867 mEvol[evolsNum[mPi]] = std::move(nEvol);
1880 shared_ptr<SubstitutionProcessCollection> SPC,
1881 map<
size_t, std::shared_ptr<SequenceEvolution>>& mSeqEvol,
1882 const map<
size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
1883 const map<string, string>& params,
1884 const string& suffix,
1885 bool suffixIsOptional,
1889 auto mPhylo = std::make_shared<PhyloLikelihoodContainer>(context, SPC);
1892 auto collNodes = mPhylo->getCollectionNodes();
1895 map<string, string> paramPhyl;
1896 paramPhyl.insert(params.begin(), params.end());
1901 map<size_t, vector<size_t>> phylosMap;
1903 for (
size_t i = 0; i < phylosName.size(); ++i)
1905 size_t poseq = phylosName[i].find(
"=");
1906 size_t phyln = TextTools::to<size_t>(phylosName[i].substr(5, poseq - 5));
1909 throw BadIntegerException(
"PhylogeneticsApplicationTools::getPhyloLikelihoodContainer : Forbidden Phylo Number", 0);
1913 map<string, string> args;
1915 string phyloName =
"";
1920 vector<size_t> vphyl;
1925 vphyl.push_back(numPhyl);
1929 phylosMap[phyln] = vphyl;
1932 vector<size_t> usedPhylo;
1938 bool verbhere(verbose);
1940 for (
const auto& it : phylosMap)
1944 if (it.second.size() != 0)
1947 size_t phylonum = it.first;
1949 std::shared_ptr<PhyloLikelihoodInterface> nPL;
1950 string phyloName =
"";
1952 map<string, string> args;
1970 size_t nData = (args.find(
"data") == args.end() ? 1 : TextTools::to<size_t>(args[
"data"]));
1972 if (mData.find(nData) == mData.end())
1978 auto data = mData.find(nData)->second;
1991 size_t nProcess = (args.find(
"process") == args.end() ? 1 : TextTools::to<size_t>(args[
"process"]));
1998 if (SPC->hasSubstitutionProcessNumber(nProcess))
2000 auto l = std::make_shared<LikelihoodCalculationSingleProcess>(collNodes, data, nProcess);
2001 nPL = make_unique<SingleProcessPhyloLikelihood>(context, l, nProcess, nData);
2003 else if (mSeqEvol.find(nProcess) != mSeqEvol.end())
2008 auto opse = dynamic_pointer_cast<OneProcessSequenceEvolution>(mSeqEvol[nProcess]);
2011 nPL = make_unique<OneProcessSequencePhyloLikelihood>(data, opse, collNodes, nProcess, nData);
2014 auto mse = dynamic_pointer_cast<MixtureSequenceEvolution>(mSeqEvol[nProcess]);
2017 nPL = make_unique<MixtureProcessPhyloLikelihood>(data, mse, collNodes, nProcess, nData);
2021 auto hse = dynamic_pointer_cast<HmmSequenceEvolution>(mSeqEvol[nProcess]);
2024 nPL = make_unique<HmmProcessPhyloLikelihood>(data, hse, collNodes, nProcess, nData);
2028 auto ase = dynamic_pointer_cast<AutoCorrelationSequenceEvolution>(mSeqEvol[nProcess]);
2031 nPL = make_unique<AutoCorrelationProcessPhyloLikelihood>(data, ase, collNodes, nProcess, nData);
2034 auto pse = dynamic_pointer_cast<PartitionSequenceEvolution>(mSeqEvol[nProcess]);
2037 nPL = make_unique<PartitionProcessPhyloLikelihood>(data, pse, collNodes, nProcess, nData);
2040 throw Exception(
"PhylogeneticsApplicationTools::getPhyloLikelihoodContainer : Unknown Sequence Evolution.");
2047 throw BadIntegerException(
"PhylogeneticsApplicationTools::getPhyloLikelihoodContainer : Unknown Process number.", (
int)nProcess);
2049 mPhylo->addPhyloLikelihood(phylonum, std::move(nPL));
2050 usedPhylo.push_back(phylonum);
2054 for (
auto it = phylosMap.begin(); it != phylosMap.end();)
2056 if (it->second.size() == 0)
2058 phylosMap.erase(it++);
2062 vector<size_t>& vphyl = it->second;
2063 for (
size_t i = vphyl.size(); i > 0; i--)
2065 vector<size_t>::iterator posp = find(usedPhylo.begin(), usedPhylo.end(), vphyl[i - 1]);
2066 if (posp != usedPhylo.end())
2067 vphyl.erase(vphyl.begin() +
static_cast<ptrdiff_t
>(i - 1));
2074 while (phylosMap.size() != 0)
2076 if (usedPhylo.size() == 0)
2084 for (map<
size_t, vector<size_t>>::iterator it = phylosMap.begin(); it != phylosMap.end(); it++)
2088 if (it->second.size() == 0)
2090 size_t phylonum = it->first;
2092 unique_ptr<PhyloLikelihoodInterface> nPL;
2093 string phyloName =
"";
2095 map<string, string> args;
2112 size_t indPhylo = 1;
2113 vector<size_t> vPhylo;
2119 vPhylo.push_back(numPhylo);
2123 if (phyloName ==
"Mixture")
2125 auto pMA = make_unique<AlignedPhyloLikelihoodMixture>(context, std::move(mPhylo), vPhylo);
2126 vector<double> vprob = ApplicationTools::getVectorParameter<double>(
"probas", args,
',',
"(" +
VectorTools::paste(vector<double>(vPhylo.size(), 1. / (
double)vPhylo.size())) +
")");
2127 if (vprob.size() != 1)
2129 if (vprob.size() != vPhylo.size())
2130 throw BadSizeException(
"Wrong size of probas description in Mixture", vprob.size(), vPhylo.size());
2132 pMA->setPhyloProb(si);
2135 nPL = std::move(pMA);
2137 else if (phyloName ==
"HMM")
2139 auto pMA = make_unique<AlignedPhyloLikelihoodHmm>(context, std::move(mPhylo), vPhylo);
2141 size_t nbP = pMA->getNumbersOfPhyloLikelihoods().size();
2143 string vs =
"(" +
VectorTools::paste(vector<double>(nbP, 1. /
static_cast<double>(nbP)),
",") +
")";
2145 for (
size_t i = 0; i < nbP; ++i)
2147 vvs += (i == 0 ?
"" :
",") + vs;
2151 RowMatrix<double> mat = ApplicationTools::getMatrixParameter<double>(
"probas", args,
',', vvs);
2158 nPL = std::move(pMA);
2160 else if (phyloName ==
"AutoCorr")
2162 auto pMA = make_unique<AlignedPhyloLikelihoodAutoCorrelation>(context, std::move(mPhylo), vPhylo);
2164 size_t nbP = pMA->getNumbersOfPhyloLikelihoods().size();
2168 vector<double> v = ApplicationTools::getVectorParameter<double>(
"lambdas", args,
',', vs);
2172 for (
size_t i = 0; i < v.size(); ++i)
2177 pMA->matchParametersValues(pl);
2179 nPL = std::move(pMA);
2181 else if (phyloName ==
"Product")
2183 auto pAP = make_unique<AlignedPhyloLikelihoodProduct>(context, std::move(mPhylo), vPhylo);
2185 nPL = std::move(pAP);
2188 throw Exception(
"PhylogeneticsApplicationTools::getPhyloLikelihoodContainer : Unknown Phylo name " + phyloName);
2196 mPhylo->addPhyloLikelihood(phylonum, std::move(nPL));
2197 usedPhylo.push_back(phylonum);
2202 for (
auto it = phylosMap.begin(); it != phylosMap.end();)
2204 if (it->second.size() == 0)
2206 phylosMap.erase(it++);
2210 vector<size_t>& vphyl = it->second;
2211 for (
size_t i = vphyl.size(); i > 0; i--)
2213 vector<size_t>::iterator posp = find(usedPhylo.begin(), usedPhylo.end(), vphyl[i - 1]);
2214 if (posp != usedPhylo.end())
2215 vphyl.erase(vphyl.begin() +
static_cast<ptrdiff_t
>(i - 1));
2222 if (mPhylo->getNumbersOfPhyloLikelihoods().size() == 0)
2236 const vector<size_t>& nPhyl = mPhylo->getNumbersOfPhyloLikelihoods();
2238 for (
size_t i = 0; i < nPhyl.size(); i++)
2250 std::shared_ptr<PhyloLikelihoodInterface> nPL;
2252 bool flag(resultDesc.substr(0, 5) ==
"phylo");
2258 nP = TextTools::to<size_t>(resultDesc.substr(5));
2268 nPL = make_shared<PhyloLikelihoodFormula>(context, mPhylo, resultDesc);
2274 if (!mPhylo->hasPhyloLikelihood(nP))
2277 nPL = mPhylo->getPhyloLikelihood(nP);
2282 mPhylo->addPhyloLikelihood(0, nPL);
2294 const string& distDescription,
2295 map<string, string>& unparsedParameterValues,
2300 map<string, string> args;
2303 if (distName ==
"Dirichlet")
2305 if (args.find(
"classes") == args.end())
2306 throw Exception(
"Missing argument 'classes' (vector of number of classes) in " + distName
2308 if (args.find(
"alphas") == args.end())
2309 throw Exception(
"Missing argument 'alphas' (vector of Dirichlet shape parameters) in Dirichlet distribution");
2310 vector<double> alphas;
2311 vector<size_t> classes;
2313 string rf = args[
"alphas"];
2318 rf = args[
"classes"];
2321 classes.push_back(TextTools::to<size_t>(strtok2.
nextToken()));
2326 for (
size_t i = 0; i < v.size(); i++)
2332 throw Exception(
"Unknown multiple distribution name: " + distName);
2340 const map<string, string>& params,
2341 const string& suffix,
2342 bool suffixIsOptional,
2348 map<string, string> args;
2369 std::shared_ptr<PhyloLikelihoodInterface> lik,
2370 const map<string, string>& params,
2371 const string& suffix,
2372 bool suffixIsOptional,
2386 if (verbose && optopt.
nstep > 1)
2396 if (dynamic_pointer_cast<SingleProcessPhyloLikelihood>(lik))
2398 dynamic_pointer_cast<SingleProcessPhyloLikelihood>(lik),
2407 unique_ptr<OptimizerInterface> finalOptimizer =
nullptr;
2408 if (finalMethod ==
"none")
2410 else if (finalMethod ==
"simplex")
2412 finalOptimizer = make_unique<DownhillSimplexMethod>(lik);
2414 else if (finalMethod ==
"powell")
2416 finalOptimizer = make_unique<PowellMultiDimensions>(lik);
2419 throw Exception(
"Unknown final optimization method: " + finalMethod);
2426 finalOptimizer->setProfiler(optopt.
profiler);
2427 finalOptimizer->setMessageHandler(optopt.
messenger);
2428 finalOptimizer->setMaximumNumberOfEvaluations(optopt.
nbEvalMax);
2429 finalOptimizer->getStopCondition()->setTolerance(optopt.
tolerance);
2430 finalOptimizer->setVerbose(verbose);
2433 finalOptimizer->optimize();
2434 n += finalOptimizer->getNumberOfEvaluations();
2442 rename(optopt.
backupFile.c_str(), bf.c_str());
2451 for (
size_t i = 0; i < pl.
size(); ++i)
2453 auto constraint = pl[i].getConstraint();
2456 double value = pl[i].getValue();
2457 if (!constraint->isCorrect(value - 1e-6) || !constraint->isCorrect(value + 1e-6))
2472 const map<string, string>& params,
2473 const string& prefix,
2474 const string& suffix,
2475 bool suffixIsOptional,
2483 if (format ==
"Newick")
2484 treeWriter =
new Newick();
2485 else if (format ==
"Nexus")
2487 else if (format ==
"NHX")
2488 treeWriter =
new Nhx(
false);
2490 throw Exception(
"Unknown format for tree writing: " + format);
2492 treeWriter->
writeTree(tree, file,
true);
2501 const vector<const PhyloTree*>& trees,
2502 const map<string, string>& params,
2503 const string& prefix,
2504 const string& suffix,
2505 bool suffixIsOptional,
2513 if (format ==
"Newick")
2514 treeWriter =
new Newick();
2515 else if (format ==
"Nexus")
2517 else if (format ==
"NHX")
2518 treeWriter =
new Nhx();
2520 throw Exception(
"Unknown format for tree writing: " + format);
2537 const map<string, string>& params,
2538 const string& prefix,
2539 const string& suffix,
2540 bool suffixIsOptional,
2550 if (format ==
"Newick")
2551 treeWriter =
new Newick();
2552 else if (format ==
"Nexus")
2554 else if (format ==
"NHX")
2555 treeWriter =
new Nhx();
2557 throw Exception(
"Unknown format for tree writing: " + format);
2561 string outtrees =
"";
2564 for (
size_t i = 0; i < vTN.size(); i++)
2566 auto tree = spc.
getTree(vTN[i]);
2568 std::vector<shared_ptr<PhyloNode>> nodes = tree->getAllNodes();
2570 for (
auto& node : nodes)
2572 if (tree->isLeaf(node) && withIds)
2595 map<string, string> globalAliases;
2596 vector<string> writtenNames;
2598 bIO.
write(model, out, globalAliases, writtenNames);
2610 (out <<
"nonhomogeneous=no").endLine();
2613 map<string, string> globalAliases;
2614 vector<string> writtenNames;
2616 bIO.
write(sp.model(0, 0), out, globalAliases, writtenNames);
2627 (out <<
"nonhomogeneous=no").endLine();
2630 map<string, string> globalAliases;
2631 vector<string> writtenNames;
2633 bIO.
write(process.
model(0, 0), out, globalAliases, writtenNames);
2639 out <<
"rate_distribution=";
2652 (out <<
"nonhomogeneous=general").endLine();
2653 (out <<
"nonhomogeneous.number_of_models=" << pNH.
getNumberOfModels()).endLine();
2655 vector<string> writtenNames;
2660 const auto model = pNH.
getModel(i);
2663 map<string, string> aliases;
2667 for (
size_t np = 0; np < pl.
size(); ++np)
2671 aliases[pl[np].getName()] = nfrom;
2675 writtenNames.clear();
2676 out.
endLine() <<
"model" << (i + 1) <<
"=";
2678 bIOsm.
write(*model, out, aliases, writtenNames);
2681 out <<
"model" << (i + 1) <<
".nodes_id=" << ids[0];
2682 for (
size_t j = 1; j < ids.size(); ++j)
2684 out <<
"," << ids[j];
2693 out <<
"nonhomogeneous.root_freq=";
2695 map<string, string> aliases;
2699 for (
size_t np = 0; np < pl.
size(); ++np)
2701 string nfrom = pNH.
getFrom(pl[np].getName());
2703 aliases[pl[np].getName()] = nfrom;
2710 out <<
"nonhomogeneous.stationarity=true";
2715 map<string, string> aliases;
2719 for (
size_t np = 0; np < pl.
size(); ++np)
2721 string nfrom = pNH.
getFrom(pl[np].getName());
2723 aliases[pl[np].getName()] = nfrom;
2726 out <<
"rate_distribution=";
2740 vector<string> writtenNames;
2745 for (
auto modn : vModN)
2747 const auto& model = *collection.
getModel(modn);
2750 map<string, string> aliases;
2756 for (
size_t np = 0; np < pl.
size(); ++np)
2760 aliases[pl[np].getName()] = nfrom;
2765 writtenNames.clear();
2766 out <<
"model" << modn <<
"=";
2768 bIOsm.
write(model, out, aliases, writtenNames);
2776 for (
size_t i = 0; i < rootFreqN.size(); ++i)
2781 writtenNames.clear();
2782 out.
endLine() <<
"root_freq" << rootFreqN[i] <<
"=";
2785 map<string, string> aliases;
2791 for (
size_t np = 0; np < pl.
size(); ++np)
2795 aliases[pl[np].getName()] = nfrom;
2807 for (
auto distn : vDistN)
2814 map<string, string> aliases;
2820 for (
size_t np = 0; np < pl.
size(); ++np)
2824 aliases[pl[np].getName()] = nfrom;
2829 writtenNames.clear();
2830 out.
endLine() <<
"rate_distribution" << distn <<
"=";
2841 if (vSce.size() > 0)
2844 vector<const ModelPath*> vMP;
2847 for (
const auto& scennum : vSce)
2853 out <<
"scenario" << scennum <<
"=";
2855 size_t nbMP = scen->getNumberOfModelPaths();
2857 for (
size_t mpn = 0; mpn < nbMP; mpn++)
2859 const auto& mp = scen->getModelPath(mpn);
2861 auto itmp = find(vMP.begin(), vMP.end(), mp.get());
2862 auto inmp = std::distance(vMP.begin(), itmp);
2863 if (itmp == vMP.end())
2864 vMP.push_back(mp.get());
2874 for (
size_t inmp = 0; inmp < vMP.size(); inmp++)
2877 out <<
"path" << inmp + 1 <<
"=";
2884 for (
const auto& mod:vMod)
2892 out <<
"model" << modN;
2904 for (
size_t i = 0; i < vprocN.size(); ++i)
2908 out <<
"process" << vprocN[i] <<
"=";
2910 if (spcm.getNumberOfModels() == 1)
2911 out <<
"Homogeneous(model=" << spcm.getModelNumbers()[0];
2914 out <<
"Nonhomogeneous(";
2915 vector<size_t> vMN = spcm.getModelNumbers();
2916 for (
size_t j = 0; j < vMN.size(); ++j)
2921 out <<
"model" << (j + 1) <<
"=" << vMN[j];
2924 vector<unsigned int> ids = spcm.getNodesWithModel(vMN[j]);
2925 out <<
"model" << (j + 1) <<
".nodes_id=(" << ids[0];
2926 for (
size_t k = 1; k < ids.size(); ++k)
2928 out <<
"," << ids[k];
2934 out <<
", tree=" << spcm.getTreeNumber();
2937 size_t dN = spcm.getRateDistributionNumber();
2942 out << size_t(dN / 10000 - 1) <<
"." << dN % 10000;
2944 if (spcm.getRootFrequencySet())
2945 out <<
", root_freq=" << spcm.getRootFrequenciesNumber();
2947 if (spcm.getModelScenario())
2948 out <<
", scenario=" << spcm.getModelScenarioNumber();
2959 out <<
"# Log likelihood = ";
2961 std::shared_ptr<const PhyloLikelihoodInterface> result = phylocont[0];
2978 auto pop = dynamic_pointer_cast<const PhyloLikelihoodFormula>(result);
2980 vector<size_t> phyldep;
2985 phyldep.push_back(1);
2989 string popout = pop->output();
3000 phyldep.push_back((
size_t)(atoi(ex.c_str())));
3009 while (phyldep.size() != 0)
3011 size_t num = phyldep[0];
3012 std::shared_ptr<const PhyloLikelihoodInterface> phyloLike = phylocont[num];
3015 auto itf = find(phyldep.begin(), phyldep.end(), num);
3016 while (itf != phyldep.end())
3019 itf = find(itf, phyldep.end(), num);
3025 if (dynamic_pointer_cast<const SingleDataPhyloLikelihoodInterface>(phyloLike))
3026 printParameters(*dynamic_pointer_cast<const SingleDataPhyloLikelihoodInterface>(phyloLike), out, num, warn);
3029 out <<
"phylo" << num <<
"=";
3031 auto mDP = dynamic_pointer_cast<const PhyloLikelihoodSetInterface>(phyloLike);
3034 if (dynamic_pointer_cast<const AlignedPhyloLikelihoodMixture>(phyloLike))
3036 auto pM = dynamic_pointer_cast<const AlignedPhyloLikelihoodMixture>(phyloLike);
3043 else if (dynamic_pointer_cast<const AlignedPhyloLikelihoodHmm>(phyloLike))
3045 auto pM = dynamic_pointer_cast<const AlignedPhyloLikelihoodHmm>(phyloLike);
3046 out <<
"HMM(probas=";
3055 else if (dynamic_pointer_cast<const AlignedPhyloLikelihoodAutoCorrelation>(phyloLike))
3057 auto pM = dynamic_pointer_cast<const AlignedPhyloLikelihoodAutoCorrelation>(phyloLike);
3059 out <<
"AutoCorr(lambdas=(";
3062 for (
unsigned int i = 0; i < pM->getHmmTransitionMatrix().cols(); ++i)
3064 vP.push_back(pM->getHmmTransitionMatrix()(i, i));
3071 else if (dynamic_pointer_cast<const AlignedPhyloLikelihoodProduct>(phyloLike))
3079 vector<size_t> vPN = mDP->getNumbersOfPhyloLikelihoods();
3081 for (
size_t i = 0; i < vPN.size(); i++)
3083 out <<
"phylo" << i + 1 <<
"=" << vPN[i];
3084 if (i != vPN.size() - 1)
3091 for (
size_t i = 0; i < vPN.size(); i++)
3093 if (find(phyldep.begin(), phyldep.end(), vPN[i]) == phyldep.end())
3094 phyldep.push_back(vPN[i]);
3114 out <<
"process=" << pMP.getSequenceEvolutionNumber();
3123 out <<
"process=" << pS.getSubstitutionProcessNumber();
3158 out <<
"HMM(probas=";
3169 out <<
"AutoCorr(lambdas=(";
3185 out <<
"Partition(";
3191 for (
unsigned int i = 0; i < vP.size(); i++)
3195 vector<size_t> v = mProcPos.find(vP[i])->second + 1;
3211 for (
size_t i = 0; i < vPN.size(); i++)
3213 out <<
"process" << i + 1 <<
"=" << vPN[i];
3214 if (i != vPN.size() - 1)
3232 std::shared_ptr<const PhyloLikelihoodInterface> result = phylocont[0];
3239 while (phyldep.size() != 0)
3241 size_t num = phyldep[0];
3243 phyldep.erase(phyldep.begin());
3245 std::shared_ptr<const PhyloLikelihoodInterface> phyloLike = phylocont[num];
3250 if (dynamic_pointer_cast<const SingleDataPhyloLikelihoodInterface>(phyloLike) && num != 0)
3251 printAnalysisInformation(*dynamic_pointer_cast<const SingleDataPhyloLikelihoodInterface>(phyloLike), info_out, warn);
3254 auto sOAP = dynamic_pointer_cast<const AlignedPhyloLikelihoodSetInterface>(phyloLike);
3260 vector<size_t> vPN = sOAP->getNumbersOfPhyloLikelihoods();
3263 phyldep.assign(vPN.begin(), vPN.end());
3268 auto sOAB = dynamic_pointer_cast<const PhyloLikelihoodSetInterface>(phyloLike);
3271 vector<size_t> vPN = sOAB->getNumbersOfPhyloLikelihoods();
3274 phyldep.assign(vPN.begin(), vPN.end());
3290 size_t nbP = phyloNum.size();
3294 StlOutputStream out(make_unique<ofstream>(infosFile.c_str(), ios::out));
3303 vector<string> colNames;
3304 colNames.push_back(
"Sites");
3305 colNames.push_back(
"lnL");
3307 for (
size_t i = 0; i < nbP; i++)
3311 for (
size_t i = 0; i < nbP; i++)
3317 vector<string> row(2 + (nbP > 1 ? 2 * nbP : 0));
3328 for (
size_t i = 0; i < nSites; i++)
3335 for (
size_t j = 0; j < nbP; j++)
3340 for (
size_t j = 0; j < nbP; j++)
3348 for (
size_t j = 0; j < nbP; j++)
3360 for (
size_t j = 0; j < vap.size(); j++)
3379 const string& infosFile,
3386 StlOutputStream out(make_unique<ofstream>(infosFile.c_str(), ios::out));
3388 std::shared_ptr<const SubstitutionProcessInterface> pSP = pSPL.getSubstitutionProcess();
3390 vector<string> colNames;
3391 colNames.push_back(
"Sites");
3392 colNames.push_back(
"is.complete");
3393 colNames.push_back(
"is.constant");
3394 colNames.push_back(
"lnL");
3396 auto pDD = pSP->getRateDistribution();
3401 nbR = pDD->getNumberOfCategories();
3404 for (
size_t i = 0; i < nbR; ++i)
3409 colNames.push_back(
"rc");
3410 colNames.push_back(
"pr");
3412 std::shared_ptr<const AlignmentDataInterface> sites = phyloLike.
getData();
3414 vector<string> row(6 + (nbR > 1 ? nbR : 0));
3415 auto infos = make_unique<DataTable>(colNames);
3417 VVdouble vvPP(pSPL.getPosteriorProbabilitiesPerSitePerClass());
3419 for (
size_t i = 0; i < sites->getNumberOfSites(); ++i)
3425 string isCompl =
"NA";
3426 string isConst =
"NA";
3447 for (
size_t j = 0; j < nbR; ++j)
3450 pr += vvPP[i][j] * pDD->getCategory(j);
3479 vector<size_t> nbProc = pSE.getSubstitutionProcessNumbers();
3481 map<size_t, size_t> mNbr;
3483 for (
auto nP : nbProc)
3485 auto& sp = pSE.substitutionProcess(nP);
3486 auto pDD = sp.getRateDistribution();
3487 mNbr[nP] = (pDD ? pDD->getNumberOfCategories() : 1);
3490 size_t maxR = max_element(mNbr.begin(), mNbr.end(), [](
const std::pair<size_t, size_t>& p1,
const std::pair<size_t, size_t>& p2){
3491 return p1.second < p2.second;
3494 StlOutputStream out(make_unique<ofstream>(infosFile.c_str(), ios::out));
3496 vector<string> colNames;
3497 colNames.push_back(
"Sites");
3498 colNames.push_back(
"is.complete");
3499 colNames.push_back(
"is.constant");
3500 colNames.push_back(
"lnL");
3503 for (
size_t i = 0; i < maxR; i++)
3508 size_t nbSites = pSE.getNumberOfSites();
3510 vector<string> row(4 + (maxR > 1 ? maxR : 0));
3511 auto infos = make_unique<DataTable>(nbSites, colNames);
3512 for (
auto nP : nbProc)
3514 auto pSPPL = dynamic_pointer_cast<const SingleProcessPhyloLikelihood>(pPPL.getPhyloLikelihood(nP));
3517 throw Exception(
"PhylogeneticsApplicationTools::printAnalysisInformation : no SingleProcessPhyloLikelihood in PartitionProcessPhyloLikelihood.");
3519 size_t nbr = mNbr[pSPPL->getSubstitutionProcessNumber()];
3521 const vector<size_t>& mPos = mProcPos.at(nP);
3523 auto sites = pSPPL->getData();
3525 for (
size_t i = 0; i < sites->getNumberOfSites(); ++i)
3527 double lnL = pSPPL->getLogLikelihoodForASite(i);
3531 string isCompl =
"NA";
3532 string isConst =
"NA";
3552 Vdouble vPP = pSPPL->getPosteriorProbabilitiesForSitePerClass(i);
3554 for (
size_t j = 0; j < nbr; ++j)
3560 for (
size_t j = nbr; j < maxR; j++)
3565 infos->setRow(mPos[i], row);
3579 StlOutputStream out(make_unique<ofstream>(infosFile.c_str(), ios::out));
3581 vector<string> colNames;
3582 colNames.push_back(
"Sites");
3583 colNames.push_back(
"is.complete");
3584 colNames.push_back(
"is.constant");
3585 colNames.push_back(
"lnL");
3587 size_t nbP = pMPL.getNumberOfSubstitutionProcess();
3591 for (
size_t i = 0; i < nbP; ++i)
3595 for (
size_t i = 0; i < nbP; ++i)
3601 auto sites = phyloLike.
getData();
3603 vector<string> row(4 + (nbP > 1 ? 2 * nbP : 0));
3606 VVdouble vvPP = pMPL.getPosteriorProbabilitiesPerSitePerProcess();
3607 VVdouble vvL = pMPL.getLikelihoodPerSitePerProcess();
3609 for (
size_t i = 0; i < sites->getNumberOfSites(); ++i)
3614 string isCompl =
"NA";
3615 string isConst =
"NA";
3635 for (
size_t j = 0; j < nbP; j++)
3639 for (
size_t j = 0; j < nbP; j++)
3662 out <<
"rate_distribution=";
3663 map<string, string> globalAliases;
3664 vector<string> writtenNames;
3675 std::shared_ptr<const Alphabet> alphabet,
3676 std::shared_ptr<const SubstitutionModelInterface> model,
3677 const map<string, string>& params,
3682 auto stateMap = model->getStateMap();
3684 unique_ptr<SubstitutionCountInterface> substitutionCount =
nullptr;
3686 map<string, string> nijtParams;
3690 if (nijtOption ==
"Laplace")
3692 size_t trunc = ApplicationTools::getParameter<size_t>(
"trunc", nijtParams, 10, suffix,
true, warn + 1);
3693 substitutionCount = make_unique<LaplaceSubstitutionCount>(model, trunc);
3695 else if (nijtOption ==
"Uniformization")
3701 substitutionCount = make_unique<UniformizationSubstitutionCount>(model, make_shared<TotalSubstitutionRegister>(stateMap), weights, distances);
3703 else if (nijtOption ==
"Decomposition")
3709 auto revModel = dynamic_pointer_cast<const ReversibleSubstitutionModelInterface>(model);
3711 substitutionCount = make_unique<DecompositionSubstitutionCount>(revModel, make_shared<TotalSubstitutionRegister>(stateMap), weights, distances);
3713 throw Exception(
"Decomposition method can only be used with reversible substitution models.");
3715 else if (nijtOption ==
"Naive")
3720 if (distanceOption !=
"")
3723 substitutionCount = make_unique<NaiveSubstitutionCount>(model, make_shared<TotalSubstitutionRegister>(stateMap),
false, weights);
3725 else if (nijtOption ==
"Label")
3727 substitutionCount = make_unique<LabelSubstitutionCount>(model);
3729 else if (nijtOption ==
"ProbOneJump")
3731 substitutionCount = make_unique<OneJumpSubstitutionCount>(model);
3741 return substitutionCount;
3748 const string& regTypeDesc,
3749 std::shared_ptr<const StateMapInterface> stateMap,
3750 std::shared_ptr<const GeneticCode> genCode,
3751 std::shared_ptr<AlphabetIndex2>& weights,
3752 std::shared_ptr<AlphabetIndex2>& distances,
3755 string regType =
"";
3756 map<string, string> regArgs;
3759 auto alphabet = stateMap->getAlphabet();
3761 unique_ptr<SubstitutionRegisterInterface> reg =
nullptr;
3763 distances =
nullptr;
3779 if (regType ==
"Combination")
3781 shared_ptr<AlphabetIndex2> w2;
3782 shared_ptr<AlphabetIndex2> d2;
3784 auto vreg = make_unique<VectorOfSubstitutionRegisters>(stateMap);
3795 vreg->addRegister(std::move(sreg));
3798 if (vreg->getNumberOfSubstitutionTypes() == 0)
3799 throw Exception(
"Missing registers reg1, reg2, ... in description of Combination");
3801 reg = std::move(vreg);
3803 else if (regType ==
"All")
3805 reg = make_unique<ComprehensiveSubstitutionRegister>(stateMap,
false);
3807 else if (regType ==
"Total")
3809 reg = make_unique<TotalSubstitutionRegister>(stateMap);
3811 else if (regType ==
"Selected")
3814 reg = make_unique<SelectedSubstitutionRegister>(stateMap, subsList);
3821 if (regType ==
"GC")
3822 reg = make_unique<GCSubstitutionRegister>(stateMap,
false);
3823 else if (regType ==
"GCw")
3824 reg = make_unique<GCSubstitutionRegister>(stateMap,
true);
3825 else if (regType ==
"TsTv")
3826 reg = make_unique<TsTvSubstitutionRegister>(stateMap);
3827 else if (regType ==
"SW")
3828 reg = make_unique<SWSubstitutionRegister>(stateMap);
3830 throw Exception(
"PhylogeneticsApplicationTools::getSubstitutionRegister: unsupported substitution categorization:" + regType +
" for alphabet " + alphabet->getAlphabetType());
3834 if (regType ==
"IntraAA")
3835 reg = make_unique<AAInteriorSubstitutionRegister>(stateMap, genCode);
3836 else if (regType ==
"InterAA")
3837 reg = make_unique<AAExteriorSubstitutionRegister>(stateMap, genCode);
3838 else if (regType ==
"GC")
3839 reg = make_unique<GCSynonymousSubstitutionRegister>(stateMap, genCode);
3840 else if (regType ==
"GC1")
3841 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 0);
3842 else if (regType ==
"GC2")
3843 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 1);
3844 else if (regType ==
"GC3")
3845 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 2);
3846 else if (regType ==
"GCw")
3847 reg = make_unique<GCSynonymousSubstitutionRegister>(stateMap, genCode,
true);
3848 else if (regType ==
"GC1w")
3849 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 0,
true);
3850 else if (regType ==
"GC2w")
3851 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 1,
true);
3852 else if (regType ==
"GC3w")
3853 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 2,
true);
3854 else if (regType ==
"TsTv")
3855 reg = make_unique<TsTvSubstitutionRegister>(stateMap, genCode);
3856 else if (regType ==
"SW")
3857 reg = make_unique<SWSubstitutionRegister>(stateMap, genCode);
3858 else if (regType ==
"KrKc")
3859 reg = make_unique<KrKcSubstitutionRegister>(stateMap, genCode);
3860 else if (regType ==
"DnDs")
3861 reg = make_unique<DnDsSubstitutionRegister>(stateMap, genCode,
false);
3863 throw Exception(
"Unsupported substitution categorization: " + regType +
" for alphabet " + alphabet->getAlphabetType());
3868 if (regType ==
"KrKc")
3869 reg = make_unique<KrKcSubstitutionRegister>(stateMap);
3871 throw Exception(
"Unsupported substitution categorization: " + regType +
" for alphabet " + alphabet->getAlphabetType());
std::shared_ptr< const FrequencySetInterface > getRootFrequencySet() const
const FrequencySetInterface & rootFrequencySet() const
std::string getFrom(const std::string &name) const
Likelihood framework based on a hmm of simple likelihoods.
Vdouble getPosteriorProbabilitiesForASitePerAligned(size_t site) const
Likelihood framework based on a hmm of simple likelihoods.
Vdouble getPosteriorProbabilitiesForASitePerAligned(size_t site) const
virtual double getLogLikelihoodForASite(size_t site) const =0
Get the log likelihood for a site, and its derivatives.
virtual size_t getNumberOfSites() const =0
Get the number of sites in the dataset.
Likelihood framework based on a mixture of aligned likelihoods.
Vdouble getPhyloProbabilities() const
Get the probabilities of the simplex.
The AlignedPhyloLikelihoodProduct class, for phylogenetic likelihood on several independent data.
Joint interface SetOf+Aligned PhylLikelihood.
virtual double getLogLikelihoodForASiteForAPhyloLikelihood(size_t site, size_t nPhyl) const =0
Get the log likelihood for a site for an aligned phyloLikelihood.
AssociationGraphObserver< N, E >::NodeIndex NodeIndex
virtual std::vector< EdgeIndex > getAllEdgesIndexes() const=0
Sequence evolution framework based on an auto-correlation of substitution processes.
const AutoCorrelationTransitionMatrix & hmmTransitionMatrix() const
double Pij(size_t i, size_t j) const override
static std::string CONSTRAINTS_AUTO
Interface for all Branch models.
The CategorySubstitutionRegisters.
void setStationarity(bool stat)
Context for dataflow node construction.
virtual int getCoordinate() const=0
static void write(const DataTable &data, std::ostream &out, const std::string &sep="\t", bool alignHeaders=false)
void addRow(const std::vector< std::string > &newRow)
virtual double getCategory(size_t categoryIndex) const=0
virtual std::string getName() const=0
void setTransitionProbabilities(const Matrix< double > &mat)
const Matrix< double > & getPij() const
Sequence evolution framework based on a hmm.
const FullHmmTransitionMatrix & hmmTransitionMatrix() const
virtual void readPhyloTrees(const std::string &path, std::vector< std::unique_ptr< PhyloTree > > &trees) const =0
Read trees from a file.
Sequence evolution framework based on a mixture of substitution processes.
const std::vector< double > & getSubProcessProbabilities() const
std::string to_string() const
Output.
Organization of submodels in mixed substitution models in a path. See class ModelScenario for a thoro...
const PathNode & getPathNode(std::shared_ptr< MixedTransitionModelInterface > mMod) const
gets the pathnode associated with a model
std::vector< std::shared_ptr< MixedTransitionModelInterface > > getModels() const
gets the MixedTransitionModel used in the ModelPath
Partial implementation of multiple processes of sequences.
size_t getNumberOfSubstitutionProcess() const
Return the number of process used for computation.
const std::vector< size_t > & getSubstitutionProcessNumbers() const
Partial implementation of the Likelihood interface for multiple processes.
The so-called 'newick' parenthetic format.
void enableExtendedBootstrapProperty(const std::string &propertyName)
a simple parser for reading trees from a Nexus file.
The so-called 'Nhx - New Hampshire eXtended' parenthetic format.
Substitution process manager for non-homogeneous / non-reversible models of evolution.
const DiscreteDistributionInterface & rateDistribution() const override
Get the rate distribution.
const std::vector< unsigned int > getNodesWithModel(size_t i) const override
Get a list of nodes id for which the given model is associated.
size_t getNumberOfModels() const override
std::shared_ptr< const BranchModelInterface > getModel(size_t n) const override
General interface for tree writers.
virtual void writePhyloTrees(const std::vector< const PhyloTree * > &trees, const std::string &path, bool overwrite) const =0
Write trees to a file.
General interface for tree writers.
virtual void writePhyloTree(const PhyloTree &tree, const std::string &path, bool overwrite) const =0
Write a tree to a file.
General interface for tree writers.
virtual void writeTree(const Tree &tree, const std::string &path, bool overwrite) const =0
Write a tree to a file.
Evolution of a sequence performed by a unique SubstitutionProcess all along the sequence.
const size_t getSubstitutionProcessNumber() const
virtual OutputStream & endLine()=0
virtual OutputStream & setPrecision(int digit)=0
virtual std::vector< std::string > getParameterNames() const
virtual void addParameter(const Parameter ¶m)
virtual bool matchParametersValues(const ParameterList ¶ms, std::vector< size_t > *updatedParameters=0)
virtual std::string getParameterNameWithoutNamespace(const std::string &name) const=0
virtual double getParameterValue(const std::string &name) const=0
virtual const ParameterList & getParameters() const=0
Sequence evolution framework based on a mixture of substitution processes.
std::map< size_t, std::vector< size_t > > & mapOfProcessSites()
The PhyloLikelihoodContainer, owns and assigns numbers to Phylolikelihoods.
std::vector< size_t > getNumbersOfPhyloLikelihoods() const
virtual const std::vector< size_t > & getNumbersOfPhyloLikelihoods() const =0
std::shared_ptr< const DiscreteDistributionInterface > getRateDistribution() const override
Get a pointer to the rate distribution (or null if there is no rate distribution).
This interface describes the evolution process of a sequence.
PhyloLikelihoods based on Sequence Evolution class, ie for which there is a (set of) processes able t...
Space and time homogeneous substitution process, without mixture.
The SingleDataPhyloLikelihood interface, for phylogenetic likelihood.
virtual std::shared_ptr< const AlignmentDataInterface > getData() const =0
Get the dataset for which the likelihood must be evaluated.
virtual size_t getNData() const =0
Get the number of dataset concerned.
Wraps a dataflow graph as a function: resultNode = f(variableNodes).
const std::string & nextToken()
bool hasMoreToken() const
std::vector< size_t > getModelNumbers() const override
std::shared_ptr< const DiscreteDistributionInterface > getRateDistribution() const override
Get a pointer to the rate distribution (or null if there is no rate distribution).
const std::vector< unsigned int > getNodesWithModel(size_t i) const override
Get a list of nodes id for which the given model is associated.
std::shared_ptr< const ModelScenario > getModelScenario() const override
Get the Model Scenario associated with this process, in case there are mixture models involved.
std::shared_ptr< const FrequencySetInterface > getRootFrequencySet() const override
std::shared_ptr< const BranchModelInterface > getModel(size_t n) const override
std::shared_ptr< const ParametrizablePhyloTree > getParametrizablePhyloTree() const override
void setModelScenario(size_t numPath)
Collection of Substitution Process, which owns all the necessary objects: Substitution models,...
std::vector< size_t > getTreeNumbers() const
std::vector< size_t > getFrequenciesNumbers() const
std::shared_ptr< FrequencySetInterface > getFrequencySet(size_t frequenciesIndex)
bool hasModelNumber(size_t n) const
std::vector< size_t > getModelNumbers() const
Get the numbers of the specified objects from the collections.
bool hasTreeNumber(size_t n) const
size_t getModelIndex(std::shared_ptr< BranchModelInterface > model) const
Return the number of a BranchModel in the collection.
DiscreteDistributionInterface & rateDistribution(size_t distributionIndex)
std::vector< size_t > getSubstitutionProcessNumbers() const
std::shared_ptr< ParametrizablePhyloTree > getTree(size_t treeIndex)
bool hasFrequenciesNumber(size_t n) const
void addOnePerBranchSubstitutionProcess(size_t nProc, size_t nMod, size_t nTree, size_t nRate, size_t nFreq, const std::vector< std::string > &sharedParameterNames)
std::shared_ptr< BranchModelInterface > getModel(size_t modelIndex)
bool hasModelScenario(size_t numPath) const
checks if the set has a ModelScenario
std::vector< size_t > getScenarioNumbers() const
bool hasDistributionNumber(size_t n) const
std::vector< size_t > getRateDistributionNumbers() const
std::shared_ptr< const ModelScenario > getModelScenario(size_t numPath) const
Get a ModelScenario from the set.
void addSubstitutionProcess(size_t nProc, std::map< size_t, std::vector< unsigned int > > mModBr, size_t nTree, size_t nRate, size_t nFreq)
void addDistribution(std::shared_ptr< DiscreteDistributionInterface > distribution, size_t distributionIndex)
SubstitutionProcessCollectionMember & substitutionProcess(size_t i)
std::shared_ptr< DiscreteDistributionInterface > getRateDistribution(size_t distributionIndex)
Get a DiscreteDistribution from the collection.
ParametrizablePhyloTree & tree(size_t treeIndex)
Get a tree from the set.
This interface describes the substitution process along the tree and sites of the alignment.
virtual const BranchModelInterface & model(size_t i) const =0
The phylogenetic tree class.
int toInt(const std::string &s, char scientificNotation='e')
double toDouble(const std::string &s, char dec='.', char scientificNotation='e')
bool isDecimalInteger(const std::string &s, char scientificNotation='e')
std::string toString(T t)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
ExtendedFloat exp(const ExtendedFloat &ef)
template void copyEigenToBpp(const ExtendedFloatMatrixXd &eigenMatrix, std::vector< std::vector< double > > &bppMatrix)
std::vector< Vdouble > VVdouble
std::vector< unsigned int > Vuint