bpp-phyl3  3.0.0
bpp::BipartitionList Class Reference

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

#include <Bpp/Phyl/Tree/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 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...
 
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
 
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_
 

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

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 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() [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 116 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 197 of file BipartitionList.cpp.

References bitBipartitionList_.

Member Function Documentation

◆ addBipartition()

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

◆ addTrivialBipartitions()

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

◆ areAllCompatible()

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

◆ areAllCompatibleWith()

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.

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

Definition at line 418 of file BipartitionList.cpp.

References addBipartition(), areCompatible(), bitBipartitionList_, deleteBipartition(), and haveSameElementsThan().

◆ areCompatible()

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

◆ areIdentical()

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

◆ 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
inlinevirtual

Implements bpp::Clonable.

Definition at line 85 of file BipartitionList.h.

References BipartitionList().

Referenced by toTree().

◆ containsBipartition()

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

◆ deleteBipartition()

void BipartitionList::deleteBipartition ( size_t  i)

◆ flip()

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.

◆ getBipartition()

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

◆ getBitBipartition()

int * BipartitionList::getBitBipartition ( size_t  i)

Definition at line 226 of file BipartitionList.cpp.

References bitBipartitionList_.

◆ getBitBipartitionList()

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

◆ getElementNames()

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

Definition at line 90 of file BipartitionList.h.

References elements_.

Referenced by bpp::BipartitionTools::buildBipartitionPair(), and toMatrix().

◆ getNumberOfBipartitions()

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

◆ getNumberOfElements()

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

Definition at line 88 of file BipartitionList.h.

References elements_.

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

◆ getPartitionSize()

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

◆ haveSameElementsThan()

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

◆ isSorted()

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

Definition at line 106 of file BipartitionList.h.

References sorted_.

Referenced by bpp::BipartitionTools::buildBipartitionPair().

◆ operator=()

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

◆ removeRedundantBipartitions()

void BipartitionList::removeRedundantBipartitions ( )

Definition at line 588 of file BipartitionList.cpp.

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

◆ removeTrivialBipartitions()

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

◆ sortByPartitionSize()

void BipartitionList::sortByPartitionSize ( )

Sort bipartitions by partition size.

Definition at line 544 of file BipartitionList.cpp.

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

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

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

◆ toTree()

unique_ptr< TreeTemplate< Node > > BipartitionList::toTree ( ) const

Member Data Documentation

◆ bitBipartitionList_

◆ elements_

◆ sorted_

bool bpp::BipartitionList::sorted_
private

Definition at line 53 of file BipartitionList.h.

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


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