|
bpp-phyl
2.1.0
|
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 (bpp::TreeTemplate< bpp::Node > &tree, const std::string &criterion) |
| Midroot the tree by minimizing a given criterion ("variance" or "sum of squares") More... | |
| static double | getRadius (bpp::TreeTemplate< bpp::Node > &tree) |
| Get the caracteristic radius of a tree (average distance to the root minimizing the sum of squared distances). 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 Node * | searchFirstNodeWithId (Node &node, int id) |
| static const Node * | searchFirstNodeWithId (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) |
| static std::vector< const Node * > | getPathBetweenAnyTwoNodes (const Node &node1, const Node &node2, bool includeAncestor=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 Node * | parenthesisToNode (const std::string &description, bool bootstrap=true, const std::string &propertyName=TreeTools::BOOTSTRAP, bool withId=false) |
| 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) 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 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, const std::string &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 DistanceMatrix * | getDistanceMatrix (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... | |
Utilitary methods working with TreeTemplate and Node objects.
Definition at line 63 of file TreeTemplateTools.h.
|
inline |
Definition at line 66 of file TreeTemplateTools.h.
|
inlinevirtual |
Definition at line 67 of file TreeTemplateTools.h.
|
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.
| node | The basal node of the subtree. |
Definition at line 752 of file TreeTemplateTools.h.
References bpp::Node::getNumberOfSons().
|
inlinestatic |
Definition at line 785 of file TreeTemplateTools.h.
References bpp::Tree::getBranchProperty(), bpp::Tree::getBranchPropertyNames(), bpp::Tree::getDistanceToFather(), bpp::Tree::getNodeName(), bpp::Tree::getNodeProperty(), bpp::Tree::getNodePropertyNames(), bpp::Tree::getSonsId(), bpp::Tree::hasDistanceToFather(), and bpp::Tree::hasNodeName().
|
static |
Remove all the branch lengths of a subtree.
| node | The root node of the subtree. |
Definition at line 541 of file TreeTemplateTools.cpp.
References bpp::Node::deleteDistanceToFather(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().
Referenced by bpp::AbstractTreeParsimonyScore::init_().
|
inlinestatic |
Recursively delete a subtree structure.
| node | The basal node of the subtree. |
Definition at line 773 of file TreeTemplateTools.h.
Referenced by dropSubtree(), dropSubtree(), dropSubtree(), bpp::TreeTemplate< bpp::NodeTemplate >::operator=(), and bpp::TreeTemplate< bpp::NodeTemplate >::~TreeTemplate().
|
inlinestatic |
Remove a leaf node and its parent node, while correcting for branch lengths.
| tree | The tree to edit. |
| leafName | The name of the leaf node. |
| NodeNotFoundException | If the node is not found. |
Definition at line 209 of file TreeTemplateTools.h.
Referenced by sampleSubtree().
|
inlinestatic |
Remove a subtree defined by its root node and its parent node, while correcting for branch lengths.
| tree | The tree to edit. |
| subtree | The subtree to remove, defined by its root node. |
| Exception | If something unexpected happens :s |
Definition at line 266 of file TreeTemplateTools.h.
References deleteSubtree(), deleteSubtree(), and deleteSubtree().
|
inlinestatic |
Retrieve all nodes ids that are ancestors of a node.
| node | The node |
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().
|
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.
| tree | The tree to which the subtree belongs. (The root is moved.) |
| criterion | The criterion to minimize. Legal values are "variance" and "sum of squares". |
| node | The root of the subtree. |
| bestRoot | The object storing the best root found, if it is better than the initial one, or otherwise left unchanged. |
Definition at line 1077 of file TreeTemplateTools.cpp.
References bpp::Node::getSons(), bpp::TreeTemplateTools::Moments_::numberOfLeaves, bpp::TreeTemplateTools::Moments_::numberOfLeaves, bpp::TreeTemplate< N >::rootAt(), bpp::TreeTemplate< N >::rootAt(), bpp::TreeTemplate< N >::rootAt(), bpp::TreeTemplateTools::Moments_::squaresSum, bpp::TreeTemplateTools::Moments_::squaresSum, bpp::TreeTemplateTools::Moments_::squaresSum, bpp::TreeTemplateTools::Moments_::squaresSum, bpp::TreeTemplateTools::Moments_::sum, bpp::TreeTemplateTools::Moments_::sum, bpp::TreeTemplateTools::Moments_::sum, bpp::TreeTemplateTools::Moments_::sum, bpp::TreeTemplateTools::Moments_::sum, bpp::TreeTemplateTools::Moments_::sum, bpp::TreeTemplateTools::Moments_::sum, bpp::TreeTemplateTools::Moments_::sum, bpp::TreeTemplateTools::Moments_::sum, bpp::TreeTemplateTools::Moments_::sum, and bpp::TreeTemplateTools::Moments_::sum.
Referenced by midRoot().
|
inlinestatic |
Retrieve all branches ids from a subtree.
| node | The node that defines the subtree. |
Definition at line 380 of file TreeTemplateTools.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getBranchesId().
|
inlinestatic |
Retrieve all branches ids from a subtree.
| node | The node that defines the subtree. |
| ids | A vector of ids. |
Definition at line 408 of file TreeTemplateTools.h.
References getNodesId(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().
|
static |
Get all the branch lengths of a subtree.
| node | The root node of the subtree. |
| NodePException | If a branch length is lacking. |
Definition at line 499 of file TreeTemplateTools.cpp.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getBranchLengths(), and bpp::TreeTemplate< bpp::NodeTemplate >::getBranchLengths().
|
static |
Retrieve all branch property objects with a given name over a (sub) tree (const version).
| 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 880 of file TreeTemplateTools.cpp.
References bpp::Node::getBranchProperty(), bpp::Node::getId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::hasBranchProperty().
|
static |
Retrieve all branch property objects with a given name over a (sub) tree.
| 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 890 of file TreeTemplateTools.cpp.
References bpp::Node::getBranchProperty(), bpp::Node::getId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::hasBranchProperty().
|
static |
Retrieve the names of all available branch properties in the tree.
| node | [in] The root node of the (sub)tree to use. |
| propertyNames | [out] a vector where names will be added. |
Definition at line 871 of file TreeTemplateTools.cpp.
References bpp::VectorTools::extend(), bpp::Node::getBranchPropertyNames(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().
|
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.
| node | The node defining the subtree to check. |
Definition at line 128 of file TreeTemplateTools.cpp.
References bpp::Node::getNumberOfSons().
Referenced by bpp::CladogramPlot::recursivePlot_(), bpp::CladogramPlot::setTree(), and bpp::CladogramPlot::treeHasChanged().
|
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.
| node | The node defining the subtree to check. |
| depths | The map that will contain all the depths of the nodes, with node pointers as keys. |
Definition at line 142 of file TreeTemplateTools.cpp.
References bpp::Node::getNumberOfSons().
|
static |
Get the total distance between to nodes.
Sum all branch lengths between two nodes.
| node1 | The first node. |
| node2 | The second node. |
Definition at line 716 of file TreeTemplateTools.cpp.
|
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.
| tree | The tree to use. |
Definition at line 804 of file TreeTemplateTools.cpp.
References bpp::TreeTemplate< N >::getLeavesNames(), and bpp::TreeTemplate< N >::getRootNode().
|
static |
Definition at line 190 of file TreeTemplateTools.cpp.
References bpp::TreeTemplateTools::Element::bootstrap, bpp::TreeTemplateTools::Element::bootstrap, bpp::TreeTemplateTools::Element::content, bpp::TreeTemplateTools::Element::content, bpp::TextTools::isEmpty(), bpp::TreeTemplateTools::Element::isLeaf, bpp::TreeTemplateTools::Element::isLeaf, bpp::TreeTemplateTools::Element::length, bpp::TreeTemplateTools::Element::length, bpp::TextTools::removeSurroundingWhiteSpaces(), bpp::TextTools::removeSurroundingWhiteSpaces(), and bpp::TextTools::removeSurroundingWhiteSpaces().
|
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.
| node | The node defining the subtree to check. |
| NodePException | If a branch length is lacking. |
Definition at line 157 of file TreeTemplateTools.cpp.
References bpp::Node::getDistanceToFather(), and bpp::Node::getNumberOfSons().
Referenced by bpp::PhylogramPlot::treeHasChanged().
|
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.
| node | The node defining the subtree to check. |
| heights | The map that will contain all the heights of the nodes, with node pointers as keys. |
| NodePException | If 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_().
|
inlinestatic |
Retrieve all inner nodes from a subtree.
| node | The node that defines the subtree. |
Definition at line 423 of file TreeTemplateTools.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getInnerNodes(), and bpp::TreeTemplate< bpp::NodeTemplate >::getInnerNodes().
|
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.
| node | The node that defines the subtree. |
| nodes | A vector to be filled with pointers toward each inner node in the subtree. |
Definition at line 439 of file TreeTemplateTools.h.
|
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.
| node | The node that defines the subtree. |
Definition at line 457 of file TreeTemplateTools.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getInnerNodesId(), and getInnerNodesId().
|
inlinestatic |
Retrieve all inner nodes ids from a subtree.
| node | The node that defines the subtree. |
| ids | A vector to be filled with the resulting ids. |
Definition at line 470 of file TreeTemplateTools.h.
References bpp::Node::getId(), getInnerNodesId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::isLeaf().
|
inlinestatic |
Get the id of a leaf given its name in a subtree.
| node | The node defining the subtree to search. |
| name | The name of the node. |
| NodeNotFoundException | If the node is not found. |
Definition at line 164 of file TreeTemplateTools.h.
References searchLeaf().
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getLeafId().
|
inlinestatic |
Retrieve all leaves from a subtree.
| node | The node that defines the subtree. |
Definition at line 84 of file TreeTemplateTools.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getLeaves(), bpp::TreeTemplate< bpp::NodeTemplate >::getLeaves(), and bpp::PatternTools::getSequenceSubset().
|
inlinestatic |
Retrieve all leaves from a subtree.
| node | The node that defines the subtree. |
| leaves | A vector of pointers toward each leaf in the subtree. |
Definition at line 98 of file TreeTemplateTools.h.
|
inlinestatic |
Retrieve all leaves ids from a subtree.
| node | The node that defines the subtree. |
Definition at line 116 of file TreeTemplateTools.h.
Referenced by getLeavesId(), and bpp::TreeTemplate< bpp::NodeTemplate >::getLeavesId().
|
inlinestatic |
Retrieve all leaves ids from a subtree.
| node | The node that defines the subtree. |
| ids | A vector of ids. |
Definition at line 129 of file TreeTemplateTools.h.
References bpp::Node::getId(), getLeavesId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::isLeaf().
|
static |
Get the leaves names of a subtree defined by a particular node.
| node | The node defining the subtree to check. |
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().
|
static |
Retrieve all node property objects with a given name over a (sub) tree (const version).
| 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 849 of file TreeTemplateTools.cpp.
References bpp::Node::getId(), bpp::Node::getNodeProperty(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::hasNodeProperty().
|
static |
Retrieve all node property objects with a given name over a (sub) tree.
| 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 859 of file TreeTemplateTools.cpp.
References bpp::Node::getId(), bpp::Node::getNodeProperty(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::hasNodeProperty().
|
static |
Retrieve the names of all available node properties in the tree.
| node | [in] The root node of the (sub)tree to use. |
| propertyNames | [out] a vector where names will be added. |
Definition at line 840 of file TreeTemplateTools.cpp.
References bpp::VectorTools::extend(), bpp::Node::getNodePropertyNames(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().
|
inlinestatic |
Retrieve all son nodes from a subtree.
| node | The node that defines the subtree. |
Definition at line 338 of file TreeTemplateTools.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getNodes(), and bpp::TreeTemplate< bpp::NodeTemplate >::getNodes().
|
inlinestatic |
Retrieve all son nodes from a subtree.
| node | The node that defines the subtree. |
| nodes | A vector of pointers toward each son node in the subtree. |
Definition at line 352 of file TreeTemplateTools.h.
|
inlinestatic |
Retrieve all nodes ids from a subtree.
| node | The node that defines the subtree. |
Definition at line 367 of file TreeTemplateTools.h.
Referenced by getBranchesId(), bpp::TreeTemplate< bpp::NodeTemplate >::getNodesId(), and getNodesId().
|
inlinestatic |
Retrieve all nodes ids from a subtree.
| node | The node that defines the subtree. |
| ids | A vector of ids. |
Definition at line 393 of file TreeTemplateTools.h.
References bpp::Node::getId(), getNodesId(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().
|
static |
Get the number of leaves of a subtree defined by a particular node.
| node | The node defining the subtree to check. |
Definition at line 80 of file TreeTemplateTools.cpp.
References bpp::Node::getNumberOfSons(), and bpp::Node::isLeaf().
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getNumberOfLeaves().
|
static |
Get the number of nodes of a subtree defined by a particular node.
| node | The node defining the subtree to check. |
Definition at line 96 of file TreeTemplateTools.cpp.
References bpp::Node::getNumberOfSons().
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getNumberOfNodes().
|
static |
Definition at line 620 of file TreeTemplateTools.cpp.
References bpp::Node::getFather(), bpp::Node::getFather(), bpp::Node::hasFather(), and bpp::Node::hasFather().
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::rootAt().
|
static |
Definition at line 668 of file TreeTemplateTools.cpp.
References bpp::Node::getFather(), bpp::Node::getFather(), bpp::Node::hasFather(), and bpp::Node::hasFather().
|
static |
Get the caracteristic radius of a tree (average distance to the root minimizing the sum of squared distances).
| tree | The tree (which is rerooted in the process). |
Definition at line 1067 of file TreeTemplateTools.cpp.
References bpp::TreeTemplate< N >::getRootNode(), midRoot(), bpp::TreeTemplateTools::Moments_::numberOfLeaves, and bpp::TreeTemplateTools::Moments_::sum.
|
static |
Draw a random tree from a list of taxa, using a Yule process.
| leavesNames | A list of taxa. |
| rooted | Tell is the output tree should be rooted. |
Definition at line 578 of file TreeTemplateTools.cpp.
References bpp::Node::addSon(), bpp::Node::addSon(), bpp::Node::addSon(), bpp::RandomTools::giveIntRandomNumberBetweenZeroAndEntry(), bpp::RandomTools::giveIntRandomNumberBetweenZeroAndEntry(), and bpp::TreeTemplate< N >::resetNodesId().
|
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.
| node1 | The node whose neighbors must be retrieved. |
| node2 | One neighbor to exclude. |
| node3 | Another neighbor to exclude. |
Definition at line 814 of file TreeTemplateTools.cpp.
References bpp::Node::getNeighbors().
Referenced by bpp::DRTreeParsimonyScore::testNNI(), bpp::DRTreeParsimonyScore::testNNI(), bpp::NNIHomogeneousTreeLikelihood::testNNI(), and bpp::NNIHomogeneousTreeLikelihood::testNNI().
|
staticprivate |
Computes the moment of a subtree.
| node | The root of the subtree |
Definition at line 1162 of file TreeTemplateTools.cpp.
References bpp::Node::getDistanceToFather(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), bpp::Node::isLeaf(), bpp::TreeTemplateTools::Moments_::numberOfLeaves, bpp::TreeTemplateTools::Moments_::numberOfLeaves, bpp::TreeTemplateTools::Moments_::numberOfLeaves, bpp::TreeTemplateTools::Moments_::numberOfLeaves, bpp::TreeTemplateTools::Moments_::numberOfLeaves, bpp::TreeTemplateTools::Moments_::squaresSum, bpp::TreeTemplateTools::Moments_::squaresSum, bpp::TreeTemplateTools::Moments_::sum, bpp::TreeTemplateTools::Moments_::sum, and bpp::TreeTemplateTools::Moments_::sum.
|
static |
Get the total length (sum of all branch lengths) of a subtree.
| node | The root node of the subtree. |
| includeAncestor | Tell 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). |
| NodePException | If a branch length is lacking. |
Definition at line 516 of file TreeTemplateTools.cpp.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getTotalLength().
|
inlinestatic |
| node | The node defining the subtree to be searched. |
| id | The id to search for. |
Definition at line 554 of file TreeTemplateTools.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::hasNode().
|
inlinestatic |
| node | The node defining the subtree to be searched. |
| name | The name to search for. |
Definition at line 601 of file TreeTemplateTools.h.
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.
| n1 | Root node of the first subtree. |
| n2 | Root node of the second subtree. |
Definition at line 902 of file TreeTemplateTools.cpp.
References bpp::Node::getName(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::getNumberOfSons(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), bpp::Node::getSon(), bpp::Node::isLeaf(), and bpp::Node::isLeaf().
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::hasSameTopologyAs().
|
static |
This method will add a given value (possibly negative) to all identifiers in a (sub)tree.
| node | The root node of the (sub)tree to use. |
| increment | The value to add. |
Definition at line 829 of file TreeTemplateTools.cpp.
References bpp::Node::getId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::setId().
|
static |
Tell is a subtree is multifurcating.
| node | The root node of the subtree. |
Definition at line 63 of file TreeTemplateTools.cpp.
References bpp::Node::getNumberOfSons(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().
Referenced by bpp::GlobalClockTreeLikelihoodFunctionWrapper::initParameters_(), and bpp::TreeTemplate< bpp::NodeTemplate >::isMultifurcating().
|
inlinestatic |
Tell if a particular node is the root of a tree i.e. if it has a father node.
| node | The node to check. |
Definition at line 621 of file TreeTemplateTools.h.
References bpp::Node::hasFather().
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::isRoot().
|
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 :
With
Where
and
are the sets of leaves on either side of the root branch,
is the distance of leaf
to the nearest end of the root branch,
is the length of the root branch, and
and
are respectively
and 
~
| tree | |
| criterion | The criterion upon which to reroot. Legal values : "variance" to minimize root-leaf distance variance (molecular clock assumption) or "sum of squares" to minimize the sum of root-leaf distance squares. |
Definition at line 1011 of file TreeTemplateTools.cpp.
References bpp::Node::addSon(), bpp::Node::addSon(), getBestRootInSubtree(), bpp::Node::getFather(), bpp::TreeTools::getMPNUId(), bpp::TreeTemplate< N >::getRootId(), bpp::TreeTemplate< N >::getRootNode(), bpp::TreeTemplate< N >::isRooted(), bpp::Node::removeSon(), bpp::TreeTemplate< N >::rootAt(), bpp::TreeTemplate< N >::rootAt(), bpp::TreeTemplate< N >::rootAt(), bpp::Node::setBranchProperty(), bpp::Node::setDistanceToFather(), bpp::Node::setId(), and bpp::TreeTemplate< N >::unroot().
Referenced by getRadius().
|
static |
Get the parenthesis description of a subtree.
| node | The node defining the subtree. |
| writeId | Tells 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. |
Definition at line 350 of file TreeTemplateTools.cpp.
References bpp::Node::getBranchProperty(), bpp::Node::getDistanceToFather(), bpp::Node::getId(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::hasBranchProperty(), bpp::Node::hasDistanceToFather(), bpp::Node::isLeaf(), and bpp::Node::isLeaf().
|
static |
Get the parenthesis description of a subtree.
| node | The node defining the subtree. |
| bootstrap | Tell 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. |
| propertyName | The name of the property to use. Only used if bootstrap = false. |
Definition at line 385 of file TreeTemplateTools.cpp.
References bpp::Node::getBranchProperty(), bpp::Node::getBranchProperty(), bpp::Node::getDistanceToFather(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::hasBranchProperty(), bpp::Node::hasBranchProperty(), bpp::Node::hasDistanceToFather(), and bpp::Node::isLeaf().
|
inlinestatic |
Swap nodes in the subtree so that they are ordered according to the underlying number of leaves.
| node | The root node of the (sub)tree to use. |
| downward | If yes, biggest subtrees (in terms of number of leaves) will come first. Otherwise, the smallest subtrees will come first. |
| orderLeaves | Tell 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 1141 of file TreeTemplateTools.h.
References orderTree_().
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::hasSameTopologyAs(), and bpp::TreeTemplate< bpp::NodeTemplate >::hasSameTopologyAs().
|
staticprivate |
Definition at line 921 of file TreeTemplateTools.cpp.
References bpp::TreeTemplateTools::OrderTreeData_::firstLeaf, bpp::TreeTemplateTools::OrderTreeData_::firstLeaf, bpp::TreeTemplateTools::OrderTreeData_::firstLeaf, bpp::TreeTemplateTools::OrderTreeData_::firstLeaf, bpp::TreeTemplateTools::OrderTreeData_::firstLeaf, bpp::TreeTemplateTools::OrderTreeData_::firstLeaf, bpp::TreeTemplateTools::OrderTreeData_::firstLeaf, bpp::TreeTemplateTools::OrderTreeData_::firstLeaf, bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), bpp::Node::hasFather(), bpp::Node::isLeaf(), bpp::TreeTemplateTools::OrderTreeData_::size, bpp::TreeTemplateTools::OrderTreeData_::size, bpp::TreeTemplateTools::OrderTreeData_::size, bpp::TreeTemplateTools::OrderTreeData_::size, bpp::VectorTools::sum(), bpp::Node::swap(), bpp::Node::swap(), bpp::VectorTools::whichMax(), bpp::VectorTools::whichMaxAll(), bpp::VectorTools::whichMin(), and bpp::VectorTools::whichMinAll().
Referenced by orderTree().
|
static |
Parse a string in the parenthesis format and convert it to a subtree.
| description | the string to parse; |
| bootstrap | Tell 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. |
| propertyName | The name of the property to store. Only used if bootstrap = false. |
| withId | Tells 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. |
Definition at line 254 of file TreeTemplateTools.cpp.
References bpp::Node::addSon(), bpp::TreeTemplateTools::Element::bootstrap, bpp::TreeTemplateTools::Element::bootstrap, bpp::TreeTemplateTools::Element::bootstrap, bpp::TreeTemplateTools::Element::bootstrap, bpp::TreeTemplateTools::Element::content, bpp::NestedStringTokenizer::hasMoreToken(), bpp::TextTools::isEmpty(), bpp::TextTools::isEmpty(), bpp::TreeTemplateTools::Element::isLeaf, bpp::TreeTemplateTools::Element::length, bpp::TreeTemplateTools::Element::length, bpp::NestedStringTokenizer::nextToken(), bpp::TextTools::removeSurroundingWhiteSpaces(), bpp::Node::setBranchProperty(), bpp::Node::setBranchProperty(), bpp::Node::setDistanceToFather(), bpp::Node::setId(), bpp::Node::setId(), bpp::Node::setName(), bpp::Node::setName(), and bpp::TextTools::toDouble().
|
static |
Parse a string in the parenthesis format and convert it to a tree.
| description | the string to parse; |
| bootstrap | Tells 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. |
| propertyName | The name of the property to store. Only used if bootstrap = false. |
| withId | Tells 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. |
| Exception | in case of bad format. |
Definition at line 332 of file TreeTemplateTools.cpp.
References bpp::TreeTemplate< N >::resetNodesId(), and bpp::TreeTemplate< N >::setRootNode().
Referenced by bpp::NexusIOTree::read(), bpp::Newick::read(), and bpp::Newick::read().
|
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.
| node | The current node in the recursion. |
| matrix | The output matrix which will be filled. |
| distsToNodeFather | Intermediate computations contianing the distances of the node to the leaves. |
Definition at line 729 of file TreeTemplateTools.cpp.
References bpp::Node::getDistanceToFather(), bpp::Node::getDistanceToFather(), bpp::Node::getName(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::getNumberOfSons(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), bpp::Node::getSon(), bpp::Node::getSon(), bpp::Node::getSon(), bpp::Node::getSon(), bpp::Node::hasFather(), and bpp::Node::isLeaf().
|
inlinestatic |
Sample a subtree by removing leaves randomly.
| tree | The tree to edit. |
| leaves | The leafs names that should be sampled. They must be found in the tree otherwise an exception will be thrown. |
| size | The 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 321 of file TreeTemplateTools.h.
References dropLeaf(), and bpp::RandomTools::giveIntRandomNumberBetweenZeroAndEntry().
|
static |
Scale a given tree.
Multiply all branch lengths by a given factor.
| node | The root node of the subtree to scale. |
| factor | The factor to multiply all branch lengths with. |
| NodePException | If a branch length is lacking. |
Definition at line 564 of file TreeTemplateTools.cpp.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::scaleTree().
| node | The node defining the subtree to be searched. |
| id | The id to search for. |
Definition at line 513 of file TreeTemplateTools.h.
References bpp::Node::getId(), bpp::Node::getNumberOfSons(), and bpp::Node::getSon().
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getNode(), bpp::TreeTemplate< bpp::NodeTemplate >::getNode(), and searchFirstNodeWithId().
|
inlinestatic |
| node | The node defining the subtree to be searched. |
| id | The id to search for. |
Definition at line 533 of file TreeTemplateTools.h.
References bpp::Node::getId(), bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and searchFirstNodeWithId().
|
inlinestatic |
Get the id of a leaf given its name in a subtree.
| node | The node defining the subtree to search. |
| name | The name of the node. |
| id | The id of the node. |
| NodeNotFoundException | If the node is not found. |
Definition at line 185 of file TreeTemplateTools.h.
Referenced by getLeafId().
|
inlinestatic |
| node | The node defining the subtree to be searched. |
| id | The id to search for. |
Definition at line 486 of file TreeTemplateTools.h.
|
inlinestatic |
| node | The node defining the subtree to be searched. |
| id | The id to search for. |
| nodes | A vector to be filled with the matching nodes. |
Definition at line 499 of file TreeTemplateTools.h.
|
inlinestatic |
| node | The node defining the subtree to be searched. |
| name | The name to search for. |
Definition at line 573 of file TreeTemplateTools.h.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getNode().
|
inlinestatic |
| node | The node defining the subtree to be searched. |
| name | The name to search for. |
| nodes | A vector to be filled with the matching nodes. |
Definition at line 586 of file TreeTemplateTools.h.
|
static |
Set all the branch lengths of a subtree.
| node | The root node of the subtree. |
| brLen | The branch length to apply. |
Definition at line 530 of file TreeTemplateTools.cpp.
References bpp::Node::getNumberOfSons(), bpp::Node::getSon(), and bpp::Node::setDistanceToFather().
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::setBranchLengths().
|
static |
Give a length to branches that don't have one in a subtree.
| node | The root node of the subtree. |
| brLen | The branch length to apply. |
Definition at line 552 of file TreeTemplateTools.cpp.
References bpp::Node::getNumberOfSons(), bpp::Node::getSon(), bpp::Node::hasDistanceToFather(), and bpp::Node::setDistanceToFather().
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::setVoidBranchLengths().
|
static |
Get the parenthesis description of a tree.
| tree | The tree to convert. |
| writeId | Tells 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. |
Definition at line 426 of file TreeTemplateTools.cpp.
References bpp::Node::getDistanceToFather(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::getNumberOfSons(), bpp::TreeTemplate< N >::getRootNode(), bpp::Node::getSon(), bpp::Node::getSon(), bpp::Node::getSon(), bpp::Node::hasDistanceToFather(), bpp::Node::hasName(), and bpp::Node::isLeaf().
Referenced by bpp::NexusIOTree::write_(), bpp::Newick::write_(), bpp::Newick::write_(), bpp::Newick::write_(), and bpp::Newick::write_().
|
static |
Get the parenthesis description of a tree.
| tree | The tree to convert. |
| bootstrap | Tell 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. |
| propertyName | The name of the property to use. Only used if bootstrap = false. |
Definition at line 456 of file TreeTemplateTools.cpp.
References bpp::Node::getBranchProperty(), bpp::Node::getBranchProperty(), bpp::Node::getName(), bpp::Node::getNumberOfSons(), bpp::Node::getNumberOfSons(), bpp::TreeTemplate< N >::getRootNode(), bpp::Node::getSon(), bpp::Node::getSon(), bpp::Node::getSon(), bpp::Node::hasBranchProperty(), bpp::Node::hasBranchProperty(), and bpp::Node::isLeaf().