bioconductor v3.9.0 Treeio

Base classes and functions for parsing and exporting phylogenetic trees. 'treeio' supports parsing analysis findings from commonly used software packages, allows linking external data to phylogeny and merging tree data obtained from different sources. It also supports exporting phylogenetic tree with heterogeneous associated data to a single tree file.

Link to this section Summary

Functions

as.treedata

drop.tip method

getNodeNum

get.placements

get.tree

get.treetext method

isTip

is.ggtree

Class "jplace" This class stores phylogenetic placements

label_branch_paml

mask

merge_tree

treeAnno.pml

raxml2nwk

read.jtree

read.astral

read.codeml

read.codeml_mlc

read.fasta

read.hyphy

read.hyphy.seq

read.iqtree

read.jplace

read.newick

read.nhx

read.paml_rst

read.phylip

read.phylip.seq

read.phylip.tree

read.phyloT

read.r8s

read.raxml

Objects exported from other packages

rename_taxa

rescale_tree

taxa_rename

Subset tree objects by related nodes

write.jtree

write.beast

write.jplace

Link to this section Functions

Link to this function

Nnodetreedata()

Nnode

Description

number of nodes

Usage

list(list("Nnode"), list("treedata"))(phy, internal.only = TRUE, ...)

Arguments

ArgumentDescription
phytreedata object
internal.onlywhether only count internal nodes
...additional parameters

Value

number of nodes

Author

guangchuang yu

Examples

Nnode(rtree(30))

as.treedata

Description

convert phylo to treedata

Usage

list(list("as.treedata"), list("phylo"))(tree, boot = NULL, ...)

Arguments

ArgumentDescription
treeinput tree, a phylo object
bootoptional, can be bootstrap value from ape::boot.phylo
...additional parameters

Details

converting phylo object to treedata object

Author

guangchuang yu

Link to this function

beast_mrbayes_parser()

read.beast

Description

read beast output

Usage

read.beast(file)
read.mrbayes(file)

Arguments

ArgumentDescription
filebeast file

Value

beast object

Author

Guangchuang Yu https://guangchuangyu.github.io

Examples

file <- system.file("extdata/BEAST", "beast_mcc.tree", package="treeio")
read.beast(file)
Link to this function

droptip_methods()

drop.tip method

Description

drop.tip method

drop.tip method

Usage

drop.tip(object, tip, ...)
drop.tip(object, tip, ...)
list(list("drop.tip"), list("phylo"))(object, tip, ...)

Arguments

ArgumentDescription
objectA treedata or phylo object
tipa vector of mode numeric or character specifying the tips to delete
...additional parameters

Value

updated object

Seealso

drop.tip

Author

Casey Dunn http://dunnlab.org and Guangchuang Yu https://guangchuangyu.github.io

Examples

nhxfile <- system.file("extdata/NHX", "ADH.nhx", package="treeio")
nhx <- read.nhx(nhxfile)
drop.tip(nhx, c("ADH2", "ADH1"))

getNodeNum

Description

calculate total number of nodes

Usage

getNodeNum(tree)
Nnode2(tree)

Arguments

ArgumentDescription
treetree object

Value

number

Author

Guangchuang Yu

Examples

getNodeNum(rtree(30))
Nnode2(rtree(30))
Link to this function

get_placements()

get.placements

Description

access placement information

Usage

get.placements(tree, ...)
list(list("get.placements"), list("jplace"))(tree, by = "best", ...)

Arguments

ArgumentDescription
treetree object
...additional parameters
byone of 'best' and 'all'

Value

placement tibble

get.tree

Description

access phylo slot

Usage

get.tree(x, ...)

Arguments

ArgumentDescription
xtree object
...additional parameters

Value

phylo object

Author

guangchuang yu

Link to this function

gettreetext_methods()

get.treetext method

Description

access tree text (newick text) from tree object

Usage

get.treetext(object, ...)
list(list("get.treetext"), list("treedata"))(object)

Arguments

ArgumentDescription
objecttreedata object
...additional parameter

Value

phylo object

isTip

Description

whether the node is a tip

Usage

isTip(.data, .node, ...)
list(list("isTip"), list("tbl_tree"))(.data, .node, ...)
list(list("isTip"), list("phylo"))(.data, .node, ...)
list(list("isTip"), list("treedata"))(.data, .node, ...)

Arguments

ArgumentDescription
.dataphylo, treedata or tbl_tree object
.nodenode number
...additional parameters

Value

logical value

Author

Guangchuang Yu

