bpp-phyl3 3.0.0
BipartitionList.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_TREE_BIPARTITIONLIST_H
6#define BPP_PHYL_TREE_BIPARTITIONLIST_H
7
10
11#include "Tree.h"
12
13// From the STL:
14#include <map>
15#include <algorithm>
16
17namespace bpp
18{
19class Node;
20template<class N> class TreeTemplate;
21
48 public virtual Clonable
49{
50private:
51 std::vector<int*> bitBipartitionList_;
52 std::vector<std::string> elements_;
53 bool sorted_;
54
55public:
63 BipartitionList(const Tree& tr, bool sorted = true, std::vector<int>* index = 0);
64
71 BipartitionList(const std::vector<std::string>& elements, const std::vector<int*>& bipl);
72
77
82
83 virtual ~BipartitionList();
84
85 BipartitionList* clone() const { return new BipartitionList(*this); }
86
87public:
88 size_t getNumberOfElements() const { return elements_.size(); }
89
90 const std::vector<std::string>& getElementNames() const { return elements_; }
91
92 size_t getNumberOfBipartitions() const { return bitBipartitionList_.size(); }
93
94 const std::vector<int*>& getBitBipartitionList() const { return bitBipartitionList_; }
95
96 std::map<std::string, bool> getBipartition(size_t i) const;
97
98 int* getBitBipartition(size_t i);
99
100 bool haveSameElementsThan(std::map<std::string, bool>& bipart) const;
101
102 void addBipartition(std::map<std::string, bool>& bipart, bool checkElements = 1);
103
104 void deleteBipartition(size_t i);
105
106 bool isSorted() const { return sorted_; }
107
108 void sortElements();
109
110 bool containsBipartition(std::map<std::string, bool>& bipart, bool checkElements = 1) const;
111
112 bool areIdentical(size_t k1, size_t k2) const;
113
115
124 bool areCompatible(size_t k1, size_t k2) const;
125
129 bool areAllCompatible() const;
130
137 bool areAllCompatibleWith(std::map<std::string, bool>& bipart, bool checkElements = true) const;
138
143
147 void addTrivialBipartitions(bool checkExisting);
148
149
153 void flip(size_t i);
154
158 size_t getPartitionSize(size_t i) const;
159
163 void sortByPartitionSize();
164
168 std::unique_ptr<TreeTemplate<Node>> toTree() const;
169
179 RowMatrix<int> toMatrix() const;
180
181private:
182 std::vector<std::string> buildBitBipartitions(const Node* nd, std::vector<int*>& bitbip, const std::vector<std::string>& elements, size_t* cpt, std::vector<int>* index) const;
183};
184} // end of namespace bpp.
185#endif // BPP_PHYL_TREE_BIPARTITIONLIST_H
This class deals with the bipartitions defined by trees.
void addTrivialBipartitions(bool checkExisting)
Adds bipartitions corresponding to external branches if missing.
std::vector< int * > bitBipartitionList_
void flip(size_t i)
Replaces ones by zeros and zeros by ones in the ith bipartition.
void sortByPartitionSize()
Sort bipartitions by partition size.
void addBipartition(std::map< std::string, bool > &bipart, bool checkElements=1)
bool containsBipartition(std::map< std::string, bool > &bipart, bool checkElements=1) const
size_t getNumberOfElements() const
bool haveSameElementsThan(std::map< std::string, bool > &bipart) const
std::vector< std::string > elements_
std::map< std::string, bool > getBipartition(size_t i) const
void removeTrivialBipartitions()
Removes bipartitions corresponding to external branches (1 vs n-1)
std::unique_ptr< TreeTemplate< Node > > toTree() const
Translate into a tree.
BipartitionList(const Tree &tr, bool sorted=true, std::vector< int > *index=0)
The main constructor.
size_t getPartitionSize(size_t i) const
Returns the size of the smallest of the two partitions (e.g. 1 for external branches)
bool areIdentical(size_t k1, size_t k2) const
const std::vector< std::string > & getElementNames() const
RowMatrix< int > toMatrix() const
Create a matrix representation of the bifurcations.
const std::vector< int * > & getBitBipartitionList() const
bool areCompatible(size_t k1, size_t k2) const
Tells whether 2 bipartitions from the list are compatible.
BipartitionList * clone() const
size_t getNumberOfBipartitions() const
BipartitionList & operator=(const BipartitionList &bipl)
Assignment operator.
int * getBitBipartition(size_t i)
void deleteBipartition(size_t i)
bool areAllCompatible() const
Tells whether all bipartitions in the list are compatible with each other.
std::vector< std::string > buildBitBipartitions(const Node *nd, std::vector< int * > &bitbip, const std::vector< std::string > &elements, size_t *cpt, std::vector< int > *index) const
bool areAllCompatibleWith(std::map< std::string, bool > &bipart, bool checkElements=true) const
Tells whether all bipartitions in the list are compatible with a given bipartition.
The phylogenetic node class.
Definition: Node.h:59
Interface for phylogenetic tree objects.
Definition: Tree.h:115
Defines the basic types of data flow nodes.