bpp-phyl3  3.0.0
CollectionNodes.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 
8 #include "CollectionNodes.h"
9 
10 using namespace std;
11 using namespace bpp;
12 
13 CollectionNodes::CollectionNodes(
14  Context& context,
15  shared_ptr<const SubstitutionProcessCollection> collection) :
17  collection_(collection), context_(context)
18 {
19  // add Independent Parameters
20  const auto& paramProc = collection_->getIndependentParameters();
21 
22  for (size_t i = 0; i < paramProc.size(); ++i)
23  {
24  shareParameter_(ConfiguredParameter::create(this->context(), paramProc[i]));
25  }
26 
27  // Share dependencies with aliased parameters
28 
29  for (size_t i = 0; i < paramProc.size(); ++i)
30  {
31  auto vs = collection_->getAlias(paramProc[i].getName());
32  auto dep = dynamic_cast<const ConfiguredParameter*>(&parameter(paramProc[i].getName()))->dependency(0);
33  for (const auto& s:vs)
34  {
35  auto newacp = ConfiguredParameter::create(this->context(), {dep}, collection_->parameter(s));
36  shareParameter_(newacp);
37  }
38  }
39 
40 
41  // rates nodes
42  auto rN = collection_->getRateDistributionNumbers();
43 
44  for (auto num : rN)
45  {
46  std::string suff = "_" + TextTools::toString(num);
47 
48  auto obj = collection_->getRateDistribution(num);
49 
50  if (!dynamic_pointer_cast<const ConstantRateDistribution>(obj))
51  distColl_.addObject(ConfiguredParametrizable::createConfigured<DiscreteDistributionInterface, ConfiguredDistribution>(this->context(), *obj, getParameters_(), suff), num);
52  }
53 
54  // models nodes
55  auto mN = collection_->getModelNumbers();
56 
57  for (auto num : mN)
58  {
59  std::string suff = "_" + TextTools::toString(num);
60 
61  const auto& obj = collection_->getModel(num);
62 
63  modelColl_.addObject(ConfiguredParametrizable::createConfigured<BranchModelInterface, ConfiguredModel>(context_, *obj, getParameters_(), suff), num);
64  }
65 
66  // frequencies nodes
67  auto fN = collection_->getFrequenciesNumbers();
68 
69  for (auto num : fN)
70  {
71  std::string suff = "_" + TextTools::toString(num);
72 
73  const auto& obj = collection_->frequencySet(num);
74 
75  freqColl_.addObject(ConfiguredParametrizable::createConfigured<FrequencySetInterface, ConfiguredFrequencySet>(context_, obj, getParameters_(), suff), num);
76  }
77 
79  // tree nodes
80  auto tN = collection_->getTreeNumbers();
81 
82  for (auto num : tN)
83  {
84  std::string suff = "_" + TextTools::toString(num);
85 
86  auto obj = collection_->getTree(num);
87 
88  treeColl_.addObject(make_shared<ProcessTree>(context_, *obj, getParameters_(), suff), num);
89  }
90 }
91 
92 std::shared_ptr<ProcessTree> CollectionNodes::getProcessTree(size_t treeIndex)
93 {
94  return std::dynamic_pointer_cast<ProcessTree>(treeColl_[treeIndex]);
95 }
const Parameter & parameter(const std::string &name) const override
virtual void shareParameter_(const std::shared_ptr< Parameter > &parameter)
ParameterList & getParameters_() override
ParametrizableCollection< ProcessTree > treeColl_
A collection of trees.
ParametrizableCollection< ConfiguredFrequencySet > freqColl_
A collection of Frequencies Sets.
std::shared_ptr< const SubstitutionProcessCollection > collection_
ParametrizableCollection< ConfiguredDistribution > distColl_
A collection of DiscreteDistributions.
std::shared_ptr< ProcessTree > getProcessTree(size_t treeIndex)
ParametrizableCollection< ConfiguredModel > modelColl_
A collection of Branch Models.
Data flow node representing a parameter.
Definition: Parameter.h:27
static std::shared_ptr< Self > create(Context &c, NodeRefVec &&deps, const Parameter &param)
Build a new ConfiguredParameter node.
Definition: Parameter.h:36
Context for dataflow node construction.
Definition: DataFlow.h:527
std::string toString(T t)
Defines the basic types of data flow nodes.