is.ggtree

Description

test whether input object is produced by ggtree function

Usage

is.ggtree(x)

Arguments

ArgumentDescription
xobject

Value

TRUE or FALSE

Author

guangchuang yu

Class "jplace" This class stores phylogenetic placements

Description

Class "jplace" This class stores phylogenetic placements

Author

guangchuang yu https://guangchuangyu.github.io

Link to this function

label_branch_paml()

label_branch_paml

Description

label branch for PAML to infer selection pressure using branch model

Usage

label_branch_paml(tree, node, label)

Arguments

ArgumentDescription
treephylo object
nodenode number
labellabel of branch, e.g. #1

Value

updated phylo object

Author

guangchuang yu

mask

Description

site mask

Usage

mask(tree_object, field, site, mask_site = FALSE)

Arguments

ArgumentDescription
tree_objecttree object
fieldselected field
sitesite
mask_siteif TRUE, site will be masked. if FALSE, selected site will not be masked, while other sites will be masked.

Value

updated tree object

Author

Guangchuang Yu

merge_tree

Description

merge two tree object

Usage

merge_tree(obj1, obj2)

Arguments

ArgumentDescription
obj1tree object 1
obj2tree object 2

Value

tree object

Author

Guangchuang Yu

treeAnno.pml

Description

tree annotation of sequence substitution by comparing to parent node

Usage

phyPML(pmlTree, type = "ml")

Arguments

ArgumentDescription
pmlTreetree in pml object, output of phangorn::optim.pml
typeone of 'ml' and 'bayes' for inferring ancestral sequences

Value

phangorn object

Author

Yu Guangchuang

Link to this function

printbeastList()

print

Description

print information of a list of beast trees

Usage

list(list("print"), list("beastList"))(x, ...)

Arguments

ArgumentDescription
xa list of beast object
...no used

Value

message

raxml2nwk

Description

convert raxml bootstrap tree to newick format

Usage

raxml2nwk(infile, outfile = "raxml.tree")

Arguments

ArgumentDescription
infileinput file
outfileoutput file

Value

newick file

Author

Guangchuang Yu

read.jtree

Description

Import tree data from jtree file, which is JSON-based text and probably output by write.jtree

Usage

read.jtree(file)

Arguments

ArgumentDescription
filetree file

Value

treedata object

Author

guangchuang yu

read.astral

Description

parse ASTRAL output newick text

Usage

read.astral(file)

Arguments

ArgumentDescription
fileASTRAL Newick file

Value

treedata object

Author

Guangchuang Yu

Examples

tt <- paste0(
"((species1,(species2,species3)'[pp1=0.75;pp2=0.24;pp3=0.01]':",
"1.2003685744180805)'[pp1=0.98;pp2=0.02;pp3=0]':0.9679599282730038,",
"((species4,species5)'[pp1=0.88;pp2=0.11;pp3=0.01]':1.2454851536484994))"
)
read.astral(textConnection(tt))

read.codeml

Description

read baseml output

Usage

read.codeml(rstfile, mlcfile, tree = "mlc", type = "Joint")

Arguments

ArgumentDescription
rstfilerst file
mlcfilemlc file
treeone of 'mlc' or 'rst'
typeone of 'Marginal' or 'Joint'

Value

A treedata object

Author

Guangchuang Yu

Examples

rstfile <- system.file("extdata/PAML_Codeml", "rst", package="treeio")
mlcfile <- system.file("extdata/PAML_Codeml", "mlc", package="treeio")
read.codeml(rstfile, mlcfile)
Link to this function

readcodeml_mlc()

read.codeml_mlc

Description

read mlc file of codeml output

Usage

read.codeml_mlc(mlcfile)

Arguments

ArgumentDescription
mlcfilemlc file

Value

A codeml_mlc object

Author

ygc

Examples

mlcfile <- system.file("extdata/PAML_Codeml", "mlc", package="treeio")
read.codeml_mlc(mlcfile)

read.fasta

Description

read FASTA file

Usage

read.fasta(fasta)

Arguments

ArgumentDescription
fastafasta file

Details

This function supports both DNA or AA sequences

Value

DNAbin or AAbin object

Author

guangchuang yu

read.hyphy

Description

read HYPHY output

Usage

read.hyphy(nwk, ancseq, tip.fasfile = NULL)

Arguments

ArgumentDescription
nwktree file in nwk format, one of hyphy output
ancseqancestral sequence file in nexus format, one of hyphy output
tip.fasfiletip sequence file

