bpp-phyl  2.2.0
bpp::BipartitionList Class Reference

This class deals with the bipartitions defined by trees. More...

#include <Bpp/Phyl/BipartitionList.h>

+ Inheritance diagram for bpp::BipartitionList:
+ Collaboration diagram for bpp::BipartitionList:

Public Member Functions

 BipartitionList (const Tree &tr, bool sorted=true, std::vector< int > *index=0)
 The main contructor. 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...
 
BipartitionListoperator= (const BipartitionList &bipl)
 Assignment operator. More...
 
virtual ~BipartitionList ()
 
BipartitionListclone () 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 throw (Exception)
 
int * getBitBipartition (size_t i) throw (Exception)
 
bool haveSameElementsThan (std::map< std::string, bool > &bipart) const
 
void addBipartition (std::map< std::string, bool > &bipart, bool checkElements=1) throw (Exception)
 
void deleteBipartition (size_t i) throw (Exception)
 
bool isSorted () const
 
void sortElements ()
 
bool containsBipartition (std::map< std::string, bool > &bipart, bool checkElements=1) const throw (Exception)
 
bool areIdentical (size_t k1, size_t k2) const throw (Exception)
 
void removeRedundantBipartitions ()
 
bool areCompatible (size_t k1, size_t k2) const throw (Exception)
 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 throw (Exception)
 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) throw (Exception)
 Replaces ones by zeros and zeros by ones in the ith bipartition. More...
 
size_t getPartitionSize (size_t i) const throw (Exception)
 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...
 
TreeTemplate< Node > * toTree () const throw (Exception)
 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_
 

Detailed Description

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).

See also
Tree
BipartitionTools
TreeTools

Definition at line 83 of file BipartitionList.h.

Constructor & Destructor Documentation

◆ BipartitionList() [1/3]

BipartitionList::BipartitionList ( const Tree tr,
bool  sorted = true,
std::vector< int > *  index = 0 
)

The main contructor.

Parameters
trThe tree to be coded as bipartitions
sortedTells whether leave names should be alphabetically sorted (recommended)
indexAn output optional vector to keep trace of the nodes id underlying each bipartition.

Definition at line 104 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() [2/3]

BipartitionList::BipartitionList ( const std::vector< std::string > &  elements,
const std::vector< int *> &  bipl 
)

An alternative constructor in which elements and bipartitions are passed directly.

Parameters
elementsLeaf names
biplThe list of bit-encoded bipartitions

Definition at line 152 of file BipartitionList.cpp.

References bitBipartitionList_, bpp::BipartitionTools::LWORD, and sorted_.

◆ BipartitionList() [3/3]

BipartitionList::BipartitionList ( const BipartitionList bipl)

◆ ~BipartitionList()

BipartitionList::~BipartitionList ( )
virtual

Definition at line 233 of file BipartitionList.cpp.

References bitBipartitionList_.

Member Function Documentation

◆ addBipartition()

void BipartitionList::addBipartition ( std::map< std::string, bool > &  bipart,
bool  checkElements = 1 
)
throw (Exception
)

◆ addTrivialBipartitions()

void BipartitionList::addTrivialBipartitions ( bool  checkExisting)

Adds bipartitions corresponding to external branches if missing.

Definition at line 560 of file BipartitionList.cpp.

References addBipartition(), containsBipartition(), and elements_.

Referenced by bpp::TreeTools::bipartitionOccurrences().

◆ areAllCompatible()

bool BipartitionList::areAllCompatible ( ) const

Tells whether all bipartitions in the list are compatible with each other.

Definition at line 439 of file BipartitionList.cpp.

References areCompatible(), and bitBipartitionList_.

Referenced by toTree().

◆ areAllCompatibleWith()

bool BipartitionList::areAllCompatibleWith ( std::map< std::string, bool > &  bipart,
bool  checkElements = true 
) const
throw (Exception
)

Tells whether all bipartitions in the list are compatible with a given bipartition.

Parameters
bipartA map representing a bipartition.
checkElementsCheck the correspondance of element sets or not.

Definition at line 454 of file BipartitionList.cpp.

◆ areCompatible()

bool BipartitionList::areCompatible ( size_t  k1,
size_t  k2 
) const
throw (Exception
)

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 403 of file BipartitionList.cpp.

References bpp::BipartitionTools::testBit().

Referenced by areAllCompatible(), bpp::BipartitionTools::areCompatible(), and bpp::TreeTools::thresholdConsensus().

◆ areIdentical()

