bpp-phyl3  3.0.0
AbstractSinglePhyloSubstitutionMapping.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 
7 using namespace bpp;
8 using namespace std;
9 
10 
12  modelTree(sppm),
13  pReg_(sppm.pReg_),
14  weights_(sppm.weights_),
15  distances_(sppm.distances_),
16  counts_(sppm.counts_ ? sppm.counts_->clone() : 0),
17  factors_(sppm.factors_ ? sppm.factors_->clone() : 0),
18  modelColl_(sppm.modelColl_),
19  mModBrid_(sppm.mModBrid_)
20 {
21  // assign correct addresses
22  unique_ptr<modelTree::EdgeIterator> nIT = allEdgesIterator();
23 
24  vector<size_t> keys = modelColl_.keys();
25 
26  for ( ; !nIT->end(); nIT->next())
27  {
28  (**nIT)->pMod_ = 0;
29  uint brid = getEdgeIndex(**nIT);
30 
31  auto sm = sppm.getEdge(brid)->pMod_;
32 
33  if (sm)
34  {
35  for (auto& k:keys)
36  {
37  if (sppm.modelColl_[k] == sm)
38  {
39  (**nIT)->pMod_ = modelColl_[k];
40  break;
41  }
42  }
43 
44  if (!(**nIT)->pMod_)
45  throw Exception("AbstractSinglePhyloSubstitutionMapping::AbstractSinglePhyloSubstitutionMapping: unable to find model for branch " + TextTools::toString(brid));
46  }
47  }
48 }
49 
50 
52 {
54  pReg_ = sppm.pReg_;
55  weights_ = sppm.weights_;
56  distances_ = sppm.distances_;
57 
58  counts_.reset(sppm.counts_ ? sppm.counts_->clone() : 0);
59  factors_.reset(sppm.factors_ ? sppm.factors_->clone() : 0);
60  modelColl_ = sppm.modelColl_;
61 
62  mModBrid_ = sppm.mModBrid_;
63 
64  // assign correct addresses
65  unique_ptr<modelTree::EdgeIterator> nIT = allEdgesIterator();
66  vector<size_t> keys = modelColl_.keys();
67 
68  for ( ; !nIT->end(); nIT->next())
69  {
70  (**nIT)->pMod_ = 0;
71 
72  uint brid = getEdgeIndex(**nIT);
73  auto sm = sppm.getEdge(brid)->pMod_;
74 
75  if (sm)
76  {
77  for (auto& k:keys)
78  {
79  if (sppm.modelColl_[k] == sm)
80  {
81  (**nIT)->pMod_ = modelColl_[k];
82  break;
83  }
84  }
85 
86  if (!(**nIT)->pMod_)
87  throw Exception("AbstractSinglePhyloSubstitutionMapping::AbstractSinglePhyloSubstitutionMapping: unable to find model for branch " + TextTools::toString(brid));
88  }
89  }
90 
91  return *this;
92 }
93 
94 
96 {
97  modelColl_.addObject(std::shared_ptr<TransitionModelInterface>(model.clone()), index);
98 
99  auto tm = modelColl_[index];
100  mModBrid_[index] = brIds;
101 
102  for (auto& id : brIds)
103  {
104  auto mb = make_shared<ModelBranch>();
105  mb->pMod_ = tm;
106 
107  associateEdge(mb, id);
108  }
109 }
The AbstractSinglePhyloSubstitutionMapping class: substitution mapping linked with a Single Process P...
std::shared_ptr< const SubstitutionRegisterInterface > pReg_
AbstractSinglePhyloSubstitutionMapping(std::shared_ptr< TreeGlobalGraph > graph, std::shared_ptr< const SubstitutionRegisterInterface > reg, std::shared_ptr< const AlphabetIndex2 > weights, std::shared_ptr< const AlphabetIndex2 > distances)
AbstractSinglePhyloSubstitutionMapping & operator=(const AbstractSinglePhyloSubstitutionMapping &sppm)
std::shared_ptr< const AlphabetIndex2 > distances_
distances of the substitutions. If null, no distances are used.
std::shared_ptr< const AlphabetIndex2 > weights_
weights of the substitutions. If null, no weights are used.
void addModel(size_t index, const TransitionModelInterface &model, Vuint brIds)
add a Substitution Model in the map, and on all branches with given Ids.
ParametrizableCollection< TransitionModelInterface > modelColl_
A collection of Transition Models.
std::map< size_t, std::vector< uint > > mModBrid_
a map <model index, vector of branch ids>
std::unique_ptr< ProbabilisticSubstitutionMapping > counts_
std::unique_ptr< ProbabilisticSubstitutionMapping > factors_
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 void associateEdge(std::shared_ptr< E > edgeObject, EdgeGraphid edge)=0
AssociationTreeGraphImplObserver< N, E, TreeGraphImpl > & operator=(bpp::AssociationTreeGraphImplObserver< N, E, TreeGraphImpl > const &treeGraphObserver)
Interface for all transition models.
TransitionModelInterface * clone() const =0
std::string toString(T t)
Defines the basic types of data flow nodes.
std::vector< unsigned int > Vuint