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 _LEGACY_PROBABILISTIC_SUBSTITUTION_MAPPING_H_
6#define _LEGACY_PROBABILISTIC_SUBSTITUTION_MAPPING_H_
7
9#include "../../Mapping/SubstitutionCount.h" // We use the latest version of the class here
10#include "../../Tree/TreeExceptions.h"
11
12#include <Bpp/Text/TextTools.h>
13
14// From the STL:
15#include <vector>
16
17namespace bpp
18{
29{
30private:
31 std::shared_ptr<const SubstitutionCountInterface> substitutionCount_;
32
38 std::vector<std::vector<std::vector<double>>> mapping_;
39
40public:
50 LegacyProbabilisticSubstitutionMapping(const Tree& tree, std::shared_ptr<const SubstitutionCountInterface> sc, size_t numberOfSites) :
53 mapping_(0)
54 {
55 setNumberOfSites(numberOfSites);
56 }
57
65 substitutionCount_(nullptr),
66 mapping_(0)
67 {}
68
69
71 {
73 }
74
76
78
80
81public:
82 size_t getNumberOfSubstitutionTypes() const override
83 {
84 if (!substitutionCount_) return 1;
85 return substitutionCount_->getNumberOfSubstitutionTypes();
86 }
87
88 double getNumberOfSubstitutions(int nodeId, size_t siteIndex, size_t type) const
89 {
90 return mapping_[siteIndex][getNodeIndex(nodeId)][type];
91 }
92
93 virtual std::vector<double> getNumberOfSubstitutions(int nodeId, size_t siteIndex) const
94 {
95 return mapping_[siteIndex][getNodeIndex(nodeId)];
96 }
97
103 virtual void setTree(const Tree& tree);
104
105 virtual void setNumberOfSites(size_t numberOfSites) override;
106
112 virtual double& operator()(size_t nodeIndex, size_t siteIndex, size_t type) override
113 {
114 return mapping_[siteIndex][nodeIndex][type];
115 }
116
122 virtual const double& operator()(size_t nodeIndex, size_t siteIndex, size_t type) const override
123 {
124 return mapping_[siteIndex][nodeIndex][type];
125 }
126
132 std::vector< std::vector<double>>& operator[](size_t siteIndex)
133 {
134 return mapping_[siteIndex];
135 }
136
142 const std::vector< std::vector<double>>& operator[](size_t siteIndex) const
143 {
144 return mapping_[siteIndex];
145 }
146};
147} // end of namespace bpp.
148
149#endif // _LEGACY_PROBABILISTIC_SUBSTITUTION_MAPPING_H_
const TreeTemplate< Node > & tree() const override
Definition: Mapping.h:132
virtual size_t getNodeIndex(int nodeId) const override
Definition: Mapping.h:184
Partial implementation of the substitution mapping interface.
Legacy data storage class for probabilistic substitution mappings.
virtual void setNumberOfSites(size_t numberOfSites) override
std::vector< std::vector< double > > & operator[](size_t siteIndex)
Direct access to substitution numbers.
LegacyProbabilisticSubstitutionMapping(const Tree &tree, std::shared_ptr< const SubstitutionCountInterface > sc, size_t numberOfSites)
Build a new LegacyProbabilisticSubstitutionMapping object.
std::shared_ptr< const SubstitutionCountInterface > substitutionCount_
LegacyProbabilisticSubstitutionMapping(const Tree &tree)
Build a new ProbabilisticSubstitutionMapping object.
virtual std::vector< double > getNumberOfSubstitutions(int nodeId, size_t siteIndex) const
const std::vector< std::vector< double > > & operator[](size_t siteIndex) const
Direct access to substitution numbers.
LegacyProbabilisticSubstitutionMapping & operator=(const LegacyProbabilisticSubstitutionMapping &psm)=default
double getNumberOfSubstitutions(int nodeId, size_t siteIndex, size_t type) const
std::vector< std::vector< std::vector< double > > > mapping_
Substitution numbers storage.
virtual const double & operator()(size_t nodeIndex, size_t siteIndex, size_t type) const override
Direct access to substitution numbers.
virtual double & operator()(size_t nodeIndex, size_t siteIndex, size_t type) override
Direct access to substitution numbers.
LegacyProbabilisticSubstitutionMapping(const LegacyProbabilisticSubstitutionMapping &psm)=default
virtual void setTree(const Tree &tree)
(Re)-set the phylogenetic tree associated to this mapping.
LegacyProbabilisticSubstitutionMapping * clone() const override
Interface for phylogenetic tree objects.
Definition: Tree.h:115
Defines the basic types of data flow nodes.