An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

---
output: github_document
---

[![Travis build status](https://travis-ci.org/USCbiostats/rphyloxml.svg?branch=master)](https://travis-ci.org/USCbiostats/rphyloxml)
[![Build status](https://ci.appveyor.com/api/projects/status/3pp6ue80rcaj4py5/branch/master?svg=true)](https://ci.appveyor.com/project/gvegayon/rphyloxml/branch/master)
[![Coverage status](https://codecov.io/gh/USCBiostats/rphyloxml/branch/master/graph/badge.svg)](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)
```