bpp-phyl3 3.0.0
ProcessTree.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_DATAFLOW_PROCESSTREE_H
6#define BPP_PHYL_LIKELIHOOD_DATAFLOW_PROCESSTREE_H
7
14
15#include "Definitions.h"
16#include "Model.h"
17#include "Parameter.h"
18
19// From the stl:
20#include <string>
21
22namespace bpp
23{
24class CollectionNodes;
25
32using DAGindexes = std::vector<uint>;
33using Speciesindex = uint;
34
35
36// Branch specific DataFlow objects
38{
39private:
44
48 std::shared_ptr<ConfiguredParameter> brlen_;
49
50 std::shared_ptr<ConfiguredModel> model_;
51
57 // Not just "size_t nMod_" because dataflow dependency is needed
58 // for createMatrix for TransitionMatrixFromModel
59
60 std::shared_ptr<NumericConstant<size_t>> nMod_;
61
63
68
69public:
73 ProcessEdge(uint speciesIndex,
74 std::shared_ptr<ConfiguredParameter> brlen,
75 std::shared_ptr<ConfiguredModel> model,
76 std::shared_ptr<NumericConstant<size_t>> nMod = 0) : speciesIndex_(speciesIndex), brlen_(brlen), model_(model), nMod_(nMod), transitionMatrix_(0), brprob_(0){}
77
81 ProcessEdge(uint speciesIndex,
82 ValueRef<double> brprob) : speciesIndex_(speciesIndex), brlen_(0), model_(0), nMod_(0), transitionMatrix_(0), brprob_(brprob){}
83
88
89 std::shared_ptr<ConfiguredModel> getModel()
90 {
91 return model_;
92 }
93
95 {
96 return *model_;
97 }
98
99 // void setModel(std::shared_ptr<ConfiguredModel> model)
100 // {
101 // model_=model;
102 // }
103
104 std::shared_ptr<ConfiguredParameter> getBrLen()
105 {
106 return brlen_;
107 }
108
109 void setBrLen(std::shared_ptr<ConfiguredParameter> brlen)
110 {
111 brlen_ = brlen;
112 }
113
115 {
116 transitionMatrix_ = transitionMatrix;
117 }
118
120 {
121 return transitionMatrix_;
122 }
123
125 {
126 return brprob_;
127 }
128
129 // void setNMod(std::shared_ptr<NumericConstant<size_t>> nMod)
130 // {
131 // nMod_=nMod;
132 // }
133
134 std::shared_ptr<NumericConstant<size_t>> getNMod()
135 {
136 return nMod_;
137 }
138
139 uint getSpeciesIndex() const
140 {
141 return speciesIndex_;
142 }
143};
144
146
147using ProcessEdgePtr = std::shared_ptr<ProcessEdge>;
148using ProcessNodePtr = std::shared_ptr<ProcessNode>;
149
150class ProcessTree : public AssociationTreeGlobalGraphObserver<ProcessNode, ProcessEdge>
151{
153
154 // CollectionNodes* nodes_;
155
156public:
162 ProcessTree(Context& context,
163 const ParametrizablePhyloTree& tree);
164
168 ProcessTree(const ProcessTree& tree,
169 ValueRef<double> rate);
170
176 ProcessTree(Context& context,
177 const ParametrizablePhyloTree& tree,
178 const ParameterList& parList,
179 const std::string& suff);
180
192 const ProcessTree& phyloTree);
193
194
195 ProcessTree* clone() const override
196 {
197 throw Exception("ProcessTree::clone should not be called.");
198 }
199
200 ProcessTree(const ProcessTree& pTree) :
202 {
203 throw Exception("ProcessTree::ProcessTree should not be called.");
204 }
205
207 {
208 throw Exception("ProcessTree::operator= should not be called.");
209 // AssociationTreeGlobalGraphObserver<ProcessNode,Value<T>>::operator=(pTree);
210 return *this;
211 }
212
213 /*
214 * @brief Get the edges indexes of the DAG that correspond to
215 * the species Index (of the Process tree).
216 */
217
218 DAGindexes getDAGEdgesIndexes(const Speciesindex speciesIndex) const;
219
220 /*
221 * For inclusion in ParametrizableCollection. Not used
222 *
223 */
225
227
228 /*
229 * Static construction methods.
230 *
231 */
232
238 static std::shared_ptr<ProcessTree> makeProcessTree(
239 Context& context,
240 std::shared_ptr<const SubstitutionProcessInterface> process,
241 ParameterList& parList,
242 const std::string& suff = "");
243
249 static std::shared_ptr<ProcessTree> makeProcessTree(CollectionNodes& collection, size_t pNum);
250};
251
263 Context& context,
264 const SubstitutionProcessInterface& process,
265 ParameterList& parList)
266{
268
269 // Build the ConfiguredModels from the BranchModels
270 auto vnMod = process.getModelNumbers();
271
272 for (auto nMod:vnMod)
273 {
274 auto mod = process.getModel(nMod);
275
276 modelColl.addObject(ConfiguredParametrizable::createConfigured<BranchModelInterface, ConfiguredModel>(context, *mod, parList, (nMod == 1 ? "" : "_" + TextTools::toString(nMod))), nMod); // suffix "_1" will be added if necessary
277 }
278
279 return modelColl;
280}
281} // end of namespace bpp
282#endif // BPP_PHYL_LIKELIHOOD_DATAFLOW_PROCESSTREE_H
const std::shared_ptr< TreeGraphImpl > getGraph() const
Likelihood transition model.
Definition: Model.h:48
Context for dataflow node construction.
Definition: DataFlow.h:527
void addObject(std::shared_ptr< N > object, size_t objectIndex)
PhyloTree with Parametrizable Phylo Branches. They SHARE their branch length parameters.
Tree Organization of Computing Nodes.
std::shared_ptr< ConfiguredParameter > brlen_
Model & BrLen, = 0 if not supporting a model.
Definition: ProcessTree.h:48
std::shared_ptr< NumericConstant< size_t > > getNMod()
Definition: ProcessTree.h:134
ValueRef< double > brprob_
Probability of the edge, used in case of mixture models.
Definition: ProcessTree.h:67
std::shared_ptr< NumericConstant< size_t > > nMod_
Optional number of submodels, in case model_ is mixed and a submodel is used.
Definition: ProcessTree.h:60
void setTransitionMatrix(ValueRef< Eigen::MatrixXd > transitionMatrix)
Definition: ProcessTree.h:114
std::shared_ptr< ConfiguredModel > model_
Definition: ProcessTree.h:50
std::shared_ptr< ConfiguredParameter > getBrLen()
Definition: ProcessTree.h:104
ValueRef< double > getProba()
Definition: ProcessTree.h:124
ConfiguredModel & model()
Definition: ProcessTree.h:94
uint getSpeciesIndex() const
Definition: ProcessTree.h:139
void setBrLen(std::shared_ptr< ConfiguredParameter > brlen)
Definition: ProcessTree.h:109
ProcessEdge(uint speciesIndex, ValueRef< double > brprob)
Construction with probability ref from Mixture model.
Definition: ProcessTree.h:81
ProcessEdge(const ProcessEdge &edge)
Copy construction.
Definition: ProcessTree.h:87
std::shared_ptr< ConfiguredModel > getModel()
Definition: ProcessTree.h:89
ValueRef< Eigen::MatrixXd > transitionMatrix_
Definition: ProcessTree.h:62
ProcessEdge(uint speciesIndex, std::shared_ptr< ConfiguredParameter > brlen, std::shared_ptr< ConfiguredModel > model, std::shared_ptr< NumericConstant< size_t > > nMod=0)
Construction with model and brlen.
Definition: ProcessTree.h:73
ValueRef< Eigen::MatrixXd > getTransitionMatrix()
Definition: ProcessTree.h:119
const Speciesindex speciesIndex_
the index of the species in the phyloTree matching this node.
Definition: ProcessTree.h:43
const ParameterList getParameters()
Definition: ProcessTree.h:224
static std::shared_ptr< ProcessTree > makeProcessTree(Context &context, std::shared_ptr< const SubstitutionProcessInterface > process, ParameterList &parList, const std::string &suff="")
Create a Process Tree following a Substitution Process. Tree Node parameters are got from ConfiguredP...
bool matchParametersValues(ParameterList &)
Definition: ProcessTree.h:226
ProcessTree & operator=(const ProcessTree &pTree)
Definition: ProcessTree.h:206
ProcessTree(Context &context, const ParametrizablePhyloTree &tree)
Build a ProcessTree with same topology as a given ParametrizablePhyloTree, and new ConfiguredParamete...
Definition: ProcessTree.cpp:20
DAGindexes getDAGEdgesIndexes(const Speciesindex speciesIndex) const
ProcessTree(const ProcessTree &pTree)
Definition: ProcessTree.h:200
ProcessTree * clone() const override
Definition: ProcessTree.h:195
This interface describes the substitution process along the tree and sites of the alignment.
virtual std::shared_ptr< const BranchModelInterface > getModel(size_t i) const =0
virtual std::vector< size_t > getModelNumbers() const =0
std::string toString(T t)
Defines the basic types of data flow nodes.
std::shared_ptr< Value< T > > ValueRef
Shared pointer alias for Value<T>.
Definition: DataFlow.h:84
std::vector< uint > DAGindexes
Helper: create a map with mutable dataflow nodes for each branch of the tree. The map is indexed by b...
ProcessComputationNode ProcessNode
Definition: ProcessTree.h:145
std::shared_ptr< ProcessNode > ProcessNodePtr
Definition: ProcessTree.h:148
uint Speciesindex
ParametrizableCollection< ConfiguredModel > makeConfiguredModelCollection(Context &context, const SubstitutionProcessInterface &process, ParameterList &parList)
Make a Collection of ConfiguredModel, from the models described in the SubstitutionProcess,...
Definition: ProcessTree.h:262
std::shared_ptr< ProcessEdge > ProcessEdgePtr
Definition: ProcessTree.h:147