Title: | Calculating Topological Properties of Phylogenies |
---|---|
Description: | Tools for calculating and viewing topological properties of phylogenetic trees. |
Authors: | Michelle Kendall [aut, cre] , Michael Boyd [aut], Caroline Colijn [aut] |
Maintainer: | Michelle Kendall <[email protected]> |
License: | GPL-2 |
Version: | 2.1.2 |
Built: | 2024-11-07 02:56:40 UTC |
Source: | https://github.com/MichelleKendall/phyloTop |
Finds the mean size of ladders in the tree
avgLadder(tree, normalise = FALSE)
avgLadder(tree, normalise = FALSE)
tree |
a tree of class |
normalise |
option to normalise the result, default is |
The mean ladder size
Michelle Kendall [email protected]
## Find the average ladder size in a random tree with 20 tips: tree <- rtree(20) plot(tree) avgLadder(tree) # and the normalised average ladder size: avgLadder(tree, normalise=TRUE)
## Find the average ladder size in a random tree with 20 tips: tree <- rtree(20) plot(tree) avgLadder(tree) # and the normalised average ladder size: avgLadder(tree, normalise=TRUE)
Finds the number of cherries in a tree. A cherry is considered to be a pair of sister tips.
cherries(tree, normalise = FALSE)
cherries(tree, normalise = FALSE)
tree |
a tree of class |
normalise |
option to normalise the result, default is |
An integer representing the number of cherries in the tree.
Michelle Kendall [email protected]
## Find the number of cherries in a random tree with 10 tips: tree <- rtree(10) plot(tree) cherries(tree) # and the normalised cherry number: cherries(tree, normalise=TRUE) ## Note that the function configShow can be used to highlight the cherries in the tree: configShow(tree, 2, edge.width=2)
## Find the number of cherries in a random tree with 10 tips: tree <- rtree(10) plot(tree) cherries(tree) # and the normalised cherry number: cherries(tree, normalise=TRUE) ## Note that the function configShow can be used to highlight the cherries in the tree: configShow(tree, 2, edge.width=2)
Finds the Colless number for a tree.
Note that the package apTreeshape
has a function colless
to compute the Colless imbalance with additional options to normalise it based on the model;
we include this simple function here for convenience within this package, and for use on objects of class phylo
and phylo4
.
colless.phylo(tree, normalise = TRUE)
colless.phylo(tree, normalise = TRUE)
tree |
a tree of class |
normalise |
option to normalise the result by dividing by the number of tip pairs. Defaults to |
The Colless imbalance number of the tree.
Michael Boyd [email protected]
Michelle Kendall [email protected]
## Find the Colless imbalance of a random tree with 10 tips: tree <- rtree(10) plot(tree) colless.phylo(tree)
## Find the Colless imbalance of a random tree with 10 tips: tree <- rtree(10) plot(tree) colless.phylo(tree)
Plot a tree, highlighting configurations of a given size.
configShow(tree, configSize, mainCol = "black", configCol = "red", ...)
configShow(tree, configSize, mainCol = "black", configCol = "red", ...)
tree |
a tree of class |
configSize |
an integer giving the configuration size of interest |
mainCol |
colour for branches which are not in configurations of the chosen size (default is black) |
configCol |
colour for branches which are in such configurations (default is red) |
... |
further arguments to be passed to plot.phylo |
A plot of the tree, highlighting the configurations of the given size.
Michelle Kendall [email protected]
Michael Boyd [email protected]
## Highlight pitchforks in a random tree with 20 tips: configShow(rtree(20),3, edge.width=2)
## Highlight pitchforks in a random tree with 20 tips: configShow(rtree(20),3, edge.width=2)
Determines the depth of each node, defined as the number of steps from the root.
(So the root has depth zero, its children have depth one, etc.)
The output is given as a list of two vectors: tipDepths
gives the depths of the tips, and nodeDepths
gives the depths of the internal nodes.
This replaces the deprecated dists
function.
The code is based on that used in the function computeHeights
in package treeCentrality
.
getDepths(tree)
getDepths(tree)
tree |
a tree of class |
A list of two vectors: tipDepths
gives the depths of the tips, and nodeDepths
gives the depths of the internal nodes.
Michelle Kendall [email protected]
## Find the node depths in a random tree: tree <- rtree(20) treeDepths <- getDepths(tree) ## Plot tree with node depths labelled: tree$tip.label <- treeDepths$tipDepths tree$node.label <- treeDepths$nodeDepths plot(tree, show.node.label=TRUE)
## Find the node depths in a random tree: tree <- rtree(20) treeDepths <- getDepths(tree) ## Plot tree with node depths labelled: tree$tip.label <- treeDepths$tipDepths tree$node.label <- treeDepths$nodeDepths plot(tree, show.node.label=TRUE)
Create a labelled genealogy from an epidemiological record
getLabGenealogy(epirecord, epsilon = 0.001234)
getLabGenealogy(epirecord, epsilon = 0.001234)
epirecord |
an epidemiological record, as output from the function |
epsilon |
an optional small number to be used for branch lengths which would otherwise be zero. |
An object of class phylo
representing the transmission tree from infectors to infectees.
Caroline Colijn [email protected]
Michelle Kendall [email protected]
## Generate an epidemiological record: myepirecord <- makeEpiRecord(c(1,2,3,4)) ## make the corresponding genealogy from this record: mygenealogy <- getLabGenealogy(myepirecord) plot(mygenealogy)
## Generate an epidemiological record: myepirecord <- makeEpiRecord(c(1,2,3,4)) ## make the corresponding genealogy from this record: mygenealogy <- getLabGenealogy(myepirecord) plot(mygenealogy)
Computes the number of internal nodes with a single tip child.
ILnumber(tree, normalise = FALSE)
ILnumber(tree, normalise = FALSE)
tree |
a tree of class |
normalise |
option to normalise the result, default is |
The integer number of internal nodes with a single tip child.
Michael Boyd [email protected]
Michelle Kendall [email protected]
## Find the IL number of a random tree with 10 tips: tree <- rtree(10) plot(tree) ILnumber(tree) ## and the normalised IL number: ILnumber(tree, normalise=TRUE)
## Find the IL number of a random tree with 10 tips: tree <- rtree(10) plot(tree) ILnumber(tree) ## and the normalised IL number: ILnumber(tree, normalise=TRUE)
Plot a tree, highlighting any ladders within it.
ladderShow( tree, mainCol = "black", ladderEdgeCol = "red", ladderNodeCol = "red", ... )
ladderShow( tree, mainCol = "black", ladderEdgeCol = "red", ladderNodeCol = "red", ... )
tree |
a tree of class |
mainCol |
colour for edges which are not ladders (default is black) |
ladderEdgeCol |
colour for ladder edges (default is red) |
ladderNodeCol |
colour for ladder nodes (default is red) |
... |
further arguments to be passed to plot.phylo |
A plot of the tree, with ladder edges and nodes highlighted by colour.
Michelle Kendall [email protected]
Michael Boyd [email protected]
## Highlight in blue the ladders in a random tree with 50 tips: tree <- rtree(50) ladderShow(tree, edge.width=2) # compare to: ladderSizes(tree)
## Highlight in blue the ladders in a random tree with 50 tips: tree <- rtree(50) ladderShow(tree, edge.width=2) # compare to: ladderSizes(tree)
Finds the sizes and positions of ladders in the tree.
A ladder is here defined to be a series of consecutive nodes in the tree,
each of which has exactly one tip child (as counted by ILnumber
).
The size of the ladder is given by the number of nodes in the chain.
ladderSizes(tree)
ladderSizes(tree)
tree |
a tree of class |
A list of:
ladderSizes the sizes of ladders in the tree
ladderNodes the ladder nodes in the tree
ladderEdges the edges between ladder nodes of the tree
Caroline Colijn [email protected]
Michelle Kendall [email protected]
## Find ladder sizes in a random tree with 20 tips: tree <- rtree(20) plot(tree) ladderSizes(tree) # note that the ladders can be highlighted in a plot using ladderShow: ladderShow(tree)
## Find ladder sizes in a random tree with 20 tips: tree <- rtree(20) plot(tree) ladderSizes(tree) # note that the ladders can be highlighted in a plot using ladderShow: ladderShow(tree)
Create an epidemiological record of infectors and infectees with corresponding infection and recovery times
makeEpiRecord(lambda, duration = 1, NumCases = 50)
makeEpiRecord(lambda, duration = 1, NumCases = 50)
lambda |
a numeric vector specifying the time varying intensity lambda(t) which is passed to |
duration |
the fixed duration of infection (default is 1) |
NumCases |
the approximate number of infected cases (default is 50) |
A matrix with columns "Infectee", "Infector", "InfnTime" (infection time), "RecTime" (recovery time), "DoneFlag".
Suitable for using with getLabGenealogy
Caroline Colijn [email protected]
Michelle Kendall [email protected]
myepirecord <- makeEpiRecord(c(1,2,3,4), duration=2, NumCases=100)
myepirecord <- makeEpiRecord(c(1,2,3,4), duration=2, NumCases=100)
Find the maximum height of tips in the tree.
maxHeight(tree, normalise = FALSE)
maxHeight(tree, normalise = FALSE)
tree |
a tree of class |
normalise |
option to normalise the result, default is |
An integer giving the maximum height of tips in the tree.
Michelle Kendall [email protected]
Caroline Colijn [email protected]
## Maximum height of tips in a random tree with 10 tips: tree <- rtree(10) plot(tree) maxHeight(tree) maxHeight(tree, normalise=TRUE)
## Maximum height of tips in a random tree with 10 tips: tree <- rtree(10) plot(tree) maxHeight(tree) maxHeight(tree, normalise=TRUE)
Finds the sizes of configurations in the tree.
nConfig(tree, maxClade = NULL)
nConfig(tree, maxClade = NULL)
tree |
a tree of class |
maxClade |
an integer between 1 and the number of tips (the default), specifying the maximum clade size of interest. |
A list with 2 entries:
cladeSizes is a vector giving the size of the clade descending at each node:tips all have the value 1, internal nodes have their number of tip descendants.
numClades is a vector where numClades[[i]] is the number of clades of size i in the tree.
All clade sizes are calculated, but the output can be restricted using maxClade
to just those of size up to 'maxClade'.
Michelle Kendall [email protected]
## Configuration sizes on a random tree with 10 tips: tree <- rtree(10) plot(tree) nodelabels() nConfig(tree)
## Configuration sizes on a random tree with 10 tips: tree <- rtree(10) plot(tree) nodelabels() nConfig(tree)
Determine the depth of a particular node in a tree, defined as the number of edges between it and the root. (So the root has depth zero, its children have depth one, etc.)
nodeDepth(tree, node)
nodeDepth(tree, node)
tree |
a tree of class |
node |
a number corresponding to a node in the tree. |
An integer corresponding to the depth of the given node.
Michelle Kendall [email protected]
## Find the depth of node 34 in a random tree with 20 tips: tree <- rtree(20) plot(tree) nodelabels() nodeDepth(tree,34)
## Find the depth of node 34 in a random tree with 20 tips: tree <- rtree(20) plot(tree) nodelabels() nodeDepth(tree,34)
Calculate the fraction of nodes with a depth greater than or equal to a given threshold.
nodeDepthFrac(tree, threshold)
nodeDepthFrac(tree, threshold)
tree |
a tree of class |
threshold |
a threshold value for node depth. |
The fraction of nodes with a depth greater than or equal to the threshold (see nodeDepth
for more details on the meaning of node depth).
Michelle Kendall [email protected]
## Find the fraction of nodes with a depth of 5 or more, in a random tree with 20 tips: tree <- rtree(20) tree$edge.length <- rep(1,38) # so that the depths are easier to view in a plot plot(tree) nodeDepthFrac(tree,threshold=5)
## Find the fraction of nodes with a depth of 5 or more, in a random tree with 20 tips: tree <- rtree(20) tree$edge.length <- rep(1,38) # so that the depths are easier to view in a plot plot(tree) nodeDepthFrac(tree,threshold=5)
For a given node, this function gives the number of tips descending from each of its two children, as a measure of imbalance.
nodeImb(tree, node)
nodeImb(tree, node)
tree |
a tree of class |
node |
a node index between 1 and 2n-1, where n is the number of tips in the tree. |
Two integers corresponding to the number of tip descendants of each of the node's two children. If the node is itself a tip, then the vector (0,0) will be returned.
Michelle Kendall [email protected]
## Find the imbalance of node 16 in a random tree with 10 tips: tree <- rtree(10) plot(tree) nodelabels() nodeImb(tree,16)
## Find the imbalance of node 16 in a random tree with 10 tips: tree <- rtree(10) plot(tree) nodelabels() nodeImb(tree,16)
Calculate the fraction of internal nodes with an imbalance greater than or equal to a given threshold.
nodeImbFrac(tree, threshold)
nodeImbFrac(tree, threshold)
tree |
a tree of class |
threshold |
a threshold value for node imbalance. |
For any internal node, the function nodeImb
gives the number of tip descendants of each of the node's descending branches. The function nodeImbFrac
returns the fraction of internal nodes where the difference between these numbers is greater than or equal to the threshold.
Michelle Kendall [email protected]
## Find the fraction of internal nodes with an imbalance of 5 or more, ## in a random tree with 20 tips: tree <- rtree(20) plot(tree) nodeImbFrac(tree,threshold=5)
## Find the fraction of internal nodes with an imbalance of 5 or more, ## in a random tree with 20 tips: tree <- rtree(20) plot(tree) nodeImbFrac(tree,threshold=5)
Calculate a range of topological properties for one or more phylogenetic trees.
phyloTop(treeList, funcs = "all", normalise = FALSE)
phyloTop(treeList, funcs = "all", normalise = FALSE)
treeList |
a |
funcs |
a list of functions. The default is to apply all of the topological functions from the package, but a subset can be specified instead. The functions available are:
|
normalise |
option to normalise the results of functions where possible. Default is |
A matrix where rows correspond to trees and columns correspond to topological properties.
Michelle Kendall [email protected]
avgLadder
, cherries
, colless.phylo
, ILnumber
, maxHeight
, pitchforks
, sackin.phylo
, stairs
## Apply all of the functions to a list of 10 random trees, each with 50 tips: phyloTop(rmtree(10,50)) ## Normalising the results where possible: phyloTop(rmtree(10,50), normalise=TRUE)
## Apply all of the functions to a list of 10 random trees, each with 50 tips: phyloTop(rmtree(10,50)) ## Normalising the results where possible: phyloTop(rmtree(10,50), normalise=TRUE)
Finds the number of pitchforks in a tree. A pitchfork is considered to be a clade with three tips.
pitchforks(tree, normalise = FALSE)
pitchforks(tree, normalise = FALSE)
tree |
a tree of class |
normalise |
option to normalise the result, default is |
An integer representing the number of pitchforks in the tree.
Michelle Kendall [email protected]
## Find the number of pitchforks in a random tree with 20 tips: tree <- rtree(20) plot(tree) pitchforks(tree) # and the normalised pitchfork number: pitchforks(tree, normalise=TRUE) ## Note that the function configShow can be used to highlight the pitchforks in the tree: configShow(tree, 3, edge.width=2)
## Find the number of pitchforks in a random tree with 20 tips: tree <- rtree(20) plot(tree) pitchforks(tree) # and the normalised pitchfork number: pitchforks(tree, normalise=TRUE) ## Note that the function configShow can be used to highlight the pitchforks in the tree: configShow(tree, 3, edge.width=2)
Creates a random phylo4 tree, in parallel to ape
's rtree
function.
rtree4(n, ...)
rtree4(n, ...)
n |
an integer giving the number of tips in the tree |
... |
further arguments to be passed to rtree |
An object of class "phylo4"
.
Michael Boyd [email protected]
Michelle Kendall [email protected]
## Create a random phylo4 tree with 10 tips: tree4 <- rtree4(10)
## Create a random phylo4 tree with 10 tips: tree4 <- rtree4(10)
Finds the Sackin index for a tree.
Note that the package apTreeshape
has a function sackin
to compute the Sackin index with additional options to normalise it based on the model;
we include this simple function here for convenience within this package, and for use on objects of class phylo
and phylo4
.
sackin.phylo(tree, normalise = FALSE)
sackin.phylo(tree, normalise = FALSE)
tree |
a tree of class |
normalise |
option to normalise the result, default is |
The Sackin index of the tree.
Michael Boyd [email protected]
Michelle Kendall [email protected]
## Sackin index of a random tree with 10 tips: sackin.phylo(rtree(10)) ## normalised Sackin index: sackin.phylo(rtree(10), normalise=TRUE)
## Sackin index of a random tree with 10 tips: sackin.phylo(rtree(10)) ## normalised Sackin index: sackin.phylo(rtree(10), normalise=TRUE)
For each node at a given distance from the root, this function finds the size of its induced subclade, i.e. its number of tip descendants.
splitTop(tree, dist)
splitTop(tree, dist)
tree |
a tree of class |
dist |
integer distance of nodes of interest from the root. |
A vector of integers, each corresponding to the clade size of a node at the given distance from the root. The clade sizes are given in ascending order and each is labelled by its node name or number. This vector can be considered as a partition of the tips or the "split topology" of the tree at a given depth.
Michelle Kendall [email protected]
Michael Boyd [email protected]
## Find the split topology of a random tree with 20 tips, at a distance 2 from the root: tree <- rtree(20) plot(tree) splitTop(tree,2)
## Find the split topology of a random tree with 20 tips, at a distance 2 from the root: tree <- rtree(20) plot(tree) splitTop(tree,2)
Calculates the staircase-ness measure defined in Norstrom et al., Evolutionary Bioinformatics online, 8:261 (2012) doi:10.4137/EBO.S9738.
stairs(tree)
stairs(tree)
tree |
a tree of class |
Two numbers corresponding to the two staircase-ness measures for a tree. These are two related measures:
1: the proportion of subtrees that are imbalanced (i.e. subtrees where the left child has more tip descendants than the right child, or vice versa)
2: the average of all the min(l,r)/max(l,r) values of each subtree, where l and r are the number of tips in the left and right children of a subtree.
Michelle Kendall [email protected]
## Find the staircase-ness measures in a random tree with 20 tips: stairs(rtree(20))
## Find the staircase-ness measures in a random tree with 20 tips: stairs(rtree(20))
Plot a tree, highlighting the clade(s) descending from the given node(s)
subtreeShow( tree, nodeList, showNodeLabels = "nodeList", mainCol = "black", subtreeCol = "red", nodeLabelCol = "lightblue", ... )
subtreeShow( tree, nodeList, showNodeLabels = "nodeList", mainCol = "black", subtreeCol = "red", nodeLabelCol = "lightblue", ... )
tree |
a tree of class |
nodeList |
a list of one or more internal nodes in the tree. |
showNodeLabels |
option of whether to show node labels. Default is "nodeList", which only labels the nodes in |
mainCol |
colour for the edges which are not highlighted (default is black). |
subtreeCol |
colour for the edges which are highlighted (default is red). |
nodeLabelCol |
background colour for any node labels shown (default is light blue) |
... |
further arguments to be passed to plot.phylo |
A plot of the tree, with clade(s) descending from the given node(s) highlighted.
Michelle Kendall [email protected]
## Highlight the clade(s) descending from nodes 23 and 35 in a random tree on 20 tips: tree <- rtree(20) subtreeShow(tree, nodeList=c(23,35)) # change aesthetics: subtreeShow(tree,nodeList=c(23,35), mainCol="navy", subtreeCol="cyan", nodeLabelCol="cyan", edge.width=2)
## Highlight the clade(s) descending from nodes 23 and 35 in a random tree on 20 tips: tree <- rtree(20) subtreeShow(tree, nodeList=c(23,35)) # change aesthetics: subtreeShow(tree,nodeList=c(23,35), mainCol="navy", subtreeCol="cyan", nodeLabelCol="cyan", edge.width=2)
Find the imbalance of each node, that is the number of tip descendants of each of its two children. With thanks to Leonid Chindelevitch for use of code from computeLRValues
from treeCentrality
.
treeImb(tree)
treeImb(tree)
tree |
a tree of class |
A matrix where rows correspond to nodes of the tree. The two column entries correspond to the number of tip descendants of each of its two children. (Note that this is the transform of the output in phyloTop version 1.0.0.) Where the row number corresponds to a tip, the entries are (0,0).
Michelle Kendall [email protected]
## Find the imbalance numbers in a random tree with 10 tips: tree <- rtree(10) plot(tree) nodelabels() treeImb(tree)
## Find the imbalance numbers in a random tree with 10 tips: tree <- rtree(10) plot(tree) nodelabels() treeImb(tree)
Find the number of nodes at each depth in the tree
widths(tree)
widths(tree)
tree |
a tree of class |
A vector of widths, where entry i is the number of nodes at depth i. There is a single node at depth 0 (the root) which is not included in the vector, for simplicity.
Caroline Colijn [email protected]
Michelle Kendall [email protected]
## Find the node widths in a random tree with 10 tips: tree <- rtree(10) tree$edge.length <- rep(1,18) # to make it easier to see the width and depths in the plot plot(tree) widths(tree)
## Find the node widths in a random tree with 10 tips: tree <- rtree(10) tree$edge.length <- rep(1,18) # to make it easier to see the width and depths in the plot plot(tree) widths(tree)