bpp-phyl3
3.0.0
|
This class deals with the bipartitions defined by trees. More...
#include <Bpp/Phyl/Tree/BipartitionList.h>
Public Member Functions | |
BipartitionList (const Tree &tr, bool sorted=true, std::vector< int > *index=0) | |
The main constructor. More... | |
BipartitionList (const std::vector< std::string > &elements, const std::vector< int * > &bipl) | |
An alternative constructor in which elements and bipartitions are passed directly. More... | |
BipartitionList (const BipartitionList &bipl) | |
Copy-constructor. More... | |
BipartitionList & | operator= (const BipartitionList &bipl) |
Assignment operator. More... | |
virtual | ~BipartitionList () |
BipartitionList * | clone () const |
size_t | getNumberOfElements () const |
const std::vector< std::string > & | getElementNames () const |
size_t | getNumberOfBipartitions () const |
const std::vector< int * > & | getBitBipartitionList () const |
std::map< std::string, bool > | getBipartition (size_t i) const |
int * | getBitBipartition (size_t i) |
bool | haveSameElementsThan (std::map< std::string, bool > &bipart) const |
void | addBipartition (std::map< std::string, bool > &bipart, bool checkElements=1) |
void | deleteBipartition (size_t i) |
bool | isSorted () const |
void | sortElements () |
bool | containsBipartition (std::map< std::string, bool > &bipart, bool checkElements=1) const |
bool | areIdentical (size_t k1, size_t k2) const |
void | removeRedundantBipartitions () |
bool | areCompatible (size_t k1, size_t k2) const |
Tells whether 2 bipartitions from the list are compatible. More... | |
bool | areAllCompatible () const |
Tells whether all bipartitions in the list are compatible with each other. More... | |
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. More... | |
void | removeTrivialBipartitions () |
Removes bipartitions corresponding to external branches (1 vs n-1) More... | |
void | addTrivialBipartitions (bool checkExisting) |
Adds bipartitions corresponding to external branches if missing. More... | |
void | flip (size_t i) |
Replaces ones by zeros and zeros by ones in the ith bipartition. More... | |
size_t | getPartitionSize (size_t i) const |
Returns the size of the smallest of the two partitions (e.g. 1 for external branches) More... | |
void | sortByPartitionSize () |
Sort bipartitions by partition size. More... | |
std::unique_ptr< TreeTemplate< Node > > | toTree () const |
Translate into a tree. More... | |
RowMatrix< int > | toMatrix () const |
Create a matrix representation of the bifurcations. More... | |
Private Member Functions | |
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 |
Private Attributes | |
std::vector< int * > | bitBipartitionList_ |
std::vector< std::string > | elements_ |
bool | sorted_ |
This class deals with the bipartitions defined by trees.
Any branch of a tree defines a bipartition, i.e. two non-overlapping subsets of leaves whose union is the whole set of leaves. A tree topology can therefore be represented by the list of bipartitions its branches define - the so-called matrix representation. Coding trees this way is useful for comparing topologies, calculating topological distances, producing consensus trees or super-trees, calculating bootstrap support.
A BipartitionList includes a set of element names (typically leaf names) and a vector of arrays of bits (int*, not bitsets, are used to allow for dynamic memory allocation). Each array of bit codes for one bipartition. Each bit in an array of bit corresponds to one element, so the order of element names matter. Bits set to zero versus bits set to one define the two partitions of elements. A BipartitionList is called sorted if its elements (leaf names) are in alphabetic order (recommended).
BipartitionList objects are typically created from a tree, in which case elements are leaf names. Note that BipartitionList is an unrooted object: a rooted or unrooted versions of the same tree will yield the same BipartitionList in which the root location is ignored. Bipartitions can be accessed as arrays of bits (e.g. getBitBipartition), or as map<string, bool>, in which keys are leaf names and true/false values define the two partitions (e.g. getBipartition, addBipartition).
Definition at line 47 of file BipartitionList.h.
BipartitionList::BipartitionList | ( | const Tree & | tr, |
bool | sorted = true , |
||
std::vector< int > * | index = 0 |
||
) |
The main constructor.
tr | The tree to be coded as bipartitions |
sorted | Tells whether leave names should be alphabetically sorted (recommended) |
index | An output optional vector to keep trace of the nodes id underlying each bipartition. |
Definition at line 68 of file BipartitionList.cpp.
References bitBipartitionList_, buildBitBipartitions(), elements_, bpp::Tree::getLeavesNames(), bpp::Tree::getNumberOfNodes(), bpp::TreeTemplate< N >::getRootNode(), bpp::Tree::isRooted(), and bpp::BipartitionTools::LWORD.
Referenced by clone().
BipartitionList::BipartitionList | ( | const std::vector< std::string > & | elements, |
const std::vector< int * > & | bipl | ||
) |
An alternative constructor in which elements and bipartitions are passed directly.
elements | Leaf names |
bipl | The list of bit-encoded bipartitions |
Definition at line 116 of file BipartitionList.cpp.
References bitBipartitionList_, bpp::BipartitionTools::LWORD, and sorted_.
BipartitionList::BipartitionList | ( | const BipartitionList & | bipl | ) |
Copy-constructor.
Definition at line 146 of file BipartitionList.cpp.
References bitBipartitionList_, getBitBipartitionList(), getNumberOfBipartitions(), getNumberOfElements(), and bpp::BipartitionTools::LWORD.
|
virtual |
Definition at line 197 of file BipartitionList.cpp.
References bitBipartitionList_.
void BipartitionList::addBipartition | ( | std::map< std::string, bool > & | bipart, |
bool | checkElements = 1 |
||
) |
Definition at line 258 of file BipartitionList.cpp.
References bpp::BipartitionTools::bit0(), bpp::BipartitionTools::bit1(), bitBipartitionList_, elements_, haveSameElementsThan(), and bpp::BipartitionTools::LWORD.
Referenced by addTrivialBipartitions(), and areAllCompatibleWith().
void BipartitionList::addTrivialBipartitions | ( | bool | checkExisting | ) |
Adds bipartitions corresponding to external branches if missing.
Definition at line 524 of file BipartitionList.cpp.
References addBipartition(), containsBipartition(), and elements_.
bool BipartitionList::areAllCompatible | ( | ) | const |
Tells whether all bipartitions in the list are compatible with each other.
Definition at line 403 of file BipartitionList.cpp.
References areCompatible(), and bitBipartitionList_.
Referenced by toTree().
bool BipartitionList::areAllCompatibleWith | ( | std::map< std::string, bool > & | bipart, |
bool | checkElements = true |
||
) | const |
Tells whether all bipartitions in the list are compatible with a given bipartition.
bipart | A map representing a bipartition. |
checkElements | Check the correspondence of element sets or not. |
Definition at line 418 of file BipartitionList.cpp.
References addBipartition(), areCompatible(), bitBipartitionList_, deleteBipartition(), and haveSameElementsThan().
bool BipartitionList::areCompatible | ( | size_t | k1, |
size_t | k2 | ||
) | const |
Tells whether 2 bipartitions from the list are compatible.
Let A=A1|A2 and B=B1|B2 be two bipartitions (such that A1 U A2 = B1 U B2 = set of leaves) A and B are said compatible if (A1 contains B1 and B2 contains A2) or (A1 contains B2 and B1 contains A2) or (B1 contains A1 and A2 contains B2) or (B2 contains A1 and A2 contains B1). Only compatible bipartitions can belong to the same tree.
Definition at line 367 of file BipartitionList.cpp.
References bitBipartitionList_, elements_, and bpp::BipartitionTools::testBit().
Referenced by areAllCompatible(), and areAllCompatibleWith().
bool BipartitionList::areIdentical | ( | size_t | k1, |
size_t | k2 | ||
) | const |
Definition at line 333 of file BipartitionList.cpp.
References bitBipartitionList_, elements_, and bpp::BipartitionTools::testBit().
Referenced by removeRedundantBipartitions().
|
private |
Definition at line 707 of file BipartitionList.cpp.
References bpp::BipartitionTools::bit0(), bpp::BipartitionTools::bit1(), bpp::Node::getFather(), bpp::Node::getId(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::hasFather().
Referenced by BipartitionList().
|
inlinevirtual |
Implements bpp::Clonable.
Definition at line 85 of file BipartitionList.h.
References BipartitionList().
Referenced by toTree().
bool BipartitionList::containsBipartition | ( | std::map< std::string, bool > & | bipart, |
bool | checkElements = 1 |
||
) | const |
Definition at line 295 of file BipartitionList.cpp.
References bitBipartitionList_, elements_, haveSameElementsThan(), and bpp::BipartitionTools::testBit().
Referenced by addTrivialBipartitions().
void BipartitionList::deleteBipartition | ( | size_t | i | ) |
Definition at line 284 of file BipartitionList.cpp.
References bitBipartitionList_.
Referenced by areAllCompatibleWith(), removeRedundantBipartitions(), and removeTrivialBipartitions().
void BipartitionList::flip | ( | size_t | i | ) |
Replaces ones by zeros and zeros by ones in the ith bipartition.
Definition at line 569 of file BipartitionList.cpp.
References bitBipartitionList_, bpp::BipartitionTools::bitNot(), elements_, and bpp::BipartitionTools::LWORD.
map< string, bool > BipartitionList::getBipartition | ( | size_t | i | ) | const |
Definition at line 207 of file BipartitionList.cpp.
References bitBipartitionList_, elements_, and bpp::BipartitionTools::testBit().
Referenced by toMatrix().
int * BipartitionList::getBitBipartition | ( | size_t | i | ) |
Definition at line 226 of file BipartitionList.cpp.
References bitBipartitionList_.
|
inline |
Definition at line 94 of file BipartitionList.h.
References bitBipartitionList_.
Referenced by BipartitionList(), bpp::BipartitionTools::buildBipartitionPair(), bpp::BipartitionTools::mergeBipartitionLists(), and operator=().
|
inline |
Definition at line 90 of file BipartitionList.h.
References elements_.
Referenced by bpp::BipartitionTools::buildBipartitionPair(), and toMatrix().
|
inline |
Definition at line 92 of file BipartitionList.h.
References bitBipartitionList_.
Referenced by BipartitionList(), bpp::BipartitionTools::buildBipartitionPair(), bpp::TreeTools::computeBootstrapValues(), operator=(), and toMatrix().
|
inline |
Definition at line 88 of file BipartitionList.h.
References elements_.
Referenced by BipartitionList(), and operator=().
size_t BipartitionList::getPartitionSize | ( | size_t | i | ) | const |
Returns the size of the smallest of the two partitions (e.g. 1 for external branches)
Definition at line 492 of file BipartitionList.cpp.
References bitBipartitionList_, elements_, and bpp::BipartitionTools::testBit().
Referenced by removeTrivialBipartitions(), and sortByPartitionSize().
bool BipartitionList::haveSameElementsThan | ( | std::map< std::string, bool > & | bipart | ) | const |
Definition at line 236 of file BipartitionList.cpp.
References elements_.
Referenced by addBipartition(), areAllCompatibleWith(), and containsBipartition().
|
inline |
Definition at line 106 of file BipartitionList.h.
References sorted_.
Referenced by bpp::BipartitionTools::buildBipartitionPair().
BipartitionList & BipartitionList::operator= | ( | const BipartitionList & | bipl | ) |
Assignment operator.
Definition at line 169 of file BipartitionList.cpp.
References bitBipartitionList_, elements_, getBitBipartitionList(), getNumberOfBipartitions(), getNumberOfElements(), bpp::BipartitionTools::LWORD, and sorted_.
void BipartitionList::removeRedundantBipartitions | ( | ) |
Definition at line 588 of file BipartitionList.cpp.
References areIdentical(), bitBipartitionList_, and deleteBipartition().
void BipartitionList::removeTrivialBipartitions | ( | ) |
Removes bipartitions corresponding to external branches (1 vs n-1)
Definition at line 512 of file BipartitionList.cpp.
References bitBipartitionList_, deleteBipartition(), and getPartitionSize().
void BipartitionList::sortByPartitionSize | ( | ) |
Sort bipartitions by partition size.
Definition at line 544 of file BipartitionList.cpp.
References bitBipartitionList_, getPartitionSize(), IntAndInt::ind, and IntAndInt::val.
void BipartitionList::sortElements | ( | ) |
Definition at line 439 of file BipartitionList.cpp.
References bpp::BipartitionTools::bit0(), bpp::BipartitionTools::bit1(), bitBipartitionList_, elements_, StringAndInt::ind, bpp::BipartitionTools::LWORD, sorted_, StringAndInt::str, and bpp::BipartitionTools::testBit().
Referenced by bpp::BipartitionTools::buildBipartitionPair(), and bpp::BipartitionTools::mergeBipartitionLists().
RowMatrix< int > BipartitionList::toMatrix | ( | ) | const |
Create a matrix representation of the bifurcations.
Each row corresponds to an element, each column to a bipartition.
NB: using RowMatrix<bool> leads to unexplained compilation error...
Definition at line 768 of file BipartitionList.cpp.
References getBipartition(), getElementNames(), and getNumberOfBipartitions().
unique_ptr< TreeTemplate< Node > > BipartitionList::toTree | ( | ) | const |
Translate into a tree.
Definition at line 614 of file BipartitionList.cpp.
References bpp::Node::addSon(), areAllCompatible(), bpp::BipartitionTools::bitOr(), clone(), elements_, bpp::BipartitionTools::LWORD, and bpp::BipartitionTools::testBit().
|
private |
Definition at line 51 of file BipartitionList.h.
Referenced by addBipartition(), areAllCompatible(), areAllCompatibleWith(), areCompatible(), areIdentical(), BipartitionList(), containsBipartition(), deleteBipartition(), flip(), getBipartition(), getBitBipartition(), getBitBipartitionList(), getNumberOfBipartitions(), getPartitionSize(), operator=(), removeRedundantBipartitions(), removeTrivialBipartitions(), sortByPartitionSize(), sortElements(), and ~BipartitionList().
|
private |
Definition at line 52 of file BipartitionList.h.
Referenced by addBipartition(), addTrivialBipartitions(), areCompatible(), areIdentical(), BipartitionList(), containsBipartition(), flip(), getBipartition(), getElementNames(), getNumberOfElements(), getPartitionSize(), haveSameElementsThan(), operator=(), sortElements(), and toTree().
|
private |
Definition at line 53 of file BipartitionList.h.
Referenced by BipartitionList(), isSorted(), operator=(), and sortElements().