knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
rphyloxml provides access to the phyloXML file format. For now, the only functions that are implemented in the package are:
write_phyloxml
: A method to coerce phylo
objects from the ape
package as phyloXML (XML) documents.read_phyloxml
: A method to read phyloXML documents into R. It returns a data frame with the structure of the tree and a nested list with each nodes' annotations.validate_phyloxml
: A wrapper of xml2::xml_validate
, which allows validating a phyloXML doc using the phyloxml.xsd schema (see here)This package has been motivated to be used with the javascript library jsPhyloSVG, for which we are currently developing an R package with the same name that provides an htmlwidget here.
You can install rphyloxml from github with:
# install.packages("devtools") devtools::install_github("USCBiostats/rphyloxml")
In the following example, we create a random tree using the rtree function from the ape package, and later on coerce it into a phyloXML document using write_phyloxml
.
library(ape) library(rphyloxml) set.seed(12) x <- rtree(3) x
z <- write_phyloxml(x) z
You can get a "nicer" view of it by doing the following:
cat(as.character(z))
And to store the document, you just need to use xml2
(which is what powers the package) as follows:
xml2::write_xml(z, "mynicetree.xml")
We will read the file amphibian_tree_of_life_Frost_DR_2006.xml available in both the package and the phyloxml website.
# Reading from the package files fn <- system.file("phyloxml/amphibian_tree_of_life_Frost_DR_2006.xml", package="rphyloxml") xmltree <- read_phyloxml(fn) str(xmltree, 4)
# We can coerce this into a mulitphylo list (apetree <- phyloxml2phylo(xmltree))[[1]]
plot(apetree, cex=.25)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.