bpp-phyl  2.3.0
bpp::TreeTemplateTools Class Reference

Utilitary methods working with TreeTemplate and Node objects. More...

#include <Bpp/Phyl/TreeTemplateTools.h>

Classes

struct  Element
 
struct  Moments_
 A structure recording, for a subtree, the sum of root-leaf distances, the sum of their squares, and the number of elements in these sums (ie. the number of leaves). More...
 
struct  OrderTreeData_
 

Public Member Functions

 TreeTemplateTools ()
 
virtual ~TreeTemplateTools ()
 

Static Public Member Functions

static std::vector< const Node * > getRemainingNeighbors (const Node *node1, const Node *node2, const Node *node3)
 Get a subset of node neighbors. More...
 
static void incrementAllIds (Node *node, int increment)
 This method will add a given value (possibly negative) to all identifiers in a (sub)tree. More...
 
static void midRoot (TreeTemplate< Node > &tree, short criterion, bool forceBranchRoot)
 Midroot the tree by minimizing a given criterion ("variance" or "sum of squares") More...
 
static double getRadius (TreeTemplate< Node > &tree)
 Get the caracteristic radius of a tree (average distance to the root minimizing the sum of squared distances). More...
 
static void unresolveUncertainNodes (Node &subtree, double threshold, const std::string &property=TreeTools::BOOTSTRAP)
 Unresolve nodes with low confidence value. More...
 
Retrieve topology information
template<class N >
static std::vector< N * > getLeaves (N &node)
 Retrieve all leaves from a subtree. More...
 
template<class N >
static void getLeaves (N &node, std::vector< N * > &leaves)
 Retrieve all leaves from a subtree. More...
 
static std::vector< int > getLeavesId (const Node &node)
 Retrieve all leaves ids from a subtree. More...
 
static void getLeavesId (const Node &node, std::vector< int > &ids)
 Retrieve all leaves ids from a subtree. More...
 
static std::vector< int > getAncestorsId (const Node &node)
 Retrieve all nodes ids that are ancestors of a node. More...
 
static int getLeafId (const Node &node, const std::string &name) throw (NodeNotFoundException)
 Get the id of a leaf given its name in a subtree. More...
 
static void searchLeaf (const Node &node, const std::string &name, int *&id) throw (NodeNotFoundException)
 Get the id of a leaf given its name in a subtree. More...
 
template<class N >
static void dropLeaf (TreeTemplate< N > &tree, const std::string &leafName) throw (NodeNotFoundException, Exception)
 Remove a leaf node and its parent node, while correcting for branch lengths. More...
 
template<class N >
static void dropSubtree (TreeTemplate< N > &tree, Node *subtree) throw (Exception)
 Remove a subtree defined by its root node and its parent node, while correcting for branch lengths. More...
 
template<class N >
static void sampleSubtree (TreeTemplate< N > &tree, const std::vector< std::string > &leaves, size_t size)
 Sample a subtree by removing leaves randomly. More...
 
template<class N >
static std::vector< N * > getNodes (N &node)
 Retrieve all son nodes from a subtree. More...
 
template<class N >
static void getNodes (N &node, std::vector< N * > &nodes)
 Retrieve all son nodes from a subtree. More...
 
static std::vector< int > getNodesId (const Node &node)
 Retrieve all nodes ids from a subtree. More...
 
static std::vector< int > getBranchesId (const Node &node)
 Retrieve all branches ids from a subtree. More...
 
static void getNodesId (const Node &node, std::vector< int > &ids)
 Retrieve all nodes ids from a subtree. More...
 
static void getBranchesId (const Node &node, std::vector< int > &ids)
 Retrieve all branches ids from a subtree. More...
 
template<class N >
static std::vector< N * > getInnerNodes (N &node)
 Retrieve all inner nodes from a subtree. More...
 
template<class N >
static void getInnerNodes (N &node, std::vector< N * > &nodes)
 Retrieve all inner nodes from a subtree. More...
 
static std::vector< int > getInnerNodesId (const Node &node)
 Retrieve all inner nodes ids from a subtree. More...
 
static void getInnerNodesId (const Node &node, std::vector< int > &ids)
 Retrieve all inner nodes ids from a subtree. More...
 
template<class N >
static std::vector< N * > searchNodeWithId (N &node, int id)
 
template<class N >
static void searchNodeWithId (N &node, int id, std::vector< N * > &nodes)
 
static NodesearchFirstNodeWithId (Node &node, int id)
 
static const NodesearchFirstNodeWithId (const Node &node, int id)
 
template<class N >
static bool hasNodeWithId (const N &node, int id)
 
template<class N >
static std::vector< N * > searchNodeWithName (N &node, const std::string &name)
 
template<class N >
static void searchNodeWithName (N &node, const std::string &name, std::vector< N * > &nodes)
 
template<class N >
static bool hasNodeWithName (const N &node, const std::string &name)
 
static bool isRoot (const Node &node)
 Tell if a particular node is the root of a tree i.e. if it has a father node. More...
 
static unsigned int getNumberOfLeaves (const Node &node)
 Get the number of leaves of a subtree defined by a particular node. More...
 
static unsigned int getNumberOfNodes (const Node &node)
 Get the number of nodes of a subtree defined by a particular node. More...
 
static std::vector< std::string > getLeavesNames (const Node &node)
 Get the leaves names of a subtree defined by a particular node. More...
 
static unsigned int getDepth (const Node &node)
 Get the depth of the subtree defined by node 'node', i.e. the maximum number of sons 'generations'. More...
 
static unsigned int getDepths (const Node &node, std::map< const Node *, unsigned int > &depths)
 Get the depths for all nodes of the subtree defined by node 'node', i.e. the maximum number of sons 'generations'. More...
 
static double getHeight (const Node &node)
 Get the height of the subtree defined by node 'node', i.e. the maximum distance between leaves and the root of the subtree. More...
 
static double getHeights (const Node &node, std::map< const Node *, double > &heights)
 Get the heights of all nodes within a subtree defined by node 'node', i.e. the maximum distance between leaves and the root of the subtree. More...
 
static bool isMultifurcating (const Node &node)
 Tell is a subtree is multifurcating. More...
 
static bool haveSameOrderedTopology (const Node &n1, const Node &n2)
 Tells if two subtrees have the same topology. More...
 
static std::vector< Node * > getPathBetweenAnyTwoNodes (Node &node1, Node &node2, bool includeAncestor=true, bool includeAncestorAtEndOfPath=true)
 
static std::vector< const Node * > getPathBetweenAnyTwoNodes (const Node &node1, const Node &node2, bool includeAncestor=true, bool includeAncestorAtEndOfPath=true)
 
template<class N >
static N * cloneSubtree (const Node &node)
 Recursively clone a subtree structure. More...
 
template<class N >
static void deleteSubtree (N *node)
 Recursively delete a subtree structure. More...
 
template<class N >
static N * cloneSubtree (const Tree &tree, int nodeId)
 