Value

A hyphy object

Author

Guangchuang Yu https://guangchuangyu.github.io

Examples

nwk <- system.file("extdata/HYPHY", "labelledtree.tree", package="treeio")
ancseq <- system.file("extdata/HYPHY", "ancseq.nex", package="treeio")
read.hyphy(nwk, ancseq)

read.hyphy.seq

Description

parse sequences from hyphy output

Usage

read.hyphy.seq(file)

Arguments

ArgumentDescription
fileoutput of hyphy ancestral sequence inference; nexus format

Value

DNAbin object

Author

guangchuang yu

Examples

ancseq <- system.file("extdata/HYPHY", "ancseq.nex", package="treeio")
read.hyphy.seq(ancseq)

read.iqtree

Description

parse IQ-TREE output

Usage

read.iqtree(file)

Arguments

ArgumentDescription
fileIQ-TREE Newick text

Value

treedata object

Author

Guangchuang Yu

read.jplace

Description

read jplace file

Usage

read.jplace(file)

Arguments

ArgumentDescription
filejplace file

Value

jplace instance

Author

Guangchuang Yu

Examples

jp <- system.file("extdata", "sample.jplace", package="treeio")
read.jplace(jp)

read.newick

Description

read newick tree

Usage

read.newick(file, node.label = "label", ...)

Arguments

ArgumentDescription
filenewick file
node.labelparse node label as 'label' or 'support' value
...additional parameter, passed to 'read.tree'

Value

phylo or treedata object

Author

guangchuang yu

read.nhx

Description

read nhx tree file

Usage

read.nhx(file)

Arguments

ArgumentDescription
filenhx file

Value

nhx object

Author

Guangchuang Yu https://guangchuangyu.github.io

Examples

nhxfile <- system.file("extdata/NHX", "ADH.nhx", package="treeio")
read.nhx(nhxfile)

read.paml_rst

Description

read rst file from paml (both baseml and codeml) output

Usage

read.paml_rst(rstfile, type = "Joint")

Arguments

ArgumentDescription
rstfilerst file
typeone of 'Marginal' or 'Joint'

Value

A treedata object

Author

Guangchuang Yu https://guangchuangyu.github.io

Examples

rstfile <- system.file("extdata/PAML_Baseml", "rst", package="treeio")
read.paml_rst(rstfile)

read.phylip

Description

parsing phylip tree format

Usage

read.phylip(file)

Arguments

ArgumentDescription
filephylip file

Value

an instance of 'phylip'

Author

Guangchuang Yu

Examples

phyfile <- system.file("extdata", "sample.phy", package="treeio")
read.phylip(phyfile)
Link to this function

readphylipseq()

read.phylip.seq

Description

read aligned sequences from phylip format

Usage

read.phylip.seq(file)

Arguments

ArgumentDescription
filephylip file, currently only sequential format is supported

Value

DNAbin object

Author

guangchuang yu

References

http://evolution.genetics.washington.edu/phylip/doc/sequence.html

Link to this function

readphyliptree()

read.phylip.tree

Description

parse tree from phylip file

Usage

read.phylip.tree(file)

Arguments

ArgumentDescription
filephylip file

Value

phylo or multiPhylo object

Author

guangchuang yu

read.phyloT

Description

parse output from phyloT

Usage

read.phyloT(file, ...)

Arguments

ArgumentDescription
filenewick tree file
...additional parameters to read.tree

Value

phylo object

Author

guangchuang yu

References

http://phylot.biobyte.de/

read.r8s

Description

parse output from r8s

Usage

read.r8s(file)

Arguments

ArgumentDescription
filer8s output log file

Value

multiPhylo object

Author

Guangchuang Yu

Examples

read.r8s(system.file("extdata/r8s", "H3_r8s_output.log", package="treeio"))

read.raxml

Description

parse RAxML bootstrapping analysis output

Usage

read.raxml(file)

Arguments

ArgumentDescription
fileRAxML bootstrapping analysis output

Value

treedata object

Author

Guangchuang Yu

Examples

raxml_file <- system.file("extdata/RAxML", "RAxML_bipartitionsBranchLabels.H3", package="treeio")
read.raxml(raxml_file)

Objects exported from other packages

Description

These objects are imported from other packages. Follow the links below to see their documentation.

