bpp-phyl
2.2.0
|
The phylogenetic tree class. More...
#include <Bpp/Phyl/BipartitionList.h>
Public Member Functions | |
TreeTemplate () | |
TreeTemplate (const TreeTemplate< N > &t) | |
TreeTemplate (const Tree &t) | |
TreeTemplate (N *root) | |
TreeTemplate< N > & | operator= (const TreeTemplate< N > &t) |
TreeTemplate< N > * | cloneSubtree (int newRootId) const |
clones a Subtree rooted at given node Id More... | |
virtual | ~TreeTemplate () |
TreeTemplate< N > * | clone () const |
std::string | getName () const |
void | setName (const std::string &name) |
int | getRootId () const |
size_t | getNumberOfLeaves () const |
size_t | getNumberOfNodes () const |
int | getLeafId (const std::string &name) const throw (NodeNotFoundException) |
std::vector< int > | getLeavesId () const |
std::vector< int > | getNodesId () const |
std::vector< int > | getInnerNodesId () const |
std::vector< int > | getBranchesId () const |
std::vector< double > | getBranchLengths () const |
std::vector< std::string > | getLeavesNames () const |
std::vector< int > | getSonsId (int parentId) const throw (NodeNotFoundException) |
std::vector< int > | getAncestorsId (int nodeId) const throw (NodeNotFoundException) |
int | getFatherId (int parentId) const throw (NodeNotFoundException) |
bool | hasFather (int nodeId) const throw (NodeNotFoundException) |
std::string | getNodeName (int nodeId) const throw (NodeNotFoundException) |
bool | hasNodeName (int nodeId) const throw (NodeNotFoundException) |
void | setNodeName (int nodeId, const std::string &name) throw (NodeNotFoundException) |
void | deleteNodeName (int nodeId) throw (NodeNotFoundException) |
bool | hasNode (int nodeId) const |
bool | isLeaf (int nodeId) const throw (NodeNotFoundException) |
bool | isRoot (int nodeId) const throw (NodeNotFoundException) |
double | getDistanceToFather (int nodeId) const |
void | setDistanceToFather (int nodeId, double length) |
void | deleteDistanceToFather (int nodeId) |
bool | hasDistanceToFather (int nodeId) const |
bool | hasNodeProperty (int nodeId, const std::string &name) const throw (NodeNotFoundException) |
void | setNodeProperty (int nodeId, const std::string &name, const Clonable &property) throw (NodeNotFoundException) |
Clonable * | getNodeProperty (int nodeId, const std::string &name) throw (NodeNotFoundException) |
const Clonable * | getNodeProperty (int nodeId, const std::string &name) const throw (NodeNotFoundException) |
Clonable * | removeNodeProperty (int nodeId, const std::string &name) throw (NodeNotFoundException) |
std::vector< std::string > | getNodePropertyNames (int nodeId) const throw (NodeNotFoundException) |
bool | hasBranchProperty (int nodeId, const std::string &name) const throw (NodeNotFoundException) |
void | setBranchProperty (int nodeId, const std::string &name, const Clonable &property) throw (NodeNotFoundException) |
Clonable * | getBranchProperty (int nodeId, const std::string &name) throw (NodeNotFoundException) |
const Clonable * | getBranchProperty (int nodeId, const std::string &name) const throw (NodeNotFoundException) |
Clonable * | removeBranchProperty (int nodeId, const std::string &name) throw (NodeNotFoundException) |
std::vector< std::string > | getBranchPropertyNames (int nodeId) const throw (NodeNotFoundException) |
void | rootAt (int nodeId) throw (NodeNotFoundException) |
Change the root node. More... | |
void | newOutGroup (int nodeId) throw (NodeNotFoundException) |
Root a tree by specifying an outgroup. More... | |
bool | isRooted () const |
Tell if the tree is rooted. More... | |
bool | unroot () throw (UnrootedTreeException) |
Unroot a rooted tree. More... | |
void | resetNodesId () |
Number nodes. More... | |
bool | isMultifurcating () const |
Tell if the tree is multifurcating. More... | |
template<class N2 > | |
bool | hasSameTopologyAs (const TreeTemplate< N2 > &tree, bool ordered=false) const |
Tells if this tree has the same topology as the one given for comparison. More... | |
std::vector< double > | getBranchLengths () throw (NodeException) |
Get all the branch lengths of a tree. More... | |
double | getTotalLength () throw (NodeException) |
Get the total length (sum of all branch lengths) of a tree. More... | |
void | setBranchLengths (double brLen) |
Set all the branch lengths of a tree. More... | |
void | setVoidBranchLengths (double brLen) |
Give a length to branches that don't have one in a tree. More... | |
void | scaleTree (double factor) throw (NodeException) |
Scale a given tree. More... | |
int | getNextId () |
Get an id. More... | |
void | swapNodes (int parentId, size_t i1, size_t i2) throw (NodeNotFoundException, IndexOutOfBoundsException) |
Specific methods | |
virtual void | setRootNode (N *root) |
virtual N * | getRootNode () |
virtual const N * | getRootNode () const |
virtual std::vector< const N * > | getLeaves () const |
virtual std::vector< N * > | getLeaves () |
virtual std::vector< const N * > | getNodes () const |
virtual std::vector< N * > | getNodes () |
virtual std::vector< const N * > | getInnerNodes () const |
virtual std::vector< N * > | getInnerNodes () |
virtual N * | getNode (int id, bool checkId=false) throw (NodeNotFoundException, Exception) |
virtual const N * | getNode (int id, bool checkId=false) const throw (NodeNotFoundException, Exception) |
virtual N * | getNode (const std::string &name) throw (NodeNotFoundException, Exception) |
virtual const N * | getNode (const std::string &name) const throw (NodeNotFoundException, Exception) |
void | rootAt (N *newRoot) |
void | newOutGroup (N *outGroup) |
Acting on topology. | |
void | swapNodes (const Tree &tree, int nodeId, size_t i1=0, size_t i2=1) throw (NodeNotFoundException,IndexOutOfBoundsException) |
Swap two son nodes. More... | |
Private Attributes | |
N * | root_ |
std::string | name_ |
The phylogenetic tree class.
This class is part of the object implementation of phylogenetic trees. Tree are made made of nodes, instances of the class Node. It is possible to use a tree with more complexe Node classes, but currently all nodes of a tree have to be of the same class.
Trees are oriented (rooted), i.e. each node has one father node and possibly many son nodes. Leaves are nodes without descendant and root is defined has the without father. Inner nodes will generally contain two descendants (the tree is then called bifurcating), but mutlifurcating trees are also allowed with this kind of description. In the rooted case, each inner node also defines a subtree. This allows to work recursively on trees, which is very convenient in most cases. To deal with non-rooted trees, we place an artificial root at a particular node: hence the root node appears to be trifurcated. This is the way unrooted trees are described in the parenthetic description, the so called Newick format.
To clone a tree from from another tree with a different template, consider using the TreeTools::cloneSutree<N>() method:
The getNextId() method sends a id value which is not used in the tree. In the current implementation, it uses the TreeTools::getMPNUId() method. This avoids to use duplicated ids, but is time consuming. In most cases, it is of better efficiency if the user deal with the ids himself, by using the Node::setId() method. The TreeTools::getMaxId() method may also prove useful in this respect. The resetNodesId() method can also be used to re-initialize all ids.
Definition at line 56 of file BipartitionList.h.
|
inline |
Definition at line 105 of file TreeTemplate.h.
|
inline |
Definition at line 108 of file TreeTemplate.h.
|
inline |
Definition at line 116 of file TreeTemplate.h.
|
inline |
Definition at line 124 of file TreeTemplate.h.
|
inlinevirtual |
Definition at line 145 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 151 of file TreeTemplate.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::hasSameTopologyAs().
|
inlinevirtual |
clones a Subtree rooted at given node Id
Implements bpp::Tree.
Definition at line 139 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 208 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 196 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 184 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 176 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 178 of file TreeTemplate.h.
|
inlinevirtual |
Get all the branch lengths of a tree.
NodeException | If a branch length is lacking. |
Implements bpp::Tree.
Definition at line 343 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 228 of file TreeTemplate.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::rootAt().
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 230 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 234 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 204 of file TreeTemplate.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::rootAt().
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 186 of file TreeTemplate.h.
|
inlinevirtual |
Definition at line 415 of file TreeTemplate.h.
|
inlinevirtual |
Definition at line 417 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 174 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 168 of file TreeTemplate.h.
|
inlinevirtual |
Definition at line 407 of file TreeTemplate.h.
Referenced by bpp::NexusIOTree::read().
|
inlinevirtual |
Definition at line 409 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 170 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 180 of file TreeTemplate.h.
Referenced by bpp::TreeTemplateTools::getDistanceMatrix().
|
inlinevirtual |
|
inlinevirtual |
Get an id.
Implements bpp::Tree.
Definition at line 383 of file TreeTemplate.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::newOutGroup().
|
inlinevirtual |
Definition at line 419 of file TreeTemplate.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::deleteDistanceToFather(), bpp::TreeTemplate< bpp::NodeTemplate >::deleteNodeName(), bpp::TreeTemplate< bpp::NodeTemplate >::getAncestorsId(), bpp::TreeTemplate< bpp::NodeTemplate >::getBranchProperty(), bpp::TreeTemplate< bpp::NodeTemplate >::getBranchPropertyNames(), bpp::TreeTemplate< bpp::NodeTemplate >::getDistanceToFather(), bpp::TreeTemplate< bpp::NodeTemplate >::getFatherId(), bpp::TreeTemplate< bpp::NodeTemplate >::getNodeName(), bpp::TreeTemplate< bpp::NodeTemplate >::getNodeProperty(), bpp::TreeTemplate< bpp::NodeTemplate >::getNodePropertyNames(), bpp::SubstitutionMappingTools::getNormalizedCountsPerBranch(), bpp::TreeTemplate< bpp::NodeTemplate >::getSonsId(), bpp::TreeTemplate< bpp::NodeTemplate >::hasBranchProperty(), bpp::TreeTemplate< bpp::NodeTemplate >::hasDistanceToFather(), bpp::TreeTemplate< bpp::NodeTemplate >::hasFather(), bpp::TreeTemplate< bpp::NodeTemplate >::hasNodeName(), bpp::TreeTemplate< bpp::NodeTemplate >::hasNodeProperty(), bpp::TreeTemplate< bpp::NodeTemplate >::isLeaf(), bpp::TreeTemplate< bpp::NodeTemplate >::isRoot(), bpp::TreeTemplate< bpp::NodeTemplate >::newOutGroup(), bpp::TreeTemplate< bpp::NodeTemplate >::removeBranchProperty(), bpp::TreeTemplate< bpp::NodeTemplate >::removeNodeProperty(), bpp::TreeTemplate< bpp::NodeTemplate >::rootAt(), bpp::TreeTemplate< bpp::NodeTemplate >::setBranchProperty(), bpp::TreeTemplate< bpp::NodeTemplate >::setDistanceToFather(), bpp::TreeTemplate< bpp::NodeTemplate >::setNodeName(), bpp::TreeTemplate< bpp::NodeTemplate >::setNodeProperty(), bpp::DRASRTreeLikelihoodData::setTree(), and bpp::DRASDRTreeLikelihoodData::setTree().
|
inlinevirtual |
Definition at line 436 of file TreeTemplate.h.
|
inlinevirtual |
Definition at line 453 of file TreeTemplate.h.
|
inlinevirtual |
Definition at line 462 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 190 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 216 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 218 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 222 of file TreeTemplate.h.
|
inlinevirtual |
Definition at line 411 of file TreeTemplate.h.
Referenced by bpp::RewardMappingTools::computeRewardVectors(), bpp::SubstitutionMappingTools::computeSubstitutionVectors(), bpp::SubstitutionMappingTools::computeSubstitutionVectorsMarginal(), bpp::SubstitutionMappingTools::computeSubstitutionVectorsNoAveraging(), bpp::SubstitutionMappingTools::computeSubstitutionVectorsNoAveragingMarginal(), bpp::TreeTemplate< bpp::NodeTemplate >::resetNodesId(), bpp::NNITopologySearch::searchBetter(), bpp::NNITopologySearch::searchFast(), and bpp::NNITopologySearch::searchPhyML().
|
inlinevirtual |
Definition at line 413 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 172 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 164 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 166 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 162 of file TreeTemplate.h.
Referenced by bpp::TreeTemplateTools::midRoot(), and bpp::TreeTemplate< bpp::NodeTemplate >::newOutGroup().
|
inlinevirtual |
Definition at line 403 of file TreeTemplate.h.
Referenced by bpp::BipartitionList::BipartitionList(), bpp::TreeTemplateTools::getDistanceMatrix(), bpp::TreeTemplateTools::getRadius(), bpp::AbstractNonHomogeneousTreeLikelihood::init_(), bpp::TreeTemplateTools::midRoot(), bpp::PhyloStatistics::setTree(), bpp::Nhx::treeToParenthesis(), and bpp::TreeTemplateTools::treeToParenthesis().
|
inlinevirtual |
Definition at line 405 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 182 of file TreeTemplate.h.
|
inlinevirtual |
Get the total length (sum of all branch lengths) of a tree.
NodeException | If a branch length is lacking. |
Implements bpp::Tree.
Definition at line 354 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 224 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 210 of file TreeTemplate.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::rootAt().
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 188 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 198 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 192 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 212 of file TreeTemplate.h.
|
inline |
Tells if this tree has the same topology as the one given for comparison.
This method compares recursively all subtrees. The comparison is performed only on the nodes names and the parental relationships. Nodes ids are ignored, and so are branch lengths and any branch/node properties. The default is to ignore the ordering of the descendants, that is (A,B),C) will be considered as having the same topology as (B,A),C). Multifurcations are permited. If ordering is ignored, a copy of the two trees to be compared is performed and are ordered before comparison, making the whole comparison slower and more memory greedy.
tree | The tree to be compared with. |
ordered | Should the ordering of the branching be taken into account? |
Definition at line 316 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 200 of file TreeTemplate.h.
|
inlinevirtual |
Tell if the tree is multifurcating.
Implements bpp::Tree.
Definition at line 293 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 202 of file TreeTemplate.h.
|
inlinevirtual |
Tell if the tree is rooted.
Implements bpp::Tree.
Definition at line 240 of file TreeTemplate.h.
Referenced by bpp::TreeTemplateTools::midRoot(), bpp::TreeTemplate< bpp::NodeTemplate >::newOutGroup(), bpp::TreeTemplate< bpp::NodeTemplate >::rootAt(), and bpp::TreeTemplate< bpp::NodeTemplate >::unroot().
|
inlinevirtual |
Root a tree by specifying an outgroup.
If the tree is rooted, unroot it first, change the root node and then reroot the tree using the previous root id. If the tree is unrooted, change the root node and then create a new root node.
nodeId | The id of the node that will be the new root. |
Implements bpp::Tree.
Definition at line 238 of file TreeTemplate.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::newOutGroup().
|
inline |
Definition at line 503 of file TreeTemplate.h.
|
inline |
Definition at line 130 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 232 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 220 of file TreeTemplate.h.
|
inlinevirtual |
Number nodes.
Implements bpp::Tree.
Definition at line 284 of file TreeTemplate.h.
Referenced by bpp::TreeTemplateTools::getRandomTree(), bpp::Nhx::parenthesisToTree(), bpp::TreeTemplateTools::parenthesisToTree(), and bpp::BipartitionList::toTree().
|
inlinevirtual |
Change the root node.
Works on unrooted tree. If the tree is rooted, the method unroots it first.
nodeId | The id of the node that will be the new root. |
Implements bpp::Tree.
Definition at line 236 of file TreeTemplate.h.
Referenced by bpp::TreeTemplateTools::getBestRootInSubtree_(), bpp::TreeTemplateTools::midRoot(), bpp::TreeTemplate< bpp::NodeTemplate >::newOutGroup(), and bpp::TreeTemplate< bpp::NodeTemplate >::rootAt().
|
inline |
Definition at line 471 of file TreeTemplate.h.
|
inlinevirtual |
Scale a given tree.
Multiply all branch lengths by a given factor.
factor | The factor to multiply all branch lengths with. |
NodeException | If a branch length is lacking. |
Implements bpp::Tree.
Definition at line 375 of file TreeTemplate.h.
|
inlinevirtual |
Set all the branch lengths of a tree.
brLen | The branch length to apply. |
Implements bpp::Tree.
Definition at line 359 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 226 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 206 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 160 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 194 of file TreeTemplate.h.
|
inlinevirtual |
Implements bpp::Tree.
Definition at line 214 of file TreeTemplate.h.
|
inlinevirtual |
Definition at line 401 of file TreeTemplate.h.
Referenced by bpp::Nhx::parenthesisToTree(), bpp::TreeTemplateTools::parenthesisToTree(), and bpp::TreeTemplate< bpp::NodeTemplate >::unroot().
|
inlinevirtual |
Give a length to branches that don't have one in a tree.
brLen | The branch length to apply. |
Implements bpp::Tree.
Definition at line 367 of file TreeTemplate.h.
|
inherited |
Swap two son nodes.
tree | The tree. |
nodeId | The node. |
i1 | First son node index. |
i2 | Second son node index. |
NodeNotFoundException | If the node is not found. |
IndexOutOfBoundsException | If one node index is not valid, or if the node |
|
inline |
Definition at line 388 of file TreeTemplate.h.
|
inlinevirtual |
Unroot a rooted tree.
UnrootedTreeException | If the tree is already rooted. |
Implements bpp::Tree.
Definition at line 242 of file TreeTemplate.h.
Referenced by bpp::TreeTemplateTools::midRoot(), bpp::TreeTemplate< bpp::NodeTemplate >::newOutGroup(), and bpp::TreeTemplate< bpp::NodeTemplate >::rootAt().
|
private |
Definition at line 101 of file TreeTemplate.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getName(), bpp::TreeTemplate< bpp::NodeTemplate >::operator=(), and bpp::TreeTemplate< bpp::NodeTemplate >::setName().
|
private |
Fields:
Definition at line 100 of file TreeTemplate.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getBranchesId(), bpp::TreeTemplate< bpp::NodeTemplate >::getBranchLengths(), bpp::TreeTemplate< bpp::NodeTemplate >::getInnerNodes(), bpp::TreeTemplate< bpp::NodeTemplate >::getInnerNodesId(), bpp::TreeTemplate< bpp::NodeTemplate >::getLeafId(), bpp::TreeTemplate< bpp::NodeTemplate >::getLeaves(), bpp::TreeTemplate< bpp::NodeTemplate >::getLeavesId(), bpp::TreeTemplate< bpp::NodeTemplate >::getLeavesNames(), bpp::TreeTemplate< bpp::NodeTemplate >::getNextId(), bpp::TreeTemplate< bpp::NodeTemplate >::getNode(), bpp::TreeTemplate< bpp::NodeTemplate >::getNodes(), bpp::TreeTemplate< bpp::NodeTemplate >::getNodesId(), bpp::TreeTemplate< bpp::NodeTemplate >::getNumberOfLeaves(), bpp::TreeTemplate< bpp::NodeTemplate >::getNumberOfNodes(), bpp::TreeTemplate< bpp::NodeTemplate >::getRootId(), bpp::TreeTemplate< bpp::NodeTemplate >::getRootNode(), bpp::TreeTemplate< bpp::NodeTemplate >::getTotalLength(), bpp::TreeTemplate< bpp::NodeTemplate >::hasNode(), bpp::TreeTemplate< bpp::NodeTemplate >::isMultifurcating(), bpp::TreeTemplate< bpp::NodeTemplate >::isRooted(), bpp::TreeTemplate< bpp::NodeTemplate >::newOutGroup(), bpp::TreeTemplate< bpp::NodeTemplate >::operator=(), bpp::TreeTemplate< bpp::NodeTemplate >::rootAt(), bpp::TreeTemplate< bpp::NodeTemplate >::scaleTree(), bpp::TreeTemplate< bpp::NodeTemplate >::setBranchLengths(), bpp::TreeTemplate< bpp::NodeTemplate >::setRootNode(), bpp::TreeTemplate< bpp::NodeTemplate >::setVoidBranchLengths(), bpp::TreeTemplate< bpp::NodeTemplate >::swapNodes(), bpp::TreeTemplate< bpp::NodeTemplate >::TreeTemplate(), bpp::TreeTemplate< bpp::NodeTemplate >::unroot(), and bpp::TreeTemplate< bpp::NodeTemplate >::~TreeTemplate().