bpp-phyl3
3.0.0
|
Generic utilitary methods dealing with trees. More...
#include <Bpp/Phyl/Tree/TreeTools.h>
Classes | |
struct | Moments_ |
Public Member Functions | |
TreeTools () | |
virtual | ~TreeTools () |
Static Public Member Functions | |
static std::unique_ptr< Tree > | MRP (const std::vector< std::unique_ptr< Tree >> &vecTr) |
Matrix Representation Parsimony supertree method. More... | |
static void | computeBootstrapValues (Tree &tree, const std::vector< std::unique_ptr< 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 std::unique_ptr< 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) |
Retrieve all leaves from a subtree. More... | |
static void | getLeavesId (const Tree &tree, int nodeId, std::vector< int > &leaves) |
Retrieve all leaves from a subtree. More... | |
static size_t | getNumberOfLeaves (const Tree &tree, int nodeId) |
Count the number of leaves from a subtree. More... | |
static int | getLeafId (const Tree &tree, int nodeId, const std::string &name) |
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) |
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) |
Get a vector of ancestor nodes between to nodes. More... | |
static std::vector< int > | getAncestors (const Tree &tree, int nodeId) |
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) |
Get the id of the last common ancestors of all specified nodes. More... | |
static size_t | getDepth (const Tree &tree, int nodeId) |
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) |
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) |
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) |
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. | |
static std::string | nodeToParenthesis (const Tree &tree, int nodeId, bool writeId=false) |
Get the parenthesis description of a subtree. More... | |
static std::string | nodeToParenthesis (const Tree &tree, int nodeId, bool bootstrap, const std::string &propertyName) |
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) |
Retrieve all nodes ids nodes from a subtree. More... | |
static void | getNodesId (const Tree &tree, int nodeId, std::vector< int > &nodes) |
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) |
Check if the ids are uniques. More... | |
Topology methods | |
static std::unique_ptr< VectorSiteContainer > | MRPEncode (const std::vector< std::unique_ptr< Tree >> &vecTr) |
Creates a sequence data set corresponding to the Matrix Representation of the input trees. More... | |
static std::unique_ptr< VectorSiteContainer > | MRPEncodeMultilabel (const std::vector< std::unique_ptr< 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) |
Calculates the Robinson-Foulds topological distance between two trees. More... | |
static std::unique_ptr< BipartitionList > | bipartitionOccurrences (const std::vector< std::unique_ptr< Tree >> &vecTr, std::vector< size_t > &bipScore) |
Counts the total number of occurrences of every bipartition from the input trees. More... | |
static std::unique_ptr< TreeTemplate< Node > > | thresholdConsensus (const std::vector< std::unique_ptr< Tree >> &vecTr, double threshold, bool checkNames=true) |
General greedy consensus tree method. More... | |
static std::unique_ptr< TreeTemplate< Node > > | fullyResolvedConsensus (const std::vector< std::unique_ptr< Tree >> &vecTr, bool checkNames=true) |
Fully-resolved greedy consensus tree method. More... | |
static std::unique_ptr< TreeTemplate< Node > > | majorityConsensus (const std::vector< std::unique_ptr< Tree >> &vecTr, bool checkNames=true) |
Majority consensus tree method. More... | |
static std::unique_ptr< TreeTemplate< Node > > | strictConsensus (const std::vector< std::unique_ptr< Tree >> &vecTr, bool checkNames=true) |
Strict consensus tree method. More... | |
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) |
Act on branch lengths. | |
static Vdouble | getBranchLengths (const Tree &tree, int nodeId) |
Get all the branch lengths of a subtree. More... | |
static double | getTotalLength (const Tree &tree, int nodeId, bool includeAncestor=true) |
Get the total length (sum of all branch lengths) of a subtree. More... | |
static void | setBranchLengths (Tree &tree, int nodeId, double brLen) |
Set all the branch lengths of a subtree. More... | |
static void | setVoidBranchLengths (Tree &tree, int nodeId, double brLen) |
Give a length to branches that don't have one in a subtree. More... | |
static void | scaleTree (Tree &tree, int nodeId, double factor) |
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) |
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 std::unique_ptr< 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) |
static void | computeBranchLengthsGrafen (Tree &tree, int nodeId, double power, double total, double &height, double &heightRaised) |
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 30 of file TreeTools.h.
|
inline |
Definition at line 33 of file TreeTools.h.
|
inlinevirtual |
Definition at line 34 of file TreeTools.h.
|
staticprivate |
Definition at line 1175 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 908 of file TreeTools.cpp.
References bpp::BipartitionTools::mergeBipartitionLists().
|
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 747 of file TreeTools.cpp.
References bpp::Tree::getNodesId(), and bpp::TextTools::toString().
Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::init_(), and bpp::AbstractHomogeneousTreeLikelihood::init_().
|
static |
Compute bootstrap values.
tree | Input tree. the BOOTSTRAP branch 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 | The output format of the tree. |
Definition at line 1072 of file TreeTools.cpp.
References bpp::BipartitionTools::areIdentical(), bpp::ApplicationTools::displayGauge(), bpp::BipartitionList::getNumberOfBipartitions(), bpp::Tree::isLeaf(), bpp::pow(), and bpp::Tree::setBranchProperty().
|
static |
Compute branch lengths using Grafen's method.
The 'height' of each node is divided 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 584 of file TreeTools.cpp.
References bpp::Tree::getRootId().
Referenced by bpp::LegacyPhylogeneticsApplicationTools::getTrees().
|
staticprivate |
Definition at line 550 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getSonsId(), bpp::Tree::hasDistanceToFather(), bpp::Tree::hasNode(), bpp::pow(), and bpp::Tree::setDistanceToFather().
|
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 1153 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getRootId(), bpp::Tree::getSonsId(), bpp::Tree::isMultifurcating(), bpp::Tree::isRooted(), and bpp::Tree::setDistanceToFather().
Referenced by bpp::LegacyPhylogeneticsApplicationTools::getTrees().
|
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 height 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 599 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getSonsId(), bpp::Tree::hasDistanceToFather(), bpp::Tree::hasNode(), and bpp::Tree::setDistanceToFather().
Referenced by bpp::LegacyPhylogeneticsApplicationTools::getTrees().
|
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 634 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 1019 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 1106 of file TreeTools.cpp.
References bpp::Tree::getFatherId(), and bpp::Tree::hasFather().
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 439 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getSonsId(), bpp::Tree::hasDistanceToFather(), and bpp::Tree::hasNode().
|
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 138 of file TreeTools.cpp.
References bpp::Tree::getSonsId(), and bpp::Tree::hasNode().
|
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 155 of file TreeTools.cpp.
References bpp::Tree::getSonsId(), and bpp::Tree::hasNode().
|
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 422 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 667 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 173 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getSonsId(), bpp::Tree::hasDistanceToFather(), and bpp::Tree::hasNode().
Referenced by bpp::LegacyPhylogeneticsApplicationTools::getTrees().
|
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 195 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getSonsId(), bpp::Tree::hasDistanceToFather(), and bpp::Tree::hasNode().
|
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 1120 of file TreeTools.cpp.
References count(), and bpp::Tree::getRootId().
|
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 84 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 42 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 49 of file TreeTools.cpp.
References bpp::Tree::getSonsId(), bpp::Tree::hasNode(), and bpp::Tree::isLeaf().
|
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 716 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 731 of file TreeTools.cpp.
Referenced by bpp::TreeTemplate< N >::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 117 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 124 of file TreeTools.cpp.
References bpp::Tree::getSonsId(), and bpp::Tree::hasNode().
|
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 64 of file TreeTools.cpp.
References bpp::Tree::getSonsId(), bpp::Tree::hasNode(), and bpp::Tree::isLeaf().
|
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 369 of file TreeTools.cpp.
References bpp::Tree::getFatherId(), bpp::Tree::hasFather(), and bpp::Tree::hasNode().
|
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 462 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::getSonsId(), bpp::Tree::hasDistanceToFather(), and bpp::Tree::hasNode().
Tells whether two trees have the same unrooted topology.
Definition at line 791 of file TreeTools.cpp.
References bpp::BipartitionTools::areIdentical(), bpp::Tree::getLeavesNames(), and bpp::VectorTools::haveSameElements().
|
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 543 of file TreeTools.cpp.
References bpp::Tree::getRootId().
|
staticprivate |
Definition at line 525 of file TreeTools.cpp.
References bpp::Tree::getSonsId(), bpp::Tree::hasNode(), and bpp::Tree::setDistanceToFather().
|
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 1026 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 684 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(), bpp::Tree::unroot(), and bpp::MatrixTools::whichMax().
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 1040 of file TreeTools.cpp.
|
static |
Creates a sequence data set corresponding to the Matrix Representation of the input trees.
Definition at line 765 of file TreeTools.cpp.
References bpp::BipartitionTools::MRPEncode().
|
static |
Creates a sequence data set corresponding to the Matrix Representation of the input multilabel trees.
Definition at line 778 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 1235 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 written. 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 256 of file TreeTools.cpp.
References bpp::Tree::getBranchProperty(), bpp::Tree::getDistanceToFather(), bpp::Tree::getNodeName(), bpp::Tree::getSonsId(), bpp::Tree::hasBranchProperty(), bpp::Tree::hasDistanceToFather(), bpp::Tree::hasNode(), and bpp::Tree::hasNoSon().
|
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 218 of file TreeTools.cpp.
References bpp::Tree::getBranchProperty(), bpp::Tree::getDistanceToFather(), bpp::Tree::getNodeName(), bpp::Tree::getSonsId(), bpp::Tree::hasBranchProperty(), bpp::Tree::hasDistanceToFather(), bpp::Tree::hasNode(), and bpp::Tree::hasNoSon().
|
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 842 of file TreeTools.cpp.
References bpp::BipartitionTools::areIdentical(), bpp::Tree::getLeavesNames(), and bpp::VectorTools::haveSameElements().
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 506 of file TreeTools.cpp.
References bpp::Tree::getDistanceToFather(), bpp::Tree::hasDistanceToFather(), bpp::Tree::hasFather(), bpp::Tree::hasNode(), and bpp::Tree::setDistanceToFather().
|
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 98 of file TreeTools.cpp.
References bpp::Tree::getNodeName(), and bpp::Tree::hasNoSon().
|
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 479 of file TreeTools.cpp.
References bpp::Tree::hasNode(), and bpp::Tree::setDistanceToFather().
|
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 492 of file TreeTools.cpp.
References bpp::Tree::hasDistanceToFather(), bpp::Tree::hasNode(), and bpp::Tree::setDistanceToFather().
|
staticprivate |
Definition at line 1204 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 1033 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 969 of file TreeTools.cpp.
References bpp::VectorTools::haveSameElements().
|
static |
Get the parenthesis description of a tree.
tree | The tree to convert. |
bootstrap | Tell is bootstrap values must be written. 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 328 of file TreeTools.cpp.
References bpp::Tree::getBranchProperty(), bpp::Tree::getNodeName(), bpp::Tree::getRootId(), bpp::Tree::getSonsId(), bpp::Tree::hasBranchProperty(), and bpp::Tree::hasNoSon().
|
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 296 of file TreeTools.cpp.
References bpp::Tree::getNodeName(), bpp::Tree::getRootId(), bpp::Tree::getSonsId(), and bpp::Tree::hasNoSon().
Referenced by bpp::NexusIOTree::write_(), and bpp::Newick::write_().
|
static |
Bootstrap tag.
Definition at line 684 of file TreeTools.h.
Referenced by bpp::Node::getBootstrapValue(), bpp::Node::hasBootstrapValue(), bpp::Nhx::Nhx(), bpp::TreeTemplateTools::nodeToParenthesis(), bpp::TreeTemplateTools::parenthesisToNode(), and bpp::TreeTemplateTools::treeToParenthesis().