bpp-phyl  2.2.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>
46 #include <Bpp/Numeric/Matrix/Matrix.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 #ifndef NO_VIRTUAL_COV
125 #else
126  Clonable*
127 #endif
128  clone() const { return new BipartitionList(*this); }
129 
130  public:
131 
132  size_t getNumberOfElements() const { return elements_.size(); }
133 
134  const std::vector<std::string>& getElementNames() const { return elements_; }
135 
136  size_t getNumberOfBipartitions() const { return bitBipartitionList_.size(); }
137 
138  const std::vector<int*> & getBitBipartitionList() const { return bitBipartitionList_; }
139 
140  std::map<std::string, bool> getBipartition(size_t i) const throw (Exception);
141 
142  int* getBitBipartition(size_t i) throw (Exception);
143 
144  bool haveSameElementsThan(std::map<std::string, bool>& bipart) const;
145 
146  void addBipartition(std::map<std::string, bool>& bipart, bool checkElements = 1) throw(Exception);
147 
148  void deleteBipartition(size_t i) throw(Exception);
149 
150  bool isSorted() const { return sorted_; }
151 
152  void sortElements();
153 
154  bool containsBipartition(std::map<std::string, bool>& bipart, bool checkElements = 1) const throw(Exception);
155 
156  bool areIdentical(size_t k1, size_t k2) const throw(Exception);
157 
159 
168  bool areCompatible(size_t k1, size_t k2) const throw(Exception);
169 
173  bool areAllCompatible() const;
174 
181  bool areAllCompatibleWith(std::map<std::string, bool>& bipart, bool checkElements = true) const throw (Exception);
182 
187 
191  void addTrivialBipartitions(bool checkExisting);
192 
193 
197  void flip(size_t i) throw(Exception);
198 
202  size_t getPartitionSize(size_t i) const throw(Exception);
203 
207  void sortByPartitionSize();
208 
212  TreeTemplate<Node>* toTree() const throw(Exception);
213 
223  RowMatrix<int> toMatrix() const;
224 
225  private:
226 
227  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;
228 
229 };
230 
231 } //end of namespace bpp.
232 
233 #endif //_BIPARTITIONLIST_H_
234 
size_t getNumberOfBipartitions() const
BipartitionList & operator=(const BipartitionList &bipl)
Assignment operator.
RowMatrix< int > toMatrix() const
Create a matrix representation of the bifurcations.
bool haveSameElementsThan(std::map< std::string, bool > &bipart) const
bool areIdentical(size_t k1, size_t k2) const
int * getBitBipartition(size_t i)
void flip(size_t i)
Replaces ones by zeros and zeros by ones in the ith bipartition.
void sortByPartitionSize()
Sort bipartitions by partition size.
bool areCompatible(size_t k1, size_t k2) const
Tells whether 2 bipartitions from the list are compatible.
STL namespace.
The phylogenetic tree class.
std::map< std::string, bool > getBipartition(size_t i) const
Interface for phylogenetic tree objects.
Definition: Tree.h:148
TreeTemplate< Node > * toTree() const
Translate into a tree.
const std::vector< std::string > & getElementNames() 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.
void addTrivialBipartitions(bool checkExisting)
Adds bipartitions corresponding to external branches if missing.
bool areAllCompatible() const
Tells whether all bipartitions in the list are compatible with each other.
std::vector< std::string > elements_
bool containsBipartition(std::map< std::string, bool > &bipart, bool checkElements=1) const
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
BipartitionList * clone() const
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)
size_t getNumberOfElements() const
The phylogenetic node class.
Definition: Node.h:90
This class deals with the bipartitions defined by trees.
void deleteBipartition(size_t i)
std::vector< int * > bitBipartitionList_
size_t getPartitionSize(size_t i) const
Returns the size of the smallest of the two partitions (e.g. 1 for external branches) ...
const std::vector< int * > & getBitBipartitionList() const