bpp-phyl3 3.0.0
ProbabilisticSubstitutionMapping.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_MAPPING_PROBABILISTICSUBSTITUTIONMAPPING_H
6#define BPP_PHYL_MAPPING_PROBABILISTICSUBSTITUTIONMAPPING_H
7
9
10#include "../Likelihood/DataFlow/DataFlowCWise.h"
11#include "SubstitutionMapping.h"
12
13// From the STL:
14#include <vector>
15
16namespace bpp
17{
33 public AssociationTreeGlobalGraphObserver<PhyloNode, PhyloBranchMapping>
34{
35public:
37
38private:
51
53
55
56public:
59
60public:
68 ProbabilisticSubstitutionMapping(const PhyloTree& tree, size_t nbTypes, size_t numberOfSites) :
70 {
72
73 std::unique_ptr<EdgeIterator> nIT = allEdgesIterator();
74 for ( ; !nIT->end(); nIT->next())
75 {
76 (**nIT)->setNumberOfSitesAndTypes(numberOfDistinctSites_, nbTypes);
77 }
78 }
79
83 ProbabilisticSubstitutionMapping(const PhyloTree& tree, size_t nbTypes, const PatternType& rootpatterns, size_t nbDistinctSites) :
84 AbstractMapping(size_t(rootpatterns.size())), AbstractSubstitutionMapping(), mapTree(tree), rootPatternLinks_(rootpatterns), usePatterns_(true), numberOfDistinctSites_(nbDistinctSites)
85 {
87 std::unique_ptr<EdgeIterator> nIT = allEdgesIterator();
88 for ( ; !nIT->end(); nIT->next())
89 {
90 (**nIT)->setNumberOfSitesAndTypes(numberOfDistinctSites_, nbTypes);
91 }
92 }
93
101 {}
102
104 {
105 return new ProbabilisticSubstitutionMapping(*this);
106 }
107
110 {}
111
113 {
116
120
121 return *this;
122 }
123
125
126public:
127 const PhyloBranchMapping& getBranch(unsigned int branchIndex) const override
128 {
129 return *getEdge(branchIndex);
130 }
131
132 PhyloBranchMapping& getBranch(unsigned int branchIndex) override
133 {
134 return *getEdge(branchIndex);
135 }
136
137 size_t getNumberOfBranches() const override
138 {
139 return getNumberOfEdges();
140 }
141
143 {
145 }
146
150 double getCount(unsigned int branchId, size_t site, size_t type) const
151 {
152 return getEdge(branchId)->getSiteTypeCount(getSiteIndex(site), type);
153 }
154
155 const std::vector<double>& getCounts(unsigned int branchId, size_t site) const
156 {
157 return getEdge(branchId)->getSiteCount(getSiteIndex(site));
158 }
159
160 void setNumberOfSitesAndTypes(size_t numberOfSites, size_t numberOfTypes);
161
162 void setNumberOfSites(size_t numberOfSites) override;
163
164 void setNumberOfSubstitutionTypes(size_t numberOfTypes) override;
165
172 double& operator()(unsigned int branchId, size_t siteIndex, size_t type) override
173 {
174 return (*getEdge(branchId))(siteIndex, type);
175 }
176
187 void fillMappingVectorForSite(size_t siteIndex, VVdouble& counts) const;
188
195 virtual const double& operator()(unsigned int branchId, size_t siteIndex, size_t type) const override
196 {
197 return (*getEdge(branchId))(siteIndex, type);
198 }
199
204 bool usePatterns() const
205 {
206 return usePatterns_;
207 }
208
214 {
215 return rootPatternLinks_;
216 }
217
218 const size_t getSiteIndex(size_t site) const
219 {
220 return usePatterns_ ? rootPatternLinks_(Eigen::Index(site)) : site;
221 }
222};
223} // end of namespace bpp.
224#endif // BPP_PHYL_MAPPING_PROBABILISTICSUBSTITUTIONMAPPING_H
Partial implementation of the mapping interface.
Definition: Mapping.h:79
Partial implementation of the substitution mapping interface.
AbstractSubstitutionMapping & operator=(const AbstractSubstitutionMapping &absm)
virtual std::unique_ptr< EdgeIterator > allEdgesIterator()=0
virtual std::shared_ptr< E > getEdge(EdgeIndex edgeIndex) const=0
AssociationTreeGraphImplObserver< N, E, TreeGraphImpl > & operator=(bpp::AssociationTreeGraphImplObserver< N, E, TreeGraphImpl > const &treeGraphObserver)
Data storage class for probabilistic substitution mappings.
ProbabilisticSubstitutionMapping(const ProbabilisticSubstitutionMapping &psm)
PatternType rootPatternLinks_
Links between sites and patterns.
ProbabilisticSubstitutionMapping(const PhyloTree &tree, size_t nbTypes, size_t numberOfSites)
Build a new ProbabilisticSubstitutionMapping object.
virtual const double & operator()(unsigned int branchId, size_t siteIndex, size_t type) const override
Direct access to substitution numbers, with COMPRESSED site positions (ie site indexes)
const PatternType getPatterns() const
returns the vector of site patterns
bool usePatterns() const
Does it use site patterns?
ProbabilisticSubstitutionMapping(const PhyloTree &tree)
Build a new ProbabilisticSubstitutionMapping object.
double & operator()(unsigned int branchId, size_t siteIndex, size_t type) override
Direct access to substitution numbers, with COMPRESSED site positions (ie site indexes)
void setNumberOfSites(size_t numberOfSites) override
void setNumberOfSitesAndTypes(size_t numberOfSites, size_t numberOfTypes)
AssociationTreeGlobalGraphObserver< PhyloNode, PhyloBranchMapping > mapTree
void setNumberOfSubstitutionTypes(size_t numberOfTypes) override
void fillMappingVectorForSite(size_t siteIndex, VVdouble &counts) const
Fill a VVdouble with the counts at a given site. The 1st coordinate of this VVdouble correspond to ed...
const PhyloBranchMapping & getBranch(unsigned int branchIndex) const override
ProbabilisticSubstitutionMapping * clone() const override
double getCount(unsigned int branchId, size_t site, size_t type) const
Retrieve the counts, with REAL site positions.
PhyloBranchMapping & getBranch(unsigned int branchIndex) override
ProbabilisticSubstitutionMapping & operator=(const ProbabilisticSubstitutionMapping &psm)
ProbabilisticSubstitutionMapping(const PhyloTree &tree, size_t nbTypes, const PatternType &rootpatterns, size_t nbDistinctSites)
the same with rootPatternLinks
const std::vector< double > & getCounts(unsigned int branchId, size_t site) const
Defines the basic types of data flow nodes.
Eigen::Matrix< size_t, -1, 1 > PatternType
std::vector< Vdouble > VVdouble