Conversion tools.

Convert from Newick standard tree description. The description is for a node, and hence is to be surrounded with parenthesis. ex: (A:0.001, (B:0.001, C:0.02)90:0.005)50:0.0005

static Element getElement (const std::string &elt) throw (IOException)
 
static NodeparenthesisToNode (const std::string &description, unsigned int &nodeCounter, bool bootstrap=true, const std::string &propertyName=TreeTools::BOOTSTRAP, bool withId=false, bool verbose=true)
 Parse a string in the parenthesis format and convert it to a subtree. More...
 
static TreeTemplate< Node > * parenthesisToTree (const std::string &description, bool bootstrap=true, const std::string &propertyName=TreeTools::BOOTSTRAP, bool withId=false, bool verbose=true) throw (Exception)
 Parse a string in the parenthesis format and convert it to a tree. More...
 
static std::string nodeToParenthesis (const Node &node, bool writeId=false)
 Get the parenthesis description of a subtree. More...
 
static std::string nodeToParenthesis (const Node &node, bool bootstrap, const std::string &propertyName)
 Get the parenthesis description of a subtree. More...
 
static std::string treeToParenthesis (const TreeTemplate< Node > &tree, bool writeId=false)
 Get the parenthesis description of a tree. More...
 
static std::string treeToParenthesis (const TreeTemplate< Node > &tree, bool bootstrap, const std::string &propertyName)
 Get the parenthesis description of a tree. More...
 
Random trees
static TreeTemplate< Node > * getRandomTree (std::vector< std::string > &leavesNames, bool rooted=true)
 Draw a random tree from a list of taxa, using a Yule process. More...
 
Retrieve properties from a (sub)tree.
static void getNodePropertyNames (const Node &node, std::vector< std::string > &propertyNames)
 Retrieve the names of all available node properties in the tree. More...
 
static void getNodeProperties (const Node &node, const std::string &propertyName, std::map< int, const Clonable * > &properties)
 Retrieve all node property objects with a given name over a (sub) tree (const version). More...
 
static void getNodeProperties (Node &node, const std::string &propertyName, std::map< int, Clonable * > &properties)
 Retrieve all node property objects with a given name over a (sub) tree. More...
 
static void getBranchPropertyNames (const Node &node, std::vector< std::string > &propertyNames)
 Retrieve the names of all available branch properties in the tree. More...
 
static void getBranchProperties (const Node &node, const std::string &propertyName, std::map< int, const Clonable * > &properties)
 Retrieve all branch property objects with a given name over a (sub) tree (const version). More...
 
static void getBranchProperties (Node &node, const std::string &propertyName, std::map< int, Clonable * > &properties)
 Retrieve all branch property objects with a given name over a (sub) tree. More...
 
static void orderTree (Node &node, bool downward=true, bool orderLeaves=false)
 Swap nodes in the subtree so that they are ordered according to the underlying number of leaves. More...
 

Static Public Attributes

static const short MIDROOT_VARIANCE = 0
 
static const short MIDROOT_SUM_OF_SQUARES = 1
 

Static Private Member Functions

static OrderTreeData_ orderTree_ (Node &node, bool downward, bool orderLeaves)
 
static Moments_ getSubtreeMoments_ (const Node *node)
 Computes the moment of a subtree. More...
 
static void getBestRootInSubtree_ (bpp::TreeTemplate< bpp::Node > &tree, short criterion, bpp::Node *node, std::pair< bpp::Node *, std::map< std::string, double > > &bestRoot)
 Find, in the branches of a subtree, the root that minimizes a criterion over the tree. More...
 

Act on branch lengths.

static Vdouble getBranchLengths (const Node &node) throw (NodePException)
 Get all the branch lengths of a subtree. More...
 
static double getTotalLength (const Node &node, bool includeAncestor=true) throw (NodePException)
 Get the total length (sum of all branch lengths) of a subtree. More...
 
static void setBranchLengths (Node &node, double brLen)
 Set all the branch lengths of a subtree. More...
 
static void deleteBranchLengths (Node &node)
 Remove all the branch lengths of a subtree. More...
 
static void setVoidBranchLengths (Node &node, double brLen)
 Give a length to branches that don't have one in a subtree. More...
 
static void scaleTree (Node &node, double factor) throw (NodePException)
 Scale a given tree. More...
 
static double getDistanceBetweenAnyTwoNodes (const Node &node1, const Node &node2)
 Get the total distance between to nodes. More...
 
static DistanceMatrixgetDistanceMatrix (const TreeTemplate< Node > &tree)
 Compute a distance matrix from a tree. More...
 
static void processDistsInSubtree_ (const Node *node, DistanceMatrix &matrix, std::vector< std::pair< std::string, double > > &distsToNodeFather)
 Inner function used by getDistanceMatrix. More...
 

Detailed Description

Utilitary methods working with TreeTemplate and Node objects.

See also
TreeTools for more generic methods.

Definition at line 62 of file TreeTemplateTools.h.

Constructor & Destructor Documentation

bpp::TreeTemplateTools::TreeTemplateTools ( )
inline

Definition at line 65 of file TreeTemplateTools.h.

virtual bpp::TreeTemplateTools::~TreeTemplateTools ( )
inlinevirtual

Definition at line 66 of file TreeTemplateTools.h.

Member Function Documentation

template<class N >
static N* bpp::TreeTemplateTools::cloneSubtree ( const Node node)
inlinestatic

Recursively clone a subtree structure.

This is a template function allowing to specify the class of the copy. The template class has to have a constructor accepting const Node& as single argument.

Parameters
nodeThe basal node of the subtree.
Returns
The basal node of the new copy.

Definition at line 756 of file TreeTemplateTools.h.

References bpp::Node::getNumberOfSons().

void TreeTemplateTools::deleteBranchLengths ( Node node)
static

Remove all the branch lengths of a subtree.

Parameters
nodeThe root node of the subtree.

Definition at line 550 of file TreeTemplateTools.cpp.

