public class TreeUtils
extends java.lang.Object
Constructor | Description |
---|---|
TreeUtils() |
Modifier and Type | Method | Description |
---|---|---|
static void |
computeAllDistances(Tree tree,
int a,
double[] dist,
double[] idist,
boolean countEdges,
double epsilon) |
|
static double |
computeDistance(Tree tree,
int a,
int b) |
compute distance between two external nodes
|
static Alignment |
extractAlignment(Tree tree) |
Extracts an alignment from a tree.
|
static Alignment |
extractAlignment(Tree tree,
boolean leaveSeqsInTree) |
Extracts an alignment from a tree.
|
static TimeOrderCharacterData |
extractTimeOrderCharacterData(Tree tree,
int units) |
Extracts a time order character data from a tree.
|
static Tree |
generationsToMutations(Tree generationTree,
MutationRateModel muModel) |
Takes a tree (in generation units) and returns a scaled version of it (in mutation units).
|
static Tree |
generationsToMutations(Tree generationTree,
MutationRateModel muModel,
double generationTime) |
Takes a tree (in generation units) and returns a scaled version of it (in mutation units).
|
static Tree |
getBootstrapSupportByCladeTree(java.lang.String attributeName,
Tree baseTree,
Tree[] alternativeTrees) |
Deprecated.
Use getReplicateCladeSupport instead
|
static IdGroup |
getLeafIdGroup(Tree tree) |
get list of the identifiers of the external nodes
|
static Node |
getNodeByName(Node root,
java.lang.String name) |
|
static Node |
getNodeByName(Tree tree,
java.lang.String name) |
|
static Tree |
getNumberRelabelledTree(Tree baseTree,
IdGroup ids) |
Create a new tree such that the labels are redifined from a base tree in such a manner:
For each leaf label
If the base label is not a number the new label is just the original label
If the base label is a number the new label appropriately index label from a set identifiers
|
static Node |
getRandomNode(Tree tree) |
Returns a uniformly distributed random node from the tree, including
both internal and external nodes.
|
static Tree |
getReplicateCladeSupport(java.lang.String attributeName,
Tree baseTree,
TreeGenerator treeGenerator,
int numberOfReplicates,
AlgorithmCallback callback) |
Generates a tree which is identical to baseTree but has attributes (defined by attributeName)
at all internal nodes excluding the root node signifying (as a value between 0 and 100) the replicate
support by clade (that is the proportion of replicates that produce the sub clade under that node)
|
static double |
getRobinsonFouldsDistance(SplitSystem s1,
Tree t2) |
computes Robinson-Foulds (1981) distance between two trees
|
static double |
getRobinsonFouldsDistance(Tree t1,
Tree t2) |
computes Robinson-Foulds (1981) distance between two trees
|
static double |
getRobinsonFouldsRescaledDistance(SplitSystem s1,
Tree t2) |
computes Robinson-Foulds (1981) distance between two trees
rescaled to a number between 0 and 1
|
static double |
getRobinsonFouldsRescaledDistance(Tree t1,
Tree t2) |
computes Robinson-Foulds (1981) distance between two trees
rescaled to a number between 0 and 1
|
static Tree |
getScaled(Tree oldTree,
double rate) |
Takes a tree and returns a scaled version of it.
|
static Tree |
getScaled(Tree oldTree,
double rate,
int newUnits) |
Takes a tree and returns a scaled version of it.
|
static Tree |
getScaled(Tree mutationRateTree,
MutationRateModel muModel) |
Takes a tree and returns a scaled version of it.
|
static Tree |
getScaled(Tree mutationRateTree,
MutationRateModel muModel,
int newUnits) |
Takes a tree and returns a scaled version of it.
|
static void |
labelInternalNodes(Tree tree) |
Labels the internal nodes of the tree using numbers starting from 0.
|
static int[] |
mapExternalIdentifiers(IdGroup idGroup,
Tree tree) |
map external identifiers in the tree to a set of given identifiers
(which can be larger than the set of external identifiers but
must contain all of them)
NOTE: for efficiency it is assumed that the node lists of the tree are
correctly maintained.
|
static Tree |
mutationsToGenerations(Tree mutationTree,
MutationRateModel muModel) |
Takes a tree (in mutation units) and returns a scaled version of it (in generation units).
|
static void |
printNH(Tree tree,
java.io.PrintWriter out) |
print a this tree in New Hampshire format
(including distances and internal labels)
|
static void |
printNH(Tree tree,
java.io.PrintWriter out,
boolean printLengths,
boolean printInternalLabels) |
print this tree in New Hampshire format
|
static void |
renameNodes(Tree tree,
java.util.Hashtable table) |
Given a translation table where the keys are the current
identifier names and the values are the new identifier names,
this method replaces the current identifiers in the tree with new
identifiers.
|
static void |
report(Tree tree,
java.io.PrintWriter out) |
|
static void |
reroot(Tree tree,
Node node) |
|
static void |
rotateByLeafCount(Tree tree) |
Rotates branches by leaf count.
|
static Tree |
scale(Tree oldTree,
double rate,
int newUnits) |
Deprecated.
use getScaled()
|
static Tree |
scale(Tree mutationRateTree,
MutationRateModel muModel) |
Deprecated.
use getScaled()
|
static Tree |
scale(Tree mutationRateTree,
MutationRateModel muModel,
int newUnits) |
Deprecated.
use getScaled()
|
public static double getRobinsonFouldsDistance(Tree t1, Tree t2)
t1
- tree 1t2
- tree 2
Definition: Assuming that t1 is the reference tree, let fn be the
false negatives, i.e. the number of edges in t1 missing in t2,
and fp the number of false positives, i.e. the number of edges
in t2 missing in t1. The RF distance is then (fn + fp)/2public static double getRobinsonFouldsDistance(SplitSystem s1, Tree t2)
s1
- tree 1 (as represented by a SplitSystem)t2
- tree 2public static double getRobinsonFouldsRescaledDistance(Tree t1, Tree t2)
t1
- tree 1t2
- tree 2public static double getRobinsonFouldsRescaledDistance(SplitSystem s1, Tree t2)
s1
- tree 1 (as represented by a SplitSystem)t2
- tree 2public static Node getRandomNode(Tree tree)
public static final Node getNodeByName(Tree tree, java.lang.String name)
tree
- The Tree supposidly containing such a named nodename
- The name of the node to find.public static final Node getNodeByName(Node root, java.lang.String name)
root
- The root node of a treename
- The name of the node to find.public static Tree mutationsToGenerations(Tree mutationTree, MutationRateModel muModel)
mutationRateModel
- the mutation rate model used for scaling
and the desired units are expected substitutions then this scale
factor should be equal to the mutation rate.newUnits
- the new units of the tree.public static Tree generationsToMutations(Tree generationTree, MutationRateModel muModel)
mutationRateModel
- the mutation rate model.
The mutation rate must be in units of mutations per site per generation.public static Tree generationsToMutations(Tree generationTree, MutationRateModel muModel, double generationTime)
mutationRateModel
- the mutation rate model in calendar units.generationTime
- the length of a generation in calendar units.
If the mutation rate is in mutations per site per year, then the
generation time will be in generations per year.public static Tree scale(Tree oldTree, double rate, int newUnits)
public static final Tree getScaled(Tree oldTree, double rate)
rate
- scale factor.public static final Tree getScaled(Tree oldTree, double rate, int newUnits)
rate
- scale factor. If the original tree is in generations
and the desired units are expected substitutions then this scale
factor should be equal to the mutation rate.newUnits
- the new units of the tree.public static Tree scale(Tree mutationRateTree, MutationRateModel muModel)
public static Tree getScaled(Tree mutationRateTree, MutationRateModel muModel)
rate
- scale factor. If the original tree is in generations
and the desired units are expected substitutions then this scale
factor should be equal to the mutation rate.public static Tree scale(Tree mutationRateTree, MutationRateModel muModel, int newUnits)
public static Tree getScaled(Tree mutationRateTree, MutationRateModel muModel, int newUnits)
rate
- scale factor. If the original tree is in generations
and the desired units are expected substitutions then this scale
factor should be equal to the mutation rate.newUnits
- the new units of the tree. (Such as the mutationTree is measured in expected substitutions/newUnits)public static void renameNodes(Tree tree, java.util.Hashtable table)
public static void rotateByLeafCount(Tree tree)
public static final IdGroup getLeafIdGroup(Tree tree)
public static final int[] mapExternalIdentifiers(IdGroup idGroup, Tree tree) throws java.lang.IllegalArgumentException
idGroup
- an ordered group of identifiersjava.lang.IllegalArgumentException
public static final void labelInternalNodes(Tree tree)
public static TimeOrderCharacterData extractTimeOrderCharacterData(Tree tree, int units)
public static Alignment extractAlignment(Tree tree, boolean leaveSeqsInTree)
public static Alignment extractAlignment(Tree tree)
public static void printNH(Tree tree, java.io.PrintWriter out)
out
- output streampublic static void printNH(Tree tree, java.io.PrintWriter out, boolean printLengths, boolean printInternalLabels)
out
- output streamprintLengths
- boolean variable determining whether
branch lengths should be included in outputprintInternalLabels
- boolean variable determining whether
internal labels should be included in outputpublic static void computeAllDistances(Tree tree, int a, double[] dist, double[] idist, boolean countEdges, double epsilon)
public static final double computeDistance(Tree tree, int a, int b)
tree
- treea
- external node 1b
- external node 2public static void report(Tree tree, java.io.PrintWriter out)
public static final Tree getBootstrapSupportByCladeTree(java.lang.String attributeName, Tree baseTree, Tree[] alternativeTrees)
public static final Tree getReplicateCladeSupport(java.lang.String attributeName, Tree baseTree, TreeGenerator treeGenerator, int numberOfReplicates, AlgorithmCallback callback)
attributeName
- the name attached to the attribute which holds the clade support valuebaseTree
- the baseTreetreeGenerator
- the source of the replicates. This approach is used of supplying an
array of trees as it can save memory! For bootstrap analysis, create an iterator that builds new trees based on bootstrap alignment.numberOfReplicates
- the number of replicates to extract from the TreeGenerator for
use in calculating clade support (does not include base tree)callback
- An AlgorithmCallback object for monitoring progresspal.gui.TreePainter.BOOTSTRAP_ATTRIBUTE_NAME
public static final Tree getNumberRelabelledTree(Tree baseTree, IdGroup ids)
baseTree
- The base treeids
- The set of identifiers