bpp-phyl3 3.0.0
PhyloLikelihoodContainer.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_LIKELIHOOD_PHYLOLIKELIHOODS_PHYLOLIKELIHOODCONTAINER_H
6#define BPP_PHYL_LIKELIHOOD_PHYLOLIKELIHOODS_PHYLOLIKELIHOODCONTAINER_H
7
8
9// From bpp-seq:
11
12#include "PhyloLikelihood.h"
14
15#include "../DataFlow/CollectionNodes.h"
16
17namespace bpp
18{
26 virtual public Clonable
27{
28private:
30
31 std::shared_ptr<CollectionNodes> collectionNodes_;
32
33protected:
34 std::map<size_t, std::shared_ptr<PhyloLikelihoodInterface>> mPhylo_;
35
36public:
38 Context& context,
39 std::shared_ptr<SubstitutionProcessCollection> sColl) :
40 context_(context),
41 collectionNodes_(std::make_shared<CollectionNodes>(context_, sColl)),
42 mPhylo_()
43 {}
44
45 PhyloLikelihoodContainer(Context& context, std::shared_ptr<CollectionNodes> sColl) :
46 context_(context),
47 collectionNodes_(sColl),
48 mPhylo_()
49 {}
50
52 {
53 throw Exception("PhyloLikelihoodContainer::clone should not be called.");
54 }
55
61 {}
62
63public:
64 /*
65 * @brief add a PhyloLikelihood in the container, at a given
66 * position.
67 *
68 * Beware! Takes possession of the PhyloLikelihood through
69 *
70 */
71 void addPhyloLikelihood(size_t pos, std::shared_ptr<PhyloLikelihoodInterface> Ap)
72 {
73 if (mPhylo_.find(pos) != mPhylo_.end())
74 throw Exception("PhyloLikelihoodContainer::addPhylolikelihood: map number already used : " + TextTools::toString(pos));
75 mPhylo_[pos] = Ap;
76 }
77
78 bool hasPhyloLikelihood(size_t pos) const
79 {
80 return mPhylo_.find(pos) != mPhylo_.end();
81 }
82
83 std::shared_ptr<const PhyloLikelihoodInterface> operator[](size_t pos) const
84 {
85 auto it = mPhylo_.find(pos);
86 return it != mPhylo_.end() ? it->second : nullptr;
87 }
88
89 std::shared_ptr<PhyloLikelihoodInterface> operator[](size_t pos)
90 {
91 auto it = mPhylo_.find(pos);
92 return it != mPhylo_.end() ? it->second : nullptr;
93 }
94
95 std::shared_ptr<const PhyloLikelihoodInterface> getPhyloLikelihood(size_t pos) const
96 {
97 auto it = mPhylo_.find(pos);
98 return it != mPhylo_.end() ? it->second : nullptr;
99 }
100
101 std::shared_ptr<PhyloLikelihoodInterface> getPhyloLikelihood(size_t pos)
102 {
103 auto it = mPhylo_.find(pos);
104 return it != mPhylo_.end() ? it->second : nullptr;
105 }
106
107 size_t getSize() const
108 {
109 return mPhylo_.size();
110 }
111
112 std::vector<size_t> getNumbersOfPhyloLikelihoods() const
113 {
114 std::vector<size_t> vnum;
115
116 for (const auto& it : mPhylo_)
117 {
118 vnum.push_back(it.first);
119 }
120
121 return vnum;
122 }
123
128 std::shared_ptr<const CollectionNodes> getCollectionNodes() const
129 {
130 return collectionNodes_;
131 }
132
133 std::shared_ptr<CollectionNodes> getCollectionNodes()
134 {
135 return collectionNodes_;
136 }
137
145 void setData(std::shared_ptr<const AlignmentDataInterface> sites, size_t nPhyl)
146 {
147 auto it = mPhylo_.find(nPhyl);
148 if (it != mPhylo_.end())
149 {
150 auto sdp = std::dynamic_pointer_cast<SingleDataPhyloLikelihoodInterface>(it->second);
151 if (sdp)
152 sdp->setData(sites);
153 }
154 }
155
156
162 std::shared_ptr<const AlignmentDataInterface> getData(size_t nPhyl) const
163 {
164 const auto it = mPhylo_.find(nPhyl);
165 if (it != mPhylo_.end())
166 {
167 auto sdp = std::dynamic_pointer_cast<SingleDataPhyloLikelihoodInterface>(it->second);
168 if (sdp)
169 return sdp->getData();
170 }
171 return nullptr;
172 }
173};
174} // end of namespace bpp.
175#endif // BPP_PHYL_LIKELIHOOD_PHYLOLIKELIHOODS_PHYLOLIKELIHOODCONTAINER_H
Context for dataflow node construction.
Definition: DataFlow.h:527
The PhyloLikelihoodContainer, owns and assigns numbers to Phylolikelihoods.
void setData(std::shared_ptr< const AlignmentDataInterface > sites, size_t nPhyl)
Set the dataset for which the likelihood must be evaluated, iff the pointed PhyloLikelihood is a Sing...
PhyloLikelihoodContainer(Context &context, std::shared_ptr< CollectionNodes > sColl)
std::map< size_t, std::shared_ptr< PhyloLikelihoodInterface > > mPhylo_
std::shared_ptr< const CollectionNodes > getCollectionNodes() const
Manage Collection Nodes.
std::shared_ptr< const PhyloLikelihoodInterface > getPhyloLikelihood(size_t pos) const
std::shared_ptr< CollectionNodes > collectionNodes_
virtual ~PhyloLikelihoodContainer()
Abstract class destructor.
PhyloLikelihoodContainer * clone() const override
std::shared_ptr< PhyloLikelihoodInterface > getPhyloLikelihood(size_t pos)
std::shared_ptr< PhyloLikelihoodInterface > operator[](size_t pos)
std::shared_ptr< const PhyloLikelihoodInterface > operator[](size_t pos) const
bool hasPhyloLikelihood(size_t pos) const
PhyloLikelihoodContainer(Context &context, std::shared_ptr< SubstitutionProcessCollection > sColl)
void addPhyloLikelihood(size_t pos, std::shared_ptr< PhyloLikelihoodInterface > Ap)
std::shared_ptr< CollectionNodes > getCollectionNodes()
std::vector< size_t > getNumbersOfPhyloLikelihoods() const
std::shared_ptr< const AlignmentDataInterface > getData(size_t nPhyl) const
Get the dataset for which the likelihood must be evaluated.
std::string toString(T t)
Defines the basic types of data flow nodes.