list(" ", " ", list(list("ape"), list(list(list("read.tree")), ", ", list(list("read.nexus")), ", ", list(list("rtree")), ", ", list(list("write.tree")), ", ", list(list("write.nexus")), ", ", list(list("Nnode")), ", ", list(list("Ntip")), ", ", list(list("is.rooted")), ", ", list(list("as.phylo")))), " ", " ", " ", list(list("dplyr"), list(list(list("full_join")))), " ", " ", " ", list(list("magrittr"), list(list(list("%>%")))), " ", " ", " ", list(list("tibble"), list(list(list("data_frame")))),

"

", " ", " ", list(list("tidytree"), list(list(list("treedata")), ", ", list(list("get.fields")), ", ", list(list("get.data")), ", ", list(list("as.treedata")), ", ", list(list("ancestor")), ", ", list(list("parent")), ", ", list(list("child")), ", ", list(list("offspring")), ", ", list(list("rootnode")))), " ")

rename_taxa

Description

rename tip label of phylogenetic tree

Usage

rename_taxa(tree, data, key, value)

Arguments

ArgumentDescription
treetree object, either treedata or phylo
datadata frame
keycolumn in data that match tip label
valuecolumn in data for rename tip label

Value

tree object

Author

Guangchuang Yu

rescale_tree

Description

rescale branch length of tree object

Usage

rescale_tree(tree_object, branch.length)

Arguments

ArgumentDescription
tree_objecttree object
branch.lengthnumerical features (e.g. dN/dS)

Value

update tree object

Author

Guangchuang Yu

root

Description

re-root a tree

Usage

list(list("root"), list("phylo"))(object, node, ...)
list(list("root"), list("treedata"))(object, node, ...)

Arguments

ArgumentDescription
objecttree object
nodenode to reroot
...additional parameters

Value

rerooted tree

Author

Guangchuang Yu

taxa_rename

Description

rename taxa

Usage

taxa_rename(tree, name)

Arguments

ArgumentDescription
treetree object
namea two column data.frame contains original name in 1st column and new name in 2nd column

Value

updated tree object with new taxa name

Author

guangchuang yu

Subset tree objects by related nodes

Description

This function allows for a tree object to be subset by specifying a node and returns all related nodes within a selected number of levels

Usage

tree_subset(tree, node, levels_back = 5, group_node = TRUE)
list(list("tree_subset"), list("phylo"))(tree, node, levels_back = 5,
  group_node = TRUE)
list(list("tree_subset"), list("treedata"))(tree, node, levels_back = 5,
  group_node = TRUE)

Arguments

ArgumentDescription
treea tree object of class phylo
nodeeither a tip label or a node number for the given tree that will be the focus of the subsetted tree
levels_backa number specifying how many nodes back from the selected node the subsetted tree should include
group_nodewhether add grouping information of selected node

Details

This function will take a tree and a specified node from that tree and subset the tree showing all relatives back to a specified number of nodes. This function allows for a combination of ancestor and offspring to return a subsetted tree that is of class phylo. This allows for easy graphing of the tree with ggtree

Examples

nwk <- system.file("extdata", "sample.nwk", package="treeio")
tree <- read.tree(nwk)

sub_tree <- tree_subset(tree, node = "A", levels_back = 3)
ggtree(sub_tree) + geom_tiplab() + geom_nodelab()

nwk <- system.file("extdata", "sample.nwk", package="treeio")
tree <- read.tree(nwk)

sub_tree <- tree_subset(tree, node = "A", levels_back = 3)
ggtree(sub_tree) + geom_tiplab() + geom_nodelab()

write.jtree

Description

Export treedata object to json tree file

Usage

write.jtree(treedata, file = "")

Arguments

ArgumentDescription
treedatatreedata object
fileoutput file. If file = "", print the output content on screen

Value

output file or file content on screen

Author

guangchuang yu

write.beast

Description

Export treedata object to BEAST NEXUS file. This function was adopted and modified from ape::write.nexus

Usage

write.beast(treedata, file = "", translate = TRUE,
  tree.name = "UNTITLED")

Arguments

ArgumentDescription
treedatatreedata object
fileoutput file. If file = "", print the output content on screen
translatewhether translate taxa labels
tree.namename of the tree

Value

output file or file content on screen

Author

guangchuang yu

Examples

nhxfile <- system.file("extdata/NHX", "phyldog.nhx", package="treeio")
nhx <- read.nhx(nhxfile)
write.beast(nhx)

write.jplace

Description

generate jplace file

Usage

write.jplace(nwk, data, outfile)

Arguments

ArgumentDescription
nwktree in newick format
dataannotation data
outfilejplace output file

Value

jplace file

Author

ygc