https://github.com/uscbiostats/rphyloxml
Read and write phyloXML files in R
https://github.com/uscbiostats/rphyloxml
phylogenetics phyloxml r rpackage xml
Last synced: 21 days ago
JSON representation
Read and write phyloXML files in R
- Host: GitHub
- URL: https://github.com/uscbiostats/rphyloxml
- Owner: USCbiostats
- License: other
- Created: 2017-12-13T00:05:17.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-10-26T20:25:49.000Z (over 5 years ago)
- Last Synced: 2026-05-31T12:11:53.512Z (about 1 month ago)
- Topics: phylogenetics, phyloxml, r, rpackage, xml
- Language: R
- Homepage: https://uscbiostats.github.io/rphyloxml/
- Size: 288 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- Changelog: ChangeLog
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---
[](https://travis-ci.org/USCbiostats/rphyloxml)
[](https://ci.appveyor.com/project/gvegayon/rphyloxml/branch/master)
[](https://codecov.io/github/USCBiostats/rphyloxml?branch=master)
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# rphyloxml
rphyloxml provides access to the [phyloXML](http://www.phyloxml.org) 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](http://www.phyloxml.org/1.20/phyloxml.xsd))
This package has been motivated to be used with the javascript library [jsPhyloSVG](http://www.jsphylosvg.org), for which we are currently developing an R package with the same name that provides an htmlwidget [here](https://uscbiostats.github.com/jsPhyloSVG).
## Installation
You can install rphyloxml from github with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("USCBiostats/rphyloxml")
```
## Writing phyloXML files
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`.
```{r random-tree}
library(ape)
library(rphyloxml)
set.seed(12)
x <- rtree(3)
x
```
```{r coercion}
z <- write_phyloxml(x)
z
```
You can get a "nicer" view of it by doing the following:
```{r nice}
cat(as.character(z))
```
And to store the document, you just need to use `xml2` (which is what powers the package) as follows:
```r
xml2::write_xml(z, "mynicetree.xml")
```
## Reading XML files
We will read the file [amphibian_tree_of_life_Frost_DR_2006.xml](http://www.phyloxml.org/examples/amphibian_tree_of_life_Frost_DR_2006.xml) available in both the package and the phyloxml website.
```{r example-read}
# 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)
```
```{r example-read-coerce}
# We can coerce this into a mulitphylo list
(apetree <- phyloxml2phylo(xmltree))[[1]]
```
```{r example-plot-read}
plot(apetree, cex=.25)
```