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"
14 #include "../Io/Nhx.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"
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,
163 map<size_t, shared_ptr<PhyloTree>> mTree;
165 for (
size_t nT = 0; nT < vTreesName.size(); nT++)
167 size_t poseq = vTreesName[nT].find(
"=");
169 size_t len = (prefix +
"tree").size();
171 string suff = vTreesName[nT].substr(len, poseq - len);
193 map<string, string> args;
197 if (treeName ==
"user")
201 if (args.find(
"format") != args.end())
202 format = args[
"format"];
212 if (format ==
"Newick")
213 treeReader =
new Newick(
true);
214 else if (format ==
"Nexus")
216 else if (format ==
"NHX")
217 treeReader =
new Nhx();
219 throw Exception(
"Unknown format for tree reading: " + format);
221 vector<unique_ptr<PhyloTree>> trees;
224 if (args.find(
"data") != args.end())
227 if (mSeq.find(seqNum) == mSeq.end())
232 vector<string> names = mSeq.find(seqNum)->second->getSequenceNames();
234 for (
auto& tree:trees)
236 auto nb1 = tree->getNumberOfLeaves();
237 tree->pruneTree(names);
238 auto nb2 = tree->getNumberOfLeaves();
260 nbTree = trees.size();
262 for (
size_t i2 = 0; i2 < trees.size(); i2++)
264 if (mTree.find(i2 + 1) != mTree.end())
270 mTree[i2 + 1] = std::move(trees[i2]);
276 if (trees.size() > 1)
277 throw Exception(
"Error : Several trees for description of " + vTreesName[nT] +
".");
279 if (trees.size() == 1)
281 if (mTree.find(num) != mTree.end())
286 mTree[num] = std::move(trees[0]);
291 else if (treeName ==
"random")
295 if (args.find(
"data") == args.end())
304 if (mSeq.find(seqNum) == mSeq.end())
307 vector<string> names = mSeq.find(seqNum)->second->getSequenceNames();
311 treetemp->setBranchLengths(1.);
315 if (mTree.find(num) != mTree.end())
329 map<string, string> cmdArgs;
335 if (cmdName ==
"Input")
339 if (midPointRootBrLengths ==
"yes")
344 for (
size_t i = 0; i < nbTree; i++)
353 else if (cmdName ==
"Equal")
357 throw Exception(
"Value for branch length must be superior to 0");
361 for (
size_t i = 0; i < nbTree; i++)
363 mTree[i + 1]->setBranchLengths(value);
367 mTree[num]->setBranchLengths(value);
369 else if (cmdName ==
"Clock")
373 for (
size_t i = 0; i < nbTree; i++)
381 else if (cmdName ==
"Grafen")
387 for (
size_t i = 0; i < nbTree; i++)
389 auto tree = mTree[i + 1];
390 if (grafenHeight ==
"input")
398 throw Exception(
"Height must be positive in Grafen's method.");
407 tree->scaleTree(h / nh);
412 auto tree = mTree[num];
413 if (grafenHeight ==
"input")
419 throw Exception(
"Height must be positive in Grafen's method.");
429 tree->scaleTree(h / nh);
433 throw Exception(
"Method '" + initBrLenMethod +
"' unknown for computing branch lengths.");
439 for (
size_t ib = 0; ib < vBrNb.size(); ib++)
441 string apeq = args[vBrNb[ib]];
442 string aveq = vBrNb[ib];
452 size_t posun = apeq.find(
"_");
453 size_t posd = aveq.find(
"_");
467 std::shared_ptr<const Alphabet> alphabet,
468 std::shared_ptr<const GeneticCode> gCode,
469 std::shared_ptr<const AlignmentDataInterface> data,
470 const map<string, string>& params,
471 map<string, string>& unparsedParams,
472 const string& suffix,
473 bool suffixIsOptional,
478 string modelDescription;
479 auto ca = dynamic_pointer_cast<const CodonAlphabet>(alphabet);
484 throw Exception(
"PhylogeneticsApplicationTools::getSubstitutionModel(): a GeneticCode instance is required for instantiating a codon model.");
492 std::map<size_t, std::shared_ptr<const AlignmentDataInterface>> mData;
503 std::shared_ptr<const Alphabet> alphabet,
504 std::shared_ptr<const GeneticCode> gCode,
505 std::shared_ptr<const AlignmentDataInterface> data,
506 const map<string, string>& params,
507 map<string, string>& unparsedParams,
508 const string& suffix,
509 bool suffixIsOptional,
514 string modelDescription;
515 auto ca = dynamic_pointer_cast<const CodonAlphabet>(alphabet);
520 throw Exception(
"PhylogeneticsApplicationTools::getBranchModel(): a GeneticCode instance is required for instantiating a codon model.");
528 std::map<size_t, std::shared_ptr<const AlignmentDataInterface>> mData;
531 auto model = bIO.
readBranchModel(alphabet, modelDescription, mData, 1,
true);
534 unparsedParams.insert(tmpUnparsedParameterValues.begin(), tmpUnparsedParameterValues.end());
542 const map<string, string>& params,
543 const string& suffix,
544 bool suffixIsOptional,
549 map<string, string> paramDist;
551 if (DistFilePath !=
"none")
554 paramDist.insert(params.begin(), params.end());
559 map<size_t, std::shared_ptr<DiscreteDistributionInterface>> mDist;
562 for (
size_t i = 0; i < vratesName.size(); ++i)
564 size_t poseq = vratesName[i].find(
"=");
566 string suff = vratesName[i].substr(17, poseq - 17);
591 if (mDist.size() == 0)
608 std::shared_ptr<const Alphabet> alphabet,
609 std::shared_ptr<const GeneticCode> gCode,
610 const map<
size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
611 const map<string, string>& params,
612 map<string, string>& unparsedParams,
613 const string& suffix,
614 bool suffixIsOptional,
618 if (dynamic_pointer_cast<const CodonAlphabet>(alphabet) && !gCode)
619 throw Exception(
"PhylogeneticsApplicationTools::getBranchModels(): a GeneticCode instance is required for instantiating codon models.");
623 map<string, string> paramModel;
625 if (ModelFilePath !=
"none")
628 paramModel.insert(params.begin(), params.end());
632 vector<size_t> modelsNum;
633 for (
const auto& name : modelsName)
635 size_t poseq = name.find(
"=");
636 if (name.find(
"nodes_id") == string::npos)
638 modelsNum.push_back(TextTools::to<size_t>(name.substr(5, poseq - 5)));
642 map<size_t, std::unique_ptr<BranchModelInterface>> mModel;
647 for (
size_t i = 0; i < modelsNum.size(); ++i)
665 unique_ptr<BranchModelInterface> model;
666 model = bIO.
readBranchModel(alphabet, modelDescription, mData, 0,
true);
670 for (
auto& it : tmpUnparsedParameterValues)
675 mModel[modelsNum[i]] = std::move(model);
687 std::shared_ptr<const Alphabet> alphabet,
688 std::shared_ptr<const GeneticCode> gCode,
689 const string& freqDescription,
690 const std::map<
size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
692 map<string, string>& sharedparams,
693 const vector<double>& rateFreqs,
697 map<string, string> unparsedParameterValues;
702 throw Exception(
"PhylogeneticsApplicationTools::getFrequencySet(): a GeneticCode instance is required for instantiating a codon frequencies set.");
706 auto pFS = bIO.
readFrequencySet(alphabet, freqDescription, mData, nData,
true);
710 sharedparams.insert(unparsedparam.begin(), unparsedparam.end());
713 if (rateFreqs.size() > 0)
715 pFS = std::make_unique<MarkovModulatedFrequencySet>(std::move(pFS), rateFreqs);
723 std::shared_ptr<const Alphabet> alphabet,
724 std::shared_ptr<const GeneticCode> gCode,
725 const std::map<
size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
727 const map<string, string>& params,
728 map<string, string>& sharedparams,
729 const vector<double>& rateFreqs,
730 const string& suffix,
731 bool suffixIsOptional,
736 if (freqDescription ==
"None")
742 map<string, string> unparams;
744 auto freq = getFrequencySet(alphabet, gCode, freqDescription, mData, nData, unparams, rateFreqs, verbose, warn + 1);
745 freq->setNamespace(
"root." + freq->getNamespace());
747 for (
auto& it : unparams)
749 sharedparams[
"root." + it.first] = it.second;
760 std::shared_ptr<const Alphabet> alphabet,
761 std::shared_ptr<const GeneticCode> gCode,
762 const map<
size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
763 const map<string, string>& params,
764 map<string, string>& sharedparams,
765 const string& suffix,
766 bool suffixIsOptional,
770 if (dynamic_pointer_cast<const CodonAlphabet>(alphabet) && !gCode)
771 throw Exception(
"PhylogeneticsApplicationTools::getRootFrequencySets(): a GeneticCode instance is required for instantiating codon frequencies sets.");
774 map<string, string> paramRF;
776 if (RootFilePath !=
"none")
779 paramRF.insert(params.begin(), params.end());
783 vector<size_t> rfNum;
784 for (
const auto& rfName : vrfName)
786 size_t poseq = rfName.find(
"=");
789 rfNum.push_back(TextTools::to<size_t>(rfName.substr(9, poseq - 9)));
798 map<size_t, std::unique_ptr<FrequencySetInterface>> mFS;
800 for (
size_t i = 0; i < rfNum.size(); ++i)
807 map<string, string> args;
814 if (args.find(
"data") != args.end())
815 nData = TextTools::to<size_t>(args[
"data"]);
817 unique_ptr<FrequencySetInterface> rFS;
821 rFS->setNamespace(
"root." + rFS->getNamespace());
825 for (
auto& it : unparsedparam)
837 mFS[rfNum[i]] = std::move(rFS);
848 const std::map<std::string, std::string>& params,
849 const map<
size_t, std::shared_ptr<BranchModelInterface>>& mModel,
850 const string& suffix,
851 bool suffixIsOptional,
856 map<string, string> paramMP;
858 if (ModelPathsPath !=
"none")
861 paramMP.insert(params.begin(), params.end());
865 map<size_t, std::unique_ptr<ModelPath>> modelPaths;
867 for (
size_t i = 0; i < vmpName.size(); ++i)
869 const auto& name = vmpName[i];
876 num = TextTools::to<size_t>(name.substr(4));
880 throw Exception(
"PhylogeneticsApplicationTools::getModelPaths: bad path number in line " + name);
883 modelPaths[num] = std::make_unique<ModelPath>();
905 auto indexo = submodel.find(
"[");
906 auto indexf = submodel.find(
"]");
907 if ((indexo == string::npos) | (indexf == string::npos))
908 throw Exception(
"PhylogeneticsApplicationTools::getModelPaths. Bad path syntax, should contain `[]' symbols: " + submodel);
910 auto pos = submodel.find(
"model");
911 if (pos == string::npos)
912 throw Exception(
"PhylogeneticsApplicationTools::getModelPaths. Missing identifier 'model' in description: " + submodel);
914 size_t num2 = TextTools::to<size_t>(submodel.substr(pos + 5, indexo - 5 - pos));
915 if (mModel.find(num2) == mModel.end())
916 throw BadIntegerException(
"PhylogeneticsApplicationTools::getModelPaths: Wrong model number",
static_cast<int>(num2));
918 auto pSM = std::dynamic_pointer_cast<MixedTransitionModelInterface>(mModel.at(num2));
920 throw Exception(
"PhylogeneticsApplicationTools::getModelPaths: Model number " +
TextTools::toString(num2) +
" ( " + mModel.at(num2)->getName() +
" ) is not Mixed.");
922 string lp2 = submodel.substr(indexo + 1, indexf - indexo - 1);
932 n2 = TextTools::to<unsigned int>(p2);
933 if (n2 <= 0 || n2 > pSM->getNumberOfModels())
936 submodelNb.push_back(n2 - 1);
940 Vuint submodnb = pSM->getSubmodelNumbers(p2);
941 if (submodelNb.size() == 0)
942 submodelNb = submodnb;
951 modelPaths[num]->setModel(pSM, submodelNb);
952 if (!modelPaths[num]->getLeadModel())
953 modelPaths[num]->setLeadModel(pSM);
956 if (verbose && (i < 10))
965 const std::map<std::string, std::string>& params,
966 const map<
size_t, std::shared_ptr<ModelPath>>& mModelPath,
967 const map<
size_t, std::shared_ptr<BranchModelInterface>>& mModel,
968 const string& suffix,
969 bool suffixIsOptional,
974 map<string, string> paramMS;
976 if (ModelPathsPath !=
"none")
979 paramMS.insert(params.begin(), params.end());
983 map<size_t, std::unique_ptr<ModelScenario>> somp;
985 for (
size_t i = 0; i < vmsName.size(); ++i)
987 const auto& name = vmsName[i];
994 num = TextTools::to<size_t>(name.substr(8));
998 throw Exception(
"PhylogeneticsApplicationTools::getModelScenarios: bad scenario number in line " + name);
1001 somp[num] = std::make_unique<ModelScenario>();
1018 bool complete =
false;
1028 if (path ==
"complete")
1030 else if (path.substr(0, 5) ==
"split")
1032 auto pos = path.find(
"model");
1033 if (pos == string::npos)
1034 throw Exception(
"PhylogeneticsApplicationTools::getModelScenarios. Missing identifier 'model' in scenario description: " + path);
1036 auto poseq = path.find(
"=", pos);
1037 size_t num2 = TextTools::to<size_t>(path.substr(poseq + 1));
1039 if (mModel.find(num2) == mModel.end())
1040 throw BadIntegerException(
"PhylogeneticsApplicationTools::getModelScenarios: Wrong model number",
static_cast<int>(num2));
1042 auto pSM = std::dynamic_pointer_cast<MixedTransitionModelInterface>(mModel.at(num2));
1044 throw Exception(
"PhylogeneticsApplicationTools::getModelScenarios: Model number " +
TextTools::toString(num2) +
" ( " + mModel.at(num2)->getName() +
" ) is not Mixed.");
1046 std::vector<std::shared_ptr<ModelPath>> modelPaths;
1048 auto nmod = pSM->getNumberOfModels();
1050 for (
unsigned int nm = 0; nm < static_cast<unsigned int>(nmod); ++nm)
1052 auto mp = std::make_shared<ModelPath>();
1053 mp->setModel(pSM,
Vuint({nm}));
1054 mp->setLeadModel(pSM);
1055 somp[num]->addModelPath(mp);
1060 numpath = TextTools::to<size_t>(path.substr(4));
1061 if (mModelPath.find(numpath) == mModelPath.end())
1064 somp[num]->addModelPath(mModelPath.at(numpath));
1069 Exception(
"PhylogeneticsApplicationTools::getModelScenarios: wrong path description " + path);
1073 throw BadIntegerException(
"PhylogeneticsApplicationTools::getModelScenarios: Wrong path number",
static_cast<int>(numpath));
1077 if (verbose && (i < 10))
1082 if (somp[num]->getNumberOfModelPaths() == 0)
1083 throw Exception(
"PhylogeneticsApplicationTools::getModelScenarios: 'complete' is not possible on empty scenarios");
1084 somp[num]->complete();
1087 somp[num]->computeModelPathsProbabilities();
1098 std::shared_ptr<const Alphabet> alphabet,
1099 std::shared_ptr<const GeneticCode> gCode,
1100 std::shared_ptr<const AlignmentDataInterface> pData,
1101 const vector< shared_ptr<PhyloTree>>& vTree,
1102 const map<string, string>& params,
1103 const string& suffix,
1104 bool suffixIsOptional,
1110 map<string, string> unparsedParams;
1112 map<size_t, std::shared_ptr<const AlignmentDataInterface>> mData;
1115 map<size_t, std::shared_ptr<PhyloTree>> mTree;
1117 for (
auto it : vTree)
1122 auto mModU = getBranchModels(alphabet, gCode, mData, params, unparsedParams, suffix, suffixIsOptional, verbose, warn);
1123 auto mMod = uniqueToSharedMap<BranchModelInterface>(mModU);
1125 auto mRootFreqU = getRootFrequencySets(alphabet, gCode, mData, params, unparsedParams, suffix, suffixIsOptional, verbose, warn);
1126 auto mRootFreq = uniqueToSharedMap<FrequencySetInterface>(mRootFreqU);
1128 auto mDist = getRateDistributions(params, suffix, suffixIsOptional, verbose);
1130 auto mPathU = getModelPaths(params, mMod, suffix, suffixIsOptional, verbose, warn);
1131 auto mPath = uniqueToSharedMap<ModelPath>(mPathU);
1133 auto mScenU = getModelScenarios(params, mPath, mMod, suffix, suffixIsOptional, verbose, warn);
1134 auto mScen = uniqueToSharedMap<ModelScenario>(mScenU);
1136 auto SPC = getSubstitutionProcessCollection(alphabet, gCode, mTree,
1137 mMod, mRootFreq, mDist, mScen,
1138 params, unparsedParams, suffix, suffixIsOptional, verbose, warn);
1141 unique_ptr<AutonomousSubstitutionProcessInterface> ASP;
1143 auto psNum = SPC->getSubstitutionProcessNumbers();
1144 if (psNum.size() == 0)
1145 throw Exception(
"PhylogeneticsApplicationTools::getSubstitutionProcess : missing process in parameters.");
1147 size_t maxps = *max_element(psNum.begin(), psNum.end());
1159 if (vmodnb.size() == 1)
1170 for (
auto nb:vmodnb)
1175 if (!NHSP->isFullySetUp(
false))
1176 throw Exception(
"PhylogeneticsApplicationTools::getSubstitutionProcess: process not fully set up.");
1178 ASP = std::move(NHSP);
1193 const map<string, string>& params,
1197 string procName =
"";
1198 map<string, string> args;
1204 if ((procName !=
"OnePerBranch") && (procName !=
"Homogeneous") && (procName !=
"Nonhomogeneous") && (procName !=
"NonHomogeneous"))
1217 if (args.find(
"tree") == args.end())
1228 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown tree number", (
int)numTree);
1235 if (args.find(
"rate") == args.end())
1249 for (uint i = 1; i <= *std::max_element(vrdn.begin(), vrdn.end()) + 1; i++)
1251 if (std::find(vrdn.begin(), vrdn.end(), i) == vrdn.end())
1257 SubProColl.
addDistribution(std::make_shared<ConstantRateDistribution>(), numRate);
1264 size_t pp = sRate.find(
".");
1266 numRate = TextTools::to<size_t>(sRate.substr(0, pp));
1269 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown rate number", (
int)numRate);
1271 if (pp != string::npos)
1273 size_t numSRate = TextTools::to<size_t>(sRate.substr(pp + 1));
1275 std::make_shared<ConstantDistribution>(
1277 10000 * (numRate + 1) + numSRate);
1279 numRate = 10000 * (numRate + 1) + numSRate;
1286 bool stationarity = (args.find(
"root_freq") == args.end());
1293 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown root frequencies number", (
int)numFreq);
1301 if (args.find(
"scenario") != args.end())
1306 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown scenario number", (
int)numScen);
1318 if (procName ==
"Homogeneous")
1320 if (args.find(
"model") == args.end())
1321 throw Exception(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember. A model number is compulsory.");
1326 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown model number",
static_cast<int>(numModel));
1328 map<size_t, vector<unsigned int>> mModBr;
1330 vector<uint> vNodes;
1336 mModBr[numModel] = vNodes;
1343 if (numRate < 10000)
1363 else if ((procName ==
"Nonhomogeneous") || (procName ==
"NonHomogeneous"))
1366 throw Exception(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : missing tree number for process " +
TextTools::toString(procName));
1368 size_t indModel = 1;
1369 map<size_t, vector<unsigned int>> mModBr;
1375 if (mModBr.find(numModel) != mModBr.end())
1376 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : model number seen twice.", (
int)numModel);
1378 vector<unsigned int> nodesId;
1384 auto tree = SubProColl.
getTree(numTree);
1385 if (descnodes ==
"All")
1387 nodesId = tree->getEdgeIndexes(tree->getSubtreeEdges(tree->getRoot()));
1389 else if (descnodes ==
"Leaves")
1391 nodesId = tree->getNodeIndexes(tree->getLeavesUnderNode(tree->getRoot()));
1393 else if (descnodes ==
"NoLeaves")
1395 auto allIds = tree->getEdgeIndexes(tree->getSubtreeEdges(tree->getRoot()));
1396 auto leavesId = tree->getNodeIndexes(tree->getLeavesUnderNode(tree->getRoot()));
1400 nodesId = ApplicationTools::getVectorParameter<unsigned int>(snodesid, args,
',',
':',
"",
"",
true, warn);
1402 mModBr[numModel] = nodesId;
1410 for (
auto& it : mModBr)
1427 else if (procName ==
"OnePerBranch")
1430 throw Exception(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : missing tree number for process " +
TextTools::toString(procName));
1432 if (args.find(
"model") == args.end())
1433 throw Exception(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember. A model number is compulsory.");
1438 throw BadIntegerException(
"PhylogeneticsApplicationTools::addSubstitutionProcessCollectionMember : unknown model number", (
int)numModel);
1440 vector<string> sharedParameters = ApplicationTools::getVectorParameter<string>(
"shared_parameters", args,
',',
"",
"",
true, 1);
1459 for (
const auto& sP : sharedParameters)
1476 std::shared_ptr<const Alphabet> alphabet,
1477 std::shared_ptr<const GeneticCode> gCode,
1478 const map<
size_t, std::shared_ptr<PhyloTree>>& mTree,
1479 const map<
size_t, std::shared_ptr<BranchModelInterface>>& mMod,
1480 const map<
size_t, std::shared_ptr<FrequencySetInterface>>& mRootFreq,
1481 const map<
size_t, std::shared_ptr<DiscreteDistributionInterface>>& mDist,
1482 const map<
size_t, std::shared_ptr<ModelScenario>>& mScen,
1483 const map<string, string>& params,
1484 map<string, string>& unparsedParams,
1485 const string& suffix,
1486 bool suffixIsOptional,
1490 auto SPC = make_unique<SubstitutionProcessCollection>();
1492 map<string, double> existingParameters;
1497 for (
const auto& itt : mTree)
1501 SPC->addTree(std::make_shared<ParametrizablePhyloTree>(*(itt.second)), itt.first);
1508 for (
const auto& itd : mDist)
1510 SPC->addDistribution(itd.second, itd.first);
1516 for (
const auto& itm : mMod)
1518 SPC->addModel(itm.second, itm.first);
1524 for (
const auto& itr : mRootFreq)
1526 SPC->addFrequencies(itr.second, itr.first);
1532 for (
const auto& itt : mScen)
1534 SPC->addScenario(itt.second, itt.first);
1542 if (vProcName.size() == 0)
1543 throw Exception(
"Missing process in construction of SubstitutionProcessCollection.");
1545 for (
size_t nT = 0; nT < vProcName.size(); nT++)
1547 size_t poseq = vProcName[nT].find(
"=");
1551 string suff = vProcName[nT].substr(len, poseq - len);
1554 num = TextTools::to<size_t>(suff);
1558 bool addok = addSubstitutionProcessCollectionMember(*SPC, num, params, (nT < 10 ? verbose :
false), warn);
1602 for (
const auto& param : params)
1607 SPC->setParameterValue(param.first, v2);
1611 if (SPC->hasParameter(param.first))
1612 unparsedParams[param.first] = param.second;
1616 SPC->aliasParameters(unparsedParams, verbose);
1626 shared_ptr<SubstitutionProcessCollection> SPC,
1627 const map<string, string>& params,
1628 map<string, string>& unparsedParams,
1629 const string& suffix,
1630 bool suffixIsOptional,
1634 map<string, string> paramEvol;
1636 paramEvol.insert(params.begin(), params.end());
1640 vector<size_t> evolsNum;
1641 for (
size_t i = 0; i < evolsName.size(); ++i)
1643 size_t poseq = evolsName[i].find(
"=");
1644 evolsNum.push_back(TextTools::to<size_t>(evolsName[i].substr(7, poseq - 7)));
1647 map<size_t, unique_ptr<SequenceEvolution>> mEvol;
1649 for (
size_t mPi = 0; mPi < evolsNum.size(); ++mPi)
1651 if (SPC->hasSubstitutionProcessNumber(evolsNum[mPi]))
1654 unique_ptr<SequenceEvolution> nEvol;
1656 string evolName =
"";
1657 map<string, string> args;
1670 if (evolName ==
"Simple")
1673 if (!SPC->hasSubstitutionProcessNumber(nproc))
1674 throw BadIntegerException(
"PhylogeneticsApplicationTools::getEvolutions. Unknown process number:", (
int)nproc);
1676 nEvol = make_unique<OneProcessSequenceEvolution>(SPC->getSubstitutionProcess(nproc), nproc);
1686 vector<size_t> vproc;
1692 vproc.push_back(numProc);
1696 if (vproc.size() == 0)
1697 throw BadIntegerException(
"PhylogeneticsApplicationTools::getEvolutions. A process number is compulsory for process", (
int)indProc);
1699 for (
size_t i = 0; i < vproc.size(); ++i)
1701 if (!SPC->hasSubstitutionProcessNumber(vproc[i]))
1702 throw BadIntegerException(
"PhylogeneticsApplicationTools::getEvolutions. Unknown process number:", (
int)vproc[i]);
1705 if (evolName ==
"Partition")
1709 vector<size_t> vMap;
1711 map<size_t, size_t> posProc;
1713 for (
size_t i = 0; i < vproc.size(); ++i)
1717 vector<size_t> procPos = ApplicationTools::getVectorParameter<size_t>(prefix +
".sites", args,
',',
':',
TextTools::toString(i),
"",
true,
true);
1719 for (
size_t j = 0; j < procPos.size(); ++j)
1721 if (posProc.find(procPos[j]) != posProc.end())
1724 posProc[procPos[j]] = vproc[i];
1728 size_t pos = posProc.begin()->first;
1730 while (posProc.find(pos) != posProc.end())
1732 vMap.push_back(posProc[pos]);
1736 if (vMap.size() != posProc.size())
1737 throw Exception(
"Error : there are gaps in the process sites");
1742 auto pMP = make_unique<PartitionSequenceEvolution>(SPC, vMap);
1744 nEvol = std::move(pMP);
1746 else if (evolName ==
"Mixture")
1748 auto pMP = make_unique<MixtureSequenceEvolution>(SPC, vproc);
1753 size_t nbP = pMP->getNumberOfSubstitutionProcess();
1755 vector<double> vprob = ApplicationTools::getVectorParameter<double>(
"probas", args,
',',
"(" +
VectorTools::paste(vector<double>(nbP, 1. / (
double)nbP)) +
")");
1756 if (vprob.size() != 1)
1758 if (vprob.size() != nbP)
1759 throw BadSizeException(
"Wrong size of probas description in Mixture", vprob.size(), nbP);
1761 pMP->setSubProcessProb(si);
1764 nEvol = std::move(pMP);
1766 else if (evolName ==
"HMM")
1768 auto pMP = make_unique<HmmSequenceEvolution>(SPC, vproc);
1773 size_t nbP = pMP->getNumberOfSubstitutionProcess();
1775 string vs =
"(" +
VectorTools::paste(vector<double>(nbP, 1. / (
double)nbP),
",") +
")";
1777 for (
size_t i = 0; i < nbP; ++i)
1779 vvs += (i == 0 ?
"" :
",") + vs;
1783 RowMatrix<double> mat = ApplicationTools::getMatrixParameter<double>(
"probas", args,
',', vvs);
1790 nEvol = std::move(pMP);
1792 else if (evolName ==
"AutoCorr")
1794 auto pMP = make_unique<AutoCorrelationSequenceEvolution>(SPC, vproc);
1796 size_t nbP = pMP->getNumberOfSubstitutionProcess();
1803 vector<double> v = ApplicationTools::getVectorParameter<double>(
"lambdas", args,
',', vs);
1807 for (
size_t i = 0; i < v.size(); ++i)
1812 pMP->matchParametersValues(pl);
1814 nEvol = std::move(pMP);
1817 throw Exception(
"Unknown Process description : " + evolName);
1826 mEvol[evolsNum[mPi]] = std::move(nEvol);
1839 shared_ptr<SubstitutionProcessCollection> SPC,
1840 map<
size_t, std::shared_ptr<SequenceEvolution>>& mSeqEvol,
1841 const map<
size_t, std::shared_ptr<const AlignmentDataInterface>>& mData,
1842 const map<string, string>& params,
1843 const string& suffix,
1844 bool suffixIsOptional,
1848 auto mPhylo = std::make_shared<PhyloLikelihoodContainer>(context, SPC);
1851 auto collNodes = mPhylo->getCollectionNodes();
1854 map<string, string> paramPhyl;
1855 paramPhyl.insert(params.begin(), params.end());
1860 map<size_t, vector<size_t>> phylosMap;
1862 for (
size_t i = 0; i < phylosName.size(); ++i)
1864 size_t poseq = phylosName[i].find(
"=");
1865 size_t phyln = TextTools::to<size_t>(phylosName[i].substr(5, poseq - 5));
1868 throw BadIntegerException(
"PhylogeneticsApplicationTools::getPhyloLikelihoodContainer : Forbidden Phylo Number", 0);
1872 map<string, string> args;
1874 string phyloName =
"";
1879 vector<size_t> vphyl;
1884 vphyl.push_back(numPhyl);
1888 phylosMap[phyln] = vphyl;
1891 vector<size_t> usedPhylo;
1897 bool verbhere(verbose);
1899 for (
const auto& it : phylosMap)
1903 if (it.second.size() != 0)
1906 size_t phylonum = it.first;
1908 std::shared_ptr<PhyloLikelihoodInterface> nPL;
1909 string phyloName =
"";
1911 map<string, string> args;
1929 size_t nData = (args.find(
"data") == args.end() ? 1 : TextTools::to<size_t>(args[
"data"]));
1931 if (mData.find(nData) == mData.end())
1937 auto data = mData.find(nData)->second;
1950 size_t nProcess = (args.find(
"process") == args.end() ? 1 : TextTools::to<size_t>(args[
"process"]));
1957 if (SPC->hasSubstitutionProcessNumber(nProcess))
1959 auto l = std::make_shared<LikelihoodCalculationSingleProcess>(collNodes, data, nProcess);
1960 nPL = make_unique<SingleProcessPhyloLikelihood>(context, l, nProcess, nData);
1962 else if (mSeqEvol.find(nProcess) != mSeqEvol.end())
1967 auto opse = dynamic_pointer_cast<OneProcessSequenceEvolution>(mSeqEvol[nProcess]);
1970 nPL = make_unique<OneProcessSequencePhyloLikelihood>(data, opse, collNodes, nProcess, nData);
1973 auto mse = dynamic_pointer_cast<MixtureSequenceEvolution>(mSeqEvol[nProcess]);
1976 nPL = make_unique<MixtureProcessPhyloLikelihood>(data, mse, collNodes, nProcess, nData);
1980 auto hse = dynamic_pointer_cast<HmmSequenceEvolution>(mSeqEvol[nProcess]);
1983 nPL = make_unique<HmmProcessPhyloLikelihood>(data, hse, collNodes, nProcess, nData);
1987 auto ase = dynamic_pointer_cast<AutoCorrelationSequenceEvolution>(mSeqEvol[nProcess]);
1990 nPL = make_unique<AutoCorrelationProcessPhyloLikelihood>(data, ase, collNodes, nProcess, nData);
1993 auto pse = dynamic_pointer_cast<PartitionSequenceEvolution>(mSeqEvol[nProcess]);
1996 nPL = make_unique<PartitionProcessPhyloLikelihood>(data, pse, collNodes, nProcess, nData);
1999 throw Exception(
"PhylogeneticsApplicationTools::getPhyloLikelihoodContainer : Unknown Sequence Evolution.");
2006 throw BadIntegerException(
"PhylogeneticsApplicationTools::getPhyloLikelihoodContainer : Unknown Process number.", (
int)nProcess);
2008 mPhylo->addPhyloLikelihood(phylonum, std::move(nPL));
2009 usedPhylo.push_back(phylonum);
2013 for (
auto it = phylosMap.begin(); it != phylosMap.end();)
2015 if (it->second.size() == 0)
2017 phylosMap.erase(it++);
2021 vector<size_t>& vphyl = it->second;
2022 for (
size_t i = vphyl.size(); i > 0; i--)
2024 vector<size_t>::iterator posp = find(usedPhylo.begin(), usedPhylo.end(), vphyl[i - 1]);
2025 if (posp != usedPhylo.end())
2026 vphyl.erase(vphyl.begin() +
static_cast<ptrdiff_t
>(i - 1));
2033 while (phylosMap.size() != 0)
2035 if (usedPhylo.size() == 0)
2043 for (map<
size_t, vector<size_t>>::iterator it = phylosMap.begin(); it != phylosMap.end(); it++)
2047 if (it->second.size() == 0)
2049 size_t phylonum = it->first;
2051 unique_ptr<PhyloLikelihoodInterface> nPL;
2052 string phyloName =
"";
2054 map<string, string> args;
2071 size_t indPhylo = 1;
2072 vector<size_t> vPhylo;
2078 vPhylo.push_back(numPhylo);
2082 if (phyloName ==
"Mixture")
2084 auto pMA = make_unique<AlignedPhyloLikelihoodMixture>(context, std::move(mPhylo), vPhylo);
2085 vector<double> vprob = ApplicationTools::getVectorParameter<double>(
"probas", args,
',',
"(" +
VectorTools::paste(vector<double>(vPhylo.size(), 1. / (
double)vPhylo.size())) +
")");
2086 if (vprob.size() != 1)
2088 if (vprob.size() != vPhylo.size())
2089 throw BadSizeException(
"Wrong size of probas description in Mixture", vprob.size(), vPhylo.size());
2091 pMA->setPhyloProb(si);
2094 nPL = std::move(pMA);
2096 else if (phyloName ==
"HMM")
2098 auto pMA = make_unique<AlignedPhyloLikelihoodHmm>(context, std::move(mPhylo), vPhylo);
2100 size_t nbP = pMA->getNumbersOfPhyloLikelihoods().size();
2102 string vs =
"(" +
VectorTools::paste(vector<double>(nbP, 1. /
static_cast<double>(nbP)),
",") +
")";
2104 for (
size_t i = 0; i < nbP; ++i)
2106 vvs += (i == 0 ?
"" :
",") + vs;
2110 RowMatrix<double> mat = ApplicationTools::getMatrixParameter<double>(
"probas", args,
',', vvs);
2117 nPL = std::move(pMA);
2119 else if (phyloName ==
"AutoCorr")
2121 auto pMA = make_unique<AlignedPhyloLikelihoodAutoCorrelation>(context, std::move(mPhylo), vPhylo);
2123 size_t nbP = pMA->getNumbersOfPhyloLikelihoods().size();
2127 vector<double> v = ApplicationTools::getVectorParameter<double>(
"lambdas", args,
',', vs);
2131 for (
size_t i = 0; i < v.size(); ++i)
2136 pMA->matchParametersValues(pl);
2138 nPL = std::move(pMA);
2140 else if (phyloName ==
"Product")
2142 auto pAP = make_unique<AlignedPhyloLikelihoodProduct>(context, std::move(mPhylo), vPhylo);
2144 nPL = std::move(pAP);
2147 throw Exception(
"PhylogeneticsApplicationTools::getPhyloLikelihoodContainer : Unknown Phylo name " + phyloName);
2155 mPhylo->addPhyloLikelihood(phylonum, std::move(nPL));
2156 usedPhylo.push_back(phylonum);
2161 for (
auto it = phylosMap.begin(); it != phylosMap.end();)
2163 if (it->second.size() == 0)
2165 phylosMap.erase(it++);
2169 vector<size_t>& vphyl = it->second;
2170 for (
size_t i = vphyl.size(); i > 0; i--)
2172 vector<size_t>::iterator posp = find(usedPhylo.begin(), usedPhylo.end(), vphyl[i - 1]);
2173 if (posp != usedPhylo.end())
2174 vphyl.erase(vphyl.begin() +
static_cast<ptrdiff_t
>(i - 1));
2181 if (mPhylo->getNumbersOfPhyloLikelihoods().size() == 0)
2195 const vector<size_t>& nPhyl = mPhylo->getNumbersOfPhyloLikelihoods();
2197 for (
size_t i = 0; i < nPhyl.size(); i++)
2209 std::shared_ptr<PhyloLikelihoodInterface> nPL;
2211 bool flag(resultDesc.substr(0, 5) ==
"phylo");
2217 nP = TextTools::to<size_t>(resultDesc.substr(5));
2227 nPL = make_shared<PhyloLikelihoodFormula>(context, mPhylo, resultDesc);
2233 if (!mPhylo->hasPhyloLikelihood(nP))
2236 nPL = mPhylo->getPhyloLikelihood(nP);
2241 mPhylo->addPhyloLikelihood(0, nPL);
2253 const string& distDescription,
2254 map<string, string>& unparsedParameterValues,
2259 map<string, string> args;
2262 if (distName ==
"Dirichlet")
2264 if (args.find(
"classes") == args.end())
2265 throw Exception(
"Missing argument 'classes' (vector of number of classes) in " + distName
2267 if (args.find(
"alphas") == args.end())
2268 throw Exception(
"Missing argument 'alphas' (vector of Dirichlet shape parameters) in Dirichlet distribution");
2269 vector<double> alphas;
2270 vector<size_t> classes;
2272 string rf = args[
"alphas"];
2277 rf = args[
"classes"];
2280 classes.push_back(TextTools::to<size_t>(strtok2.
nextToken()));
2285 for (
size_t i = 0; i < v.size(); i++)
2291 throw Exception(
"Unknown multiple distribution name: " + distName);
2299 const map<string, string>& params,
2300 const string& suffix,
2301 bool suffixIsOptional,
2307 map<string, string> args;
2328 std::shared_ptr<PhyloLikelihoodInterface> lik,
2329 const map<string, string>& params,
2330 const string& suffix,
2331 bool suffixIsOptional,
2345 if (verbose && optopt.
nstep > 1)
2355 if (dynamic_pointer_cast<SingleProcessPhyloLikelihood>(lik))
2357 dynamic_pointer_cast<SingleProcessPhyloLikelihood>(lik),
2366 unique_ptr<OptimizerInterface> finalOptimizer =
nullptr;
2367 if (finalMethod ==
"none")
2369 else if (finalMethod ==
"simplex")
2371 finalOptimizer = make_unique<DownhillSimplexMethod>(lik);
2373 else if (finalMethod ==
"powell")
2375 finalOptimizer = make_unique<PowellMultiDimensions>(lik);
2378 throw Exception(
"Unknown final optimization method: " + finalMethod);
2385 finalOptimizer->setProfiler(optopt.
profiler);
2386 finalOptimizer->setMessageHandler(optopt.
messenger);
2387 finalOptimizer->setMaximumNumberOfEvaluations(optopt.
nbEvalMax);
2388 finalOptimizer->getStopCondition()->setTolerance(optopt.
tolerance);
2389 finalOptimizer->setVerbose(verbose);
2392 finalOptimizer->optimize();
2393 n += finalOptimizer->getNumberOfEvaluations();
2401 rename(optopt.
backupFile.c_str(), bf.c_str());
2410 for (
size_t i = 0; i < pl.
size(); ++i)
2412 auto constraint = pl[i].getConstraint();
2415 double value = pl[i].getValue();
2416 if (!constraint->isCorrect(value - 1e-6) || !constraint->isCorrect(value + 1e-6))
2431 const map<string, string>& params,
2432 const string& prefix,
2433 const string& suffix,
2434 bool suffixIsOptional,
2442 if (format ==
"Newick")
2443 treeWriter =
new Newick();
2444 else if (format ==
"Nexus")
2446 else if (format ==
"NHX")
2447 treeWriter =
new Nhx(
false);
2449 throw Exception(
"Unknown format for tree writing: " + format);
2451 treeWriter->
writeTree(tree, file,
true);
2460 const vector<const PhyloTree*>& trees,
2461 const map<string, string>& params,
2462 const string& prefix,
2463 const string& suffix,
2464 bool suffixIsOptional,
2472 if (format ==
"Newick")
2473 treeWriter =
new Newick();
2474 else if (format ==
"Nexus")
2476 else if (format ==
"NHX")
2477 treeWriter =
new Nhx();
2479 throw Exception(
"Unknown format for tree writing: " + format);
2496 const map<string, string>& params,
2497 const string& prefix,
2498 const string& suffix,
2499 bool suffixIsOptional,
2509 if (format ==
"Newick")
2510 treeWriter =
new Newick();
2511 else if (format ==
"Nexus")
2513 else if (format ==
"NHX")
2514 treeWriter =
new Nhx();
2516 throw Exception(
"Unknown format for tree writing: " + format);
2522 for (
size_t i = 0; i < vTN.size(); i++)
2524 auto tree = spc.
getTree(vTN[i]);
2526 std::vector<shared_ptr<PhyloNode>> nodes = tree->getAllNodes();
2528 for (
auto& node : nodes)
2530 if (tree->isLeaf(node) && withIds)
2552 map<string, string> globalAliases;
2553 vector<string> writtenNames;
2555 bIO.
write(model, out, globalAliases, writtenNames);
2567 (out <<
"nonhomogeneous=no").endLine();
2570 map<string, string> globalAliases;
2571 vector<string> writtenNames;
2573 bIO.
write(sp.model(0, 0), out, globalAliases, writtenNames);
2584 (out <<
"nonhomogeneous=no").endLine();
2587 map<string, string> globalAliases;
2588 vector<string> writtenNames;
2590 bIO.
write(process.
model(0, 0), out, globalAliases, writtenNames);
2596 out <<
"rate_distribution=";
2609 (out <<
"nonhomogeneous=general").endLine();
2610 (out <<
"nonhomogeneous.number_of_models=" << pNH.
getNumberOfModels()).endLine();
2612 vector<string> writtenNames;
2617 const auto model = pNH.
getModel(i);
2620 map<string, string> aliases;
2624 for (
size_t np = 0; np < pl.
size(); ++np)
2628 aliases[pl[np].getName()] = nfrom;
2632 writtenNames.clear();
2633 out.
endLine() <<
"model" << (i + 1) <<
"=";
2635 bIOsm.
write(*model, out, aliases, writtenNames);
2638 out <<
"model" << (i + 1) <<
".nodes_id=" << ids[0];
2639 for (
size_t j = 1; j < ids.size(); ++j)
2641 out <<
"," << ids[j];
2650 out <<
"nonhomogeneous.root_freq=";
2652 map<string, string> aliases;
2656 for (
size_t np = 0; np < pl.
size(); ++np)
2658 string nfrom = pNH.
getFrom(pl[np].getName());
2660 aliases[pl[np].getName()] = nfrom;
2667 out <<
"nonhomogeneous.stationarity=true";
2672 map<string, string> aliases;
2676 for (
size_t np = 0; np < pl.
size(); ++np)
2678 string nfrom = pNH.
getFrom(pl[np].getName());
2680 aliases[pl[np].getName()] = nfrom;
2683 out <<
"rate_distribution=";
2697 vector<string> writtenNames;
2702 for (
auto modn : vModN)
2704 const auto& model = *collection.
getModel(modn);
2707 map<string, string> aliases;
2713 for (
size_t np = 0; np < pl.
size(); ++np)
2717 aliases[pl[np].getName()] = nfrom;
2722 writtenNames.clear();
2723 out <<
"model" << modn <<
"=";
2725 bIOsm.
write(model, out, aliases, writtenNames);
2733 for (
size_t i = 0; i < rootFreqN.size(); ++i)
2738 writtenNames.clear();
2739 out.
endLine() <<
"root_freq" << rootFreqN[i] <<
"=";
2742 map<string, string> aliases;
2748 for (
size_t np = 0; np < pl.
size(); ++np)
2752 aliases[pl[np].getName()] = nfrom;
2764 for (
auto distn : vDistN)
2771 map<string, string> aliases;
2777 for (
size_t np = 0; np < pl.
size(); ++np)
2781 aliases[pl[np].getName()] = nfrom;
2786 writtenNames.clear();
2787 out.
endLine() <<
"rate_distribution" << distn <<
"=";
2798 if (vSce.size() > 0)
2801 vector<const ModelPath*> vMP;
2804 for (
const auto& scennum : vSce)
2810 out <<
"scenario" << scennum <<
"=";
2812 size_t nbMP = scen->getNumberOfModelPaths();
2814 for (
size_t mpn = 0; mpn < nbMP; mpn++)
2816 const auto& mp = scen->getModelPath(mpn);
2818 auto itmp = find(vMP.begin(), vMP.end(), mp.get());
2819 auto inmp = std::distance(vMP.begin(), itmp);
2820 if (itmp == vMP.end())
2821 vMP.push_back(mp.get());
2831 for (
size_t inmp = 0; inmp < vMP.size(); inmp++)
2834 out <<
"path" << inmp + 1 <<
"=";
2841 for (
const auto& mod:vMod)
2849 out <<
"model" << modN;
2861 for (
size_t i = 0; i < vprocN.size(); ++i)
2865 out <<
"process" << vprocN[i] <<
"=";
2867 if (spcm.getNumberOfModels() == 1)
2868 out <<
"Homogeneous(model=" << spcm.getModelNumbers()[0];
2871 out <<
"Nonhomogeneous(";
2872 vector<size_t> vMN = spcm.getModelNumbers();
2873 for (
size_t j = 0; j < vMN.size(); ++j)
2878 out <<
"model" << (j + 1) <<
"=" << vMN[j];
2881 vector<unsigned int> ids = spcm.getNodesWithModel(vMN[j]);
2882 out <<
"model" << (j + 1) <<
".nodes_id=(" << ids[0];
2883 for (
size_t k = 1; k < ids.size(); ++k)
2885 out <<
"," << ids[k];
2891 out <<
", tree=" << spcm.getTreeNumber();
2894 size_t dN = spcm.getRateDistributionNumber();
2899 out << size_t(dN / 10000 - 1) <<
"." << dN % 10000;
2901 if (spcm.getRootFrequencySet())
2902 out <<
", root_freq=" << spcm.getRootFrequenciesNumber();
2904 if (spcm.getModelScenario())
2905 out <<
", scenario=" << spcm.getModelScenarioNumber();
2916 out <<
"# Log likelihood = ";
2918 std::shared_ptr<const PhyloLikelihoodInterface> result = phylocont[0];
2935 auto pop = dynamic_pointer_cast<const PhyloLikelihoodFormula>(result);
2937 vector<size_t> phyldep;
2942 phyldep.push_back(1);
2946 string popout = pop->output();
2957 phyldep.push_back((
size_t)(atoi(ex.c_str())));
2966 while (phyldep.size() != 0)
2968 size_t num = phyldep[0];
2969 std::shared_ptr<const PhyloLikelihoodInterface> phyloLike = phylocont[num];
2972 auto itf = find(phyldep.begin(), phyldep.end(), num);
2973 while (itf != phyldep.end())
2976 itf = find(itf, phyldep.end(), num);
2982 if (dynamic_pointer_cast<const SingleDataPhyloLikelihoodInterface>(phyloLike))
2983 printParameters(*dynamic_pointer_cast<const SingleDataPhyloLikelihoodInterface>(phyloLike), out, num, warn);
2986 out <<
"phylo" << num <<
"=";
2988 auto mDP = dynamic_pointer_cast<const PhyloLikelihoodSetInterface>(phyloLike);
2991 if (dynamic_pointer_cast<const AlignedPhyloLikelihoodMixture>(phyloLike))
2993 auto pM = dynamic_pointer_cast<const AlignedPhyloLikelihoodMixture>(phyloLike);
3000 else if (dynamic_pointer_cast<const AlignedPhyloLikelihoodHmm>(phyloLike))
3002 auto pM = dynamic_pointer_cast<const AlignedPhyloLikelihoodHmm>(phyloLike);
3003 out <<
"HMM(probas=";
3012 else if (dynamic_pointer_cast<const AlignedPhyloLikelihoodAutoCorrelation>(phyloLike))
3014 auto pM = dynamic_pointer_cast<const AlignedPhyloLikelihoodAutoCorrelation>(phyloLike);
3016 out <<
"AutoCorr(lambdas=(";
3019 for (
unsigned int i = 0; i < pM->getHmmTransitionMatrix().cols(); ++i)
3021 vP.push_back(pM->getHmmTransitionMatrix()(i, i));
3028 else if (dynamic_pointer_cast<const AlignedPhyloLikelihoodProduct>(phyloLike))
3036 vector<size_t> vPN = mDP->getNumbersOfPhyloLikelihoods();
3038 for (
size_t i = 0; i < vPN.size(); i++)
3040 out <<
"phylo" << i + 1 <<
"=" << vPN[i];
3041 if (i != vPN.size() - 1)
3048 for (
size_t i = 0; i < vPN.size(); i++)
3050 if (find(phyldep.begin(), phyldep.end(), vPN[i]) == phyldep.end())
3051 phyldep.push_back(vPN[i]);
3071 out <<
"process=" << pMP.getSequenceEvolutionNumber();
3080 out <<
"process=" << pS.getSubstitutionProcessNumber();
3115 out <<
"HMM(probas=";
3126 out <<
"AutoCorr(lambdas=(";
3142 out <<
"Partition(";
3148 for (
unsigned int i = 0; i < vP.size(); i++)
3152 vector<size_t> v = mProcPos.find(vP[i])->second + 1;
3168 for (
size_t i = 0; i < vPN.size(); i++)
3170 out <<
"process" << i + 1 <<
"=" << vPN[i];
3171 if (i != vPN.size() - 1)
3189 std::shared_ptr<const PhyloLikelihoodInterface> result = phylocont[0];
3196 while (phyldep.size() != 0)
3198 size_t num = phyldep[0];
3200 phyldep.erase(phyldep.begin());
3202 std::shared_ptr<const PhyloLikelihoodInterface> phyloLike = phylocont[num];
3207 if (dynamic_pointer_cast<const SingleDataPhyloLikelihoodInterface>(phyloLike) && num != 0)
3208 printAnalysisInformation(*dynamic_pointer_cast<const SingleDataPhyloLikelihoodInterface>(phyloLike), info_out, warn);
3211 auto sOAP = dynamic_pointer_cast<const AlignedPhyloLikelihoodSetInterface>(phyloLike);
3215 printAnalysisInformation(*sOAP, info_out, warn);
3217 vector<size_t> vPN = sOAP->getNumbersOfPhyloLikelihoods();
3220 phyldep.assign(vPN.begin(), vPN.end());
3225 auto sOAB = dynamic_pointer_cast<const PhyloLikelihoodSetInterface>(phyloLike);
3228 vector<size_t> vPN = sOAB->getNumbersOfPhyloLikelihoods();
3231 phyldep.assign(vPN.begin(), vPN.end());
3247 size_t nbP = phyloNum.size();
3251 StlOutputStream out(make_unique<ofstream>(infosFile.c_str(), ios::out));
3260 vector<string> colNames;
3261 colNames.push_back(
"Sites");
3262 colNames.push_back(
"lnL");
3264 for (
size_t i = 0; i < nbP; i++)
3268 for (
size_t i = 0; i < nbP; i++)
3274 vector<string> row(2 + (nbP > 1 ? 2 * nbP : 0));
3285 for (
size_t i = 0; i < nSites; i++)
3292 for (
size_t j = 0; j < nbP; j++)
3297 for (
size_t j = 0; j < nbP; j++)
3305 for (
size_t j = 0; j < nbP; j++)
3317 for (
size_t j = 0; j < vap.size(); j++)
3336 const string& infosFile,
3343 StlOutputStream out(make_unique<ofstream>(infosFile.c_str(), ios::out));
3345 std::shared_ptr<const SubstitutionProcessInterface> pSP = pSPL.getSubstitutionProcess();
3347 vector<string> colNames;
3348 colNames.push_back(
"Sites");
3349 colNames.push_back(
"is.complete");
3350 colNames.push_back(
"is.constant");
3351 colNames.push_back(
"lnL");
3353 auto pDD = pSP->getRateDistribution();
3358 nbR = pDD->getNumberOfCategories();
3361 for (
size_t i = 0; i < nbR; ++i)
3366 colNames.push_back(
"rc");
3367 colNames.push_back(
"pr");
3369 std::shared_ptr<const AlignmentDataInterface> sites = phyloLike.
getData();
3371 vector<string> row(6 + (nbR > 1 ? nbR : 0));
3372 auto infos = make_unique<DataTable>(colNames);
3374 VVdouble vvPP(pSPL.getPosteriorProbabilitiesPerSitePerClass());
3376 for (
size_t i = 0; i < sites->getNumberOfSites(); ++i)
3382 string isCompl =
"NA";
3383 string isConst =
"NA";
3404 for (
size_t j = 0; j < nbR; ++j)
3407 pr += vvPP[i][j] * pDD->getCategory(j);
3436 vector<size_t> nbProc = pSE.getSubstitutionProcessNumbers();
3438 map<size_t, size_t> mNbr;
3440 for (
auto nP : nbProc)
3442 auto& sp = pSE.substitutionProcess(nP);
3443 auto pDD = sp.getRateDistribution();
3444 mNbr[nP] = (pDD ? pDD->getNumberOfCategories() : 1);
3447 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){
3448 return p1.second < p2.second;
3451 StlOutputStream out(make_unique<ofstream>(infosFile.c_str(), ios::out));
3453 vector<string> colNames;
3454 colNames.push_back(
"Sites");
3455 colNames.push_back(
"is.complete");
3456 colNames.push_back(
"is.constant");
3457 colNames.push_back(
"lnL");
3460 for (
size_t i = 0; i < maxR; i++)
3465 size_t nbSites = pSE.getNumberOfSites();
3467 vector<string> row(4 + (maxR > 1 ? maxR : 0));
3468 auto infos = make_unique<DataTable>(nbSites, colNames);
3469 for (
auto nP : nbProc)
3471 auto pSPPL = dynamic_pointer_cast<const SingleProcessPhyloLikelihood>(pPPL.getPhyloLikelihood(nP));
3474 throw Exception(
"PhylogeneticsApplicationTools::printAnalysisInformation : no SingleProcessPhyloLikelihood in PartitionProcessPhyloLikelihood.");
3476 size_t nbr = mNbr[pSPPL->getSubstitutionProcessNumber()];
3478 const vector<size_t>& mPos = mProcPos.at(nP);
3480 auto sites = pSPPL->getData();
3482 for (
size_t i = 0; i < sites->getNumberOfSites(); ++i)
3484 double lnL = pSPPL->getLogLikelihoodForASite(i);
3488 string isCompl =
"NA";
3489 string isConst =
"NA";
3509 Vdouble vPP = pSPPL->getPosteriorProbabilitiesForSitePerClass(i);
3511 for (
size_t j = 0; j < nbr; ++j)
3517 for (
size_t j = nbr; j < maxR; j++)
3522 infos->setRow(mPos[i], row);
3536 StlOutputStream out(make_unique<ofstream>(infosFile.c_str(), ios::out));
3538 vector<string> colNames;
3539 colNames.push_back(
"Sites");
3540 colNames.push_back(
"is.complete");
3541 colNames.push_back(
"is.constant");
3542 colNames.push_back(
"lnL");
3544 size_t nbP = pMPL.getNumberOfSubstitutionProcess();
3548 for (
size_t i = 0; i < nbP; ++i)
3552 for (
size_t i = 0; i < nbP; ++i)
3558 auto sites = phyloLike.
getData();
3560 vector<string> row(4 + (nbP > 1 ? 2 * nbP : 0));
3563 VVdouble vvPP = pMPL.getPosteriorProbabilitiesPerSitePerProcess();
3564 VVdouble vvL = pMPL.getLikelihoodPerSitePerProcess();
3566 for (
size_t i = 0; i < sites->getNumberOfSites(); ++i)
3571 string isCompl =
"NA";
3572 string isConst =
"NA";
3592 for (
size_t j = 0; j < nbP; j++)
3596 for (
size_t j = 0; j < nbP; j++)
3619 out <<
"rate_distribution=";
3620 map<string, string> globalAliases;
3621 vector<string> writtenNames;
3632 std::shared_ptr<const Alphabet> alphabet,
3633 std::shared_ptr<const SubstitutionModelInterface> model,
3634 const map<string, string>& params,
3639 auto stateMap = model->getStateMap();
3641 unique_ptr<SubstitutionCountInterface> substitutionCount =
nullptr;
3643 map<string, string> nijtParams;
3647 if (nijtOption ==
"Laplace")
3649 size_t trunc = ApplicationTools::getParameter<size_t>(
"trunc", nijtParams, 10, suffix,
true, warn + 1);
3650 substitutionCount = make_unique<LaplaceSubstitutionCount>(model, trunc);
3652 else if (nijtOption ==
"Uniformization")
3658 substitutionCount = make_unique<UniformizationSubstitutionCount>(model, make_shared<TotalSubstitutionRegister>(stateMap), weights, distances);
3660 else if (nijtOption ==
"Decomposition")
3666 auto revModel = dynamic_pointer_cast<const ReversibleSubstitutionModelInterface>(model);
3668 substitutionCount = make_unique<DecompositionSubstitutionCount>(revModel, make_shared<TotalSubstitutionRegister>(stateMap), weights, distances);
3670 throw Exception(
"Decomposition method can only be used with reversible substitution models.");
3672 else if (nijtOption ==
"Naive")
3677 if (distanceOption !=
"")
3680 substitutionCount = make_unique<NaiveSubstitutionCount>(model, make_shared<TotalSubstitutionRegister>(stateMap),
false, weights);
3682 else if (nijtOption ==
"Label")
3684 substitutionCount = make_unique<LabelSubstitutionCount>(model);
3686 else if (nijtOption ==
"ProbOneJump")
3688 substitutionCount = make_unique<OneJumpSubstitutionCount>(model);
3698 return substitutionCount;
3705 const string& regTypeDesc,
3706 std::shared_ptr<const StateMapInterface> stateMap,
3707 std::shared_ptr<const GeneticCode> genCode,
3708 std::shared_ptr<AlphabetIndex2>& weights,
3709 std::shared_ptr<AlphabetIndex2>& distances,
3712 string regType =
"";
3713 map<string, string> regArgs;
3716 auto alphabet = stateMap->getAlphabet();
3718 unique_ptr<SubstitutionRegisterInterface> reg =
nullptr;
3720 distances =
nullptr;
3736 if (regType ==
"Combination")
3738 shared_ptr<AlphabetIndex2> w2;
3739 shared_ptr<AlphabetIndex2> d2;
3741 auto vreg = make_unique<VectorOfSubstitutionRegisters>(stateMap);
3750 auto sreg = getSubstitutionRegister(regDesc, stateMap, genCode, w2, d2);
3752 vreg->addRegister(std::move(sreg));
3755 if (vreg->getNumberOfSubstitutionTypes()==0)
3756 throw Exception(
"Missing registers reg1, reg2, ... in description of Combination");
3758 reg = std::move(vreg);
3760 else if (regType ==
"All")
3762 reg = make_unique<ComprehensiveSubstitutionRegister>(stateMap,
false);
3764 else if (regType ==
"Total")
3766 reg = make_unique<TotalSubstitutionRegister>(stateMap);
3768 else if (regType ==
"Selected")
3771 reg = make_unique<SelectedSubstitutionRegister>(stateMap, subsList);
3778 if (regType ==
"GC")
3779 reg = make_unique<GCSubstitutionRegister>(stateMap,
false);
3780 else if (regType ==
"GCw")
3781 reg = make_unique<GCSubstitutionRegister>(stateMap,
true);
3782 else if (regType ==
"TsTv")
3783 reg = make_unique<TsTvSubstitutionRegister>(stateMap);
3784 else if (regType ==
"SW")
3785 reg = make_unique<SWSubstitutionRegister>(stateMap);
3787 throw Exception(
"PhylogeneticsApplicationTools::getSubstitutionRegister: unsupported substitution categorization:" + regType +
" for alphabet " + alphabet->getAlphabetType());
3791 if (regType ==
"IntraAA")
3792 reg = make_unique<AAInteriorSubstitutionRegister>(stateMap, genCode);
3793 else if (regType ==
"InterAA")
3794 reg = make_unique<AAExteriorSubstitutionRegister>(stateMap, genCode);
3795 else if (regType ==
"GC")
3796 reg = make_unique<GCSynonymousSubstitutionRegister>(stateMap, genCode);
3797 else if (regType ==
"GC1")
3798 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 0);
3799 else if (regType ==
"GC2")
3800 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 1);
3801 else if (regType ==
"GC3")
3802 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 2);
3803 else if (regType ==
"GCw")
3804 reg = make_unique<GCSynonymousSubstitutionRegister>(stateMap, genCode,
true);
3805 else if (regType ==
"GC1w")
3806 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 0,
true);
3807 else if (regType ==
"GC2w")
3808 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 1,
true);
3809 else if (regType ==
"GC3w")
3810 reg = make_unique<GCPositionSubstitutionRegister>(stateMap, genCode, 2,
true);
3811 else if (regType ==
"TsTv")
3812 reg = make_unique<TsTvSubstitutionRegister>(stateMap, genCode);
3813 else if (regType ==
"SW")
3814 reg = make_unique<SWSubstitutionRegister>(stateMap, genCode);
3815 else if (regType ==
"KrKc")
3816 reg = make_unique<KrKcSubstitutionRegister>(stateMap, genCode);
3817 else if (regType ==
"DnDs")
3818 reg = make_unique<DnDsSubstitutionRegister>(stateMap, genCode,
false);
3820 throw Exception(
"Unsupported substitution categorization: " + regType +
" for alphabet " + alphabet->getAlphabetType());
3825 if (regType ==
"KrKc")
3826 reg = make_unique<KrKcSubstitutionRegister>(stateMap);
3828 throw Exception(
"Unsupported substitution categorization: " + regType +
" for alphabet " + alphabet->getAlphabetType());
const FrequencySetInterface & rootFrequencySet() const
std::shared_ptr< const FrequencySetInterface > getRootFrequencySet() 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.
size_t getNumberOfModels() const override
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 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).
std::shared_ptr< const ModelScenario > getModelScenario() const override
Get the Model Scenario associated with this process, in case there are mixture models involved.
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 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 > getRateDistributionNumbers() const
DiscreteDistributionInterface & rateDistribution(size_t distributionIndex)
std::vector< size_t > getSubstitutionProcessNumbers() const
std::vector< size_t > getModelNumbers() const
Get the numbers of the specified objects from the collections.
bool hasModelNumber(size_t n) const
std::shared_ptr< const ModelScenario > getModelScenario(size_t numPath) const
Get a ModelScenario from the set.
bool hasTreeNumber(size_t n) const
std::shared_ptr< FrequencySetInterface > getFrequencySet(size_t frequenciesIndex)
size_t getModelIndex(std::shared_ptr< BranchModelInterface > model) const
Return the number of a BranchModel in the collection.
SubstitutionProcessCollectionMember & substitutionProcess(size_t i)
std::shared_ptr< DiscreteDistributionInterface > getRateDistribution(size_t distributionIndex)
Get a DiscreteDistribution from the collection.
std::vector< size_t > getScenarioNumbers() const
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::vector< size_t > getFrequenciesNumbers() const
bool hasModelScenario(size_t numPath) const
checks if the set has a ModelScenario
std::shared_ptr< BranchModelInterface > getModel(size_t modelIndex)
bool hasDistributionNumber(size_t n) const
void addDistribution(std::shared_ptr< DiscreteDistributionInterface > distribution, size_t distributionIndex)
void addSubstitutionProcess(size_t nProc, std::map< size_t, std::vector< unsigned int >> mModBr, size_t nTree, size_t nRate, size_t nFreq)
std::vector< size_t > getTreeNumbers() const
std::shared_ptr< ParametrizablePhyloTree > getTree(size_t treeIndex)
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