bpp-phyl
2.2.0
|
Generic utilitary methods dealing with trees. More...
#include <Bpp/Phyl/TreeTools.h>
Classes | |
struct | Moments_ |
Public Member Functions | |
TreeTools () | |
virtual | ~TreeTools () |
Static Public Member Functions | |
static Tree * | MRP (const std::vector< Tree *> &vecTr) |
Matrix Representation Parsimony supertree method. More... | |
static void | computeBootstrapValues (Tree &tree, const std::vector< Tree *> &vecTr, bool verbose=true, int format=0) |
Compute bootstrap values. More... | |
static void | constrainedMidPointRooting (Tree &tree) |
Determine the mid-point position of the root along the branch that already contains the root. Consequently, the topology of the rooted tree remains identical. More... | |
static Tree * | MRPMultilabel (const std::vector< Tree *> &vecTr) |
Matrix Representation Parsimony supertree method for multilabel trees. More... | |
Retrieve topology information | |
static std::vector< int > | getLeavesId (const Tree &tree, int nodeId) throw (NodeNotFoundException) |
Retrieve all leaves from a subtree. More... | |
static void | getLeavesId (const Tree &tree, int nodeId, std::vector< int > &leaves) throw (NodeNotFoundException) |
Retrieve all leaves from a subtree. More... | |
static size_t | getNumberOfLeaves (const Tree &tree, int nodeId) throw (NodeNotFoundException) |
Count the number of leaves from a subtree. More... | |
static int | getLeafId (const Tree &tree, int nodeId, const std::string &name) throw (NodeNotFoundException) |
Get the id of a leaf given its name in a subtree. More... | |
static void | searchLeaf (const Tree &tree, int nodeId, const std::string &name, int *&id) throw (NodeNotFoundException) |
Get the id of a leaf given its name in a subtree. More... | |
static std::vector< int > | getPathBetweenAnyTwoNodes (const Tree &tree, int nodeId1, int nodeId2, bool includeAncestor=true) throw (NodeNotFoundException) |
Get a vector of ancestor nodes between to nodes. More... | |
static std::vector< int > | getAncestors (const Tree &tree, int nodeId) throw (NodeNotFoundException) |
Get a list of all ids of parents nodes, from the current node (not included) to the root of the tree. More... | |
static int | getLastCommonAncestor (const Tree &tree, const std::vector< int > &nodeIds) throw (NodeNotFoundException, Exception) |
Get the id of the last common ancestors of all specified nodes. More... | |
static size_t | getDepth (const Tree &tree, int nodeId) throw (NodeNotFoundException) |
Get the depth of the subtree defined by node 'node', i.e. the maximum number of sons 'generations'. More... | |
static size_t | getDepths (const Tree &tree, int nodeId, std::map< int, size_t > &depths) throw (NodeNotFoundException) |
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 Tree &tree, int nodeId) throw (NodeNotFoundException,NodeException) |
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 Tree &tree, int nodeId, std::map< int, double > &heights) throw (NodeNotFoundException,NodeException) |
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... | |
Conversion tools. | |
Convert to 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 std::string | nodeToParenthesis (const Tree &tree, int nodeId, bool writeId=false) throw (NodeNotFoundException) |
Get the parenthesis description of a subtree. More... | |
static std::string | nodeToParenthesis (const Tree &tree, int nodeId, bool bootstrap, const std::string &propertyName) throw (NodeNotFoundException) |
Get the parenthesis description of a subtree. More... | |
static std::string | treeToParenthesis (const Tree &tree, bool writeId=false) |
Get the parenthesis description of a tree. More... | |
static std::string | treeToParenthesis (const Tree &tree, bool bootstrap, const std::string &propertyName) |
Get the parenthesis description of a tree. More... | |
Deal with identifiers | |
static std::vector< int > | getNodesId (const Tree &tree, int nodeId) throw (NodeNotFoundException) |
Retrieve all nodes ids nodes from a subtree. More... | |
static void | getNodesId (const Tree &tree, int nodeId, std::vector< int > &nodes) throw (NodeNotFoundException) |
Retrieve all nodes ids from a subtree. More... | |
static int | getMaxId (const Tree &tree, int id) |
Get the maximum identifier used in a (sub)tree. More... | |
static int | getMPNUId (const Tree &tree, int id) |
Get the minimum positive non-used identifier in a (sub)tree. More... | |
static bool | checkIds (const Tree &tree, bool throwException) throw (Exception) |
Check if the ids are uniques. More... | |
Topology methods | |
static VectorSiteContainer * | MRPEncode (const std::vector< Tree *> &vecTr) |
Creates a sequence data set corresponding to the Matrix Representation of the input trees. More... | |
static VectorSiteContainer * | MRPEncodeMultilabel (const std::vector< Tree *> &vecTr) |
Creates a sequence data set corresponding to the Matrix Representation of the input multilabel trees. More... | |
static bool | haveSameTopology (const Tree &tr1, const Tree &tr2) |
Tells whether two trees have the same unrooted topology. More... | |
static int | robinsonFouldsDistance (const Tree &tr1, const Tree &tr2, bool checkNames=true, int *missing_in_tr2=NULL, int *missing_in_tr1=NULL) throw (Exception) |
Calculates the Robinson-Foulds topological distance between two trees. More... | |
static BipartitionList * | bipartitionOccurrences (const std::vector< Tree *> &vecTr, std::vector< size_t > &bipScore) |
Counts the total number of occurrences of every bipartition from the input trees. More... | |
static TreeTemplate< Node > * | thresholdConsensus (const std::vector< Tree *> &vecTr, double threshold, bool checkNames=true) throw (Exception) |
General greedy consensus tree method. More... | |
static TreeTemplate< Node > * | fullyResolvedConsensus (const std::vector< Tree *> &vecTr, bool checkNames=true) |
Fully-resolved greedy consensus tree method. More... | |
static TreeTemplate< Node > * | majorityConsensus (const std::vector< Tree *> &vecTr, bool checkNames=true) |
Majority consensus tree method. More... | |
static TreeTemplate< Node > * | strictConsensus (const std::vector< Tree *> &vecTr, bool checkNames=true) |
Strict consensus tree method. More... | |
Act on branch lengths. | |
static Vdouble | getBranchLengths (const Tree &tree, int nodeId) throw (NodeNotFoundException,NodeException) |
Get all the branch lengths of a subtree. More... | |
static double | getTotalLength (const Tree &tree, int nodeId, bool includeAncestor=true) throw (NodeNotFoundException,NodeException) |
Get the total length (sum of all branch lengths) of a subtree. More... | |
static void | setBranchLengths (Tree &tree, int nodeId, double brLen) throw (NodeNotFoundException) |
Set all the branch lengths of a subtree. More... | |
static void | setVoidBranchLengths (Tree &tree, int nodeId, double brLen) throw (NodeNotFoundException) |
Give a length to branches that don't have one in a subtree. More... | |
static void | scaleTree (Tree &tree, int nodeId, double factor) throw (NodeNotFoundException,NodeException) |
Scale a given tree. More... | |
static void | initBranchLengthsGrafen (Tree &tree) |
Grafen's method to initialize branch lengths. More... | |
static void | computeBranchLengthsGrafen (Tree &tree, double power=1, bool init=true) throw (NodeException) |
Compute branch lengths using Grafen's method. More... | |
static double | convertToClockTree (Tree &tree, int nodeId, bool noneg=false) |
Modify a tree's branch lengths to make a clock tree, by rebalancing branch lengths. More... | |
static double | convertToClockTree2 (Tree &tree, int nodeId) |
Modify a tree's branch lengths to make a clock tree, by rescaling subtrees. More... | |
static double | getDistanceBetweenAnyTwoNodes (const Tree &tree, int nodeId1, int nodeId2) |
Get the total distance between two nodes. More... | |
static DistanceMatrix * | getDistanceMatrix (const Tree &tree) |
Compute a distance matrix from a tree. More... | |
static void | midpointRooting (Tree &tree) |
(Re)root the tree using the midpoint method. More... | |
static size_t | initBranchLengthsGrafen (Tree &tree, int nodeId) throw (NodeNotFoundException) |
static void | computeBranchLengthsGrafen (Tree &tree, int nodeId, double power, double total, double &height, double &heightRaised) throw (NodeNotFoundException,NodeException) |
Some properties. | |
static const std::string | BOOTSTRAP = "bootstrap" |
Bootstrap tag. More... | |
static Moments_ | statFromNode_ (Tree &tree, int rootId) |
static double | bestRootPosition_ (Tree &tree, int nodeId1, int nodeId2, double length) |
Generic utilitary methods dealing with trees.
These methods work with all Tree object. However, depending on the tree implementation, they may not be the most efficient.
Definition at line 66 of file TreeTools.h.
|
inline |
Definition at line 69 of file TreeTools.h.
|
inlinevirtual |
Definition at line 70 of file TreeTools.h.
|
staticprivate |
Definition at line 1227 of file TreeTools.cpp.
References bpp::TreeTools::Moments_::N, and bpp::TreeTools::Moments_::sum.
|
static |
Counts the total number of occurrences of every bipartition from the input trees.
Returns the list of distinct bipartitions found at least once in the set of input trees, and writes the number of occurrence of each of these bipartitions in vector bipScore.
vecTr | Vector of input trees (must share a common set of leaves - not checked in this function) |
bipScore | Output as the numbers of occurrences of the returned distinct bipartitions |
Definition at line 958 of file TreeTools.cpp.
References bpp::BipartitionList::addTrivialBipartitions(), bpp::BipartitionList::areIdentical(), bpp::BipartitionList::deleteBipartition(), bpp::BipartitionList::getNumberOfBipartitions(), bpp::BipartitionList::getNumberOfElements(), bpp::BipartitionList::getPartitionSize(), bpp::BipartitionTools::mergeBipartitionLists(), and bpp::BipartitionList::removeTrivialBipartitions().
|
static |
Check if the ids are uniques.
tree | The tree to check. |
throwException | If set to true, the function throws qn exception if a duplicated is found. |
Definition at line 783 of file TreeTools.cpp.
Referenced by bpp::AbstractHomogeneousTreeLikelihood::init_(), and bpp::AbstractNonHomogeneousTreeLikelihood::init_().
|
static |
Compute bootstrap values.
tree | Input tree. the BOOTSTRAP banch property of the tree will be modified if it already exists. |
vecTr | A list of trees to compare to 'tree'. |
verbose | Tell if a progress bar should be displayed. |
format | If null or positive, bootstrap values are reported as percentage, with the given number of decimal digits. If negative, bootstrap calues are the raw number of tree occurrences. |
Definition at line 1124 of file TreeTools.cpp.
References bpp::BipartitionTools::areIdentical(), bpp::BipartitionList::getNumberOfBipartitions(), bpp::Tree::isLeaf(), and bpp::Tree::setBranchProperty().
|
static |
Compute branch lengths using Grafen's method.
The 'height' of each node is devided by the total height of the tree, and the ratio is raised at power 'rho'. A value of rho=0 hence returns a star tree.
Reference: Grafen A. The phylogenetic regression. Philos Trans R Soc Lond B Biol Sci. 1989; 326(1233):119-57
tree | The tree to use. |
power | The rho parameter. |
init | Tell if the height must be initialized by calling the initBranchLengthsGrafen() method. Otherwise use branch lengths. |
NodeException | If init=false and one branch length is lacking. |
Definition at line 618 of file TreeTools.cpp.
|
staticprivate |
Definition at line 583 of file TreeTools.cpp.
|
static |
Determine the mid-point position of the root along the branch that already contains the root. Consequently, the topology of the rooted tree remains identical.
This code uses two inner functions to compute the mid-point position: statFromNode_ and bestRootPosition_. This code is inspired by a code performing a similar calculation in Seaview (Guindon et al., 2010, Mol. Biol. Evol. 27(2):221-4).
tree | The rooted tree for which the root has to be moved to its mid-point position, along the branch where it already stands. |
Definition at line 1205 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getRootId(), bpp::Tree::getSonsId(), bpp::Tree::isMultifurcating(), bpp::Tree::isRooted(), and bpp::Tree::setDistanceToFather().
|
static |
Modify a tree's branch lengths to make a clock tree, by rebalancing branch lengths.
The height of each node is set to the mean height of all son nodes. This may however lead to negative branch lengths, since the mean heigth may be inferior to one of the son heights, due to short branch lengths. If the 'noneg' is set to yes, the mean height is checked against all son heights. If it is inferior to one of the son heights, the maximum son height is used instead. This results in a multifurcation.
This method is recursive and will be applied on all sons nodes.
tree | The tree to use. |
nodeId | The node defining the subtree. |
noneg | Tell if the correction for non negative branch lengths must be used. |
NodeNotFoundException | If the node is not found. |
NodeException | If one branch length is lacking. |
Definition at line 634 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getSonsId(), bpp::Tree::hasDistanceToFather(), bpp::Tree::hasNode(), and bpp::Tree::setDistanceToFather().
|
static |
Modify a tree's branch lengths to make a clock tree, by rescaling subtrees.
The height of each node is set to the mean height of all son nodes. All branch lengths of the corresponding subtrees are updated proportionally. This algorithm is smaller than the convertToClockTree method, but may be more accurate.
This method is recursive and will be applied on all sons nodes.
tree | The tree to use. |
nodeId | The node defining the subtree. |
NodeNotFoundException | If the node is not found. |
NodeException | If one branch length is lacking. |
Definition at line 669 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getSonsId(), bpp::Tree::hasDistanceToFather(), and bpp::Tree::hasNode().
|
static |
Fully-resolved greedy consensus tree method.
Calls thresholdConsensus with threshold=0, i.e. no constraint on the number of occurrence of bipartitions. The resulting tree is fully resolved.
vecTr | Vector of input trees (must share a common set of leaves - checked if checkNames is true) |
checkNames | Tell whether we should check the trees first. |
Definition at line 1074 of file TreeTools.cpp.
|
static |
Get a list of all ids of parents nodes, from the current node (not included) to the root of the tree.
tree | The tree to use. |
nodeId | The id of node defining the subtree. |
NodeNotFoundException | If the node is not found. |
Definition at line 1158 of file TreeTools.cpp.
|
static |
Get all the branch lengths of a subtree.
tree | The tree. |
nodeId | The node defining the subtree. |
NodeNotFoundException | If the node is not found. |
NodeException | If a branch length is lacking. |
Definition at line 472 of file TreeTools.cpp.
|
static |
Get the depth of the subtree defined by node 'node', i.e. the maximum number of sons 'generations'.
ex:
Depth of node 'N1' id 2, depth of node 'N2' is 1, depth of leaves is 0.
tree | The tree. |
nodeId | The id of node defining the subtree. |
NodeNotFoundException | If the node is not found. |
Definition at line 174 of file TreeTools.cpp.
|
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.
tree | The tree. |
nodeId | The id of node defining the subtree. |
depths | The map that will contain all the depths of the nodes, with node ids as keys. |
NodeNotFoundException | If the node is not found. |
Definition at line 191 of file TreeTools.cpp.
|
static |
Get the total distance between two nodes.
Sum all branch lengths between two nodes.
tree | The tree to consider. |
nodeId1 | First node id. |
nodeId2 | Second node id. |
NodeNotFoundException | If the node is not found. |
Definition at line 455 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), and bpp::Tree::hasNode().
|
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.
tree | The tree to use. |
Definition at line 702 of file TreeTools.cpp.
References bpp::Tree::getLeafId(), and bpp::Tree::getLeavesNames().
|
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.
tree | The tree. |
nodeId | The id of node defining the subtree. |
NodeNotFoundException | If the node is not found. |
NodeException | If a branch length is lacking. |
Definition at line 209 of file TreeTools.cpp.
|
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.
tree | The tree. |
nodeId | The id of node defining the subtree. |
heights | The map that will contain all the heights of the nodes, with node ids as keys. |
NodeNotFoundException | If the node is not found. |
NodeException | If a branch length is lacking. |
Definition at line 231 of file TreeTools.cpp.
|
static |
Get the id of the last common ancestors of all specified nodes.
Nodes id need not correspond to leaves.
tree | The tree to use. |
nodeIds | The ids of the input nodes. |
NodeNotFoundException | If at least of of input node is not found. |
Definition at line 1172 of file TreeTools.cpp.
|
static |
Get the id of a leaf given its name in a subtree.
tree | The tree |
nodeId | The id of node defining the subtree. |
name | The name of the node. |
NodeNotFoundException | If the node is not found. |
Definition at line 118 of file TreeTools.cpp.
|
static |
Retrieve all leaves from a subtree.
tree | The tree |
nodeId | The id of node defining the subtree. |
NodeNotFoundException | If the node is not found. |
Definition at line 76 of file TreeTools.cpp.
|
static |
Retrieve all leaves from a subtree.
tree | The tree |
nodeId | The id of node defining the subtree. |
leaves | A vector with the ids of all leaves in the subtree. |
NodeNotFoundException | If the node is not found. |
Definition at line 83 of file TreeTools.cpp.
|
static |
Get the maximum identifier used in a (sub)tree.
This is a recursive method.
tree | The tree to check. |
id | The identifier of the subtree from which the recursion will be performed. Use id=tree.getRootId() to search for the whole tree. |
Definition at line 752 of file TreeTools.cpp.
References bpp::Tree::getSonsId().
|
static |
Get the minimum positive non-used identifier in a (sub)tree.
This method uses the recursive method getNodesId, and then sort the ids.
tree | The tree to check. |
id | The identifier of the subtree from which the recursion will be performed. Use id=tree.getRootId() to search for the whole tree. |
Definition at line 767 of file TreeTools.cpp.
Referenced by bpp::TreeTemplate< bpp::NodeTemplate >::getNextId(), and bpp::TreeTemplateTools::midRoot().
|
static |
Retrieve all nodes ids nodes from a subtree.
tree | The tree |
nodeId | The id of the node that defines the subtree. |
NodeNotFoundException | If the node is not found. |
Definition at line 153 of file TreeTools.cpp.
Referenced by bpp::RNonHomogeneousMixedTreeLikelihood::init().
|
static |
Retrieve all nodes ids from a subtree.
tree | The tree |
nodeId | The id of the node that defines the subtree. |
nodes | A vector of ids of each node in the subtree. |
NodeNotFoundException | If the node is not found. |
Definition at line 160 of file TreeTools.cpp.
|
static |
Count the number of leaves from a subtree.
tree | The tree |
nodeId | The id of node defining the subtree. |
NodeNotFoundException | If the node is not found. |
Definition at line 98 of file TreeTools.cpp.
|
static |
Get a vector of ancestor nodes between to nodes.
tree | The tree to use. |
nodeId1 | Id of first node. |
nodeId2 | Id of second node. |
includeAncestor | Tell if the common ancestor must be included in the vector. |
NodeNotFoundException | If the node is not found. |
Definition at line 401 of file TreeTools.cpp.
|
static |
Get the total length (sum of all branch lengths) of a subtree.
tree | The tree. |
nodeId | The node defining 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). |
NodeNotFoundException | If the node is not found. |
NodeException | If a branch length is lacking. |
Definition at line 495 of file TreeTools.cpp.
Tells whether two trees have the same unrooted topology.
Note that the location of the root, if any, is ignored.
Definition at line 841 of file TreeTools.cpp.
References bpp::BipartitionTools::areIdentical(), bpp::Tree::getLeavesNames(), bpp::BipartitionList::getNumberOfBipartitions(), bpp::BipartitionList::getPartitionSize(), bpp::BipartitionList::removeRedundantBipartitions(), bpp::BipartitionList::removeTrivialBipartitions(), and bpp::BipartitionList::sortByPartitionSize().
|
static |
Grafen's method to initialize branch lengths.
Each height of the node (total distance from the leaves) is set equal to the number of leaf nodes for the corresponding subtrees - 1 for inner nodes, 0 for leaves.
If the tree already has branch lengths, they will be ignored.
Reference: Grafen A. The phylogenetic regression. Philos Trans R Soc Lond B Biol Sci. 1989; 326(1233):119-57
tree | The tree. |
Definition at line 576 of file TreeTools.cpp.
References bpp::Tree::getRootId().
|
staticprivate |
Definition at line 558 of file TreeTools.cpp.
|
static |
Majority consensus tree method.
Calls thresholdConsensus with threshold=0.5: internal branches present in a majority of trees are kept.
vecTr | Vector of input trees (must share a common set of leaves - checked if checkNames is true) |
checkNames | Tell whether we should check the trees first. |
Definition at line 1081 of file TreeTools.cpp.
|
static |
(Re)root the tree using the midpoint method.
This methods compute the pairwise distance matrix from the tree and get the maximum distance. The root is then set on the branch located at half this distance.
tree | The tree to (re)root. |
Definition at line 719 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getFatherId(), bpp::Tree::getLeafId(), bpp::Tree::getRootId(), bpp::Tree::getSonsId(), bpp::Tree::isRooted(), bpp::Tree::newOutGroup(), bpp::Tree::setDistanceToFather(), and bpp::Tree::unroot().
Matrix Representation Parsimony supertree method.
This implementation of the MRP method takes a BIONJ tree (Jukes-Cantor distances) as the starting tree and optimizes the parsimony score using only NNI (in a PHYML-like way).
vecTr | A vector of trees. |
Definition at line 1095 of file TreeTools.cpp.
References bpp::BioNJ::computeTree(), bpp::DistanceEstimation::getMatrix(), bpp::AbstractAgglomerativeDistanceMethod::getTree(), MRPEncode(), bpp::OptimizationTools::optimizeTreeNNI(), and bpp::BioNJ::setDistanceMatrix().
|
static |
Creates a sequence data set corresponding to the Matrix Representation of the input trees.
Definition at line 801 of file TreeTools.cpp.
References bpp::BipartitionTools::MRPEncode().
Referenced by MRP(), and MRPMultilabel().
|
static |
Creates a sequence data set corresponding to the Matrix Representation of the input multilabel trees.
Definition at line 821 of file TreeTools.cpp.
References bpp::BipartitionTools::MRPEncodeMultilabel().
Matrix Representation Parsimony supertree method for multilabel trees.
This implementation of the MRP method takes a BIONJ tree (Jukes-Cantor distances) as the starting tree and optimizes the parsimony score using only NNI (in a PHYML-like way).
vecTr | A vector of trees. |
Definition at line 1287 of file TreeTools.cpp.
References bpp::BioNJ::computeTree(), bpp::DistanceEstimation::getMatrix(), bpp::AbstractAgglomerativeDistanceMethod::getTree(), MRPEncode(), bpp::OptimizationTools::optimizeTreeNNI(), and bpp::BioNJ::setDistanceMatrix().
|
static |
Get the parenthesis description of a subtree.
tree | The tree |
nodeId | The id of 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. |
NodeNotFoundException | If the node is not found. |
Definition at line 254 of file TreeTools.cpp.
|
static |
Get the parenthesis description of a subtree.
tree | The tree |
nodeId | 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. |
NodeNotFoundException | If the node is not found. |
Definition at line 292 of file TreeTools.cpp.
|
static |
Calculates the Robinson-Foulds topological distance between two trees.
The two trees must share a common set of leaves (checked if checkNames is true) Three numbers are calculated:
tr1 | First input tree. |
tr2 | Second input tree. |
missing_in_tr2 | Output as the number of bipartitions occurring in the first tree but not the second |
missing_in_tr1 | Output as the number of bipartitions occurring in the second tree but not the first |
checkNames | Tell whether we should check the trees first. |
Exception | If checkNames is set to true and trees do not share the same leaves names. |
Definition at line 892 of file TreeTools.cpp.
References bpp::BipartitionTools::areIdentical(), bpp::BipartitionList::getNumberOfBipartitions(), bpp::BipartitionList::getPartitionSize(), bpp::BipartitionList::removeTrivialBipartitions(), and bpp::BipartitionList::sortByPartitionSize().
Referenced by bpp::OptimizationTools::buildDistanceTree().
|
static |
Scale a given tree.
Multiply all branch lengths by a given factor.
tree | The tree. |
nodeId | The node defining the subtree. |
factor | The factor to multiply all branch lengths with. |
NodeNotFoundException | If the node is not found. |
NodeException | If a branch length is lacking. |
Definition at line 539 of file TreeTools.cpp.
|
static |
Get the id of a leaf given its name in a subtree.
tree | The tree |
nodeId | The id of node defining the subtree. |
name | The name of the node. |
id | The id of the node. |
NodeNotFoundException | If the node is not found. |
Definition at line 133 of file TreeTools.cpp.
|
static |
Set all the branch lengths of a subtree.
tree | The tree. |
nodeId | The node defining the subtree. |
brLen | The branch length to apply. |
NodeNotFoundException | If the node is not found. |
Definition at line 512 of file TreeTools.cpp.
|
static |
Give a length to branches that don't have one in a subtree.
tree | The tree. |
nodeId | The node defining the subtree. |
brLen | The branch length to apply. |
NodeNotFoundException | If the node is not found. |
Definition at line 525 of file TreeTools.cpp.
|
staticprivate |
Definition at line 1256 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getSonsId(), bpp::Tree::isLeaf(), bpp::TreeTools::Moments_::N, bpp::TreeTools::Moments_::squaredSum, and bpp::TreeTools::Moments_::sum.
|
static |
Strict consensus tree method.
Calls thresholdConsensus with threshold=1: only internal branches present in all trees are kept.
vecTr | Vector of input trees (must share a common set of leaves - checked if checkNames is true) |
checkNames | Tell whether we should check the trees first. |
Definition at line 1088 of file TreeTools.cpp.
|
static |
General greedy consensus tree method.
Calculates the consensus tree of a set of trees defined from the number of occurrences of bipartitions. Bipartitions are considered in decreasing score order. A bipartition is included if it is compatible with all previously included bipartitions, and if its score is higher than a threshold.
vecTr | Vector of input trees (must share a common set of leaves - checked if checkNames is true) |
threshold | Minimal acceptable score =number of occurrence of a bipartition/number of trees (0.<=threshold<=1.) |
checkNames | Tell whether we should check the trees first. |
Definition at line 1022 of file TreeTools.cpp.
References bpp::BipartitionList::areCompatible(), bpp::BipartitionList::deleteBipartition(), bpp::BipartitionList::getNumberOfBipartitions(), bpp::BipartitionList::getPartitionSize(), and bpp::BipartitionList::toTree().
|
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 330 of file TreeTools.cpp.
References bpp::Tree::getNodeName(), bpp::Tree::getRootId(), bpp::Tree::getSonsId(), and bpp::Tree::isLeaf().
Referenced by bpp::NexusIOTree::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 362 of file TreeTools.cpp.
References bpp::Tree::getBranchProperty(), bpp::Tree::getNodeName(), bpp::Tree::getRootId(), bpp::Tree::getSonsId(), bpp::Tree::hasBranchProperty(), and bpp::Tree::isLeaf().
|
static |
Bootstrap tag.
Definition at line 723 of file TreeTools.h.
Referenced by bpp::Newick::disableExtendedBootstrapProperty(), bpp::Node::getBootstrapValue(), bpp::Node::hasBootstrapValue(), bpp::Nhx::Nhx(), bpp::TreeTemplateTools::nodeToParenthesis(), bpp::TreeTemplateTools::parenthesisToNode(), and bpp::TreeTemplateTools::treeToParenthesis().