11 #include "../Likelihood/DataFlow/ForwardLikelihoodTree.h"
20 using namespace numeric;
30 const vector<uint>& edgeIds,
31 std::shared_ptr<const SubstitutionRegisterInterface> reg,
32 std::shared_ptr<const AlphabetIndex2> weights,
33 std::shared_ptr<const AlphabetIndex2> distances,
34 short unresolvedOption,
40 throw Exception(
"SubstitutionMappingTools::computeSubstitutionVectors(). Likelihood object is not initialized.");
44 if (edgeIds.size() == 0)
45 return make_unique<ProbabilisticSubstitutionMapping>(
46 sp.parametrizablePhyloTree(),
47 reg->getNumberOfSubstitutionTypes(),
52 return computeCounts(rltc, edgeIds, substitutionCount, unresolvedOption, threshold, verbose);
59 const vector<uint>& edgeIds,
61 short unresolvedOption,
67 throw Exception(
"SubstitutionMappingTools::computeCounts(). Likelihood object is not initialized.");
71 if (edgeIds.size() == 0)
72 return make_unique<ProbabilisticSubstitutionMapping>(
73 sp.parametrizablePhyloTree(),
83 std::map<const SubstitutionModelInterface*, std::shared_ptr<SubstitutionCountInterface>> mModCount;
85 for (
auto speciesId : edgeIds)
87 const auto& dagIndexes = rltc.
getEdgesIds(speciesId, 0);
89 for (
auto id:dagIndexes)
91 const auto& edge = processTree->getEdge(
id);
94 auto model = edge->getModel();
96 auto nMod = edge->getNMod();
98 auto tm = dynamic_pointer_cast<const TransitionModelInterface>(model->targetValue());
100 shared_ptr<const SubstitutionModelInterface> sm =
nullptr;
104 sm = dynamic_pointer_cast<const SubstitutionModelInterface>(tm);
107 throw Exception(
"SubstitutionMappingTools::computeCounts : SubstitutionVectors possible only for SubstitutionModels, not in branch " +
TextTools::toString(speciesId) +
". Got model " + tm->getName());
111 size_t nmod = nMod->targetValue();
113 auto ttm = dynamic_pointer_cast<const MixedTransitionModelInterface>(tm);
115 throw Exception(
"SubstitutionMappingTools::computeCounts : Expecting Mixed model in branch " +
TextTools::toString(speciesId) +
". Got model " + tm->getName());
117 sm = dynamic_pointer_cast<const SubstitutionModelInterface>(ttm->getNModel(nmod));
123 if (mModCount.find(sm.get()) == mModCount.end())
125 mModCount[sm.get()] = std::shared_ptr<SubstitutionCountInterface>(substitutionCount.
clone());
126 mModCount[sm.get()]->setSubstitutionModel(sm);
132 auto ppt = sp.getParametrizablePhyloTree();
137 size_t nbClasses = sp.getNumberOfClasses();
140 size_t nbNodes = edgeIds.size();
156 unique_ptr<ProbabilisticSubstitutionMapping::mapTree::EdgeIterator> brIt = substitutions->allEdgesIterator();
159 for ( ; !brIt->end(); brIt->next())
164 shared_ptr<PhyloBranchMapping> br = **brIt;
167 uint speciesId = substitutions->getEdgeIndex(br);
174 vector<RowLik> substitutionsForCurrentNode(nbTypes);
176 for (
auto& sub : substitutionsForCurrentNode)
181 for (
size_t ncl = 0; ncl < nbClasses; ncl++)
184 double pr = sp.getProbabilityForModel(ncl);
186 vector<RowLik> substitutionsForCurrentClass(nbTypes);
187 for (
auto& sub:substitutionsForCurrentClass)
192 const auto& dagIndexes = rltc.
getEdgesIds(speciesId, ncl);
194 Eigen::MatrixXd npxy;
197 for (
auto id : dagIndexes)
199 auto edge = processTree->getEdge(
id);
201 auto tm = dynamic_pointer_cast<const TransitionModelInterface>(edge->model().targetValue());
203 auto nMod = edge->getNMod();
205 shared_ptr<const SubstitutionModelInterface> sm =
nullptr;
208 sm = dynamic_pointer_cast<const SubstitutionModelInterface>(tm);
211 size_t nmod = nMod->targetValue();
213 auto ttm = dynamic_pointer_cast<const MixedTransitionModelInterface>(tm);
214 sm = dynamic_pointer_cast<const SubstitutionModelInterface>(ttm->getNModel(nmod));
217 auto subCount = mModCount[sm.get()];
226 const Eigen::MatrixXd& pxy = edge->getTransitionMatrix()->targetValue();
230 for (
size_t t = 0; t < nbTypes; ++t)
234 subCount->storeAllNumbersOfSubstitutions(edge->getBrLen()->getValue(), t + 1, npxy);
236 npxy.array() *= pxy.array();
240 auto counts = npxy * likelihoodsBotEdge;
242 auto bb = (
cwise(likelihoodsTopEdge) *
cwise(counts)).colwise().sum();
244 Eigen::VectorXd ff(likelihoodsBotEdge.cols());
245 switch (unresolvedOption)
251 for (
auto i = 0; i < ff.size(); i++)
253 const DataLik s = likelihoodsBotEdge.col(i).sum();
266 auto cc = bb /
cwise(likelihoodsFather);
274 for (
size_t t = 0; t < nbTypes; ++t)
276 substitutionsForCurrentNode[t] += substitutionsForCurrentClass[t] * pr;
282 for (
size_t i = 0; i < nbDistinctSites; ++i)
284 for (
size_t t = 0; t < nbTypes; ++t)
286 double x =
convert(substitutionsForCurrentNode[t](Eigen::Index(i)));
295 if (threshold >= 0 && x > threshold)
315 return substitutions;
322 const vector<uint>& edgeIds,
323 std::shared_ptr<const BranchedModelSet> nullModels,
324 std::shared_ptr<const SubstitutionRegisterInterface> reg,
325 std::shared_ptr<const AlphabetIndex2> distances,
326 short unresolvedOption,
331 throw Exception(
"SubstitutionMappingTools::computeNormalizations(). Likelihood object is not initialized.");
335 if (edgeIds.size() == 0)
336 return make_unique<ProbabilisticSubstitutionMapping>(
337 sp.parametrizablePhyloTree(),
338 reg->getNumberOfSubstitutionTypes(),
348 std::map<const SubstitutionModelInterface*, std::vector<std::shared_ptr<DecompositionReward>>> mModRewards;
350 const auto& stateMap = sp.stateMap();
352 size_t nbTypes = reg->getNumberOfSubstitutionTypes();
354 size_t nbStates = stateMap.getNumberOfModelStates();
355 vector<int> supportedStates = stateMap.getAlphabetStates();
357 vector<shared_ptr<UserAlphabetIndex1>> vusai(nbTypes);
358 for (
auto& usai : vusai)
363 for (
auto speciesId : edgeIds)
365 const auto& dagIndexes = rltc.
getEdgesIds(speciesId, 0);
368 auto nullmodel = nullModels->getModelForBranch(speciesId);
370 for (
auto id : dagIndexes)
372 const auto& edge = processTree->getEdge(
id);
373 if (edge->getBrLen())
375 auto model = edge->getModel();
377 auto nMod = edge->getNMod();
379 auto tm = dynamic_pointer_cast<const TransitionModelInterface>(model->targetValue());
381 shared_ptr<const SubstitutionModelInterface> sm =
nullptr;
384 sm = dynamic_pointer_cast<const SubstitutionModelInterface>(tm);
387 throw Exception(
"SubstitutionMappingTools::computeCounts : SubstitutionVectors possible only for SubstitutionModels, not in branch " +
TextTools::toString(speciesId) +
". Got model " + tm->getName());
391 size_t nmod = nMod->targetValue();
393 auto ttm = dynamic_pointer_cast<const MixedTransitionModelInterface>(tm);
395 throw Exception(
"SubstitutionMappingTools::computeCounts : Expecting Mixed model in branch " +
TextTools::toString(speciesId) +
". Got model " + tm->getName());
397 sm = dynamic_pointer_cast<const SubstitutionModelInterface>(ttm->getNModel(nmod));
404 if (mModRewards.find(sm.get()) == mModRewards.end())
407 shared_ptr<const SubstitutionModelInterface> nullsm =
nullptr;
411 nullsm = dynamic_pointer_cast<const SubstitutionModelInterface>(nullmodel);
414 throw Exception(
"SubstitutionMappingTools::computeNormalizations : SubstitutionVectors possible only for SubstitutionModels, not in branch " +
TextTools::toString(speciesId) +
"for null model " + nullmodel->getName());
418 size_t nmod = nMod->targetValue();
420 auto nullttm = dynamic_pointer_cast<const MixedTransitionModelInterface>(nullmodel);
422 throw Exception(
"SubstitutionMappingTools::computeNormalizations : Expecting Mixed model in branch " +
TextTools::toString(speciesId) +
" for null model " + nullttm->getName());
424 nullsm = dynamic_pointer_cast<const SubstitutionModelInterface>(nullttm->getNModel(nmod));
427 throw Exception(
"SubstitutionMappingTools::computeNormalizations : Expecting Substitution model for submodel " +
TextTools::toString(nmod) +
" of null mixed model " + nullmodel->getName() +
" in branch " +
TextTools::toString(speciesId));
430 for (
auto& usai : vusai)
432 for (
size_t i = 0; i < nbStates; ++i)
434 usai->setIndex(supportedStates[i], 0);
438 for (
size_t i = 0; i < nbStates; ++i)
440 for (
size_t j = 0; j < nbStates; ++j)
444 size_t nbt = reg->getType(i, j);
446 vusai[nbt - 1]->setIndex(supportedStates[i], vusai[nbt - 1]->getIndex(supportedStates[i]) + nullsm->Qij(i, j) * (distances ? distances->getIndex(supportedStates[i], supportedStates[j]) : 1));
451 mModRewards[sm.get()] = vector<std::shared_ptr<DecompositionReward>>(nbTypes);
452 auto& mMdodsm = mModRewards[sm.get()];
453 for (
size_t t = 0; t < nbTypes; ++t)
455 mMdodsm[t] = make_shared<DecompositionReward>(nullsm, vusai[t]);
468 size_t nbNodes = edgeIds.size();
469 size_t nbClasses = sp.getNumberOfClasses();
475 unique_ptr<ProbabilisticSubstitutionMapping> normalizations(
new ProbabilisticSubstitutionMapping(*sp.getParametrizablePhyloTree(), nbTypes, rootPatternLinks, nbDistinctSites));
485 unique_ptr<ProbabilisticSubstitutionMapping::mapTree::EdgeIterator> brIt = normalizations->allEdgesIterator();
487 Eigen::MatrixXd rpxy;
490 for ( ; !brIt->end(); brIt->next())
495 shared_ptr<PhyloBranchMapping> br = **brIt;
498 uint speciesId = normalizations->getEdgeIndex(br);
503 vector<RowLik> rewardsForCurrentNode(nbTypes);
504 for (
auto& sub:rewardsForCurrentNode)
509 for (
size_t ncl = 0; ncl < nbClasses; ncl++)
512 double pr = sp.getProbabilityForModel(ncl);
514 vector<RowLik> rewardsForCurrentClass(nbTypes);
515 for (
auto& sub:rewardsForCurrentClass)
520 const auto& dagIndexes = rltc.
getEdgesIds(speciesId, ncl);
523 for (
auto id:dagIndexes)
525 auto edge = processTree->getEdge(
id);
527 auto tm = dynamic_pointer_cast<const TransitionModelInterface>(edge->getModel()->targetValue());
529 auto nMod = edge->getNMod();
531 shared_ptr<const SubstitutionModelInterface> sm =
nullptr;
534 sm = dynamic_pointer_cast<const SubstitutionModelInterface>(tm);
537 size_t nmod = nMod->targetValue();
539 auto ttm = dynamic_pointer_cast<const MixedTransitionModelInterface>(tm);
540 sm = dynamic_pointer_cast<const SubstitutionModelInterface>(ttm->getNModel(nmod));
544 auto subReward = mModRewards[sm.get()];
553 const Eigen::MatrixXd& pxy = edge->getTransitionMatrix()->accessValueConst();
557 for (
size_t t = 0; t < nbTypes; ++t)
560 subReward[t]->storeAllRewards(edge->getBrLen()->getValue(), rpxy);
562 rpxy.array() *= pxy.array();
566 auto rew = rpxy * likelihoodsBotEdge;
568 auto bb = (
cwise(likelihoodsTopEdge) *
cwise(rew)).colwise().sum();
571 Eigen::VectorXd ff(likelihoodsBotEdge.cols());
573 switch (unresolvedOption)
579 for (
auto i = 0; i < ff.size(); i++)
581 const DataLik s = likelihoodsBotEdge.col(i).sum();
594 auto cc = bb /
cwise(likelihoodsFather);
601 for (
size_t t = 0; t < nbTypes; ++t)
603 rewardsForCurrentNode[t] += rewardsForCurrentClass[t] * pr;
608 for (
size_t i = 0; i < nbDistinctSites; ++i)
610 for (
size_t t = 0; t < nbTypes; ++t)
612 (*br)(i, t) =
convert(rewardsForCurrentNode[t](Eigen::Index(i)));
624 return normalizations;
632 const vector<uint>& edgeIds,
633 std::shared_ptr<const BranchedModelSet> nullModels,
634 std::shared_ptr<const SubstitutionRegisterInterface> reg,
635 std::shared_ptr<const AlphabetIndex2> weights,
636 std::shared_ptr<const AlphabetIndex2> distances,
639 short unresolvedOption,
643 unique_ptr<ProbabilisticSubstitutionMapping> counts(computeCounts(rltc, edgeIds, reg, weights, distances, unresolvedOption, threshold, verbose));
644 unique_ptr<ProbabilisticSubstitutionMapping> factors(computeNormalizations(rltc, edgeIds, nullModels, reg, distances, unresolvedOption, verbose));
645 return computeNormalizedCounts(*counts, *factors, edgeIds, perTimeUnit, siteSize);
653 const vector<uint>& edgeIds,
657 unique_ptr<ProbabilisticSubstitutionMapping> normCounts(counts.
clone());
664 unique_ptr<ProbabilisticSubstitutionMapping::mapTree::EdgeIterator> brIt = normCounts->allEdgesIterator();
666 for ( ; !brIt->end(); brIt->next())
668 shared_ptr<PhyloBranchMapping> brNormCount = **brIt;
670 VVdouble& brnCou = brNormCount->getCounts();
673 uint edid = normCounts->getEdgeIndex(brNormCount);
677 for (
auto& brk : brnCou)
684 shared_ptr<PhyloBranchMapping> brFactor = factors.
getEdge(edid);
685 shared_ptr<PhyloBranchMapping> brCount = counts.
getEdge(edid);
687 const VVdouble& cou = brCount->getCounts();
688 const VVdouble& fac = brFactor->getCounts();
694 double slg = (!perTimeUnit ? brCount->getLength() : 1) / siteSize;
696 for (
size_t k = 0; k < nbDistinctSites; ++k)
703 for (
size_t t = 0; t < nbTypes; ++t)
705 ncou_k[t] = (fac_k[t] != 0 ? cou_k[t] / fac_k[t] * slg : 0);
721 auto pt = make_unique<PhyloTree>(counts);
724 unique_ptr<ProbabilisticSubstitutionMapping::mapTree::EdgeIterator> brIt = counts.
allEdgesIterator();
726 for ( ; !brIt->end(); brIt->next())
728 shared_ptr<PhyloBranchMapping> brm = (**brIt);
731 for (
size_t i = 0; i < nbSites; ++i)
733 x += brm->getSiteTypeCount(counts.
getSiteIndex(i), type);
749 auto pt = make_unique<PhyloTree>(counts);
752 unique_ptr<ProbabilisticSubstitutionMapping::mapTree::EdgeIterator> brIt = counts.
allEdgesIterator();
754 for ( ; !brIt->end(); brIt->next())
756 shared_ptr<PhyloBranchMapping> brm = (**brIt);
761 for (
size_t i = 0; i < nbSites; ++i)
763 x += brm->getSiteTypeCount(counts.
getSiteIndex(i), type);
764 f += brf->getSiteTypeCount(counts.
getSiteIndex(i), type);
767 pt->getEdge(counts.
getEdgeIndex(brm))->setLength(x / f);
780 const vector<uint>& ids)
783 size_t nbBr = idc.size();
792 for (
size_t j = 0; j < nbSites; ++j)
797 for (
size_t k = 0; k < nbBr; ++k)
801 for (
size_t i = 0; i < nbTypes; ++i)
803 resSB[i] = counts(idc[k], siteIndex, i);
818 unique_ptr<ProbabilisticSubstitutionMapping::mapTree::EdgeIterator> brIt = counts.
allEdgesIterator();
822 for ( ; !brIt->end(); brIt->next())
835 unique_ptr<ProbabilisticSubstitutionMapping::mapTree::EdgeIterator> brIt = counts.
allEdgesIterator();
839 for ( ; !brIt->end(); brIt->next())
841 shared_ptr<PhyloBranchMapping> brm = (**brIt);
844 shared_ptr<PhyloBranchMapping> brf = factors.
getEdge(edid);
857 const vector<uint>& ids)
860 size_t nbBr = idc.size();
867 for (
size_t k = 0; k < nbSites; ++k)
872 for (
size_t i = 0; i < nbBr; ++i)
874 (*resS)[i] = countsf[idc[i]];
883 const vector<uint>& ids)
886 size_t nbBr = idc.size();
893 for (
size_t k = 0; k < nbSites; ++k)
898 for (
size_t i = 0; i < nbBr; ++i)
900 (*resS)[i] = countsf[idc[i]];
915 shared_ptr<PhyloBranchMapping> br = counts.
getEdge(branchId);
917 for (
size_t i = 0; i < nbSites; ++i)
919 for (
size_t t = 0; t < nbTypes; ++t)
921 v[t] += br->getSiteTypeCount(counts.
getSiteIndex(i), t);
932 const vector<uint>& ids)
949 const vector<uint>& ids)
952 size_t nbBr = idc.size();
959 for (
size_t i = 0; i < idc.size(); i++)
962 for (
size_t nbt = 0; nbt < nbTypes; nbt++)
964 result[nbt][i] = cou[nbt];
977 const vector<uint>& ids,
978 std::shared_ptr<const SubstitutionRegisterInterface> reg,
979 std::shared_ptr<const AlphabetIndex2> weights,
980 std::shared_ptr<const AlphabetIndex2> distances,
981 short unresolvedOption,
985 auto psm = computeCounts(rltc, ids, reg, weights, distances, unresolvedOption, threshold, verbose);
987 VVdouble result = getCountsPerTypePerBranch(*psm, ids);
989 auto creg = dynamic_pointer_cast<const CategorySubstitutionRegister>(reg);
991 if (creg && !creg->isStationary())
993 size_t nbTypes = result[0].size();
995 for (
size_t k = 0; k < ids.size(); ++k)
997 vector<double> freqs(0);
1000 vector<double> freqsTypes(creg->getNumberOfCategories());
1001 for (
size_t i = 0; i < freqs.size(); ++i)
1003 size_t c = creg->getCategory(i);
1004 freqsTypes[c - 1] += freqs[i];
1010 for (
size_t t = 0; t < nbTypes; ++t)
1012 result[k][t] /= freqsTypes[creg->getCategoryFrom(t + 1) - 1];
1018 result[k] = (result[k] / s2) * s;
1038 shared_ptr<PhyloBranchMapping> br = counts.
getEdge(
id);
1039 for (
size_t t = 0; t < nbTypes; ++t)
1041 v[t] += (*br)(siteIndex, t);
1063 double lg = (!perTimeUnit ? 0 : 1);
1064 unique_ptr<ProbabilisticSubstitutionMapping::mapTree::EdgeIterator> brIt = counts.
allEdgesIterator();
1065 for ( ; !brIt->end(); brIt->next())
1067 for (
size_t t = 0; t < nbTypes; ++t)
1069 v[t] += (***brIt)(siteIndex, t);
1072 lg += (**brIt)->getLength();
1075 double slg = lg / siteSize;
1077 unique_ptr<ProbabilisticSubstitutionMapping::mapTree::EdgeIterator> nrIt = factors.
allEdgesIterator();
1078 for ( ; !nrIt->end(); nrIt->next())
1080 for (
size_t t = 0; t < nbTypes; ++t)
1082 n[t] += (***nrIt)(siteIndex, t);
1086 for (
size_t t = 0; t < nbTypes; ++t)
1088 v[t] = v[t] / n[t] * slg;
1100 const vector<uint>& ids,
1112 double lg = (!perTimeUnit ? 0 : 1);
1115 shared_ptr<PhyloBranchMapping> br = counts.
getEdge(
id);
1116 for (
size_t t = 0; t < nbTypes; ++t)
1118 v[t] += (*br)(siteIndex, t);
1121 lg += br->getLength();
1124 double slg = lg / siteSize;
1128 shared_ptr<PhyloBranchMapping> br = factors.
getEdge(
id);
1129 for (
size_t t = 0; t < nbTypes; ++t)
1131 n[t] += (*br)(siteIndex, t);
1135 for (
size_t t = 0; t < nbTypes; ++t)
1137 v[t] = v[t] / n[t] * slg;
1156 for (
size_t k = 0; k < nbSites; ++k)
1175 for (
size_t k = 0; k < nbSites; ++k)
1188 const vector<uint>& ids,
1199 for (
size_t k = 0; k < nbSites; ++k)
1212 double sumSquare = 0;
1214 unique_ptr<ProbabilisticSubstitutionMapping::mapTree::EdgeIterator> brIt = counts.
allEdgesIterator();
1217 for ( ; !brIt->end(); brIt->next())
1220 for (
size_t t = 0; t < nbTypes; ++t)
1222 sum += (***brIt)(siteIndex, t);
1225 sumSquare += sum * sum;
1227 return sqrt(sumSquare);
1236 const string& filename,
1237 const vector<uint>& ids,
1241 size_t nbSites = counts.size();
1244 size_t nbBr = counts[0].size();
1248 file.open(filename.c_str());
1251 for (
size_t i = 0; i < nbBr; ++i)
1253 file <<
"\t" << ids[i];
1257 for (
size_t k = 0; k < nbSites; ++k)
1259 const Vdouble& countS = counts[k];
1261 for (
size_t i = 0; i < nbBr; ++i)
1263 file <<
"\t" << countS[i];
1274 const string& filename,
1279 size_t nbSites = counts.size();
1282 size_t nbTypes = counts[0].size();
1286 file.open(filename.c_str());
1289 for (
size_t i = 0; i < nbTypes; ++i)
1295 for (
size_t k = 0; k < nbSites; ++k)
1298 const Vdouble& resS = counts[k];
1299 for (
size_t i = 0; i < nbTypes; ++i)
1301 file <<
"\t" << resS[i];
1311 const string& filename,
1316 size_t nbSites = counts.size();
1320 size_t nbTypes = counts[0].size();
1324 file.open(filename.c_str());
1326 for (
size_t i = 0; i < nbTypes; ++i)
1329 for (
size_t k = 0; k < nbSites; ++k)
1331 sumtype += counts[k][i];
1334 file << reg.
getTypeName(i + 1) <<
"\t" << sumtype << endl;
1343 const string& filenamePrefix,
1344 const vector<uint>& ids,
1349 size_t nbSites = counts.size();
1352 size_t nbBr = counts[0].size();
1355 size_t nbTypes = counts[0][0].size();
1360 for (
size_t i = 0; i < nbTypes; ++i)
1366 string path = filenamePrefix + name + string(
".count");
1369 file.open(path.c_str());
1372 for (
size_t k = 0; k < nbBr; ++k)
1374 file <<
"\t" << ids[k];
1378 for (
size_t j = 0; j < nbSites; ++j)
1384 for (
size_t k = 0; k < nbBr; ++k)
1386 file <<
"\t" << resS[k][i];
1404 throw IOException(
"SubstitutionMappingTools::writeToStream. Can't write to stream.");
1413 unique_ptr<ProbabilisticSubstitutionMapping::mapTree::EdgeIterator> brIt = substitutions.
allEdgesIterator();
1415 for ( ; !brIt->end(); brIt->next())
1417 const shared_ptr<PhyloBranchMapping> br = **brIt;
1419 out << substitutions.
getEdgeIndex(br) <<
"\t" << br->getLength();
1423 out <<
"\t" << (*br)(substitutions.
getSiteIndex(i), type);
1437 vector<string> ids = data->getColumn(0);
1438 data->deleteColumn(0);
1439 data->deleteColumn(0);
1441 size_t nbSites = data->getNumberOfColumns();
1446 for ( ; !brIt->end(); brIt->next())
1448 const shared_ptr<PhyloBranchMapping> br = **brIt;
1450 for (
size_t j = 0; j < nbSites; j++)
1457 for (
size_t i = 0; i < nbSites; ++i)
1459 string siteTxt = data->getColumnName(i);
1461 if (siteTxt.substr(0, 4) ==
"Site")
1462 site = TextTools::to<int>(siteTxt.substr(4));
1464 site = TextTools::to<int>(siteTxt);
void setSitePosition(size_t index, int position)
Set the position of a given site.
size_t getNumberOfSites() const
size_t getNumberOfSubstitutionTypes() const
virtual std::vector< EdgeIndex > getAllEdgesIndexes() const=0
virtual std::unique_ptr< EdgeIterator > allEdgesIterator()=0
virtual EdgeIndex getEdgeIndex(const std::shared_ptr< E > edgeObject) const=0
virtual std::shared_ptr< E > getEdge(EdgeIndex edgeIndex) const=0
virtual int getCoordinate() const=0
static std::unique_ptr< DataTable > read(std::istream &in, const std::string &sep="\t", bool header=true, int rowNames=-1)
Analytical substitution count using the eigen decomposition method.
const char * what() const noexcept override
static Self Zero(Eigen::Index rows, Eigen::Index cols)
SiteLikelihoodsRef getLikelihoodsAtNodeForClass(uint nodeId, size_t nCat)
Get shrunked conditional likelihood matrix at Node (ie just above the node), for a given rate class.
const SubstitutionProcessInterface & substitutionProcess() const
Return the ref to the SubstitutionProcess.
std::shared_ptr< ForwardLikelihoodTree > getForwardLikelihoodTree(size_t nCat)
ConditionalLikelihoodRef getBackwardLikelihoodsAtEdgeForClass(uint edgeId, size_t nCat)
ConditionalLikelihoodRef getForwardLikelihoodsAtNodeForClass(uint nodeId, size_t nCat)
const PatternType & getRootArrayPositions() const
size_t getNumberOfDistinctSites() const
const DAGindexes & getEdgesIds(uint speciesId, size_t nCat) const
Get indexes of the non-empty edges in the Likelihood DAG that have a given species index for a given ...
std::shared_ptr< ProcessTree > getTreeNode(size_t nCat)
Get process tree for a rate category.
virtual bool isInitialized() const
Data storage class for probabilistic substitution mappings.
ProbabilisticSubstitutionMapping * clone() const override
size_t getNumberOfDistinctSites() const
void setNumberOfSites(size_t numberOfSites) override
const size_t getSiteIndex(size_t site) const
size_t getNumberOfBranches() const override
double getProbaAtNode(PhyloTree::NodeIndex nodeId)
The SubstitutionsCount interface.
virtual SubstitutionCountInterface * clone() const =0
virtual size_t getNumberOfSubstitutionTypes() const
Short cut function, equivalent to getSubstitutionRegister().getNumberOfSubstitutionTypes().
The SubstitutionRegister interface.
virtual std::string getTypeName(size_t type) const =0
Get the name of a given substitution type.
virtual const CoreSiteInterface & site(size_t siteIndex) const=0
double toDouble(const std::string &s, char dec='.', char scientificNotation='e')
std::string toString(T t)
bool isinf(const double &d)
R convert(const F &from, const Dimension< R > &)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
std::vector< VVdouble > VVVdouble
std::vector< Vdouble > VVdouble
std::vector< unsigned int > Vuint