bpp-phyl3 3.0.0
AlignedPhyloLikelihoodSet.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
6
7using namespace std;
8using namespace bpp;
9
10
11AbstractAlignedPhyloLikelihoodSet::AbstractAlignedPhyloLikelihoodSet(
12 Context& context,
13 std::shared_ptr<PhyloLikelihoodContainer> pC,
14 bool inCollection,
15 const std::string& prefix) :
17 AbstractPhyloLikelihoodSet(context, pC, inCollection, prefix),
19{
20 for (auto np:nPhylo_)
21 {
22 auto aPL = getAlignedPhyloLikelihood(np);
23
24 if (!aPL)
25 throw Exception("AlignedPhyloLikelihoodSet::AlignedPhyloLikelihoodSet :non aligned PhyloLikelihood: " + TextTools::toString(np));
26 if (getNumberOfSites() == 0)
27 setNumberOfSites(aPL->getNumberOfSites());
28 else if (aPL->getNumberOfSites() != getNumberOfSites())
29 throw BadSizeException("AlignedPhyloLikelihoodSet::AlignedPhyloLikelihoodSet: mismatch lengths between aligned PhyloLikelihood: ", aPL->getNumberOfSites(), getNumberOfSites());
30 }
31}
32
33/*************************************************************/
34
36 Context& context,
37 std::shared_ptr<PhyloLikelihoodContainer> pC,
38 const std::vector<size_t>& nPhylo,
39 bool inCollection,
40 const std::string& prefix) :
42 AbstractPhyloLikelihoodSet(context, pC, nPhylo, inCollection, prefix),
44{
45 for (auto np : nPhylo)
46 {
47 auto aPL = getAlignedPhyloLikelihood(np);
48
49 if (!aPL)
50 throw Exception("AlignedPhyloLikelihoodSet::AlignedPhyloLikelihoodSet :non aligned PhyloLikelihood: " + TextTools::toString(np));
51 if (getNumberOfSites() == 0)
52 setNumberOfSites(aPL->getNumberOfSites());
53 else if (aPL->getNumberOfSites() != getNumberOfSites())
54 throw BadSizeException("AlignedPhyloLikelihoodSet::AlignedPhyloLikelihoodSet: mismatch lengths between aligned PhyloLikelihood: ", aPL->getNumberOfSites(), getNumberOfSites());
55 }
56}
57
58/******************************************************************************/
59
60bool AbstractAlignedPhyloLikelihoodSet::addPhyloLikelihood(size_t nPhyl, const std::string& suff)
61{
62 auto aPL = getAlignedPhyloLikelihood(nPhyl);
63
64 if (aPL && (getNumberOfSites() == 0 || aPL->getNumberOfSites() == getNumberOfSites()))
65 {
67 {
68 if (getNumberOfSites() == 0)
69 setNumberOfSites(aPL->getNumberOfSites());
70 return true;
71 }
72 else
73 return false;
74 }
75
76 return false;
77}
78
79/******************************************************************************/
bool addPhyloLikelihood(size_t nPhyl, const std::string &suff) override
adds a PhyloLikelihood already stored in the m ap, iff it is an AlignedPhyloLikelihood of the same si...
std::shared_ptr< const AlignedPhyloLikelihoodInterface > getAlignedPhyloLikelihood(size_t nPhyl) const override
AbstractAlignedPhyloLikelihoodSet(Context &context, std::shared_ptr< PhyloLikelihoodContainer > pC, bool inCollection=true, const std::string &prefix="")
size_t getNumberOfSites() const
Get the number of sites in the dataset.
The PhyloLikelihoodSet class, to manage a subset of PhyloLikelihoods from a given PhyloLikelihoodCont...
std::vector< size_t > nPhylo_
vector of AbstractPhyloLikelihood numbers
virtual bool addPhyloLikelihood(size_t nPhyl, const std::string &suff="") override
adds a PhyloLikelihood already stored in the PhyloLikelihoodContainer, iff it is an AbstractPhyloLike...
Context for dataflow node construction.
Definition: DataFlow.h:527
std::string toString(T t)
Defines the basic types of data flow nodes.