bpp-phyl  2.4.0
BipartitionList.h
Go to the documentation of this file.
1 //
2 // File: BipartitionList.h
3 // Created by: Nicolas Galtier and Julien Dutheil
4 // Created on: Tue Apr 13 15:09 2007
5 //
6 
7 /*
8 Copyright or © or Copr. CNRS, (November 16, 2004)
9 
10 This software is a computer program whose purpose is to provide classes
11 for phylogenetic data analysis.
12 
13 This software is governed by the CeCILL license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's author, the holder of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _BIPARTITIONLIST_H_
41 #define _BIPARTITIONLIST_H_
42 
43 #include "Tree.h"
44 
45 #include <Bpp/Utils/MapTools.h>
47 
48 // From the STL:
49 #include <map>
50 #include <algorithm>
51 
52 namespace bpp
53 {
54 
55 class Node;
56 template<class N> class TreeTemplate;
57 
84  public virtual Clonable
85 {
86  private:
87 
88  std::vector<int*> bitBipartitionList_;
89  std::vector<std::string> elements_;
90  bool sorted_;
91 
92  public:
93 
101  BipartitionList(const Tree& tr, bool sorted = true, std::vector<int>* index = 0);
102 
109  BipartitionList(const std::vector<std::string>& elements, const std::vector<int*>& bipl);
110 
114  BipartitionList(const BipartitionList& bipl);
115 
120 
121  virtual ~BipartitionList();
122 
123  BipartitionList* clone() const { return new BipartitionList(*this); }
124 
125  public:
126 
127  size_t getNumberOfElements() const { return elements_.size(); }
128 
129  const std::vector<std::string>& getElementNames() const { return elements_; }
130 
131  size_t getNumberOfBipartitions() const { return bitBipartitionList_.size(); }
132 
133  const std::vector<int*> & getBitBipartitionList() const { return bitBipartitionList_; }
134 
135  std::map<std::string, bool> getBipartition(size_t i) const;
136 
137  int* getBitBipartition(size_t i);
138 
139  bool haveSameElementsThan(std::map<std::string, bool>& bipart) const;
140 
141  void addBipartition(std::map<std::string, bool>& bipart, bool checkElements = 1);
142 
143  void deleteBipartition(size_t i);
144 
145  bool isSorted() const { return sorted_; }
146 
147  void sortElements();
148 
149  bool containsBipartition(std::map<std::string, bool>& bipart, bool checkElements = 1) const;
150 
151  bool areIdentical(size_t k1, size_t k2) const;
152 
154 
163  bool areCompatible(size_t k1, size_t k2) const;
164 
168  bool areAllCompatible() const;
169 
176  bool areAllCompatibleWith(std::map<std::string, bool>& bipart, bool checkElements = true) const;
177 
182 
186  void addTrivialBipartitions(bool checkExisting);
187 
188 
192  void flip(size_t i);
193 
197  size_t getPartitionSize(size_t i) const;
198 
202  void sortByPartitionSize();
203 
207  TreeTemplate<Node>* toTree() const;
208 
218  RowMatrix<int> toMatrix() const;
219 
220  private:
221 
222  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;
223 
224 };
225 
226 } //end of namespace bpp.
227 
228 #endif //_BIPARTITIONLIST_H_
229 
size_t getPartitionSize(size_t i) const
Returns the size of the smallest of the two partitions (e.g. 1 for external branches) ...
BipartitionList & operator=(const BipartitionList &bipl)
Assignment operator.
bool haveSameElementsThan(std::map< std::string, bool > &bipart) const
RowMatrix< int > toMatrix() const
Create a matrix representation of the bifurcations.
const std::vector< int * > & getBitBipartitionList() const
int * getBitBipartition(size_t i)
void flip(size_t i)
Replaces ones by zeros and zeros by ones in the ith bipartition.
BipartitionList * clone() const
void sortByPartitionSize()
Sort bipartitions by partition size.
The phylogenetic tree class.
Interface for phylogenetic tree objects.
Definition: Tree.h:148
bool areCompatible(size_t k1, size_t k2) const
Tells whether 2 bipartitions from the list are compatible.
void addTrivialBipartitions(bool checkExisting)
Adds bipartitions corresponding to external branches if missing.
std::vector< std::string > elements_
bool areAllCompatible() const
Tells whether all bipartitions in the list are compatible with each other.
BipartitionList(const Tree &tr, bool sorted=true, std::vector< int > *index=0)
The main contructor.
void removeTrivialBipartitions()
Removes bipartitions corresponding to external branches (1 vs n-1)
void addBipartition(std::map< std::string, bool > &bipart, bool checkElements=1)
const std::vector< std::string > & getElementNames() const
The phylogenetic node class.
Definition: Node.h:90
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
This class deals with the bipartitions defined by trees.
void deleteBipartition(size_t i)
bool isSorted() const
std::vector< int * > bitBipartitionList_
size_t getNumberOfElements() const
bool containsBipartition(std::map< std::string, bool > &bipart, bool checkElements=1) const
bool areIdentical(size_t k1, size_t k2) 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.
std::map< std::string, bool > getBipartition(size_t i) const
size_t getNumberOfBipartitions() const
TreeTemplate< Node > * toTree() const
Translate into a tree.