References bpp::Node::deleteDistanceToFather(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().

Referenced by cloneSubtree(), and bpp::AbstractTreeParsimonyScore::init_().

template<class N >
static void bpp::TreeTemplateTools::deleteSubtree ( N *  node)
inlinestatic

Recursively delete a subtree structure.

Parameters
nodeThe basal node of the subtree.

Definition at line 777 of file TreeTemplateTools.h.

Referenced by dropSubtree(), bpp::TreeTemplate< bpp::NodeTemplate >::operator=(), and bpp::TreeTemplate< bpp::NodeTemplate >::~TreeTemplate().

template<class N >
static void bpp::TreeTemplateTools::dropLeaf ( TreeTemplate< N > &  tree,
const std::string &  leafName 
)
throw (NodeNotFoundException,
Exception
)
inlinestatic

Remove a leaf node and its parent node, while correcting for branch lengths.

Parameters
treeThe tree to edit.
leafNameThe name of the leaf node.
Exceptions
NodeNotFoundExceptionIf the node is not found.

Definition at line 210 of file TreeTemplateTools.h.

Referenced by sampleSubtree().

template<class N >
static void bpp::TreeTemplateTools::dropSubtree ( TreeTemplate< N > &  tree,
Node subtree 
)
throw (Exception
)
inlinestatic

Remove a subtree defined by its root node and its parent node, while correcting for branch lengths.

Parameters
treeThe tree to edit.
subtreeThe subtree to remove, defined by its root node.
Exceptions
ExceptionIf something unexpected happens :s

Definition at line 267 of file TreeTemplateTools.h.

References deleteSubtree().

static std::vector<int> bpp::TreeTemplateTools::getAncestorsId ( const Node node)
inlinestatic

Retrieve all nodes ids that are ancestors of a node.

Parameters
nodeThe node
Returns
A vector of ids.

Definition at line 145 of file TreeTemplateTools.h.

References bpp::Node::getFather(), bpp::Node::getId(), and bpp::Node::hasFather().

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getAncestorsId().

void TreeTemplateTools::getBestRootInSubtree_ ( bpp::TreeTemplate< bpp::Node > &  tree,
short  criterion,
bpp::Node node,
std::pair< bpp::Node *, std::map< std::string, double > > &  bestRoot 
)
staticprivate

Find, in the branches of a subtree, the root that minimizes a criterion over the tree.

The branches are explored recursively. For each branch leaving the input node, the method computes the best root position, possibly updates the bestRoot parameter, then recurses.

Parameters
treeThe tree to which the subtree belongs. (The root is moved.)
criterionThe criterion to minimize. Legal values are TreeTemplateTools::MIDROOT_VARIANCE and TreeTemplateTools::MIDROOT_SUM_OF_SQUARES.
nodeThe root of the subtree.
bestRootThe object storing the best root found, if it is better than the initial one, or otherwise left unchanged.
Author
Nicolas Rochette, Manolo Gouy

Definition at line 1181 of file TreeTemplateTools.cpp.

References bpp::Node::getSons(), bpp::TreeTemplateTools::Moments_::numberOfLeaves, bpp::TreeTemplate< N >::rootAt(), bpp::TreeTemplateTools::Moments_::squaresSum, and bpp::TreeTemplateTools::Moments_::sum.

static std::vector<int> bpp::TreeTemplateTools::getBranchesId ( const Node node)
inlinestatic

Retrieve all branches ids from a subtree.

Parameters
nodeThe node that defines the subtree.
Returns
A vector of ids.

Definition at line 382 of file TreeTemplateTools.h.

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getBranchesId().

static void bpp::TreeTemplateTools::getBranchesId ( const Node node,
std::vector< int > &  ids 
)
inlinestatic

Retrieve all branches ids from a subtree.

Parameters
nodeThe node that defines the subtree.
idsA vector of ids.

Definition at line 410 of file TreeTemplateTools.h.

References getNodesId(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().

Vdouble TreeTemplateTools::getBranchLengths ( const Node node)
throw (NodePException
)
static

Get all the branch lengths of a subtree.

Parameters
nodeThe root node of the subtree.
Returns
A vector with all branch lengths.
Exceptions
NodePExceptionIf a branch length is lacking.

Definition at line 508 of file TreeTemplateTools.cpp.

Referenced by cloneSubtree(), and bpp::TreeTemplate< bpp::NodeTemplate >::getBranchLengths().

void TreeTemplateTools::getBranchProperties ( const Node node,
const std::string &  propertyName,
std::map< int, const Clonable * > &  properties 
)
static

Retrieve all branch property objects with a given name over a (sub) tree (const version).

Parameters
node[in] The root node of the (sub)tree to use.
propertyName[in] The name of the property to retrieve.
properties[out] A map with pointers toward the properties as values, and node ids as key. If a node does not contain the given property, then no entry in the map is created. If an entry already exists in the map, it will be replaced, but the underlying property will not be destroyed. Property objects are not cloned when added to the map, but passed as pointers.

Definition at line 916 of file TreeTemplateTools.cpp.

References bpp::Node::getBranchProperty(), bpp::Node::getId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::hasBranchProperty().

Referenced by bpp::TreeTemplateTools::Element::Element().

void TreeTemplateTools::getBranchProperties ( Node node,
const std::string &  propertyName,
std::map< int, Clonable * > &  properties 
)
static

Retrieve all branch property objects with a given name over a (sub) tree.

Parameters
node[in] The root node of the (sub)tree to use.
propertyName[in] The name of the property to retrieve.
properties[out] A map with pointers toward the properties as values, and node ids as key. If a node does not contain the given property, then no entry in the map is created. If an entry already exists in the map, it will be replaced, but the underlying property will not be destroyed. Property objects are not cloned when added to the map, but passed as pointers.

Definition at line 926 of file TreeTemplateTools.cpp.

References bpp::Node::getBranchProperty(), bpp::Node::getId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::hasBranchProperty().

void TreeTemplateTools::getBranchPropertyNames ( const Node node,
std::vector< std::string > &  propertyNames 
)
static

Retrieve the names of all available branch properties in the tree.

Parameters
node[in] The root node of the (sub)tree to use.
propertyNames[out] a vector where names will be added.

Definition at line 907 of file TreeTemplateTools.cpp.

References bpp::VectorTools::extend(), bpp::Node::getBranchPropertyNames(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().

Referenced by bpp::TreeTemplateTools::Element::Element().

unsigned int TreeTemplateTools::getDepth ( const Node node)
static

Get the depth of the subtree defined by node 'node', i.e. the maximum number of sons 'generations'.

ex:

*    +----------A
*    |
* ---+ N1     +-------B
*    |        |
*    +--------+ N2
*             |
*             +------C
* 

Depth of node 'N1' id 2, depth of node 'N2' is 1, depth of leaves is 0.

Parameters
nodeThe node defining the subtree to check.
Returns
The depth of the subtree.

Definition at line 128 of file TreeTemplateTools.cpp.

References bpp::Node::getNumberOfSons().

Referenced by isRoot(), bpp::CladogramPlot::recursivePlot_(), bpp::CladogramPlot::setTree(), and bpp::CladogramPlot::treeHasChanged().

unsigned int TreeTemplateTools::getDepths ( const Node node,
std::map< const Node *, unsigned int > &  depths 
)
static

Get the depths for all nodes of the subtree defined by node 'node', i.e. the maximum number of sons 'generations'.

ex:

*    +----------A
*    |
* ---+ N1     +-------B
*    |        |
*    +--------+ N2
*             |
*             +------C
* 

Depth of node 'N1' id 2, depth of node 'N2' is 1, depth of leaves is 0.

Parameters
nodeThe node defining the subtree to check.
depthsThe map that will contain all the depths of the nodes, with node pointers as keys.
Returns
The depth of the subtree.

Definition at line 142 of file TreeTemplateTools.cpp.

References bpp::Node::getNumberOfSons().

Referenced by isRoot().

double TreeTemplateTools::getDistanceBetweenAnyTwoNodes ( const Node node1,
const Node node2 
)
static

Get the total distance between to nodes.

Sum all branch lengths between two nodes.

Parameters
node1The first node.
node2The second node.
Returns
The sum of all branch lengths between the two nodes.

Definition at line 752 of file TreeTemplateTools.cpp.

Referenced by cloneSubtree().

DistanceMatrix * TreeTemplateTools::getDistanceMatrix ( const TreeTemplate< Node > &  tree)
static

Compute a distance matrix from a tree.

Compute all distances between each leaves and store them in a matrix. A new DistanceMatrix object is created, and a pointer toward it is returned. The destruction of this matrix is left up to the user.

From version 1.9 of Bio++, this function has been rewritten in a more efficient way and does not use getDistanceBetweenAnyTwoNodes anymore, but makes use of a more clever pass on the tree. The new function now works well on trees with thousands of leaves.

See also
getDistanceBetweenAnyTwoNodes
Author
Nicolas Rochette
Parameters
treeThe tree to use.
Returns
The distance matrix computed from tree.

Definition at line 840 of file TreeTemplateTools.cpp.

References bpp::TreeTemplate< N >::getLeavesNames(), and bpp::TreeTemplate< N >::getRootNode().

Referenced by cloneSubtree().

double TreeTemplateTools::getHeight ( const Node node)
static

Get the height of the subtree defined by node 'node', i.e. the maximum distance between leaves and the root of the subtree.

The distance do not include the branch length of the subtree root node. The height of a leaf is hence 0.

Parameters
nodeThe node defining the subtree to check.
Returns
The height of the subtree.
Exceptions
NodePExceptionIf a branch length is lacking.

Definition at line 157 of file TreeTemplateTools.cpp.

References bpp::Node::getDistanceToFather(), and bpp::Node::getNumberOfSons().

Referenced by isRoot(), and bpp::PhylogramPlot::treeHasChanged().

double TreeTemplateTools::getHeights ( const Node node,
std::map< const Node *, double > &  heights 
)
static

Get the heights of all nodes within a subtree defined by node 'node', i.e. the maximum distance between leaves and the root of the subtree.

The height of a leaf is 0.

Parameters
nodeThe node defining the subtree to check.
heightsThe map that will contain all the heights of the nodes, with node pointers as keys.
Returns
The height of the subtree.
Exceptions
NodePExceptionIf a branch length is lacking.

Definition at line 173 of file TreeTemplateTools.cpp.

References bpp::Node::getDistanceToFather(), and bpp::Node::getNumberOfSons().

Referenced by bpp::GlobalClockTreeLikelihoodFunctionWrapper::initParameters_(), and isRoot().

template<class N >
static std::vector<N*> bpp::TreeTemplateTools::getInnerNodes ( N &  node)
inlinestatic

Retrieve all inner nodes from a subtree.

Parameters
nodeThe node that defines the subtree.
Returns
A vector of pointers toward each inner node in the subtree.

Definition at line 425 of file TreeTemplateTools.h.

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getInnerNodes().

template<class N >
static void bpp::TreeTemplateTools::getInnerNodes ( N &  node,
std::vector< N * > &  nodes 
)
inlinestatic

Retrieve all inner nodes from a subtree.

A inner node is a node with degree > 1, that is, all nodes but the leaves, be they terminal or not.

Parameters
nodeThe node that defines the subtree.
nodesA vector to be filled with pointers toward each inner node in the subtree.

Definition at line 441 of file TreeTemplateTools.h.

static std::vector<int> bpp::TreeTemplateTools::getInnerNodesId ( const Node node)
inlinestatic

Retrieve all inner nodes ids from a subtree.

A inner node is a node with degree > 1, that is, all nodes but the leaves, be they terminal or not.

Parameters
nodeThe node that defines the subtree.
Returns
A vector of ids.

Definition at line 459 of file TreeTemplateTools.h.

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getInnerNodesId(), and getInnerNodesId().

static void bpp::TreeTemplateTools::getInnerNodesId ( const Node node,
std::vector< int > &  ids 
)
inlinestatic

Retrieve all inner nodes ids from a subtree.

Parameters
nodeThe node that defines the subtree.
idsA vector to be filled with the resulting ids.

Definition at line 472 of file TreeTemplateTools.h.

References bpp::Node::getId(), getInnerNodesId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::isLeaf().

static int bpp::TreeTemplateTools::getLeafId ( const Node node,
const std::string &  name 
)
throw (NodeNotFoundException
)
inlinestatic

Get the id of a leaf given its name in a subtree.

Parameters
nodeThe node defining the subtree to search.
nameThe name of the node.
Returns
The id of the node.
Exceptions
NodeNotFoundExceptionIf the node is not found.

Definition at line 165 of file TreeTemplateTools.h.

References searchLeaf().

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getLeafId().

template<class N >
static std::vector<N*> bpp::TreeTemplateTools::getLeaves ( N &  node)
inlinestatic

Retrieve all leaves from a subtree.

Parameters
nodeThe node that defines the subtree.
Returns
A vector of pointers toward each leaf in the subtree.

Definition at line 82 of file TreeTemplateTools.h.

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getLeaves(), and bpp::PatternTools::getSequenceSubset().

template<class N >
static void bpp::TreeTemplateTools::getLeaves ( N &  node,
std::vector< N * > &  leaves 
)
inlinestatic

Retrieve all leaves from a subtree.

Parameters
nodeThe node that defines the subtree.
leavesA vector of pointers toward each leaf in the subtree.

Definition at line 96 of file TreeTemplateTools.h.

static std::vector<int> bpp::TreeTemplateTools::getLeavesId ( const Node node)
inlinestatic

Retrieve all leaves ids from a subtree.

Parameters
nodeThe node that defines the subtree.
Returns
A vector of ids.

Definition at line 114 of file TreeTemplateTools.h.

Referenced by getLeavesId(), and bpp::TreeTemplate< bpp::NodeTemplate >::getLeavesId().

static void bpp::TreeTemplateTools::getLeavesId ( const Node node,
std::vector< int > &  ids 
)
inlinestatic

Retrieve all leaves ids from a subtree.

Parameters
nodeThe node that defines the subtree.
idsA vector of ids.

Definition at line 127 of file TreeTemplateTools.h.

References bpp::Node::getId(), getLeavesId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::isLeaf().

vector< string > TreeTemplateTools::getLeavesNames ( const Node node)
static

Get the leaves names of a subtree defined by a particular node.

Parameters
nodeThe node defining the subtree to check.
Returns
The list of all leaves names.

Definition at line 108 of file TreeTemplateTools.cpp.

References bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::isLeaf().

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getLeavesNames(), and isRoot().

void TreeTemplateTools::getNodeProperties ( const Node node,
const std::string &  propertyName,
std::map< int, const Clonable * > &  properties 
)
static

Retrieve all node property objects with a given name over a (sub) tree (const version).

Parameters
node[in] The root node of the (sub)tree to use.
propertyName[in] The name of the property to retrieve.
properties[out] A map with pointers toward the properties as values, and node ids as key. If a node does not contain the given property, then no entry in the map is created. If an entry already exists in the map, it will be replaced, but the underlying property will not be destroyed. Property objects are not cloned when added to the map, but passed as pointers.

Definition at line 885 of file TreeTemplateTools.cpp.

References bpp::Node::getId(), bpp::Node::getNodeProperty(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::hasNodeProperty().

Referenced by bpp::TreeTemplateTools::Element::Element().

void TreeTemplateTools::getNodeProperties ( Node node,
const std::string &  propertyName,
std::map< int, Clonable * > &  properties 
)
static

Retrieve all node property objects with a given name over a (sub) tree.

Parameters
node[in] The root node of the (sub)tree to use.
propertyName[in] The name of the property to retrieve.
properties[out] A map with pointers toward the properties as values, and node ids as key. If a node does not contain the given property, then no entry in the map is created. If an entry already exists in the map, it will be replaced, but the underlying property will not be destroyed. Property objects are not cloned when added to the map, but passed as pointers.

Definition at line 895 of file TreeTemplateTools.cpp.

References bpp::Node::getId(), bpp::Node::getNodeProperty(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::hasNodeProperty().

void TreeTemplateTools::getNodePropertyNames ( const Node node,
std::vector< std::string > &  propertyNames 
)
static

Retrieve the names of all available node properties in the tree.

Parameters
node[in] The root node of the (sub)tree to use.
propertyNames[out] a vector where names will be added.

Definition at line 876 of file TreeTemplateTools.cpp.

References bpp::VectorTools::extend(), bpp::Node::getNodePropertyNames(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().

Referenced by bpp::TreeTemplateTools::Element::Element().

template<class N >
static std::vector<N*> bpp::TreeTemplateTools::getNodes ( N &  node)
inlinestatic

Retrieve all son nodes from a subtree.

Parameters
nodeThe node that defines the subtree.
Returns
A vector of pointers toward each son node in the subtree.

Definition at line 340 of file TreeTemplateTools.h.

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getNodes().

template<class N >
static void bpp::TreeTemplateTools::getNodes ( N &  node,
std::vector< N * > &  nodes 
)
inlinestatic

Retrieve all son nodes from a subtree.

Parameters
nodeThe node that defines the subtree.
nodesA vector of pointers toward each son node in the subtree.

Definition at line 354 of file TreeTemplateTools.h.

static std::vector<int> bpp::TreeTemplateTools::getNodesId ( const Node node)
inlinestatic

Retrieve all nodes ids from a subtree.

Parameters
nodeThe node that defines the subtree.
Returns
A vector of ids.

Definition at line 369 of file TreeTemplateTools.h.

Referenced by getBranchesId(), bpp::TreeTemplate< bpp::NodeTemplate >::getNodesId(), and getNodesId().

static void bpp::TreeTemplateTools::getNodesId ( const Node node,
std::vector< int > &  ids 
)
inlinestatic

Retrieve all nodes ids from a subtree.

Parameters
nodeThe node that defines the subtree.
idsA vector of ids.

Definition at line 395 of file TreeTemplateTools.h.

References bpp::Node::getId(), getNodesId(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().

unsigned int TreeTemplateTools::getNumberOfLeaves ( const Node node)
static

Get the number of leaves of a subtree defined by a particular node.

Parameters
nodeThe node defining the subtree to check.
Returns
The number of leaves.

Definition at line 80 of file TreeTemplateTools.cpp.

References bpp::Node::getNumberOfSons(), and bpp::Node::isLeaf().

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getNumberOfLeaves(), and isRoot().

unsigned int TreeTemplateTools::getNumberOfNodes ( const Node node)
static

Get the number of nodes of a subtree defined by a particular node.

Parameters
nodeThe node defining the subtree to check.
Returns
The number of nodes.

Definition at line 96 of file TreeTemplateTools.cpp.

References bpp::Node::getNumberOfSons().

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getNumberOfNodes(), and isRoot().

vector< Node * > TreeTemplateTools::getPathBetweenAnyTwoNodes ( Node node1,
Node node2,
bool  includeAncestor = true,
bool  includeAncestorAtEndOfPath = true 
)
static
vector< const Node * > TreeTemplateTools::getPathBetweenAnyTwoNodes ( const Node node1,
const Node node2,
bool  includeAncestor = true,
bool  includeAncestorAtEndOfPath = true 
)
static

Definition at line 690 of file TreeTemplateTools.cpp.

References bpp::Node::getFather(), and bpp::Node::hasFather().

double TreeTemplateTools::getRadius ( TreeTemplate< Node > &  tree)
static

Get the caracteristic radius of a tree (average distance to the root minimizing the sum of squared distances).

Parameters
treeThe tree (which is rerooted in the process).

Definition at line 1137 of file TreeTemplateTools.cpp.

References bpp::TreeTemplate< N >::getRootNode(), midRoot(), bpp::TreeTemplateTools::Moments_::numberOfLeaves, and bpp::TreeTemplateTools::Moments_::sum.

Referenced by orderTree().

TreeTemplate< Node > * TreeTemplateTools::getRandomTree ( std::vector< std::string > &  leavesNames,
bool  rooted = true 
)
static

Draw a random tree from a list of taxa, using a Yule process.

Parameters
leavesNamesA list of taxa.
rootedTell is the output tree should be rooted.
Returns
A random tree with all corresponding taxa.

Definition at line 587 of file TreeTemplateTools.cpp.

References bpp::Node::addSon(), and bpp::TreeTemplate< N >::resetNodesId().

Referenced by bpp::TreeTemplateTools::Element::Element().

std::vector< const Node * > TreeTemplateTools::getRemainingNeighbors ( const Node node1,
const Node node2,
const Node node3 
)
static

Get a subset of node neighbors.

Get all neighbors of node node1 that are neither node1 nor node2. This method is useful for topology manipulations, like NNI.

Parameters
node1The node whose neighbors must be retrieved.
node2One neighbor to exclude.
node3Another neighbor to exclude.
Returns
A vector of neighbors.

Definition at line 850 of file TreeTemplateTools.cpp.

References bpp::Node::getNeighbors().

Referenced by bpp::TreeTemplateTools::Element::Element(), bpp::DRTreeParsimonyScore::testNNI(), and bpp::NNIHomogeneousTreeLikelihood::testNNI().

TreeTemplateTools::Moments_ TreeTemplateTools::getSubtreeMoments_ ( const Node node)
staticprivate
double TreeTemplateTools::getTotalLength ( const Node node,
bool  includeAncestor = true 
)
throw (NodePException
)
static

Get the total length (sum of all branch lengths) of a subtree.

Parameters
nodeThe root node of the subtree.
includeAncestorTell if the branch length of the most ancient node should be included in the counting. (this should be set to false if this node is the root of the tree for instance).
Returns
The total length of the subtree.
Exceptions
NodePExceptionIf a branch length is lacking.

Definition at line 525 of file TreeTemplateTools.cpp.

Referenced by cloneSubtree(), and bpp::TreeTemplate< bpp::NodeTemplate >::getTotalLength().

template<class N >
static bool bpp::TreeTemplateTools::hasNodeWithId ( const N &  node,
int  id 
)
inlinestatic
Parameters
nodeThe node defining the subtree to be searched.
idThe id to search for.
Returns
True if the subtree contains a node with the specified id.

Definition at line 558 of file TreeTemplateTools.h.

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::hasNode().

template<class N >
static bool bpp::TreeTemplateTools::hasNodeWithName ( const N &  node,
const std::string &  name 
)
inlinestatic
Parameters
nodeThe node defining the subtree to be searched.
nameThe name to search for.
Returns
True if the subtree contains a node with the specified name.

Definition at line 605 of file TreeTemplateTools.h.

bool TreeTemplateTools::haveSameOrderedTopology ( const Node n1,
const Node n2 
)
static

Tells if two subtrees have the same topology.

The comparison is based on parental relationships and leaf names only, node ids and all branch/node properties are ignored. The ordering of son nodes is taken into account so that ((A,B),C) will be considered different from ((B,A),C). Considerer ordering the trees first if you want to perform a strict topological comparison.

Parameters
n1Root node of the first subtree.
n2Root node of the second subtree.
Returns
true if the two subtrees have the same topology.

Definition at line 938 of file TreeTemplateTools.cpp.

References bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::isLeaf().

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::hasSameTopologyAs(), and isRoot().

void TreeTemplateTools::incrementAllIds ( Node node,
int  increment 
)
static

This method will add a given value (possibly negative) to all identifiers in a (sub)tree.

Parameters
nodeThe root node of the (sub)tree to use.
incrementThe value to add.

Definition at line 865 of file TreeTemplateTools.cpp.

References bpp::Node::getId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::setId().

Referenced by bpp::TreeTemplateTools::Element::Element().

bool TreeTemplateTools::isMultifurcating ( const Node node)
static

Tell is a subtree is multifurcating.

Parameters
nodeThe root node of the subtree.
Returns
True is the subtree contains at least one multifurcating node (including the root node).

Definition at line 63 of file TreeTemplateTools.cpp.

References bpp::Node::getNumberOfSons(), and bpp::Node::getSon().

Referenced by bpp::GlobalClockTreeLikelihoodFunctionWrapper::initParameters_(), bpp::TreeTemplate< bpp::NodeTemplate >::isMultifurcating(), and isRoot().

static bool bpp::TreeTemplateTools::isRoot ( const Node node)
inlinestatic

Tell if a particular node is the root of a tree i.e. if it has a father node.

Parameters
nodeThe node to check.
Returns
True if node does not have a father.

Definition at line 625 of file TreeTemplateTools.h.

References getDepth(), getDepths(), getHeight(), getHeights(), getLeavesNames(), getNumberOfLeaves(), getNumberOfNodes(), getPathBetweenAnyTwoNodes(), bpp::Node::hasFather(), haveSameOrderedTopology(), and isMultifurcating().

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::isRoot().

void TreeTemplateTools::midRoot ( TreeTemplate< Node > &  tree,
short  criterion,
bool  forceBranchRoot 
)
static

Midroot the tree by minimizing a given criterion ("variance" or "sum of squares")

For each branch, the best root position, according to the given criterion, is computed analytically.

For the 'variance' criterion :

\[ (n_1+n_2)^2 V(x) = (n_1+n_2) \left[ \sum_{F_1} (d_i + x \delta )^2 + \sum_{F_2} (d_i + (1-x) \delta )^2 \right] - \left[ \sum_{F_1} (d_i + x \delta) + \sum_{F_2} (d_i + (1-x) \delta) \right]^2 = A x^2 + B x + C \]

With

\[ \begin{array}{rcl} A &=& 4 n_1 n_2 \delta^2 \\ B &=& 4 \delta ( n_2 S_1 - n_1 S_2 - n_1 n_2 \delta ) \\ C &=& (n_1+n_2) (C_1+C_2) + n_1 n_2 \delta^2 + 2 n_1 S_2 \delta - 2 n_2 S_1 \delta - (S_1+S_2)^2 \\ \end{array} \]

Where $F_1$ and $F_2$ are the sets of leaves on either side of the root branch, $d_i$ is the distance of leaf $i$ to the nearest end of the root branch, $\delta$ is the length of the root branch, and $S_k$ and $C_k$ are respectively $\sum_{F_k} d_i$ and $\sum_{F_k} d_i^2$

~

If force_branch_root==true, then the function will always root the tree on a branch. To do so, in cases where the root is placed on a node, a new node new_root is created between the root and its nearest child. If force_branch_root==false, it may be placed on a node.

Parameters
tree
criterionThe criterion upon which to reroot. Legal values : TreeTemplateTools::MIDROOT_VARIANCE to minimize root-leaf distance variance (molecular clock assumption) or TreeTemplateTools::MIDROOT_SUM_OF_SQUARES to minimize the sum of root-leaf distance squares.
forceBranchRootIf true, the root must be placed on a branch, otherwise it may also be placed on a node.
Author
Nicolas Rochette

Definition at line 1049 of file TreeTemplateTools.cpp.

References bpp::Node::addSon(), bpp::Node::getBranchProperty(), bpp::Node::getBranchPropertyNames(), bpp::Node::getDistanceToFather(), bpp::Node::getFather(), bpp::TreeTools::getMPNUId(), bpp::TreeTemplate< N >::getRootId(), bpp::TreeTemplate< N >::getRootNode(), bpp::Node::getSons(), bpp::TreeTemplate< N >::isRooted(), bpp::Node::removeSon(), bpp::TreeTemplate< N >::rootAt(), bpp::Node::setBranchProperty(), bpp::Node::setDistanceToFather(), bpp::Node::setId(), bpp::TextTools::toString(), and bpp::TreeTemplate< N >::unroot().

Referenced by getRadius(), and orderTree().

string TreeTemplateTools::nodeToParenthesis ( const Node node,
bool  writeId = false 
)
static

Get the parenthesis description of a subtree.

Parameters
nodeThe node defining the subtree.
writeIdTells if node ids must be printed. This will overwrite bootstrap values if there are ones. Leaves id will be added to the leave names, separated by a '_' character.
Returns
A string in the parenthesis format.

Definition at line 358 of file TreeTemplateTools.cpp.

References bpp::TreeTools::BOOTSTRAP, bpp::Node::getBranchProperty(), bpp::Node::getDistanceToFather(), bpp::Node::getId(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::hasBranchProperty(), bpp::Node::hasDistanceToFather(), and bpp::Node::isLeaf().

Referenced by bpp::TreeTemplateTools::Element::Element().

string TreeTemplateTools::nodeToParenthesis ( const Node node,
bool  bootstrap,
const std::string &  propertyName 
)
static

Get the parenthesis description of a subtree.

Parameters
nodeThe node defining the subtree.
bootstrapTell is bootstrap values must be writen. If so, the content of the property with name TreeTools::BOOTSTRAP will be written as bootstrap value. The property should be a Number<double> object. Otherwise, the content of the property with name 'propertyName' will be written. In this later case, the property should be a String object.
propertyNameThe name of the property to use. Only used if bootstrap = false.
Returns
A string in the parenthesis format.

Definition at line 393 of file TreeTemplateTools.cpp.

References bpp::TreeTools::BOOTSTRAP, bpp::Node::getBranchProperty(), bpp::Node::getDistanceToFather(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::hasBranchProperty(), bpp::Node::hasDistanceToFather(), and bpp::Node::isLeaf().

static void bpp::TreeTemplateTools::orderTree ( Node node,
bool  downward = true,
bool  orderLeaves = false 
)
inlinestatic

Swap nodes in the subtree so that they are ordered according to the underlying number of leaves.

Parameters
nodeThe root node of the (sub)tree to use.
downwardIf yes, biggest subtrees (in terms of number of leaves) will come first. Otherwise, the smallest subtrees will come first.
orderLeavesTell if leaves have to be ordered alphabetically. This ensures that two identical topology will always have the same ordered tree, whatever the initial ordering of nodes.

Definition at line 1151 of file TreeTemplateTools.h.

References bpp::TreeTools::BOOTSTRAP, getRadius(), midRoot(), orderTree_(), and unresolveUncertainNodes().

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::hasSameTopologyAs().

Node * TreeTemplateTools::parenthesisToNode ( const std::string &  description,
unsigned int &  nodeCounter,
bool  bootstrap = true,
const std::string &  propertyName = TreeTools::BOOTSTRAP,
bool  withId = false,
bool  verbose = true 
)
static

Parse a string in the parenthesis format and convert it to a subtree.

Parameters
descriptionthe string to parse;
nodeCounter[Output] Count all created nodes.
bootstrapTell is real bootstrap values are expected. If so, a property with name TreeTools::BOOTSTRAP will be created and stored at the corresponding node. The property value will be of type Number<double>. Otherwise, an object of type String will be created and stored with the property name propertyName.
propertyNameThe name of the property to store. Only used if bootstrap = false.
withIdTells if node ids have been stored in the tree. If set at "true", no bootstrap or property values can be read. Node ids are positioned as bootstrap values for internal nodes, and are concatenated to leaf names after a "_" sign.
verboseTell if some information should be displayed, like progress bars for large trees.
Returns
A pointer toward a dynamically created subtree.

Definition at line 254 of file TreeTemplateTools.cpp.

References bpp::Node::addSon(), bpp::TreeTools::BOOTSTRAP, bpp::TreeTemplateTools::Element::bootstrap, bpp::TreeTemplateTools::Element::content, bpp::ApplicationTools::displayUnlimitedGauge(), bpp::StringTokenizer::getToken(), bpp::NestedStringTokenizer::hasMoreToken(), bpp::TextTools::isEmpty(), bpp::TreeTemplateTools::Element::isLeaf, bpp::TreeTemplateTools::Element::length, bpp::NestedStringTokenizer::nextToken(), bpp::StringTokenizer::numberOfRemainingTokens(), bpp::TextTools::removeSurroundingWhiteSpaces(), bpp::Node::setBranchProperty(), bpp::Node::setDistanceToFather(), bpp::Node::setId(), bpp::Node::setName(), bpp::TextTools::toDouble(), and bpp::TextTools::toInt().

Referenced by bpp::TreeTemplateTools::Element::Element().

TreeTemplate< Node > * TreeTemplateTools::parenthesisToTree ( const std::string &  description,
bool  bootstrap = true,
const std::string &  propertyName = TreeTools::BOOTSTRAP,
bool  withId = false,
bool  verbose = true 
)
throw (Exception
)
static

Parse a string in the parenthesis format and convert it to a tree.

Parameters
descriptionthe string to parse;
bootstrapTells if real bootstrap values are expected. If so, a property with name TreeTools::BOOTSTRAP will be created and stored at the corresponding node. The property value will be of type Number<double>. Otherwise, an object of type String will be created and stored with the property name propertyName.
propertyNameThe name of the property to store. Only used if bootstrap = false.
withIdTells if node ids have been stored in the tree. If set at "true", no bootstrap or property values can be read. Node ids are positioned as bootstrap values for internal nodes, and are concatenated to leaf names after a "_" sign.
verboseTell if some information should be displayed, like progress bars for large trees.
Returns
A pointer toward a dynamically created tree.
Exceptions
Exceptionin case of bad format.

Definition at line 335 of file TreeTemplateTools.cpp.

References bpp::OutputStream::endLine(), bpp::ApplicationTools::message, bpp::TreeTemplate< N >::resetNodesId(), and bpp::TreeTemplate< N >::setRootNode().

Referenced by bpp::TreeTemplateTools::Element::Element(), bpp::NexusIOTree::read(), and bpp::Newick::read().

void TreeTemplateTools::processDistsInSubtree_ ( const Node node,
DistanceMatrix matrix,
std::vector< std::pair< std::string, double > > &  distsToNodeFather 
)
staticprivate

Inner function used by getDistanceMatrix.

(1) Retrieves leaf-leaf distances in node's subtree and writes them in the distance matrix. (2) Returns distances from node's father to those leaves.

Parameters
nodeThe current node in the recursion.
matrixThe output matrix which will be filled.
distsToNodeFatherIntermediate computations contianing the distances of the node to the leaves.

Definition at line 765 of file TreeTemplateTools.cpp.

References bpp::Node::getDistanceToFather(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), bpp::Node::hasFather(), and bpp::Node::isLeaf().

Referenced by cloneSubtree().

template<class N >
static void bpp::TreeTemplateTools::sampleSubtree ( TreeTemplate< N > &  tree,
const std::vector< std::string > &  leaves,
size_t  size 
)
inlinestatic

Sample a subtree by removing leaves randomly.

Parameters
treeThe tree to edit.
leavesThe leafs names that should be sampled. They must be found in the tree otherwise an exception will be thrown.
sizeThe number of leaves in the final sample. If greater or equal to the number of leaf names, the function returns without doing anything.

Definition at line 322 of file TreeTemplateTools.h.

References dropLeaf(), and bpp::RandomTools::giveIntRandomNumberBetweenZeroAndEntry().

void TreeTemplateTools::scaleTree ( Node node,
double  factor 
)
throw (NodePException
)
static

Scale a given tree.

Multiply all branch lengths by a given factor.

Parameters
nodeThe root node of the subtree to scale.
factorThe factor to multiply all branch lengths with.
Exceptions
NodePExceptionIf a branch length is lacking.

Definition at line 573 of file TreeTemplateTools.cpp.

Referenced by cloneSubtree(), and bpp::TreeTemplate< bpp::NodeTemplate >::scaleTree().

static Node* bpp::TreeTemplateTools::searchFirstNodeWithId ( Node node,
int  id 
)
inlinestatic
Parameters
nodeThe node defining the subtree to be searched.
idThe id to search for.
Returns
The first node encountered with the given id, or 0 if no node with the given id is found.

Definition at line 515 of file TreeTemplateTools.h.

References bpp::Node::getId(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getNode(), and searchFirstNodeWithId().

static const Node* bpp::TreeTemplateTools::searchFirstNodeWithId ( const Node node,
int  id 
)
inlinestatic
Parameters
nodeThe node defining the subtree to be searched.
idThe id to search for.
Returns
The first node encountered with the given id, or 0 if no node with the given id is found.

Definition at line 536 of file TreeTemplateTools.h.

References bpp::Node::getId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and searchFirstNodeWithId().

static void bpp::TreeTemplateTools::searchLeaf ( const Node node,
const std::string &  name,
int *&  id 
)
throw (NodeNotFoundException
)
inlinestatic

Get the id of a leaf given its name in a subtree.

Parameters
nodeThe node defining the subtree to search.
nameThe name of the node.
idThe id of the node.
Exceptions
NodeNotFoundExceptionIf the node is not found.

Definition at line 186 of file TreeTemplateTools.h.

Referenced by getLeafId().

template<class N >
static std::vector<N*> bpp::TreeTemplateTools::searchNodeWithId ( N &  node,
int  id 
)
inlinestatic
Parameters
nodeThe node defining the subtree to be searched.
idThe id to search for.
Returns
Nodes with the specified id.

Definition at line 488 of file TreeTemplateTools.h.

template<class N >
static void bpp::TreeTemplateTools::searchNodeWithId ( N &  node,
int  id,
std::vector< N * > &  nodes 
)
inlinestatic
Parameters
nodeThe node defining the subtree to be searched.
idThe id to search for.
nodesA vector to be filled with the matching nodes.

Definition at line 501 of file TreeTemplateTools.h.

template<class N >
static std::vector<N*> bpp::TreeTemplateTools::searchNodeWithName ( N &  node,
const std::string &  name 
)
inlinestatic
Parameters
nodeThe node defining the subtree to be searched.
nameThe name to search for.
Returns
Nodes with the specified name.

Definition at line 577 of file TreeTemplateTools.h.

Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getNode().

template<class N >
static void bpp::TreeTemplateTools::searchNodeWithName ( N &  node,
const std::string &  name,
std::vector< N * > &  nodes 
)
inlinestatic
Parameters
nodeThe node defining the subtree to be searched.
nameThe name to search for.
nodesA vector to be filled with the matching nodes.

Definition at line 590 of file TreeTemplateTools.h.

void TreeTemplateTools::setBranchLengths ( Node node,
double  brLen 
)
static

Set all the branch lengths of a subtree.

Parameters
nodeThe root node of the subtree.
brLenThe branch length to apply.

Definition at line 539 of file TreeTemplateTools.cpp.

References bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::setDistanceToFather().

Referenced by cloneSubtree(), and bpp::TreeTemplate< bpp::NodeTemplate >::setBranchLengths().

void TreeTemplateTools::setVoidBranchLengths ( Node node,
double  brLen 
)
static

Give a length to branches that don't have one in a subtree.

Parameters
nodeThe root node of the subtree.
brLenThe branch length to apply.

Definition at line 561 of file TreeTemplateTools.cpp.

References bpp::Node::getNumberOfSons(), bpp::Node::getSon(), bpp::Node::hasDistanceToFather(), and bpp::Node::setDistanceToFather().

Referenced by cloneSubtree(), and bpp::TreeTemplate< bpp::NodeTemplate >::setVoidBranchLengths().

string TreeTemplateTools::treeToParenthesis ( const TreeTemplate< Node > &  tree,
bool  writeId = false 
)
static

Get the parenthesis description of a tree.

Parameters
treeThe tree to convert.
writeIdTells if node ids must be printed. This will overwrite bootstrap values if there are ones. Leaves id will be added to the leave names, separated by a '_' character.
Returns
A string in the parenthesis format.

Definition at line 434 of file TreeTemplateTools.cpp.

References bpp::Node::getDistanceToFather(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::TreeTemplate< N >::getRootNode(), bpp::Node::getSon(), bpp::Node::hasDistanceToFather(), bpp::Node::hasName(), and bpp::Node::isLeaf().

Referenced by bpp::TreeTemplateTools::Element::Element(), bpp::NexusIOTree::write_(), and bpp::Newick::write_().

string TreeTemplateTools::treeToParenthesis ( const TreeTemplate< Node > &  tree,
bool  bootstrap,
const std::string &  propertyName 
)
static

Get the parenthesis description of a tree.

Parameters
treeThe tree to convert.
bootstrapTell is bootstrap values must be writen. If so, the content of the property with name TreeTools::BOOTSTRAP will be written as bootstrap value. The property should be a Number<double> object. Otherwise, the content of the property with name 'propertyName' will be written. In this later case, the property should be a String object.
propertyNameThe name of the property to use. Only used if bootstrap = false.
Returns
A string in the parenthesis format.

Definition at line 464 of file TreeTemplateTools.cpp.

References bpp::TreeTools::BOOTSTRAP, bpp::Node::getBranchProperty(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::TreeTemplate< N >::getRootNode(), bpp::Node::getSon(), bpp::Node::hasBranchProperty(), and bpp::Node::isLeaf().

void TreeTemplateTools::unresolveUncertainNodes ( Node subtree,
double  threshold,
const std::string &  property = TreeTools::BOOTSTRAP 
)
static

Unresolve nodes with low confidence value.

The underlying branches will be removed, resulting in a multifurcation. the branch length of the removed node is added to the length of its son nodes, so that pairwise phylogenetic distances are conserved along the tree. Leaves are not checked. Node with missing values are ignored.

Author
Julien Dutheil.
Parameters
subtreeThe node defining the subtree where nodes should be collapsed.
thresholdThe minimum value for which a node is considered to be confident.
propertyThe branch property to be considered as a confidence value (bootstrap values by default).

Definition at line 1147 of file TreeTemplateTools.cpp.

References bpp::Node::addSon(), bpp::Node::getBranchProperty(), bpp::Node::getDistanceToFather(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), bpp::Node::hasBranchProperty(), bpp::Node::removeSon(), and bpp::Node::setDistanceToFather().

Referenced by orderTree().

Member Data Documentation

const short TreeTemplateTools::MIDROOT_SUM_OF_SQUARES = 1
static

Definition at line 1279 of file TreeTemplateTools.h.

Referenced by orderTree_().

const short TreeTemplateTools::MIDROOT_VARIANCE = 0
static

Definition at line 1278 of file TreeTemplateTools.h.

Referenced by orderTree_().


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