bool BipartitionList::areIdentical ( size_t  k1,
size_t  k2 
) const
throw (Exception
)

◆ buildBitBipartitions()

vector< string > BipartitionList::buildBitBipartitions ( const Node nd,
std::vector< int *> &  bitbip,
const std::vector< std::string > &  elements,
size_t *  cpt,
std::vector< int > *  index 
) const
private

◆ clone()

BipartitionList* bpp::BipartitionList::clone ( ) const
inline

Definition at line 128 of file BipartitionList.h.

References BipartitionList().

Referenced by toTree().

◆ containsBipartition()

bool BipartitionList::containsBipartition ( std::map< std::string, bool > &  bipart,
bool  checkElements = 1 
) const
throw (Exception
)

◆ deleteBipartition()

void BipartitionList::deleteBipartition ( size_t  i)
throw (Exception
)

◆ flip()

void BipartitionList::flip ( size_t  i)
throw (Exception
)

Replaces ones by zeros and zeros by ones in the ith bipartition.

Definition at line 605 of file BipartitionList.cpp.

References bpp::BipartitionTools::bitNot(), and bpp::BipartitionTools::LWORD.

Referenced by toTree().

◆ getBipartition()

map< string, bool > BipartitionList::getBipartition ( size_t  i) const
throw (Exception
)

Definition at line 243 of file BipartitionList.cpp.

References bpp::BipartitionTools::testBit().

Referenced by toMatrix().

◆ getBitBipartition()

int * BipartitionList::getBitBipartition ( size_t  i)
throw (Exception
)

Definition at line 262 of file BipartitionList.cpp.

◆ getBitBipartitionList()

const std::vector<int*>& bpp::BipartitionList::getBitBipartitionList ( ) const
inline

◆ getElementNames()

const std::vector<std::string>& bpp::BipartitionList::getElementNames ( ) const
inline

Definition at line 134 of file BipartitionList.h.

References elements_.

Referenced by toMatrix().

◆ getNumberOfBipartitions()

◆ getNumberOfElements()

size_t bpp::BipartitionList::getNumberOfElements ( ) const
inline

Definition at line 132 of file BipartitionList.h.

References elements_.

Referenced by BipartitionList(), bpp::TreeTools::bipartitionOccurrences(), operator=(), and toTree().

◆ getPartitionSize()

size_t BipartitionList::getPartitionSize ( size_t  i) const
throw (Exception
)

◆ haveSameElementsThan()

bool BipartitionList::haveSameElementsThan ( std::map< std::string, bool > &  bipart) const

Definition at line 272 of file BipartitionList.cpp.

References elements_.

Referenced by addBipartition(), and containsBipartition().

◆ isSorted()

bool bpp::BipartitionList::isSorted ( ) const
inline

Definition at line 150 of file BipartitionList.h.

References sorted_.

◆ operator=()

BipartitionList & BipartitionList::operator= ( const BipartitionList bipl)

◆ removeRedundantBipartitions()

void BipartitionList::removeRedundantBipartitions ( )

◆ removeTrivialBipartitions()

void BipartitionList::removeTrivialBipartitions ( )

Removes bipartitions corresponding to external branches (1 vs n-1)

Definition at line 548 of file BipartitionList.cpp.

References bitBipartitionList_, deleteBipartition(), and getPartitionSize().

Referenced by bpp::TreeTools::bipartitionOccurrences(), bpp::TreeTools::haveSameTopology(), and bpp::TreeTools::robinsonFouldsDistance().

◆ sortByPartitionSize()

void BipartitionList::sortByPartitionSize ( )

Sort bipartitions by partition size.

Definition at line 580 of file BipartitionList.cpp.

References bitBipartitionList_, getPartitionSize(), IntAndInt::ind, and IntAndInt::val.

Referenced by bpp::TreeTools::haveSameTopology(), bpp::TreeTools::robinsonFouldsDistance(), and toTree().

◆ sortElements()

◆ toMatrix()

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...

Returns
A boolean matrix.

Definition at line 804 of file BipartitionList.cpp.

References getBipartition(), getElementNames(), and getNumberOfBipartitions().

◆ toTree()

Member Data Documentation

◆ bitBipartitionList_

◆ elements_

std::vector<std::string> bpp::BipartitionList::elements_
private

◆ sorted_

bool bpp::BipartitionList::sorted_
private

Definition at line 90 of file BipartitionList.h.

Referenced by BipartitionList(), isSorted(), operator=(), and sortElements().


The documentation for this class was generated from the following files: