bpp-phyl3 3.0.0
DRTreeParsimonyScore.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_PARSIMONY_DRTREEPARSIMONYSCORE_H
6#define BPP_PHYL_PARSIMONY_DRTREEPARSIMONYSCORE_H
7
8
9#include "../Tree/NNISearchable.h"
10#include "../Tree/TreeTools.h"
12#include "DRTreeParsimonyData.h"
13
14namespace bpp
15{
23 public virtual NNISearchable
24{
25private:
26 std::unique_ptr<DRTreeParsimonyData> parsimonyData_;
28
29public:
31 std::shared_ptr<TreeTemplate<Node>> tree,
32 std::shared_ptr<const SiteContainerInterface> data,
33 bool verbose = true,
34 bool includeGaps = false);
35
37 std::shared_ptr<TreeTemplate<Node>> tree,
38 std::shared_ptr<const SiteContainerInterface> data,
39 std::shared_ptr<const StateMapInterface> statesMap,
40 bool verbose = true);
41
43
45
46 virtual ~DRTreeParsimonyScore();
47
48 DRTreeParsimonyScore* clone() const override { return new DRTreeParsimonyScore(*this); }
49
50private:
51 void init_(std::shared_ptr<const SiteContainerInterface> data, bool verbose);
52
53protected:
59 virtual void computeScores();
63 virtual void computeScoresPreorder(const Node*);
67 virtual void computeScoresPostorder(const Node*);
68
69public:
70 unsigned int getScore() const override;
71 unsigned int getScoreForSite(size_t site) const override;
72
81 const DRTreeParsimonyNodeData& pData,
82 std::vector<Bitset>& rBitsets,
83 std::vector<unsigned int>& rScores);
84
94 const DRTreeParsimonyNodeData& pData,
95 const Node* source,
96 std::vector<Bitset>& rBitsets,
97 std::vector<unsigned int>& rScores);
98
106 static void computeScoresForNode(
107 const DRTreeParsimonyNodeData& pData, std::vector<Bitset>& rBitsets,
108 std::vector<unsigned int>& rScores);
109
122 static void computeScoresFromArrays(
123 const std::vector<const std::vector<Bitset>*>& iBitsets,
124 const std::vector<const std::vector<unsigned int>*>& iScores,
125 std::vector<Bitset>& oBitsets,
126 std::vector<unsigned int>& oScores);
127
133 double getTopologyValue() const override { return getScore(); }
134
135 double testNNI(int nodeId) const override;
136
137 void doNNI(int nodeId) override;
138
139 const Tree& topology() const override { return tree(); }
140
141 void topologyChangeTested(const TopologyChangeEvent& event) override
142 {
143 parsimonyData_->reInit();
145 }
146
147 void topologyChangeSuccessful(const TopologyChangeEvent& event) override {}
153 static std::string PARSIMONY_SOLUTION_STATE;
154
160 void setNodeState(Node* node, size_t state);
161
167 size_t getNodeState(const Node* node);
168
172 void computeSolution();
173};
174} // end of namespace bpp.
175#endif // BPP_PHYL_PARSIMONY_DRTREEPARSIMONYSCORE_H
Partial implementation of the TreeParsimonyScore interface.
const Tree & tree() const override
Get the tree for which scores are computed.
Parsimony data structure for a node.
Double recursive implementation of interface TreeParsimonyScore.
static void computeScoresPostorderForNode(const DRTreeParsimonyNodeData &pData, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
Compute bitsets and scores for each site for a node, in postorder.
void init_(std::shared_ptr< const SiteContainerInterface > data, bool verbose)
static void computeScoresFromArrays(const std::vector< const std::vector< Bitset > * > &iBitsets, const std::vector< const std::vector< unsigned int > * > &iScores, std::vector< Bitset > &oBitsets, std::vector< unsigned int > &oScores)
Compute bitsets and scores from an array of arrays.
unsigned int getScoreForSite(size_t site) const override
Get the score for a given site for the current tree, i.e. the total minimum number of changes in the ...
DRTreeParsimonyScore(std::shared_ptr< TreeTemplate< Node > > tree, std::shared_ptr< const SiteContainerInterface > data, bool verbose=true, bool includeGaps=false)
void topologyChangeSuccessful(const TopologyChangeEvent &event) override
Tell that a topology change is definitive.
void topologyChangeTested(const TopologyChangeEvent &event) override
Notify a topology change event.
virtual void computeScoresPreorder(const Node *)
Compute scores (preorder algorithm).
static std::string PARSIMONY_SOLUTION_STATE
std::unique_ptr< DRTreeParsimonyData > parsimonyData_
size_t getNodeState(const Node *node)
Extracts the state of a node in a mapping.
DRTreeParsimonyScore & operator=(const DRTreeParsimonyScore &tp)
unsigned int getScore() const override
Get the score for the current tree, i.e. the total minimum number of changes in the tree.
void setNodeState(Node *node, size_t state)
Sets the state of a node in a mapping.
virtual void computeScores()
Compute all scores.
double getTopologyValue() const override
Get the current score of this NNISearchable object.
double testNNI(int nodeId) const override
Send the score of a NNI movement, without performing it.
static void computeScoresForNode(const DRTreeParsimonyNodeData &pData, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
Compute bitsets and scores for each site for a node, in all directions.
virtual void computeScoresPostorder(const Node *)
Compute scores (postorder algorithm).
const Tree & topology() const override
Get the tree associated to this NNISearchable object.
void doNNI(int nodeId) override
Perform a NNI movement.
static void computeScoresPreorderForNode(const DRTreeParsimonyNodeData &pData, const Node *source, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
Compute bitsets and scores for each site for a node, in preorder.
void computeSolution()
Compute a maximum parsimony solution in DELTRAN manner.
DRTreeParsimonyScore * clone() const override
Interface for Nearest Neighbor Interchanges algorithms.
Definition: NNISearchable.h:63
The phylogenetic node class.
Definition: Node.h:59
Class for notifying new toplogy change events.
The phylogenetic tree class.
Definition: TreeTemplate.h:59
Interface for phylogenetic tree objects.
Definition: Tree.h:115
Defines the basic types of data flow nodes.