rotl/ 0000755 0001762 0000144 00000000000 14442613417 011240 5 ustar ligges users rotl/NAMESPACE 0000644 0001762 0000144 00000006204 14441553346 012464 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method("[",otl_ott_id)
S3method(candidate_for_synth,study_meta)
S3method(flags,match_names)
S3method(flags,taxon_info)
S3method(flags,taxon_mrca)
S3method(get_publication,study_meta)
S3method(get_study_year,study_meta)
S3method(get_tree_ids,study_meta)
S3method(inspect,match_names)
S3method(is_in_tree,default)
S3method(is_in_tree,otl_ott_id)
S3method(is_suppressed,match_names)
S3method(is_suppressed,taxon_info)
S3method(is_suppressed,taxon_mrca)
S3method(list_trees,matched_studies)
S3method(ott_id,match_names)
S3method(ott_id,taxon_info)
S3method(ott_id,taxon_mrca)
S3method(ott_id,tol_mrca)
S3method(ott_id,tol_node)
S3method(ott_id,tol_summary)
S3method(print,study_external_data)
S3method(print,study_ids)
S3method(print,study_meta)
S3method(print,tnrs_contexts)
S3method(print,tol_mrca)
S3method(print,tol_node)
S3method(print,tol_summary)
S3method(source_list,tol_mrca)
S3method(source_list,tol_node)
S3method(source_list,tol_summary)
S3method(synonyms,match_names)
S3method(synonyms,taxon_info)
S3method(tax_lineage,taxon_info)
S3method(tax_lineage,tol_node)
S3method(tax_name,match_names)
S3method(tax_name,taxon_info)
S3method(tax_name,taxon_mrca)
S3method(tax_name,tol_mrca)
S3method(tax_name,tol_node)
S3method(tax_name,tol_summary)
S3method(tax_rank,match_names)
S3method(tax_rank,taxon_info)
S3method(tax_rank,taxon_mrca)
S3method(tax_rank,tol_mrca)
S3method(tax_rank,tol_node)
S3method(tax_rank,tol_summary)
S3method(tax_sources,match_names)
S3method(tax_sources,taxon_info)
S3method(tax_sources,taxon_mrca)
S3method(tax_sources,tol_mrca)
S3method(tax_sources,tol_node)
S3method(tax_sources,tol_summary)
S3method(tol_lineage,tol_node)
S3method(unique_name,match_names)
S3method(unique_name,taxon_info)
S3method(unique_name,taxon_mrca)
S3method(unique_name,tol_mrca)
S3method(unique_name,tol_node)
S3method(unique_name,tol_summary)
S3method(update,match_names)
export(candidate_for_synth)
export(flags)
export(get_publication)
export(get_study)
export(get_study_meta)
export(get_study_subtree)
export(get_study_tree)
export(get_study_year)
export(get_tree_ids)
export(inspect)
export(is_in_tree)
export(is_suppressed)
export(list_trees)
export(ott_id)
export(source_list)
export(strip_ott_ids)
export(studies_find_studies)
export(studies_find_trees)
export(studies_properties)
export(study_external_IDs)
export(synonyms)
export(tax_lineage)
export(tax_name)
export(tax_rank)
export(tax_sources)
export(taxon_external_IDs)
export(taxonomy_about)
export(taxonomy_mrca)
export(taxonomy_subtree)
export(taxonomy_taxon_info)
export(tnrs_contexts)
export(tnrs_infer_context)
export(tnrs_match_names)
export(tol_about)
export(tol_induced_subtree)
export(tol_lineage)
export(tol_mrca)
export(tol_node_info)
export(tol_subtree)
export(unique_name)
import(ape)
importFrom(httr,GET)
importFrom(httr,POST)
importFrom(httr,content)
importFrom(httr,parse_url)
importFrom(jsonlite,fromJSON)
importFrom(jsonlite,toJSON)
importFrom(jsonlite,unbox)
importFrom(rentrez,entrez_link)
importFrom(rentrez,entrez_search)
importFrom(rlang,interrupt)
importFrom(rncl,read_newick_phylo)
importFrom(stats,na.omit)
importFrom(stats,setNames)
importFrom(stats,update)
rotl/LICENSE 0000644 0001762 0000144 00000000117 14441553346 012247 0 ustar ligges users YEAR: 2017
COPYRIGHT HOLDER: Francois Michonneau, Joseph W. Brown, David Winter rotl/README.md 0000644 0001762 0000144 00000015576 14442036167 012536 0 ustar ligges users
[](https://github.com/ropensci/rotl/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/github/ropensci/rotl?branch=master)
[](https://www.r-pkg.org/pkg/rotl)
[](https://www.r-pkg.org/pkg/rotl)
[](https://github.com/ropensci/software-review/issues/17)
[](https://www.repostatus.org/#active)
# rotl: An R interface to Open Tree API
`rotl` is an R package to interact with the Open Tree of Life data APIs.
It was initially developed as part of the NESCENT/OpenTree/Arbor
hackathon.
Client libraries to interact with the Open Tree of Life API also exists
for [Python](https://github.com/OpenTreeOfLife/pyopentree) and
[Ruby](https://github.com/SpeciesFileGroup/bark).
## Installation
The current stable version is available from CRAN, and can be installed
by typing the following at the prompt in R:
``` r
install.packages("rotl")
```
If you want to test the development version, you first need to install
the `remotes` package.
``` r
install.packages("remotes")
```
Then you can install `rotl` using:
``` r
remotes::install_github("ropensci/rotl")
```
## Vignettes
There are three vignettes:
- Start by checking out the “How to use `rotl`?” by typing:
`vignette("rotl", package="rotl")` after installing the package.
- Then explore how you can use `rotl` with other packages to combine
your data with trees from the Open Tree of Life project by typing:
`vignette("data_mashups", package="rotl")`.
- The vignette “Using the Open Tree Synthesis in a comparative
analysis” demonstrates how you can reproduce an analysis of a
published paper by downloading the tree they used, and data from the
supplementary material: `vignette("meta-analysis", package="rotl")`.
The vignettes are also available from CRAN: [How to use
`rotl`?](https://cran.r-project.org/package=rotl/vignettes/rotl.html),
[Data
mashups](https://cran.r-project.org/package=rotl/vignettes/data_mashups.html),
and [Using the Open Tree synthesis in a comparative
analysis](https://cran.r-project.org/package=rotl/vignettes/meta-analysis.html).
## Quick start
### Get a little bit of the big Open Tree tree
Taxonomic names are represented in the Open Tree by numeric identifiers,
the `ott_ids` (Open Tree Taxonomy identifiers). To extract a portion of
a tree from the Open Tree, you first need to find `ott_ids` for a set of
names using the `tnrs_match_names` function:
``` r
library(rotl)
apes <- c("Pongo", "Pan", "Gorilla", "Hoolock", "Homo")
(resolved_names <- tnrs_match_names(apes))
```
## search_string unique_name approximate_match score ott_id is_synonym
## 1 pongo Pongo FALSE 1 417949 FALSE
## 2 pan Pan FALSE 1 417957 FALSE
## 3 gorilla Gorilla FALSE 1 417969 FALSE
## 4 hoolock Hoolock FALSE 1 712902 FALSE
## 5 homo Homo FALSE 1 770309 FALSE
## flags number_matches
## 1 2
## 2 sibling_higher 2
## 3 sibling_higher 1
## 4 1
## 5 sibling_higher 1
Now we can get the tree with just those tips:
``` r
tr <- tol_induced_subtree(ott_ids = ott_id(resolved_names))
```
## Warning in collapse_singles(tr, show_progress): Dropping singleton nodes with
## labels: mrcaott83926ott6145147, mrcaott83926ott3607728, mrcaott83926ott3607876,
## mrcaott83926ott3607873, mrcaott83926ott3607687, mrcaott83926ott3607716,
## mrcaott83926ott3607689, mrcaott83926ott3607732, mrcaott770295ott3607719,
## mrcaott770295ott3607692, Ponginae ott1082538, Hylobatidae ott166544
``` r
plot(tr)
```

The code above can be summarized in a single pipe:
``` r
library(magrittr)
## or expressed as a pipe:
c("Pongo", "Pan", "Gorilla", "Hoolock", "Homo") %>%
tnrs_match_names() %>%
ott_id() %>%
tol_induced_subtree() %>%
plot()
```
## Warning in collapse_singles(tr, show_progress): Dropping singleton nodes with
## labels: mrcaott83926ott6145147, mrcaott83926ott3607728, mrcaott83926ott3607876,
## mrcaott83926ott3607873, mrcaott83926ott3607687, mrcaott83926ott3607716,
## mrcaott83926ott3607689, mrcaott83926ott3607732, mrcaott770295ott3607719,
## mrcaott770295ott3607692, Ponginae ott1082538, Hylobatidae ott166544

## Citation and Manuscript
To cite `rotl` in publications pleases use:
> Michonneau, F., Brown, J. W. and Winter, D. J. (2016), rotl: an R
> package to interact with the Open Tree of Life data. Methods in
> Ecology and Evolution. 7(12):1476-1481. doi:
> [10.1111/2041-210X.12593](https://doi.org/10.1111/2041-210X.12593)
You may also want to cite the paper for the Open Tree of Life
> Hinchliff, C. E., et al. (2015). Synthesis of phylogeny and taxonomy
> into a comprehensive tree of life. Proceedings of the National Academy
> of Sciences 112.41 (2015): 12764-12769 doi:
> [10.1073/pnas.1423041112](https://doi.org/10.1073/pnas.1423041112)
The manuscript in *Methods in Ecology and Evolution* includes additional
examples on how to use the package. The manuscript and the code it
contains are also hosted on GitHub at:
## Versioning
Starting with v3.0.0 of the package, the major and minor version numbers
(the first 2 digits of the version number) will be matched to those of
the API. The patch number (the 3rd digit of the version number) will be
used to reflect bug fixes and other changes that are independent from
changes to the API.
`rotl` can be used to access other versions of the API (if they are
available) but most likely the high level functions will not work.
Instead, you will need to parse the output yourself using the “raw”
returns from the unexported low-level functions (all prefixed with a
`.`). For instance to use the `tnrs/match_names` endpoint for `v2` of
the API:
``` r
rotl:::.tnrs_match_names(c("pan", "pango", "gorilla", "hoolock", "homo"), otl_v = "v2")
```
### Code of Conduct
Please note that this project is released with a [Contributor Code of
Conduct](https://github.com/ropensci/rotl/blob/master/CONDUCT.md). By
participating in this project you agree to abide by its terms.
[](https://ropensci.org/)
rotl/man/ 0000755 0001762 0000144 00000000000 14441644631 012014 5 ustar ligges users rotl/man/get_study_tree.Rd 0000644 0001762 0000144 00000004345 14441553346 015341 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/studies.R
\name{get_study_tree}
\alias{get_study_tree}
\title{Study Tree}
\usage{
get_study_tree(
study_id = NULL,
tree_id = NULL,
object_format = c("phylo"),
tip_label = c("original_label", "ott_id", "ott_taxon_name"),
file_format,
file,
deduplicate = TRUE,
...
)
}
\arguments{
\item{study_id}{the identifier of a study (character)}
\item{tree_id}{the identifier of a tree within the study}
\item{object_format}{the class of the object to be returned
(default and currently only possible value \code{phylo} from
the \code{ape} package).}
\item{tip_label}{the format of the tip
labels. \dQuote{\code{original_label}} (default) returns the
original labels as provided in the study,
\dQuote{\code{ott_id}} labels are replaced by their ott IDs,
\dQuote{\code{ott_taxon_name}} labels are replaced by their
Open Tree Taxonomy taxon name.}
\item{file_format}{the format of the file to be generated
(\code{newick} default, \code{nexus}, or \code{json}).}
\item{file}{the file name where the output of the function will be
saved.}
\item{deduplicate}{logical (default \code{TRUE}). If the tree
returned by the study contains duplicated taxon names, should they
be made unique? It is normally illegal for NEXUS/Newick tree
strings to contain duplicated tip names. This is a workaround to
circumvent this requirement. If \code{TRUE}, duplicated tip labels
will be appended \code{_1}, \code{_2}, etc.}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
if \code{file_format} is missing, an object of class
\code{phylo}, otherwise a logical indicating whether the file
was successfully created.
}
\description{
Returns a specific tree from within a study
}
\examples{
\dontrun{
tree <- get_study_tree(study_id="pg_1144", tree_id="tree2324")
## comparison of the first few tip labels depending on the options used
head(get_study_tree(study_id="pg_1144", tree_id="tree2324", tip_label="original_label")$tip.label)
head(get_study_tree(study_id="pg_1144", tree_id="tree2324", tip_label="ott_id")$tip.label)
head(get_study_tree(study_id="pg_1144", tree_id="tree2324", tip_label="ott_taxon_name")$tip.label)
}
}
rotl/man/rotl.Rd 0000644 0001762 0000144 00000003503 14442060313 013252 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rotl-package.R
\docType{package}
\name{rotl}
\alias{rotl}
\title{An Interface to the Open Tree of Life API}
\description{
The Open Tree of Life is an NSF funded project that is generating
an online, comprehensive phylogenetic tree for 1.8 million
species. \code{rotl} provides an interface that allows you to
query and retrieve the parts of the tree of life that is of
interest to you.
}
\details{
\code{rotl} provides function to most of the end points the API
provides. The documentation of the API is available at:
\url{https://github.com/OpenTreeOfLife/opentree/wiki/Open-Tree-of-Life-APIs}
}
\section{Customizing API calls}{
All functions that use API end points can take 2 arguments to
customize the API call and are passed as \code{...} arguments.
\itemize{
\item{ \code{otl_v} } { This argument controls which version
of the API your call is using. The default value for this
argument is a call to the non-exported function
\code{otl_version()} which returns the current version of the
Open Tree of Life APIs (v2).}
\item{ \code{dev_url} } { This argument controls whether to use
the development version of the API. By default, \code{dev_url}
is set to \code{FALSE}, using \code{dev_url = TRUE} in your
function calls will use the development version.}
}
For example, to use the development version of the API, you
could use: \code{tnrs_match_names("anas", dev_url=TRUE)}
Additional arguments can also be passed to the
\code{\link[httr]{GET}} and \code{\link[httr]{POST}} methods.
}
\section{Acknowledgments}{
This package was started during the Open Tree of Life Hackathon
organized by the OpenTree of Life, the NESCent Hackathon
Interoperability Phylogenetic group, and Arbor.
}
rotl/man/studies_find_trees.Rd 0000644 0001762 0000144 00000005627 14441553346 016201 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/studies.R
\name{studies_find_trees}
\alias{studies_find_trees}
\title{Find Trees}
\usage{
studies_find_trees(
property = NULL,
value = NULL,
verbose = FALSE,
exact = FALSE,
detailed = TRUE,
...
)
}
\arguments{
\item{property}{The property to be searched on (character)}
\item{value}{The property-value to be searched on (character)}
\item{verbose}{Should the output include all metadata? (logical,
default \code{FALSE})}
\item{exact}{Should exact matching be used for the value?
(logical, default \code{FALSE})}
\item{detailed}{Should a detailed report be provided? If
\code{TRUE} (default), the output will include metadata about
the study that include trees matching the property. Otherwise,
only information about the trees will be provided.}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
A data frame that summarizes the trees found (and their
associated studies) for the requested criteria. If a study has
more than 5 trees, the \code{tree_ids} of the first ones will
be shown, followed by \code{...} to indicate that more are
present.
If \code{detailed=FALSE}, the data frame will include the
study ids of the study (\code{study_ids}), the number of trees
in this study that match the search criteria
(\code{n_matched_trees}), the tree ids that match the search
criteria (\code{match_tree_ids}).
If \code{detailed=TRUE}, in addition of the fields listed
above, the data frame will also contain the total number of
trees associated with the study (\code{n_trees}), all the tree
ids associated with the study (\code{tree_ids}), the tree id
that is a potential candidate for inclusion in the synthetic
tree (if any) (\code{candidate}), the year the study was
published (\code{study_year}), the title of the study
(\code{title}), the DOI for the study (\code{study_doi}).
}
\description{
Return a list of studies for which trees match a given set of
properties
}
\details{
The list of possible values to be used as values for the argument
\code{property} can be found using the function
\code{\link{studies_properties}}.
}
\examples{
\dontrun{
res <- studies_find_trees(property="ot:ottTaxonName", value="Drosophila",
detailed=FALSE)
## summary of the trees and associated studies that match this criterion
res
## With metadata about the studies (default)
res <- studies_find_trees(property="ot:ottTaxonName", value="Drosophila",
detailed=TRUE)
## The list of trees for each study that match the search criteria
list_trees(res)
## the trees for a given study
list_trees(res, study_id = "pg_2769")
}
}
\seealso{
\code{\link{studies_properties}} which lists properties
the studies can be searched on. \code{\link{list_trees}} for
listing the trees that match the query.
}
rotl/man/taxonomy_taxon_info.Rd 0000644 0001762 0000144 00000004457 14441553346 016421 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/taxonomy.R
\name{taxonomy_taxon_info}
\alias{taxonomy_taxon_info}
\alias{tax_rank.taxon_info}
\alias{tax_name.taxon_info}
\alias{unique_name.taxon_info}
\alias{synonyms.taxon_info}
\alias{ott_id.taxon_info}
\alias{tax_sources.taxon_info}
\alias{is_suppressed.taxon_info}
\alias{flags.taxon_info}
\title{Taxon information}
\usage{
taxonomy_taxon_info(
ott_ids,
include_children = FALSE,
include_lineage = FALSE,
include_terminal_descendants = FALSE,
...
)
\method{tax_rank}{taxon_info}(tax, ...)
\method{tax_name}{taxon_info}(tax, ...)
\method{unique_name}{taxon_info}(tax, ...)
\method{synonyms}{taxon_info}(tax, ...)
\method{ott_id}{taxon_info}(tax, ...)
\method{tax_sources}{taxon_info}(tax, ...)
\method{is_suppressed}{taxon_info}(tax, ...)
\method{flags}{taxon_info}(tax, ...)
}
\arguments{
\item{ott_ids}{the ott ids of the taxon of interest (numeric or
character containing only numbers)}
\item{include_children}{whether to include information about all
the children of this taxon. Default \code{FALSE}.}
\item{include_lineage}{whether to include information about all
the higher level taxa that include the \code{ott_ids}.
Default \code{FALSE}.}
\item{include_terminal_descendants}{whether to include the list of
terminal \code{ott_ids} contained in the \code{ott_ids}
provided.}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
\item{tax}{an object generated by the \code{taxonomy_taxon_info}
function}
}
\value{
\code{taxonomy_taxon_info} returns a list detailing
information about the taxa. \code{tax_rank} and
\code{tax_name} return a vector. \code{synonyms} returns a
list whose elements are the synonyms for each of the
\code{ott_id} requested.
}
\description{
Information about taxa.
}
\details{
Given a vector of ott ids, \code{taxonomy_taxon_info} returns
information about the specified taxa.
The functions \code{tax_rank}, \code{tax_name}, and
\code{synonyms} can extract this information from an object
created by the \code{taxonomy_taxon_info()}.
}
\examples{
\dontrun{
req <- taxonomy_taxon_info(ott_id=515698)
tax_rank(req)
tax_name(req)
synonyms(req)
}
}
\seealso{
\code{\link{tnrs_match_names}} to obtain \code{ott_id}
from a taxonomic name.
}
rotl/man/tol_subtree.Rd 0000644 0001762 0000144 00000003020 14441553346 014627 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tol.R
\name{tol_subtree}
\alias{tol_subtree}
\title{Extract a subtree from the synthetic tree}
\usage{
tol_subtree(ott_id = NULL, node_id = NULL, label_format = NULL, file, ...)
}
\arguments{
\item{ott_id}{Numeric. The ott id of the node in the tree that should
serve as the root of the tree returned.}
\item{node_id}{Character. The node id of the node in the tree that should
serve as the root of the tree returned.}
\item{label_format}{Character. Defines the label type; one of
\dQuote{\code{name}}, \dQuote{\code{id}}, or
\dQuote{\code{name_and_id}} (the default).}
\item{file}{If specified, the function will write the subtree to a
file in newick format.}
\item{...}{additional arguments to customize the API call (see
\code{\link{rotl}} for more information).}
}
\value{
If no value is specified to the \code{file} argument
(default), a phylogenetic tree of class \code{phylo}.
Otherwise, the function returns invisibly a logical indicating
whether the file was successfully created.
}
\description{
Extract a subtree from the synthetic tree from an Open Tree node id.
}
\details{
Given a node, return the subtree of the synthetic tree descended
from that node. The start node may be specified using either a node id
or an ott id, but not both. If the specified node is not in the
synthetic tree an error will be returned. There is a size limit of
25000 tips for this method.
}
\examples{
\dontrun{
res <- tol_subtree(ott_id=241841)}
}
rotl/man/source_list.Rd 0000644 0001762 0000144 00000001511 14441553346 014636 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/methods.R, R/tol.R
\name{source_list}
\alias{source_list}
\alias{source_list.tol_summary}
\title{List of studies used in the Tree of Life}
\usage{
source_list(tax, ...)
\method{source_list}{tol_summary}(tax, ...)
}
\arguments{
\item{tax}{a list containing a \code{source_id_map} slot.}
\item{...}{additional arguments (currently unused)}
}
\value{
a data frame
}
\description{
Retrieve the detailed information for the list of studies used in
the Tree of Life.
}
\details{
This function takes the object resulting from
\code{tol_about(study_list = TRUE)}, \code{tol_mrca()},
\code{tol_node_info()}, and returns a data frame listing the
\code{tree_id}, \code{study_id} and \code{git_sha} for the
studies currently included in the Tree of Life.
}
rotl/man/studies_properties.Rd 0000644 0001762 0000144 00000002203 14441553346 016236 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/studies.R
\name{studies_properties}
\alias{studies_properties}
\title{Properties of the Studies}
\usage{
studies_properties(...)
}
\arguments{
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
A list of the study properties that can be used to find
studies and trees that are contributing to the synthetic tree.
}
\description{
Return the list of study properties that can be used to search
studies and trees used in the synthetic tree.
}
\details{
The list returned has 2 elements \code{tree_properties} and
\code{studies_properties}. Each of these elements lists additional
arguments to customize the API request properties that can be used
to search for trees and studies that are contributing to the
synthetic tree. The definitions of these properties are available
from
\url{https://github.com/OpenTreeOfLife/phylesystem-api/wiki/NexSON}
}
\examples{
\dontrun{
all_the_properties <- studies_properties()
unlist(all_the_properties$tree_properties)
}
}
\seealso{
\code{\link{studies_find_trees}}
}
rotl/man/taxonomy_subtree.Rd 0000644 0001762 0000144 00000004364 14441553346 015723 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/taxonomy.R
\name{taxonomy_subtree}
\alias{taxonomy_subtree}
\title{Taxonomy subtree}
\usage{
taxonomy_subtree(
ott_id = NULL,
output_format = c("taxa", "newick", "phylo", "raw"),
label_format = NULL,
file,
...
)
}
\arguments{
\item{ott_id}{The ott id of the taxon of interest.}
\item{output_format}{the format of the object to be returned. See
the \sQuote{Return} section.}
\item{label_format}{Character. Defines the label type; one of
\dQuote{\code{name}}, \dQuote{\code{id}}, or
\dQuote{\code{name_and_id}} (the default).}
\item{file}{the file name where to save the output of the
function. Ignored unless \code{output_format} is set to
\dQuote{\code{phylo}}.}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
If the \code{file} argument is missing: \itemize{
\item{\dQuote{\code{taxa}}} { a list of the taxa names
(species) in slot \code{tip_label}, and higher-level taxonomy
(e.g., families, genera) in slot \code{edge_label}, descending
from the taxa corresponding to the \code{ott_id} provided. }
\item{\dQuote{\code{newick}}} { a character vector containing
the newick formatted string corresponding to the taxonomic
subtree for the \code{ott_id} provided. }
\item{\dQuote{\code{phylo}}} { an object of the class
\code{phylo} from the \code{ape} package. }
\item{\dQuote{\code{raw}}} { the direct output from the API,
i.e., a list with an element named \sQuote{newick} that
contains the subtree as a newick formatted string. }
}
If a \code{file} argument is provided (and
\code{output_format} is set to \dQuote{\code{phylo}}), a
logical indicating whether the file was successfully created.
}
\description{
Given an ott id, return the inclusive taxonomic subtree descended
from the specified taxon.
}
\details{
If the output of this function is exported to a file, the only
possible value for the \code{output_format} argument is
\dQuote{\code{newick}}. If the file provided already exists, it
will be silently overwritten.
}
\examples{
\dontrun{
req <- taxonomy_subtree(ott_id=515698)
plot(taxonomy_subtree(ott_id=515698, output_format="phylo"))
}
}
rotl/man/synonyms.match_names.Rd 0000644 0001762 0000144 00000003467 14441553346 016474 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/match_names.R
\name{synonyms.match_names}
\alias{synonyms.match_names}
\title{List the synonyms for a given name}
\usage{
\method{synonyms}{match_names}(tax, row_number, taxon_name, ott_id, ...)
}
\arguments{
\item{tax}{a data frame generated by the
\code{\link{tnrs_match_names}} function}
\item{row_number}{the row number corresponding to the name for
which to list the synonyms}
\item{taxon_name}{the taxon name corresponding to the name for
which to list the synonyms}
\item{ott_id}{the ott id corresponding to the name for which to
list the synonyms}
\item{...}{currently ignored}
}
\value{
a list whose elements are all synonym names (as vectors of
character) for the taxonomic names that match the query (the
names of the elements of the list).
}
\description{
When querying the Taxonomic Name Resolution Services for a
particular taxonomic name, the API returns as possible matches all
names that include the queried name as a possible synonym. This
function allows you to explore other synonyms for an accepted
name, and allows you to determine why the name you queried is
returning an accepted synonym.
}
\details{
To list synonyms for a given taxonomic name, you need to provide
the object resulting from a call to the
\code{\link{tnrs_match_names}} function, as well as one of either
the row number corresponding to the name in this object, the name
itself (as used in the original query), or the ott_id listed for
this name. Otherwise, the synonyms for all the currently matched
names are returned.
}
\examples{
\dontrun{
echino <- tnrs_match_names(c("Diadema", "Acanthaster", "Fromia"))
## These 3 calls are identical
synonyms(echino, taxon_name="Acanthaster")
synonyms(echino, row_number=2)
synonyms(echino, ott_id=337928)
}
}
rotl/man/taxonomy-methods.Rd 0000644 0001762 0000144 00000001657 14441553346 015635 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/methods.R
\name{tax_rank}
\alias{tax_rank}
\alias{ott_id}
\alias{synonyms}
\alias{tax_sources}
\alias{is_suppressed}
\alias{unique_name}
\alias{tax_name}
\title{Methods for Taxonomy}
\usage{
tax_rank(tax, ...)
ott_id(tax, ...)
synonyms(tax, ...)
tax_sources(tax, ...)
is_suppressed(tax, ...)
unique_name(tax, ...)
tax_name(tax, ...)
}
\arguments{
\item{tax}{an object returned by \code{\link{taxonomy_taxon_info}},
\code{\link{taxonomy_mrca}}, or \code{\link{tnrs_match_names}}}
\item{...}{additional arguments (see
\code{\link{tnrs_match_names}})}
}
\description{
Methods for dealing with objects containing taxonomic information
(Taxonomy, TNRS endpoints)
}
\details{
This is the page for the generic methods. See the help pages for
\code{\link{taxonomy_taxon_info}}, \code{\link{taxonomy_mrca}}, and
\code{\link{tnrs_match_names}} for more information.
}
rotl/man/tol_induced_subtree.Rd 0000644 0001762 0000144 00000004062 14441553346 016331 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tol.R
\name{tol_induced_subtree}
\alias{tol_induced_subtree}
\title{Subtree from the Open Tree of Life}
\usage{
tol_induced_subtree(
ott_ids = NULL,
node_ids = NULL,
label_format = NULL,
file,
...
)
}
\arguments{
\item{ott_ids}{Numeric vector. OTT ids indicating nodes to be used as tips
in the induced tree.}
\item{node_ids}{Character vector. Node ids indicating nodes to be used as
tips in the induced tree.}
\item{label_format}{Character. Defines the label type; one of
\dQuote{\code{name}}, \dQuote{\code{id}}, or \dQuote{\code{name_and_id}}
(the default).}
\item{file}{If specified, the function will write the subtree to a file in
newick format.}
\item{...}{additional arguments to customize the API call (see
\code{\link{rotl}} for more information).}
}
\value{
If no value is specified to the \code{file} argument
(default), a phylogenetic tree of class \code{phylo}.
Otherwise, the function returns invisibly a logical indicating
whether the file was successfully created.
Note that the tree returned when specifying a file name with the
\code{file} argument is the \dQuote{raw} Newick string returned by Open
Tree of Life. This string contains singleton nodes, and therefore will
be different from the tree returned as a \code{phylo} object which will
not contain these singleton nodes.
}
\description{
Return the induced subtree on the synthetic tree that relates a list of nodes.
}
\details{
Return a tree with tips corresponding to the nodes identified in
the input set that is consistent with the topology of the current
synthetic tree. This tree is equivalent to the minimal subtree
induced on the draft tree by the set of identified nodes.
}
\examples{
\dontrun{
## Result as a `phylo` object
res <- tol_induced_subtree(ott_ids = c(292466, 267845, 316878, 102710))
## Raw Newick string from Open Tree of Life
tree_file <- tempfile(fileext = ".tre")
tol_induced_subtree(ott_ids = c(292466, 267845, 316878, 102710),
file=tree_file)
}
}
rotl/man/tax_lineage.Rd 0000644 0001762 0000144 00000001633 14441553346 014570 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/methods.R, R/taxonomy.R
\name{tax_lineage}
\alias{tax_lineage}
\alias{tax_lineage.taxon_info}
\title{Lineage of a taxon}
\usage{
tax_lineage(tax, ...)
\method{tax_lineage}{taxon_info}(tax, ...)
}
\arguments{
\item{tax}{an object created by \code{\link{taxonomy_taxon_info}}
using the argument \code{include_lineage=TRUE}.}
\item{...}{additional arguments (currently unused).}
}
\value{
A list with one slot per taxon that contains a data frame
with 3 columns: the taxonomy rank, the name, and unique name
for all taxa included in the lineage of the taxon up to the
root of the tree.
}
\description{
Extract the lineage information (higher taxonomy) from an object
returned by \code{\link{taxonomy_taxon_info}}.
}
\details{
The object passed to this function must have been created using
the argument \code{include_lineage=TRUE}.
}
rotl/man/list_trees.Rd 0000644 0001762 0000144 00000002441 14441553346 014463 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/studies-methods.R
\name{list_trees}
\alias{list_trees}
\alias{list_trees.matched_studies}
\title{List trees ids in objects returned by
\code{\link{studies_find_studies}} and
\code{\link{studies_find_trees}}.}
\usage{
list_trees(matched_studies, ...)
\method{list_trees}{matched_studies}(matched_studies, study_id, ...)
}
\arguments{
\item{matched_studies}{an object created by
\code{studies_find_trees} or \code{studies_find_studies}.}
\item{...}{Currently unused}
\item{study_id}{a \code{study_id} listed in the object returned by
\code{studies_find_trees}}
}
\value{
\code{list_trees} returns a list of the tree_ids for each
study that match the requested criteria. If a \code{study_id}
is provided, then only the trees for this study are returned
as a vector.
}
\description{
\code{list_trees} returns all trees associated with a particular
study when used on an object returned by
\code{\link{studies_find_studies}}, but only the trees that match
the search criteria when used on objects returned by
\code{\link{studies_find_trees}}.
}
\seealso{
\code{\link{studies_find_studies}} and
\code{\link{studies_find_trees}}. The help for these functions
have examples demonstrating the use of \code{list_trees}.
}
rotl/man/tnrs_infer_context.Rd 0000644 0001762 0000144 00000001771 14441553346 016230 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tnrs.R
\name{tnrs_infer_context}
\alias{tnrs_infer_context}
\title{Infer the taxonomic context from a list of names}
\usage{
tnrs_infer_context(names = NULL, ...)
}
\arguments{
\item{names}{Vector of taxon names.}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
A list including the context name, the context ott id and
possibly the names in the query that have an ambiguous
taxonomic meaning in the query.
}
\description{
Return a taxonomic context given a list of taxonomic names
}
\details{
Find the least inclusive taxonomic context that includes all the
unambiguous names in the input set. Unambiguous names are names
with exact matches to non-homonym taxa. Ambiguous names (those
without exact matches to non-homonym taxa) are indicated in
results.
}
\examples{
\dontrun{
res <- tnrs_infer_context(names=c("Stellula calliope", "Struthio camelus"))
}
}
rotl/man/match_names-methods.Rd 0000644 0001762 0000144 00000003556 14441553346 016236 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/match_names.R, R/methods.R
\name{ott_id.match_names}
\alias{ott_id.match_names}
\alias{flags.match_names}
\alias{flags}
\title{\code{ott_id} and \code{flags} for taxonomic names matched
by \code{tnrs_match_names}}
\usage{
\method{ott_id}{match_names}(tax, row_number, taxon_name, ott_id, ...)
\method{flags}{match_names}(tax, row_number, taxon_name, ott_id, ...)
flags(tax, ...)
}
\arguments{
\item{tax}{an object returned by \code{\link{tnrs_match_names}}}
\item{row_number}{the row number corresponding to the name for
which to list the synonyms}
\item{taxon_name}{the taxon name corresponding to the name for
which to list the synonyms}
\item{ott_id}{the ott id corresponding to the name for which to
list the synonyms}
\item{...}{currently ignored}
}
\value{
A list of the ott ids or flags for the taxonomic names
matched with \code{\link{tnrs_match_names}}, for either one or
all the names.
}
\description{
\code{rotl} provides a collection of functions that allows users
to extract relevant information from an object generated by
\code{\link{tnrs_match_names}} function.
}
\details{
These methods optionally accept one of the arguments
\code{row_number}, \code{taxon_name} or \code{ott_id} to retrieve
the corresponding information for one of the matches in the object
returned by the \code{\link{tnrs_match_names}} function.
If these arguments are not provided, these methods can return
information for the matches currently listed in the object
returned by \code{\link{tnrs_match_names}}.
}
\examples{
\dontrun{
rsp <- tnrs_match_names(c("Diadema", "Tyrannosaurus"))
rsp$ott_id # ott id for match currently in use
ott_id(rsp) # similar as above but elements are named
## flags() is useful for instance to determine if a taxon is extinct
flags(rsp, taxon_name="Tyrannosaurus")
}
}
rotl/man/tnrs_contexts.Rd 0000644 0001762 0000144 00000002005 14441553346 015217 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tnrs.R
\name{tnrs_contexts}
\alias{tnrs_contexts}
\title{TNRS contexts}
\usage{
tnrs_contexts(...)
}
\arguments{
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
Returns invisibly a list for each major clades (e.g.,
animals, microbes, plants, fungi, life) whose elements
contains the possible contexts.
}
\description{
This function returns a list of pre-defined taxonomic contexts
(i.e. clades) which can be used to limit the scope of tnrs
queries.
}
\details{
Taxonomic contexts are available to limit the scope of TNRS
searches. These contexts correspond to uncontested higher taxa
such as 'Animals' or 'Land plants'. This service returns a list
containing all available taxonomic context names, which may be
used as input (via the \code{context_name} argument in other
functions) to limit the search scope of other services including
\code{\link{tnrs_match_names}}.
}
rotl/man/tol_about.Rd 0000644 0001762 0000144 00000007660 14442034340 014273 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tol.R
\name{tol_about}
\alias{tol_about}
\alias{tax_rank.tol_summary}
\alias{tax_sources.tol_summary}
\alias{unique_name.tol_summary}
\alias{tax_name.tol_summary}
\alias{ott_id.tol_summary}
\title{Information about the Tree of Life}
\usage{
tol_about(include_source_list = FALSE, ...)
\method{tax_rank}{tol_summary}(tax, ...)
\method{tax_sources}{tol_summary}(tax, ...)
\method{unique_name}{tol_summary}(tax, ...)
\method{tax_name}{tol_summary}(tax, ...)
\method{ott_id}{tol_summary}(tax, ...)
}
\arguments{
\item{include_source_list}{Logical (default =
\code{FALSE}). Return an ordered list of source trees.}
\item{...}{additional arguments to customize the API call (see
\code{\link{rotl}} for more information).}
\item{tax}{an object created with a call to \code{tol_about}.}
}
\value{
An invisible list of synthetic tree summary statistics:
\itemize{
\item {date_created} {String. The creation date of the tree.}
\item {num_source_studies} {Integer. The number of studies
(publications)used as sources.}
\item {num_source_trees} {The number of trees used as sources
(may be >1 tree per study).}
\item {taxonomy_version} {The Open Tree Taxonomy version used
as a source.}
\item {filtered_flags} {List. Taxa with these taxonomy flags were
not used in construction of the tree.}
\item {root} {List. Describes the root node:}
\itemize{
\item {node_id} {String. The canonical identifier of the node.}
\item {num_tips} {Numeric. The number of descendant tips.}
\item {taxon} {A list of taxonomic properties:}
\itemize{
\item {ott_id} {Numeric. The OpenTree Taxonomy ID (ott_id).}
\item {name} {String. The taxonomic name of the queried node.}
\item {unique_name} {String. The string that uniquely
identifies the taxon in OTT.}
\item {rank} {String. The taxonomic rank of the taxon in OTT.}
\item {tax_sources} {List. A list of identifiers for taxonomic
sources, such as other taxonomies, that define taxa judged
equivalent to this taxon.}
}
}
\item {source_list} {List. Present only if
\code{include_source_list} is \code{TRUE}. The sourceid
ordering is the precedence order for synthesis, with
relationships from earlier trees in the list having priority
over those from later trees in the list. See
\code{source_id_map} below for study details.}
\item {source_id_map} {Named list of lists. Present only if
\code{include_source_list} is \code{TRUE}. Names correspond to
the \sQuote{sourceids} used in \code{source_list}
above. Source trees will have the following properties:}
\itemize{
\item {git_sha} {String. The git SHA identifying a particular source
version.}
\item {tree_id} {String. The tree id associated with the study id used.}
\item {study_id} {String. The study identifier. Will typically include
a prefix ("pg_" or "ot_").}
}
\item {synth_id} {The unique string for this version of the tree.}
}
}
\description{
Basic information about the Open Tree of Life (the synthetic tree)
}
\details{
Summary information about the current draft tree of life,
including information about the list of trees and the taxonomy
used to build it. The object returned by \code{tol_about} can
be passed to the taxonomy methods (\code{tax_name()},
\code{tax_rank()}, \code{tax_sources()}, \code{ott_id}), to
extract relevant taxonomic information for the root of the
synthetic tree.
}
\examples{
\dontrun{
res <- tol_about()
tax_sources(res)
ott_id(res)
studies <- source_list(tol_about(include_source_list=TRUE))}
}
\seealso{
\code{\link{source_list}} to explore the list of studies
used in the synthetic tree (see example).
}
rotl/man/taxon_external_IDs.Rd 0000644 0001762 0000144 00000001675 14441553346 016110 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/external_data.R
\name{taxon_external_IDs}
\alias{taxon_external_IDs}
\title{Get external identifiers for data associated with an Open Tree taxon}
\usage{
taxon_external_IDs(taxon_id)
}
\arguments{
\item{taxon_id}{An open tree study ID}
}
\value{
a data.frame in which each row represents a unique record in an
external database. The column "source" provides and abbreviated name for the
database, and "id" the unique ID for the record.
}
\description{
The Open Tree taxonomy is a synthesis of multiple reference taxonomies. This
function retrieves identifiers to external taxonomic records that have
contributed the rank, position and definition of a given Open Tree taxon.
}
\examples{
\dontrun{
gibbon_IDs <- taxon_external_IDs(712902)
}
}
\seealso{
tnrs_matchnames, which can be used to search for taxa by name.
taxonomy_taxon, for more information about a given taxon.
}
rotl/man/figures/ 0000755 0001762 0000144 00000000000 14441553346 013462 5 ustar ligges users rotl/man/figures/logo.svg 0000644 0001762 0000144 00000350147 14441553346 015155 0 ustar ligges users
rotl/man/get_study_subtree.Rd 0000644 0001762 0000144 00000004307 14441553346 016051 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/studies.R
\name{get_study_subtree}
\alias{get_study_subtree}
\title{Study Subtree}
\usage{
get_study_subtree(
study_id,
tree_id,
subtree_id,
object_format = c("phylo"),
tip_label = c("original_label", "ott_id", "ott_taxon_name"),
file_format,
file,
deduplicate = TRUE,
...
)
}
\arguments{
\item{study_id}{the study identifier (character)}
\item{tree_id}{the tree identifier (character)}
\item{subtree_id, }{either a node id that specifies a subtree or
\dQuote{ingroup} which returns the ingroup for this subtree.}
\item{object_format}{the class of the object returned by the
function (default, and currently only possibility \code{phylo}
from the \code{ape} package)}
\item{tip_label}{the format of the tip
labels. \dQuote{\code{original_label}} (default) returns the
original labels as provided in the study,
\dQuote{\code{ott_id}} labels are replaced by their ott IDs,
\dQuote{\code{ott_taxon_name}} labels are replaced by their
Open Tree Taxonomy taxon name.}
\item{file_format}{character, the file format to use to save the
results of the query (possible values, \sQuote{newick} or
\sQuote{nexus}).}
\item{file}{character, the path and file name where the output
should be written.}
\item{deduplicate}{logical (default \code{TRUE}). If the tree
returned by the study contains duplicated taxon names, should
they be made unique? It is normally illegal for NEXUS/Newick
tree strings to contain duplicated tip names. This is a
workaround to circumvent this requirement. If \code{TRUE},
duplicated tip labels will be appended \code{_1}, \code{_2},
etc.}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\description{
Retrieve subtree from a specific tree in the Open Tree of Life data store
}
\examples{
\dontrun{
small_tr <- get_study_subtree(study_id="pg_1144", tree_id="tree5800", subtree_id="node991044")
ingroup <- get_study_subtree(study_id="pg_1144", tree_id="tree5800", subtree_id="ingroup")
nexus_file <- tempfile(fileext=".nex")
get_study_subtree(study_id="pg_1144", tree_id="tree5800", subtree_id="ingroup", file=nexus_file,
file_format="nexus")
}
}
rotl/man/taxonomy_about.Rd 0000644 0001762 0000144 00000002124 14441553346 015354 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/taxonomy.R
\name{taxonomy_about}
\alias{taxonomy_about}
\title{Information about the Open Tree Taxonomy}
\usage{
taxonomy_about(...)
}
\arguments{
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
A list with the following properties:
\itemize{
\item {weburl} {String. The release page for this version
of the taxonomy.}
\item {author} {String. The author string.}
\item {name} {String. The name of the taxonomy.}
\item {source} {String. The full identifying information for
this version of the taxonomy.}
\item {version} {String. The version number of the taxonomy.}
}
}
\description{
Summary information about the Open Tree Taxonomy (OTT)
}
\details{
Return metadata and information about the taxonomy
itself. Currently, the available metadata is fairly sparse, but
includes (at least) the version, and the location from which the
complete taxonomy source files can be downloaded.
}
\examples{
\dontrun{
taxonomy_about()
}
}
rotl/man/get_study_meta.Rd 0000644 0001762 0000144 00000003750 14441553346 015327 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/studies-methods.R, R/studies.R
\name{get_tree_ids}
\alias{get_tree_ids}
\alias{get_publication}
\alias{candidate_for_synth}
\alias{get_study_year}
\alias{get_tree_ids.study_meta}
\alias{get_publication.study_meta}
\alias{candidate_for_synth.study_meta}
\alias{get_study_year.study_meta}
\alias{get_study_meta}
\title{Study Metadata}
\usage{
get_tree_ids(sm)
get_publication(sm)
candidate_for_synth(sm)
get_study_year(sm)
\method{get_tree_ids}{study_meta}(sm)
\method{get_publication}{study_meta}(sm)
\method{candidate_for_synth}{study_meta}(sm)
\method{get_study_year}{study_meta}(sm)
get_study_meta(study_id, ...)
}
\arguments{
\item{sm}{an object created by \code{get_study_meta}}
\item{study_id}{the study identifier (character)}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
named-list containing the metadata associated with the
study requested
}
\description{
Retrieve metadata about a study in the Open Tree of Life datastore.
}
\details{
\code{get_study_meta} returns a long list of attributes for the
studies that are contributing to the synthetic tree. To help with
the extraction of relevant information from this list, several
helper functions exists: \itemize{
\item {get_tree_ids} { The identifiers of the trees
associated with the study }
\item {get_publication} { The citation information of the
publication for the study. The DOI (or URL) for the study is
available as an attribute to the returned object (i.e.,
\code{attr(object, "DOI")} ) }.
\item {candidate_for_synth} { The identifier of the tree(s) from
the study used in the synthetic tree. This is a subset of the
result of \code{get_tree_ids}.
\item {get_study_year} { The year of publication of the study. }
}
}
}
\examples{
\dontrun{
req <- get_study_meta("pg_719")
get_tree_ids(req)
candidate_for_synth(req)
get_publication(req)
get_study_year(req)
}
}
rotl/man/studies_find_studies.Rd 0000644 0001762 0000144 00000004776 14441553346 016543 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/studies.R
\name{studies_find_studies}
\alias{studies_find_studies}
\title{Find a Study}
\usage{
studies_find_studies(
property = NULL,
value = NULL,
verbose = FALSE,
exact = FALSE,
detailed = TRUE,
...
)
}
\arguments{
\item{property}{The property to be searched on (character)}
\item{value}{The property value to be searched on (character)}
\item{verbose}{Should the output include all metadata (logical
default \code{FALSE})}
\item{exact}{Should exact matching be used? (logical, default
\code{FALSE})}
\item{detailed}{If \code{TRUE} (default), the function will return
a data frame that summarizes information about the study (see
\sQuote{Value}). Otherwise, it only returns the study
identifiers.}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
If \code{detailed=TRUE}, the function returns a data frame
listing the study id (\code{study_ids}), the number of trees
associated with this study (\code{n_trees}), the tree ids (at
most 5) associated with the studies (\code{tree_ids}), the
tree id that is a candidate for the synthetic tree if any
(\code{candidate}), the year of publication of the study
(\code{study_year}), the title of the publication for the
study (\code{title}), and the DOI (Digital Object Identifier)
for the study (\code{study_doi}).
If \code{detailed=FALSE}, the function returns a data frame
with a single column containing the study identifiers.
}
\description{
Return the identifiers of studies that match given properties
}
\examples{
\dontrun{
## To match a study for which the identifier is already known
one_study <- studies_find_studies(property="ot:studyId", value="pg_719")
list_trees(one_study)
## To find studies pertaining to Mammals
mammals <- studies_find_studies(property="ot:focalCladeOTTTaxonName",
value="mammalia")
## To extract the tree identifiers for each of the studies
list_trees(mammals)
## ... or for a given study
list_trees(mammals, "ot_308")
## Just the identifiers without other information about the studies
mammals <- studies_find_studies(property="ot:focalCladeOTTTaxonName",
value="mammalia", detailed=FALSE)
}
}
\seealso{
\code{\link{studies_properties}} which lists properties
against which the studies can be
searched. \code{\link{list_trees}} that returns a list for all
tree ids associated with a study.
}
rotl/man/tnrs_match_names.Rd 0000644 0001762 0000144 00000007142 14441645015 015631 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tnrs.R
\name{tnrs_match_names}
\alias{tnrs_match_names}
\title{Match names to the Open Tree Taxonomy}
\usage{
tnrs_match_names(
names = NULL,
context_name = "All life",
do_approximate_matching = TRUE,
ids = NULL,
include_suppressed = FALSE,
...
)
}
\arguments{
\item{names}{taxon names to be queried. Currently limited to 10,000 names
for exact matches and 2,500 names for approximate matches (character
vector)}
\item{context_name}{name of the taxonomic context to be searched (length-one
character vector or \code{NULL}). Must match (case sensitive) one of the
values returned by \code{\link{tnrs_contexts}}. Default to "All life".}
\item{do_approximate_matching}{A logical indicating whether or not to
perform approximate string (a.k.a. \dQuote{fuzzy}) matching. Using
\code{FALSE} will greatly improve speed. Default, however, is \code{TRUE}.}
\item{ids}{A vector of ids to use for identifying names. These will be
assigned to each name in the names array. If ids is provided, then ids and
names must be identical in length.}
\item{include_suppressed}{Ordinarily, some quasi-taxa, such as incertae
sedis buckets and other non-OTUs, are suppressed from TNRS results. If
this parameter is true, these quasi-taxa are allowed as possible TNRS
results.}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
A data frame summarizing the results of the query. The original
query output is appended as an attribute to the returned object (and can
be obtained using \code{attr(object, "original_response")}).
}
\description{
Match taxonomic names to the Open Tree Taxonomy.
}
\details{
Accepts one or more taxonomic names and returns information about
potential matches for these names to known taxa in the Open Tree
Taxonomy.
This service uses taxonomic contexts to disambiguate homonyms and misspelled
names; a context may be specified using the \code{context_name} argument.
The default value for \code{context_name} is "All life". If no context is
specified (i.e., \code{context_name} is set to \code{NULL}), then the
context will be inferred (i.e., the shallowest taxonomic context that
contains all unambiguous names in the input). Taxonomic contexts are
uncontested higher taxa that have been selected to allow limits to be
applied to the scope of TNRS searches (e.g. 'match names only within
flowering plants'). Once a context has been identified (either
user-specified or inferred), all taxon name matches will performed only
against taxa within that context. For a list of available taxonomic
contexts, see \code{\link{tnrs_contexts}}.
A name is considered unambiguous if it is not a synonym and has
only one exact match to any taxon name in the entire taxonomy.
When the name search returns multiple matches, the taxon with the highest
match score is returned. If the name returned is not the one you intended,
you can use the \code{inspect} function to check the other taxa returned by
your search. The
\href{https://docs.ropensci.org/rotl/articles/rotl.html#how-to-change-the-ott-ids-assigned-to-my-taxa}{Getting
Started vignette} has more information on how to do this.
Several functions listed in the \sQuote{See also} section can be
used to inspect and manipulate the object generated by this
function.
}
\examples{
\dontrun{
deuterostomes <- tnrs_match_names(names=c("echinodermata", "xenacoelomorpha",
"chordata", "hemichordata"))
}
}
\seealso{
\code{\link{inspect.match_names}},
\code{\link{update.match_names}}, \code{\link{synonyms.match_names}}.
}
rotl/man/match_names.Rd 0000644 0001762 0000144 00000005000 14441553346 014557 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/match_names.R
\name{inspect.match_names}
\alias{inspect.match_names}
\alias{inspect}
\alias{update.match_names}
\title{Inspect and Update alternative matches for a name returned
by tnrs_match_names}
\usage{
\method{inspect}{match_names}(response, row_number, taxon_name, ott_id, ...)
inspect(response, ...)
\method{update}{match_names}(object, row_number, taxon_name, ott_id, new_row_number, new_ott_id, ...)
}
\arguments{
\item{response}{an object generated by the
\code{\link{tnrs_match_names}} function}
\item{row_number}{the row number corresponding to the name to
inspect}
\item{taxon_name}{the taxon name corresponding to the name to
inspect}
\item{ott_id}{the ott id corresponding to the name to inspect}
\item{...}{currently ignored}
\item{object}{an object created by \code{\link{tnrs_match_names}}}
\item{new_row_number}{the row number in the output of
\code{\link{inspect}} to replace the taxa specified by
\code{row_number}, \code{taxon_name}, or \code{ott_id}.}
\item{new_ott_id}{the ott id of the taxon to replace the taxa
specified by \code{row_number}, \code{taxon_name}, or
\code{ott_id}.}
}
\value{
a data frame
}
\description{
Taxonomic names may have different meanings in different taxonomic
contexts, as the same genus name can be applied to animals and
plants for instance. Additionally, the meaning of a taxonomic name
may have change throughout its history, and may have referred to a
different taxon in the past. In such cases, a given names might
have multiple matches in the Open Tree Taxonomy. These functions
allow users to inspect (and update) alternative meaning of a given
name and its current taxonomic status according to the Open Tree
Taxonomy.
}
\details{
To inspect alternative taxonomic meanings of a given name, you
need to provide the object resulting from a call to the
tnrs_match_names function, as well as one of either the row number
corresponding to the name in this object, the name itself (as used
in the original query), or the ott_id listed for this name.
To update one of the name, you also need to provide the row number
in which the name to be replaced appear or its ott id.
}
\examples{
\dontrun{
matched_names <- tnrs_match_names(c("holothuria", "diadema", "boletus"))
inspect(matched_names, taxon_name="diadema")
new_matched_names <- update(matched_names, taxon_name="diadema",
new_ott_id = 631176)
new_matched_names
}
}
\seealso{
\code{\link{tnrs_match_names}}
}
rotl/man/taxonomy_mrca.Rd 0000644 0001762 0000144 00000003316 14441553346 015170 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/taxonomy.R
\name{taxonomy_mrca}
\alias{taxonomy_mrca}
\alias{tax_rank.taxon_mrca}
\alias{tax_name.taxon_mrca}
\alias{ott_id.taxon_mrca}
\alias{unique_name.taxon_mrca}
\alias{tax_sources.taxon_mrca}
\alias{flags.taxon_mrca}
\alias{is_suppressed.taxon_mrca}
\title{Taxonomic MRCA}
\usage{
taxonomy_mrca(ott_ids = NULL, ...)
\method{tax_rank}{taxon_mrca}(tax, ...)
\method{tax_name}{taxon_mrca}(tax, ...)
\method{ott_id}{taxon_mrca}(tax, ...)
\method{unique_name}{taxon_mrca}(tax, ...)
\method{tax_sources}{taxon_mrca}(tax, ...)
\method{flags}{taxon_mrca}(tax, ...)
\method{is_suppressed}{taxon_mrca}(tax, ...)
}
\arguments{
\item{ott_ids}{a vector of ott ids for the taxa whose MRCA is to
be found (numeric).}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
\item{tax}{an object generated by the \code{taxonomy_mrca}
function}
}
\value{
\itemize{
\item{\code{taxonomy_mrca}} { returns a list about the
taxonomic information relating to the MRCA for the ott_ids
provided. }
\item{\code{tax_rank}} { returns a character vector of the
taxonomic rank for the MRCA. }
\item{\code{tax_name}} { returns a character vector the
Open Tree Taxonomy name for the MRCA. }
\item{\code{ott_id}} { returns a numeric vector of the ott id
for the MRCA. }
}
}
\description{
Taxonomic Least Inclusive Common Ancestor (MRCA)
}
\details{
Given a set of OTT ids, get the taxon that is the most recent common
ancestor (the MRCA) of all the identified taxa.
}
\examples{
\dontrun{
req <- taxonomy_mrca(ott_ids=c(515698,590452,643717))
tax_rank(req)
tax_name(req)
ott_id(req)
}
}
rotl/man/get_study.Rd 0000644 0001762 0000144 00000003742 14441553346 014322 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/studies.R
\name{get_study}
\alias{get_study}
\title{Get all the trees associated with a particular study}
\usage{
get_study(
study_id = NULL,
object_format = c("phylo", "nexml"),
file_format,
file,
...
)
}
\arguments{
\item{study_id}{the study ID for the study of interest (character)}
\item{object_format}{the class of the object the query should
return (either \code{phylo} or \code{nexml}). Ignored if
\code{file_format} is specified.}
\item{file_format}{the format of the file to be generated
(\code{newick}, \code{nexus}, \code{nexml} or \code{json}).}
\item{file}{the file name where the output of the function will be
saved.}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
if \code{file_format} is missing, an object of class
\code{phylo} or \code{nexml}, otherwise a logical indicating
whether the file was successfully created.
}
\description{
Returns the trees associated with a given study
}
\details{
If \code{file_format} is missing, the function returns an object
of the class \code{phylo} from the \code{ape} package
(default), or an object of the class \code{nexml} from the
\code{RNeXML} package.
Otherwise \code{file_format} can be either \code{newick},
\code{nexus}, \code{nexml} or \code{json}, and the function will
generate a file of the selected format. In this case, a file name
needs to be provided using the argument \code{file}. If a file
with the same name already exists, it will be silently
overwritten.
}
\examples{
\dontrun{
that_one_study <- get_study(study_id="pg_719", object_format="phylo")
if (require(RNeXML)) { ## if RNeXML is installed get the object directly
nexml_study <- get_study(study_id="pg_719", object_format="nexml")
} else { ## otherwise write it to a file
get_study(study_id="pg_719", file_format="nexml", file=tempfile(fileext=".nexml"))
}
}
}
\seealso{
\code{\link{get_study_meta}}
}
rotl/man/strip_ott_ids.Rd 0000644 0001762 0000144 00000001635 14441553346 015200 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tol.R
\name{strip_ott_ids}
\alias{strip_ott_ids}
\title{Strip OTT ids from tip labels}
\usage{
strip_ott_ids(tip_labels, remove_underscores = FALSE)
}
\arguments{
\item{tip_labels}{a character vector containing tip labels (most
likely the \code{tip.label} element from a tree returned by
\code{\link{tol_induced_subtree}}}
\item{remove_underscores}{logical (defaults to FALSE). If set to
TRUE underscores in tip labels are converted to spaces}
}
\value{
A character vector containing the contents of
\code{tip_labels} with any OTT ids removed.
}
\description{
Strip OTT ids from tip labels
}
\examples{
\dontrun{
genera <- c("Perdix", "Setophaga", "Cinclus", "Struthio")
tr <- tol_induced_subtree(ott_ids=c(102710, 285198, 267845, 292466))
tr$tip.label \%in\% genera
tr$tip.label <- strip_ott_ids(tr$tip.label)
tr$tip.label \%in\% genera
}
}
rotl/man/tol_node_info.Rd 0000644 0001762 0000144 00000010413 14442034340 015107 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/methods.R, R/tol.R
\name{tol_lineage}
\alias{tol_lineage}
\alias{tol_node_info}
\alias{tax_rank.tol_node}
\alias{tax_sources.tol_node}
\alias{unique_name.tol_node}
\alias{tax_name.tol_node}
\alias{ott_id.tol_node}
\alias{source_list.tol_node}
\alias{tax_lineage.tol_node}
\alias{tol_lineage.tol_node}
\title{Node info}
\usage{
tol_lineage(tax, ...)
tol_node_info(ott_id = NULL, node_id = NULL, include_lineage = FALSE, ...)
\method{tax_rank}{tol_node}(tax, ...)
\method{tax_sources}{tol_node}(tax, ...)
\method{unique_name}{tol_node}(tax, ...)
\method{tax_name}{tol_node}(tax, ...)
\method{ott_id}{tol_node}(tax, ...)
\method{source_list}{tol_node}(tax, ...)
\method{tax_lineage}{tol_node}(tax, ...)
\method{tol_lineage}{tol_node}(tax, ...)
}
\arguments{
\item{tax}{an object returned by \code{tol_node_info}.}
\item{...}{additional arguments to customize the API call (see
?rotl for more information)}
\item{ott_id}{Numeric. The OpenTree taxonomic identifier.}
\item{node_id}{Character. The OpenTree node identifier.}
\item{include_lineage}{Logical (default = FALSE). Whether to return the
lineage of the node from the synthetic tree.}
}
\value{
\code{tol_node_info} returns an invisible list of summary
information about the queried node:
\itemize{
\item {node_id} {String. The canonical identifier of the node.}
\item {num_tips} {Numeric. The number of descendant tips.}
\item {partial_path_of} {List. The edge below this synthetic tree node
is compatible with the edge below each of these input tree nodes (one
per tree). Each returned element is reported as sourceid:nodeid.}
\item {query} { The node id that resolved to this node. This can differ
from the node_id field if the query id is not canonical. }
\item {taxon} {A list of taxonomic properties. Only returned if
the queried node is a taxon. Each source has:}
\itemize{
\item {ott_id} {Numeric. The OpenTree Taxonomy ID (ottID).}
\item {name} {String. The taxonomic name of the queried node.}
\item {unique_name} {String. The string that uniquely
identifies the taxon in OTT.}
\item {rank} {String. The taxonomic rank of the taxon in OTT.}
\item {tax_sources} {List. A list of identifiers for taxonomic
sources, such as other taxonomies, that define taxa judged
equivalent to this taxon.}
}
The following properties list support/conflict for the node across
synthesis source trees. All properties involve sourceid keys and
nodeid values (see \code{source_id_map} below).
\item {supported_by} {List. Input tree nodes (one per tree) that support
this synthetic tree node. Each returned element is reported as
sourceid:nodeid.}
\item {terminal} {List. Input tree nodes (one per tree) that are
equivalent to this synthetic tree node (via an exact mapping, or the
input tree terminal may be the only terminal descended from this
synthetic tree node. Each returned element is reported as
sourceid:nodeid.}
\item {conflicts_with} {Named list of lists. Names correspond to
sourceid keys. Each list contains input tree node ids (one or more per
tree) that conflict with this synthetic node.}
}
\code{tol_lineage} and \code{tax_lineage} return data
frames. \code{tol_lineage} indicate for each ancestor its
node identifier, the number of tips descending from that
node, and whether it corresponds to a taxonomic level.
}
\description{
Get summary information about a node in the synthetic tree
}
\details{
Returns summary information about a node in the graph. The
node of interest may be specified using either a node id or an
taxon id, but not both. If the specified node or OTT id is not
in the graph, an error will be returned.
If the argument \code{include_lineage=TRUE} is used, you can
use \code{tax_lineage()} or \code{tol_lineage} to return the
taxonomic information or the node information for all the
ancestors to this node, down to the root of the tree.
}
\examples{
\dontrun{
birds <- tol_node_info(ott_id=81461, include_lineage=TRUE)
source_list(birds)
tax_rank(birds)
ott_id(birds)
tax_lineage(birds)
tol_lineage(birds)}
}
rotl/man/is_in_tree.Rd 0000644 0001762 0000144 00000002631 14441553346 014427 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/is_in_tree.R
\name{is_in_tree}
\alias{is_in_tree}
\title{Check that OTT ids occur in the Synthetic Tree}
\usage{
is_in_tree(ott_ids, ...)
}
\arguments{
\item{ott_ids}{a vector of Open Tree Taxonomy identifiers}
\item{...}{additional arguments to customize the API request (see
\code{\link{rotl}} package documentation).}
}
\value{
A named logical vector. \code{TRUE} indicates that the OTT
id is in the synthetic tree, and \code{FALSE} that it is not.
}
\description{
Some valid taxonomic names do not occur in the Synthetic
Tree. This convenience function allows you to check whether a
given Open Tree Taxonomy identifier (OTT id) is in the tree. A taxonomic
name may not occur in the synthetic tree because (1) it is an
extinct or invalid taxon, or (2) it is part of a group that is not
monophyletic in the tree.
}
\examples{
\dontrun{
plant_families <- c("Asteraceae", "Solanaceae", "Poaceae", "Amaranthaceae",
"Zamiaceae", "Araceae", "Juncaceae")
matched_names <- tnrs_match_names(plant_families)
## This fails because some ott ids are not in the tree
## plant_tree <- tol_induced_subtree(ott_id(matched_names))
## So let's check which ones are actually in the tree first:
in_tree <- is_in_tree(ott_id(matched_names))
## This now works:
plant_tree <- tol_induced_subtree(ott_id(matched_names)[in_tree])
}
}
rotl/man/tol_mrca.Rd 0000644 0001762 0000144 00000013436 14442034340 014101 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tol.R
\name{tol_mrca}
\alias{tol_mrca}
\alias{tax_sources.tol_mrca}
\alias{unique_name.tol_mrca}
\alias{tax_name.tol_mrca}
\alias{tax_rank.tol_mrca}
\alias{ott_id.tol_mrca}
\alias{source_list.tol_mrca}
\title{MRCA of taxa from the synthetic tree}
\usage{
tol_mrca(ott_ids = NULL, node_ids = NULL, ...)
\method{tax_sources}{tol_mrca}(tax, ...)
\method{unique_name}{tol_mrca}(tax, ...)
\method{tax_name}{tol_mrca}(tax, ...)
\method{tax_rank}{tol_mrca}(tax, ...)
\method{ott_id}{tol_mrca}(tax, ...)
\method{source_list}{tol_mrca}(tax, ...)
}
\arguments{
\item{ott_ids}{Numeric vector. The ott ids for which the MRCA is desired.}
\item{node_ids}{Character vector. The node ids for which the MRCA is desired.}
\item{...}{additional arguments to customize the API call (see
\code{\link{rotl}} for more information).}
\item{tax}{an object returned by \code{tol_mrca()}.}
}
\value{
An invisible list of the MRCA node properties:
\itemize{
\item {mrca} {List of node properties.}
\itemize{
\item {node_id} {String. The canonical identifier of the node.}
\item {num_tips} {Numeric. The number of descendant tips.}
\item {taxon} {A list of taxonomic properties. Only returned if
the queried node is a taxon. (If the node is not a taxon, a
\code{nearest_taxon} list is returned (see below)).}
\itemize{
\item {ott_id} {Numeric. The OpenTree Taxonomy ID (ottID).}
\item {name} {String. The taxonomic name of the queried node.}
\item {unique_name} {String. The string that uniquely
identifies the taxon in OTT.}
\item {rank} {String. The taxonomic rank of the taxon in OTT.}
\item {tax_sources} {List. A list of identifiers for taxonomic
sources, such as other taxonomies, that define taxa judged
equivalent to this taxon.}
}
The following properties list support/conflict for the node across
synthesis source trees. All properties involve sourceid keys and
nodeid values (see \code{source_id_map} below) Not all properties are
are present for every node.
\item {partial_path_of} {List. The edge below this synthetic tree node
is compatible with the edge below each of these input tree nodes (one
per tree). Each returned element is reported as sourceid:nodeid.}
\item {supported_by} {List. Input tree nodes (one per tree) that support
this synthetic tree node. Each returned element is reported as
sourceid:nodeid.}
\item {terminal} {List. Input tree nodes (one per tree) that are equivalent
to this synthetic tree node (via an exact mapping, or the input tree
terminal may be the only terminal descended from this synthetic tree node.
Each returned element is reported as sourceid:nodeid.}
\item {conflicts_with} {Named list of lists. Names correspond to
sourceid keys. Each list contains input tree node ids (one or more per tree)
that conflict with this synthetic node.}
}
\item {nearest_taxon} {A list of taxonomic properties of the nearest rootward
taxon node to the MRCA node. Only returned if the MRCA node is a not taxon
(otherwise the \code{taxon} list above is returned).}
\itemize{
\item {ott_id} {Numeric. The OpenTree Taxonomy ID (ottID).}
\item {name} {String. The taxonomic name of the queried node.}
\item {unique_name} {String. The string that uniquely
identifies the taxon in OTT.}
\item {rank} {String. The taxonomic rank of the taxon in OTT.}
\item {tax_sources} {List. A list of identifiers for taxonomic
sources, such as other taxonomies, that define taxa judged
equivalent to this taxon.}
}
\item {source_id_map} {Named list of lists. Names correspond to the
sourceid keys used in the support/conflict properties of the \code{mrca}
list above. Source trees will have the following properties:}
\itemize{
\item {git_sha} {The git SHA identifying a particular source
version.}
\item {tree_id} {The tree id associated with the study id used.}
\item {study_id} {The study identifier. Will typically include
a prefix ("pg_" or "ot_").}
}
The only sourceid that does not correspond to a source tree is the taxonomy,
which will have the name "ott"+`taxonomy_version`, and the value is the
ott_id of the taxon in that taxonomy version. "Taxonomy" will only ever
appear in \code{supported_by}.
}
}
\description{
Most Recent Common Ancestor for a set of nodes
}
\details{
Get the MRCA of a set of nodes on the current synthetic
tree. Accepts any combination of node ids and ott ids as
input. Returns information about the most recent common
ancestor (MRCA) node as well as the most recent taxonomic
ancestor (MRTA) node (the closest taxonomic node to the MRCA
node in the synthetic tree; the MRCA and MRTA may be the same
node). If they are the same, the taxonomic information will be
in the \code{mrca} slot, otherwise they will be in the
\code{nearest_taxon} slot of the list. If any of the specified
nodes is not in the synthetic tree an error will be returned.
Taxonomic methods (\code{tax_sources()}, \code{ott_id()},
\code{unique_name()}, ...) are available on the objects
returned by \code{tol_mrca()}. If the MRCA node is MRTA, the
name of the object returned by these methods will start with
\sQuote{ott}, otherwise it will start with \sQuote{mrca}.
}
\examples{
\dontrun{
birds_mrca <- tol_mrca(ott_ids=c(412129, 119214))
ott_id(birds_mrca)
tax_sources(birds_mrca)
}
}
rotl/man/study_external_IDs.Rd 0000644 0001762 0000144 00000002562 14441553346 016123 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/external_data.R
\name{study_external_IDs}
\alias{study_external_IDs}
\title{Get external identifiers for data associated with an Open Tree study}
\usage{
study_external_IDs(study_id)
}
\arguments{
\item{study_id}{An open tree study ID}
}
\value{
A study_external_data object (which inherits from a list) which
contains some of the following.
doi, character, the DOI for the paper describing this study
external_data_url, character, a URL to an external data repository
(e.g. a treebase entry) if one exists.
pubmed_id character, the unique ID for this study in the NCBI's pubmed database
popset_ids character, vector of IDs for the NCBI's popset database
nucleotide_ids character, vector of IDs for the NCBI's nucleotide database
}
\description{
Data associated with studies contributing to the Open Tree synthesis may
be available from other databases. In particular, trees and alignments
may be available from treebase and DNA sequences and bibliographic
information associated with a given study may be available from the NCBI.
This function retrieves that information for a given study.
}
\examples{
\dontrun{
flies <- studies_find_studies(property="ot:focalCladeOTTTaxonName", value="Drosophilidae")
study_external_IDs(flies[2,]$study_ids)
}
}
\seealso{
studies_find_studies (used to discover study IDs)
}
rotl/DESCRIPTION 0000644 0001762 0000144 00000004223 14442613417 012747 0 ustar ligges users Package: rotl
Title: Interface to the 'Open Tree of Life' API
Version: 3.1.0
Authors@R:
c(person(given = "Francois",
family = "Michonneau",
role = c("aut", "cre"),
email = "francois.michonneau@gmail.com",
comment = c(ORCID = "0000-0002-9092-966X")),
person(given = "Joseph",
family = "Brown",
role = "aut",
comment = c(ORCID = "0000-0002-3835-8062")),
person(given = "David",
family = "Winter",
role = "aut",
comment = c(ORCID = "0000-0002-6165-0029")),
person(given = "Scott",
family = "Chamberlain",
role = "rev",
comment = c(ORCID = "0000-0003-1444-9135")))
Description: An interface to the 'Open Tree of Life' API to retrieve
phylogenetic trees, information about studies used to assemble the
synthetic tree, and utilities to match taxonomic names to 'Open Tree
identifiers'. The 'Open Tree of Life' aims at assembling a
comprehensive phylogenetic tree for all named species.
License: BSD_2_clause + file LICENSE
URL: https://docs.ropensci.org/rotl/, https://github.com/ropensci/rotl
BugReports: https://github.com/ropensci/rotl/issues
Depends: R (>= 3.1.1)
Imports: ape, curl (>= 3.0.0), httr, jsonlite, rentrez, rlang, rncl (>=
0.6.0)
Suggests: knitr (>= 1.12), MCMCglmm, phylobase, readxl, rmarkdown (>=
0.7), RNeXML, testthat
VignetteBuilder: knitr
Encoding: UTF-8
X-schema.org-isPartOf: https://ropensci.org
X-schema.org-keywords: metadata, ropensci, phylogenetics,
independant-contrasts, biodiversity
X-schema.org-relatedLink: https://codemeta.github.io/codemetar
RoxygenNote: 7.2.1
NeedsCompilation: no
Packaged: 2023-06-15 09:34:25 UTC; francois
Author: Francois Michonneau [aut, cre]
(),
Joseph Brown [aut] (),
David Winter [aut] (),
Scott Chamberlain [rev] ()
Maintainer: Francois Michonneau
Repository: CRAN
Date/Publication: 2023-06-15 13:50:07 UTC
rotl/build/ 0000755 0001762 0000144 00000000000 14442555441 012341 5 ustar ligges users rotl/build/vignette.rds 0000644 0001762 0000144 00000000451 14442555441 014700 0 ustar ligges users RMO0ֲ/ ?qW&$iHܐI&?~/ !ҁhEfBZ|h}i|~)kTX4FYmBWwZ)Zޙɬf%WlWq,7Ƒl{(JP+&CjYbV|pDv3Hr0QneH=d%
O;S(i/pF<vz;5fa9Ժx؈&O2m~+J4AQH.JS6iY rotl/tests/ 0000755 0001762 0000144 00000000000 14441553346 012405 5 ustar ligges users rotl/tests/test-all.R 0000644 0001762 0000144 00000000051 14441553346 014251 0 ustar ligges users ###
library(testthat)
test_check("rotl")
rotl/tests/testthat/ 0000755 0001762 0000144 00000000000 14442555441 014244 5 ustar ligges users rotl/tests/testthat/test-external.R 0000644 0001762 0000144 00000002362 14441553346 017172 0 ustar ligges users context("Study external data")
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
all_sources <- c("doi", "pubmed_id", "external_data_url", "popset_ids", "nucleotide_ids")
all_data <- study_external_IDs("pg_1940")
}
test_that("We can recover dois, pmids, NCBI IDs", {
skip_on_cran()
expect_that(all_data, is_a("study_external_data"))
expect_named(all_data)
})
test_that("We can handle studies with missing external IDs", {
skip_on_cran()
expect_warning(
missing_data <- study_external_IDs("ot_97"), "skipping NCBI"
)
expect_named(missing_data)
expect_that(missing_data, is_a("study_external_data"))
expect_equal(sum(is.na(match(all_sources, names(missing_data)))), 2) # we really skipped the NCBI
})
test_that("The print functions for external data objects work", {
skip_on_cran()
missing_data <- study_external_IDs("ot_91")
expect_output(print(all_data), "External data identifiers for study")
expect_output(print(missing_data), "External data identifiers for study")
})
context("Taxon external data")
test_that("We can recover external IDs for Open Tree taxa", {
skip_on_cran()
gibbon_IDs <- taxon_external_IDs(712902)
expect_that(gibbon_IDs, is_a("data.frame"))
expect_equal(names(gibbon_IDs), c("source", "id"))
})
rotl/tests/testthat/test-api-taxonomy.R 0000644 0001762 0000144 00000005355 14441553346 020002 0 ustar ligges users context("taxonomy API")
############################################################################
## .taxonomy_taxon_info ##
############################################################################
test_that("ott_id is not null for .taxonomy_taxon_info", {
skip_on_cran()
expect_error(
.taxonomy_taxon_info(NULL),
"must supply"
)
})
test_that("ott_id is of length 1 for .taxonomy_taxon_info", {
skip_on_cran()
expect_error(
.taxonomy_taxon_info(c(123, 456, 789)),
"Must only supply"
)
})
test_that("ott_id is a numeric for .taxonomy_taxon_info", {
skip_on_cran()
expect_error(
.taxonomy_taxon_info(TRUE),
"look like numbers"
)
})
test_that("include_lineage is a flag", {
skip_on_cran()
expect_error(
.taxonomy_taxon_info(ott_id = 515698, include_lineage = c(TRUE, FALSE)),
"is not a flag"
)
expect_error(
.taxonomy_taxon_info(ott_id = 515698, include_lineage = c("na")),
"is not a flag"
)
expect_error(
.taxonomy_taxon_info(ott_id = 515698, include_lineage = c(1235)),
"is not a flag"
)
})
test_that("list_terminal_descendants is a flag", {
skip_on_cran()
expect_error(
.taxonomy_taxon_info(ott_id = 515698, include_terminal_descendants = c(TRUE, FALSE)),
"is not a flag"
)
expect_error(
.taxonomy_taxon_info(ott_id = 515698, include_terminal_descendants = c("na")),
"is not a flag"
)
expect_error(
.taxonomy_taxon_info(ott_id = 515698, include_terminal_descendants = c(1235)),
"is not a flag"
)
})
############################################################################
## .taxonomy_subtree ##
############################################################################
test_that("ott_id is not null for .taxonomy_subtree", {
skip_on_cran()
expect_error(
.taxonomy_subtree(NULL),
"must supply"
)
})
test_that("ott_id is of length 1 for .taxonomy_subtree", {
skip_on_cran()
expect_error(
.taxonomy_subtree(c(123, 456, 789)),
"Must only supply"
)
})
test_that("ott_id is a numeric for .taxonomy_subtree", {
skip_on_cran()
expect_error(
.taxonomy_subtree(TRUE),
"look like numbers"
)
})
############################################################################
## .taxonomy_mrca ##
############################################################################
test_that("ott_id is not null for .taxonomy_lica", {
skip_on_cran()
expect_error(
.taxonomy_mrca(NULL),
"must supply"
)
})
test_that("ott_id is a numeric for .taxonomy_lica", {
skip_on_cran()
expect_error(
.taxonomy_mrca(TRUE),
"look like numbers"
)
})
rotl/tests/testthat/test-tnrs.R 0000644 0001762 0000144 00000005602 14441644666 016344 0 ustar ligges users context("tnrs")
############################################################################
## tnrs_match_names ##
############################################################################
test_that("tnrs_match_names fails if incorrect context is provided", {
skip_on_cran()
expect_error(
tnrs_match_names("felis", context_name = "Cats"),
"Check possible values using tnrs_contexts"
)
})
test_that("tnrs_match_names warns if single invalid name provided", {
skip_on_cran()
expect_warning(
tnrs_match_names("fluffy", do_approximate_matching = FALSE),
"are not matched"
)
})
test_that("tnrs_match_names warns if at least one name is not matched", {
skip_on_cran()
expect_warning(
tnrs_match_names(c("fluffy", "felis"), do_approximate_matching = FALSE),
"are not matched"
)
})
test_that("tnrs_match_names warns if some names are duplicated", {
skip_on_cran()
expect_warning(tnrs_match_names(c("pan", "pongo", "Pan", "pongo", "felis", "feLis")))
})
test_that("object returned by tnrs_match_names have the correct data type", {
skip_on_cran()
birds <- c("stercorarius parasiticus", "ficedula albicollis", "sterna dougallii")
taxa <- tnrs_match_names(birds, do_approximate_matching = FALSE)
expect_true(is.logical(taxa[["approximate_match"]]))
expect_true(is.logical(taxa[["is_synonym"]]))
expect_equal(sum(taxa[["score"]]), 3)
})
test_that("tnrs_match_names deals correctly with non-exact matches", {
skip_on_cran()
birds <- c("stercorarius parasiticus", "ficedula albicollis", "sternadougallii")
expect_warning(
taxa <- tnrs_match_names(birds, do_approximate_matching = FALSE),
"are not matched"
)
expect_equal(nrow(taxa), 3L)
expect_equivalent(
taxa[match("sternadougallii", taxa[["search_string"]]), ],
list("sternadougallii", NA_character_, NA, NA_real_, NA_integer_, NA, NA_character_, NA_integer_)
)
})
## everything else is covered by the match_names + the API tests
############################################################################
## tnrs_contexts ##
############################################################################
test_that("tnrs_contexts", {
skip_on_cran()
tc <- tnrs_contexts()
expect_true(inherits(tc, "tnrs_contexts"))
expect_true(all(names(tc) %in% c("ANIMALS", "MICROBES", "FUNGI", "PLANTS", "LIFE")))
})
############################################################################
## tnrs_infer_context ##
############################################################################
test_that("tnrs_infer_context", {
skip_on_cran()
tic <- tnrs_infer_context(c("Felis", "Leo"))
expect_equal(tic[["context_name"]], "Mammals")
expect_equal(tic[["context_ott_id"]], 244265)
expect_equal(tic[["ambiguous_names"]][[1]], "Leo")
})
rotl/tests/testthat/test-match_names.R 0000644 0001762 0000144 00000032246 14441553346 017633 0 ustar ligges users context("match names")
hol_ott_id <- 924443
############################################################################
## check_args_match_names ##
############################################################################
context("check_args_match_names")
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
rsp <- tnrs_match_names(names = c("holothuria", "diadema", "fromia"))
}
test_that(
"error generated if object provided isn't created by tnrs_match_names",
expect_error(
rotl:::check_args_match_names(letters),
"was not created using"
)
)
test_that("error generated if no argument is provided", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp),
"You must specify"
)
})
test_that("error generated if row_number and taxon_name are provided", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp,
row_number = 1,
taxon_name = "holothuria"
),
"must use only one of "
)
})
test_that("error generated if row_number and ott_id are provided", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp,
row_number = 1,
ott_id = hol_ott_id
),
"must use only one of"
)
})
test_that("error generated if ott_id and taxon_name are provided", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp,
taxon_name = "holothuria",
ott_id = hol_ott_id
),
"must use only one of"
)
})
test_that("error generated if row_number is not numeric", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp, row_number = TRUE),
"must be a numeric"
)
})
test_that("error generated if ott_id is not numeric", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp, ott_id = TRUE),
"must look like a number"
)
})
test_that("error generated if taxon_name is not character", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp, taxon_name = TRUE),
"must be a character"
)
})
test_that("error generated if row_number if not one of the row", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp, row_number = 10),
"is not a valid row number"
)
expect_error(
rotl:::check_args_match_names(rsp, row_number = 1.5),
"is not a valid row number"
)
expect_error(
rotl:::check_args_match_names(rsp, row_number = 0),
"is not a valid row number"
)
})
test_that("error generated if invalid taxon_name", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp, taxon_name = "echinodermata"),
"Can't find"
)
expect_error(
rotl:::check_args_match_names(rsp, taxon_name = NA_character_),
"Can't find"
)
})
test_that("error generated if invalid ott id", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp, ott_id = 66666),
"Can't find"
)
})
test_that("error generated if more than 1 value for row_number is provided", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp, row_number = c(1, 2, 3)),
"You must supply a single element"
)
})
test_that("error generated if more than 1 value for taxon_name is provided", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp, taxon_name = c("holothuria", "diadema")),
"You must supply a single element"
)
})
test_that("error generated if more than 1 value for ott_id is provided", {
skip_on_cran()
expect_error(
rotl:::check_args_match_names(rsp, ott_id = c(5004030, 4930522, 240396)),
"only 1 element should be provided"
)
})
############################################################################
## inspect.match_names ##
############################################################################
context("inspect.match_names")
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
rsp <- tnrs_match_names(names = c("holothuria", "diadema", "fromia"))
expect_warning(rsp_na <- tnrs_match_names(names = c(
"diadema", "fluffy",
"hemichordata", "escherichia"
)))
diadema_ids <- c(4930522, 631176, 643831, 6356093, 4024672)
}
test_that("correct data is being returned when asked to lookup by taxon name", {
skip_on_cran()
tt <- inspect(rsp, taxon_name = "diadema")[["ott_id"]]
expect_true(all(tt %in% diadema_ids))
})
test_that("correct data is being returned when asked to lookup by ott_id", {
skip_on_cran()
tt <- inspect(rsp, ott_id = ott_id(rsp)[2])[["ott_id"]]
expect_true(all(tt %in% diadema_ids))
})
test_that("correct data is being returned when asked to lookup by row number", {
skip_on_cran()
tt <- inspect(rsp, row_number = 2)[["ott_id"]]
expect_true(all(tt %in% diadema_ids))
})
## with missing data
test_that("correct data is being returned when asked to lookup by taxon name (with missing data)", {
skip_on_cran()
tt <- inspect(rsp_na, taxon_name = "diadema")[["ott_id"]]
expect_true(all(tt %in% diadema_ids))
expect_true(is.na(inspect(rsp_na, taxon_name = "fluffy")[["ott_id"]]))
})
test_that("correct data is being returned when asked to lookup by ott_id (with missing data)", {
skip_on_cran()
tt <- inspect(rsp_na, ott_id = ott_id(rsp)[2])[["ott_id"]]
expect_true(all(tt %in% diadema_ids))
})
test_that("correct data is being returned when asked to lookup by row number (with missing data)", {
skip_on_cran()
tt <- inspect(rsp_na, row_number = 1)[["ott_id"]]
expect_true(all(tt %in% diadema_ids))
expect_true(is.na(inspect(rsp_na, row_number = 2)[["ott_id"]]))
})
############################################################################
## synonyms.match_names ##
############################################################################
context("list_synonym_match_names")
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
tax_rsp <- c("Holothuria", "Diadema", "Fromia")
rsp <- tnrs_match_names(names = tax_rsp)
tax_rsp_na <- c("Holothuria", "Diadema", "fluffy", "Fromia")
expect_warning(rsp_na <- tnrs_match_names(names = tax_rsp_na))
}
test_that("synonyms", {
skip_on_cran()
tt <- synonyms(rsp)
expect_true(inherits(tt, "list"))
expect_equal(
names(tt),
c("Holothuria", "Diadema", "Fromia")
)
})
test_that("correct synonyms are being returned when asked to look up by taxon name", {
skip_on_cran()
tt <- synonyms(rsp, taxon_name = "holothuria")
expect_true(any(grepl("^Holothuria", names(tt))))
})
test_that("holothuria is present in each element of the list", {
skip_on_cran()
tt <- synonyms(rsp, taxon_name = "holothuria")
expect_true(all(sapply(tt, function(x) any(grepl("holothuria", x, ignore.case = TRUE)))))
expect_true(any(grepl("Halodeima", tt[["Holothuria"]])))
})
test_that("correct synonyms are being returned when asked to look up by row number", {
skip_on_cran()
tt <- synonyms(rsp, row_number = 1)
expect_true(any(grepl("^Holothuria", names(tt))))
expect_true(any(grepl("Halodeima", tt[["Holothuria"]])))
})
test_that("correct synonyms are being returned when asked to look up by ott id", {
skip_on_cran()
tt <- synonyms(rsp, ott_id = 924443)
expect_true(any(grepl("^Holothuria", names(tt))))
expect_true(any(grepl("Halodeima", tt[["Holothuria"]])))
})
## with missing data
test_that("synonyms", {
skip_on_cran()
tt <- synonyms(rsp_na)
expect_true(inherits(tt, "list"))
expect_equal(
names(tt),
c("Holothuria", "Diadema", "Fromia")
)
})
test_that("correct synonyms are being returned when asked to look up by taxon name", {
skip_on_cran()
tt <- synonyms(rsp_na, taxon_name = "holothuria")
expect_true(any(grepl("^Holothuria", names(tt))))
expect_true(is.na(synonyms(rsp_na, taxon_name = "fluffy")[[1]]))
})
test_that("correct synonyms are being returned when asked to look up by row number", {
skip_on_cran()
tt <- synonyms(rsp_na, row_number = 1)
expect_true(any(grepl("^Holothuria", names(tt))))
expect_true(any(grepl("Halodeima", tt[["Holothuria"]])))
expect_true(is.na(synonyms(rsp_na, row_number = 3)[[1]]))
})
test_that("correct synonyms are being returned when asked to look up by ott id", {
skip_on_cran()
tt <- synonyms(rsp_na, ott_id = 924443)
expect_true(any(grepl("^Holothuria", names(tt))))
expect_true(any(grepl("Halodeima", tt[["Holothuria"]])))
})
############################################################################
## update.match_names ##
############################################################################
context("update.match_names")
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
rsp <- tnrs_match_names(names = c("holothuria", "diadema", "fromia"))
}
test_that("error message if missing both new arguments", {
skip_on_cran()
expect_error(
update(rsp, row_number = 1),
"You must specify either"
)
})
test_that("error message if both new arguments are provided", {
skip_on_cran()
expect_error(
update(rsp,
row_number = 1,
new_row_number = 1,
new_ott_id = 6666
),
"You must use only"
)
})
test_that("error message if wrong new row number provided", {
skip_on_cran()
expect_error(
update(rsp,
row_number = 1,
new_row_number = 10
),
"is not a valid row number"
)
expect_error(
update(rsp,
row_number = 1,
new_row_number = 1.5
),
"is not a valid row number"
)
})
test_that("error message if wrong new ott id provided", {
skip_on_cran()
expect_error(
update(rsp,
row_number = 1,
new_ott_id = 66666
),
"Can't find"
)
})
test_that("it works correctly when providing a new row number", {
skip_on_cran()
new_rsp <- update(
rsp,
row_number = 2,
new_row_number = 2
)
expect_equal(
new_rsp[new_rsp$search_string == "diadema", "ott_id"],
4024672
)
})
test_that("it works correctly when providing a new ott id", {
skip_on_cran()
new_rsp <- update(rsp,
row_number = 2,
new_ott_id = 631176
)
expect_equal(
new_rsp[new_rsp$search_string == "diadema", "ott_id"],
631176L
)
})
test_that("it produces warning when trying to update with unmatched name", {
skip_on_cran()
expect_warning(new_rsp <- update(rsp_na, row_number = 3, new_row_number = 1))
expect_identical(new_rsp, rsp_na)
})
############################################################################
## flags method ##
############################################################################
context("flags method for class match_names")
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
tax_rsp <- c(
"Tyrannosaurus", "Helicoplacus", "Ctenocystis",
"Holothuria", "Echinoidea"
)
rsp <- tnrs_match_names(tax_rsp)
}
test_that("flags with no arguments", {
skip_on_cran()
flags_rsp <- flags(rsp)
expect_equal(length(flags_rsp), 5)
expect_equivalent(
sapply(flags_rsp, length),
c(2, 3, 3, 0, 0)
)
})
test_that("flags with row number", {
skip_on_cran()
flags_rsp <- flags(rsp, 1)
expect_true(inherits(flags_rsp, "list"))
expect_equal(length(flags_rsp), 1)
expect_equal(length(flags_rsp[[1]]), 2)
expect_true(inherits(flags_rsp[[1]], "character"))
expect_equal(names(flags_rsp), tax_rsp[1])
})
test_that("flags with taxon name", {
skip_on_cran()
flags_rsp <- flags(rsp, taxon_name = "Tyrannosaurus")
expect_true(inherits(flags_rsp, "list"))
expect_equal(length(flags_rsp), 1)
expect_equal(length(flags_rsp[[1]]), 2)
expect_true(inherits(flags_rsp[[1]], "character"))
expect_equal(names(flags_rsp), tax_rsp[1])
})
test_that("flags with ott id", {
skip_on_cran()
flags_rsp <- flags(rsp, ott_id = 664348)
expect_true(inherits(flags_rsp, "list"))
expect_equal(length(flags_rsp), 1)
expect_equal(length(flags_rsp[[1]]), 2)
expect_true(inherits(flags_rsp[[1]], "character"))
expect_equal(names(flags_rsp), tax_rsp[1])
})
############################################################################
## ott_id method ##
############################################################################
context("ott_id method for class match_names")
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
tax_rsp <- c(
"Tyrannosaurus", "Helicoplacus", "Ctenocystis",
"Holothuria", "Echinoidea"
)
rsp <- tnrs_match_names(tax_rsp)
}
test_that("ott_id with no arguments", {
skip_on_cran()
expect_true(inherits(ott_id(rsp), "list"))
expect_true(inherits(ott_id(rsp), "otl_ott_id"))
expect_equal(names(ott_id(rsp)), tax_rsp)
expect_equal(ott_id(rsp)[["Holothuria"]][[1]], hol_ott_id)
})
test_that("ott_id with row number", {
skip_on_cran()
expect_equal(length(ott_id(rsp, 4)), 1)
expect_true(inherits(ott_id(rsp, 4), "list"))
expect_equivalent(ott_id(rsp, 4)[[1]], hol_ott_id)
})
test_that("ott_id with taxon name", {
skip_on_cran()
expect_equal(length(ott_id(rsp, taxon_name = "Holothuria")), 1)
expect_true(inherits(ott_id(rsp, taxon_name = "Holothuria"), "list"))
expect_equivalent(ott_id(rsp, taxon_name = "Holothuria")[[1]], hol_ott_id)
})
test_that("ott_id with ott id", {
skip_on_cran()
expect_equal(length(ott_id(rsp, ott_id = hol_ott_id)), 1)
expect_true(inherits(ott_id(rsp, ott_id = hol_ott_id), "list"))
expect_equivalent(ott_id(rsp, ott_id = hol_ott_id)[[1]], hol_ott_id)
})
rotl/tests/testthat/test-tree_to_labels.R 0000644 0001762 0000144 00000004234 14441553346 020333 0 ustar ligges users context("test tree_to_labels")
test_that("basic tree 1", {
tree1 <- "((raccon:19.19959,bear:6.80041)InnerNode1:0.84600,((sea_lion:11.99700,seal:12.00300)InnerNode2:7.52973,((monkey:100.85930,cat:47.14069):20.59201,weasel:18.87953):2.09460):3.87382,dog:25.46154);"
res_tree1 <- tree_to_labels(tree1)
expect_equal(res_tree1$tip_label, c("raccon", "bear", "sea_lion", "seal", "monkey", "cat", "weasel", "dog"))
expect_equal(res_tree1$edge_label, c("InnerNode1", "InnerNode2"))
})
test_that("basic tree 2", {
tree2 <- "(Bovine:0.69395,(Gibbon:0.36079,(Orang:0.33636,(Gorilla:0.17147,(Chimp:0.19268, Human:0.11927):0.08386):0.06124):0.15057):0.54939,Mouse:1.21460):0.10;"
res_tree2 <- tree_to_labels(tree2)
expect_equal(res_tree2$tip_label, c("Bovine", "Gibbon", "Orang", "Gorilla", "Chimp", "Human", "Mouse"))
expect_equal(res_tree2$edge_label, character(0))
})
test_that("basic tree 3", {
tree3 <- "(Bovine:0.69395,(Hylobates:0.36079,(Pongo:0.33636,(G._Gorilla:0.17147, (P._paniscus:0.19268,H._sapiens:0.11927):0.08386):0.06124):0.15057):0.54939, Rodent:1.21460);"
res_tree3 <- tree_to_labels(tree3)
expect_equal(res_tree3$tip_label, c("Bovine", "Hylobates", "Pongo", "G._Gorilla", "P._paniscus", "H._sapiens", "Rodent"))
expect_equal(res_tree3$edge_label, character(0))
})
test_that("only 1 tip", {
tree_tip <- "A;"
res_tree_tip <- tree_to_labels(tree_tip)
expect_equal(res_tree_tip$tip_label, "A")
expect_equal(res_tree_tip$edge_label, character(0))
})
test_that("only 1 tip with parentheses", {
tree_tip <- "(A);"
res_tree_tip <- tree_to_labels(tree_tip)
expect_equal(res_tree_tip$tip_label, "A")
expect_equal(res_tree_tip$edge_label, character(0))
})
test_that("only 1 tip and 1 internal", {
tree_tip <- "(A)B;"
res_tree_tip <- tree_to_labels(tree_tip)
expect_equal(res_tree_tip$tip_label, "A")
expect_equal(res_tree_tip$edge_label, "B")
})
test_that("tree with singletons", {
tree_sing <- "(((((A)cats,B)dogs,(C,D)ducks)frogs)animals,E)fungi;"
res_tree_sing <- tree_to_labels(tree_sing)
expect_equal(res_tree_sing$tip_label, LETTERS[1:5])
expect_equal(res_tree_sing$edge_label, c("cats", "dogs", "ducks", "frogs", "animals", "fungi"))
})
rotl/tests/testthat/test-base.R 0000644 0001762 0000144 00000003313 14441553346 016257 0 ustar ligges users context("base functions")
test_that("otl_url returns the correct strings", {
skip_on_cran()
expect_match(otl_url(dev = TRUE), "^https://devapi.opentreeoflife.org$")
expect_match(otl_url(dev = FALSE), "^https://api.opentreeoflife.org$")
})
test_that("otl_version", {
skip_on_cran()
expect_equal(otl_version(), "v3")
expect_equal(otl_version("foobar"), "foobar")
})
test_that("otl_ottid_from_label", {
skip_on_cran()
expect_equal(
otl_ottid_from_label("flkdjfs_ott314343"),
314343
)
})
test_that("errors that would otherwise not get caught in phylo_from_otl", {
expect_error(
phylo_from_otl(list(something = "((A, B), C);")),
"Cannot find tree"
)
expect_error(phylo_from_otl(999), "I don't know how to deal with this format")
})
############################################################################
## check_numeric ##
############################################################################
test_that("check_numeric works on integer", {
expect_true(check_numeric("123"))
expect_true(check_numeric(123))
expect_true(check_numeric(123L))
expect_true(check_numeric(list(123)))
})
test_that("check_numeric fails if there are characters", {
expect_false(check_numeric("A123"))
expect_false(check_numeric("1A23"))
expect_false(check_numeric("123A"))
expect_false(check_numeric("12-3"))
})
test_that("check_numeric fails with more exotic types", {
expect_false(check_numeric(NA))
expect_false(check_numeric(TRUE))
expect_false(check_numeric(1.23))
expect_false(check_numeric(0.9999999999999))
})
test_that(
"check_numeric fails if more than 1 element provided",
expect_error(check_numeric(c(1, 2)))
)
rotl/tests/testthat/test-tol.R 0000644 0001762 0000144 00000035376 14441553346 016161 0 ustar ligges users ############################################################################
## tol_about ##
############################################################################
context("test tol_about (and in turn print.tol_summary)")
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
req <- tol_about(include_source_list = TRUE)
}
test_that("Names in object returned are correct/match the docs", {
skip_on_cran()
expect_true(all(names(req) %in%
c(
"source_list", "date_created", "root", "num_source_trees",
"taxonomy_version", "num_source_studies",
"filtered_flags", "synth_id", "source_id_map"
)))
expect_true(all(names(req$root) %in%
c("taxon", "num_tips", "node_id")))
expect_true(all(names(req$root$taxon) %in%
c("tax_sources", "name", "unique_name", "rank", "ott_id")))
expect_true(all(names(source_list(req)) %in% c(
"study_id",
"tree_id",
"git_sha"
)))
expect_error(
source_list(tol_about(include_source_list = FALSE)),
"has been created using"
)
expect_true(nrow(source_list(req)) > 1)
expect_true(all(grepl("^(ot|pg)", source_list(req)[["study_id"]])))
expect_true(all(grepl("^tr", source_list(req)[["tree_id"]], ignore.case = TRUE)))
})
test_that("tol_node tax_rank method", {
skip_on_cran()
expect_true(inherits(
tax_rank(req),
c("otl_rank", "list")
))
expect_equal(tax_rank(req)[[1]], "no rank")
})
test_that("tol_node ott_id method", {
skip_on_cran()
expect_true(inherits(
ott_id(req),
c("otl_ott_id", "list")
))
expect_equal(ott_id(req)[[1]], 93302)
expect_equal(names(ott_id(req)), "cellular organisms")
})
test_that("tol_node tax_sources", {
skip_on_cran()
expect_true(inherits(
tax_sources(req),
c("otl_tax_sources", "list")
))
expect_true(any(grepl("ncbi", tax_sources(req)[[1]])))
expect_equal(names(tax_sources(req)), "cellular organisms")
})
test_that("tol_node unique_name", {
skip_on_cran()
expect_true(inherits(
unique_name(req),
c("otl_unique_name", "list")
))
expect_equal(unique_name(req)[[1]], "cellular organisms")
expect_equal(names(unique_name(req)), "cellular organisms")
})
test_that("tol_node tax_name", {
skip_on_cran()
expect_true(inherits(
tax_name(req),
c("otl_name", "list")
))
expect_equal(tax_name(req)[[1]], "cellular organisms")
expect_equal(names(tax_name(req)), "cellular organisms")
})
### ott_id() --------------------------------------------------------------------
test_that("taxonomy_taxon_info with ott_id for tol_about", {
skip_on_cran()
expect_equal(
ott_id(req),
ott_id(taxonomy_taxon_info(ott_id(req)))
)
})
## can't do that, it's pulling the whole tree
## test_that("taxonomy_subtree with ott_id for tol_about", {
## taxonomy_subtree(ott_id = ott_id(req))
## })
test_that("tol_node_info with ott_id for tol_about", {
skip_on_cran()
expect_equal(
ott_id(req),
ott_id(tol_node_info(ott_id(req)))
)
})
## can't do that, it's pulling the whole tree
## test_that("tol_subtree with ott_id for tol_about", {
## tol_subtree(ott_id = ott_id(req))
## })
test_that("tol_mrca with ott_id for tol_about", {
skip_on_cran()
expect_equal(
ott_id(req)[1],
ott_id(tol_mrca(ott_id(req)))[1]
)
})
test_that("tol_induced_subtree with ott_id for tol_about", {
skip_on_cran()
expect_error(
tol_induced_subtree(ott_id(req)),
"least two valid"
)
})
test_that("taxonomy_mrca with ott_id for tol_about", {
skip_on_cran()
expect_equal(
ott_id(req),
ott_id(taxonomy_mrca(ott_id(req)))
)
})
############################################################################
## tol_subtree ##
############################################################################
context("test tol_subtree")
test_that("tol_subtree fails if ott_id is invalid", {
skip_on_cran()
expect_error(tol_subtree(ott_id = 6666666))
})
test_that("tol_subtree fails if more than one ott_id is provided", {
skip_on_cran()
expect_error(
tol_subtree(ott_id = c(666666, 6666667)),
"Please provide a single"
)
})
test_that("tol_subtree fails if ott_id doesn't look like a number", {
skip_on_cran()
expect_error(
tol_subtree(ott_id = "111A1111"),
"must look like numbers"
)
})
test_that("tol_subtree returns a phylo object by default", {
skip_on_cran()
expect_warning(
expect_true(inherits(tol_subtree(ott_id = 81461), "phylo")),
"Dropping"
)
})
test_that("tol_subtree returns a newick file when providing a file argument", {
skip_on_cran()
ff <- tempfile(fileext = ".tre")
tr <- tol_subtree(ott_id = 81461, file = ff)
expect_true(tr)
expect_true(grepl("^\\(", readLines(ff, n = 1, warn = FALSE)))
})
############################################################################
## tol_induced_subtree ##
############################################################################
context("test tol_induced_subtree")
test_that("warning for node ids that are not in TOL graph", {
skip_on_cran()
expect_error(
tol_induced_subtree(ott_ids = c(357968, 867416, 939325, 9999999)),
"not found"
)
})
test_that("error if ott_ids provided don't look like numbers", {
skip_on_cran()
expect_error(
tol_induced_subtree(ott_ids = c("13242", "kitten")),
"must look like numbers"
)
})
## test_that("warning for ott ids not in tree",
## ???)
test_that("tol_induced_subtree generates a newick file when providing a file argument", {
skip_on_cran()
ff <- tempfile(fileext = ".tre")
tr <- tol_induced_subtree(ott_ids = c(292466, 267845, 292466), file = ff)
expect_true(tr)
expect_true(grepl("^\\(", readLines(ff, n = 1, warn = FALSE)))
})
############################################################################
## tol_mrca ##
############################################################################
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
birds <- tol_mrca(ott_ids = c(412129, 292466))
hol <- tol_mrca(c(431586, 957434))
mono <- tol_mrca(ott_ids = c(962377, 79623))
}
test_that("tol_mrca fails if ott_ids are not numbers", {
skip_on_cran()
expect_error(
tol_mrca(ott_ids = c(13243, "a13415")),
"must look like numbers"
)
})
test_that("tol_mrca returns a list", {
skip_on_cran()
expect_true(inherits(birds, "list"))
expect_true(inherits(birds, "tol_mrca"))
expect_true(all(names(birds) %in%
c(
"mrca",
"source_id_map",
"synth_id"
)))
})
test_that("methods for tol_mrca where the node is a taxon", {
skip_on_cran()
expect_true(inherits(
tax_sources(hol),
c("otl_tax_sources", "list")
))
expect_true(inherits(
unique_name(hol),
c("otl_unique_name", "list")
))
expect_true(inherits(
tax_name(hol),
c("otl_name", "list")
))
expect_true(inherits(
tax_rank(hol),
c("otl_rank", "list")
))
expect_true(inherits(
ott_id(hol),
c("otl_ott_id", "list")
))
expect_true(length(tax_sources(hol)[[1]]) > 1)
expect_true(any(grepl("worms", tax_sources(hol)[[1]])))
expect_equal(unique_name(hol)[[1]], "Holothuria")
expect_equal(tax_name(hol)[[1]], "Holothuria")
expect_equal(tax_rank(hol)[[1]], "genus")
expect_equal(ott_id(hol)[[1]], 924443)
expect_equal(names(tax_sources(hol)), "Holothuria")
expect_true(all(names(source_list(hol)) %in% c(
"tree_id",
"study_id",
"git_sha"
)))
expect_equal(attr(tax_sources(hol), "taxon_type"), "mrca")
})
test_that("methods for tol_mrca where the node is not a taxon", {
skip_on_cran()
expect_true(inherits(birds, "list"))
expect_true(inherits(
tax_sources(birds),
c("otl_tax_sources", "list")
))
expect_true(inherits(
unique_name(birds),
c("otl_unique_name", "list")
))
expect_true(inherits(
tax_name(birds),
c("otl_name", "list")
))
expect_true(inherits(
tax_rank(birds),
c("otl_rank", "list")
))
expect_true(inherits(
ott_id(birds),
c("otl_ott_id", "list")
))
expect_true(length(tax_sources(birds)[[1]]) >= 1)
expect_true(any(grepl("ncbi", tax_sources(birds)[[1]])))
expect_equal(unique_name(birds)[[1]], "Aves")
expect_equal(tax_name(birds)[[1]], "Aves")
expect_equal(tax_rank(birds)[[1]], "class")
expect_equal(ott_id(birds)[[1]], 81461)
expect_equal(names(ott_id(birds)), "Aves")
expect_true(all(names(source_list(birds)) %in% c(
"tree_id",
"study_id",
"git_sha"
)))
expect_equal(attr(tax_sources(birds), "taxon_type"), "mrca")
})
### ott_id() --------------------------------------------------------------------
test_that("taxonomy_taxon_info with ott_id for tol_mrca", {
skip_on_cran()
expect_equal(
ott_id(mono)[1],
ott_id(taxonomy_taxon_info(ott_id(mono)))[1]
)
})
test_that("taxonomy_subtree with ott_id for tol_mrca", {
skip_on_cran()
tt <- taxonomy_subtree(ott_id = ott_id(mono))
expect_true(length(tt[["tip_label"]]) > 10)
expect_true(length(tt[["edge_label"]]) > 7)
})
test_that("tol_node_info with ott_id for tol_mrca", {
skip_on_cran()
expect_equal(
ott_id(mono)[1],
ott_id(tol_node_info(ott_id(mono)))[1]
)
})
test_that("tol_subtree with ott_id for tol_mrca", {
skip_on_cran()
expect_warning(
tt <- tol_subtree(ott_id = ott_id(mono)),
"Dropping"
)
expect_true(inherits(tt, "phylo"))
expect_true(length(tt$tip.label) > 1)
expect_true(length(tt$node.label) > 1)
})
test_that("tol_mrca with ott_id for tol_mrca", {
skip_on_cran()
expect_equal(
ott_id(mono)[1],
ott_id(tol_mrca(ott_id(mono)))[1]
)
})
test_that("tol_induced_subtree with ott_id for tol_mrca", {
skip_on_cran()
expect_error(
tol_induced_subtree(ott_id(mono)),
"least two valid"
)
})
test_that("taxonomy_mrca with ott_id for tol_mrca", {
skip_on_cran()
expect_equivalent(
ott_id(mono),
ott_id(taxonomy_mrca(ott_id(mono)))
)
})
############################################################################
## strip_ott_ids ##
############################################################################
test_that("OTT ids can be striped from tip labels to allow taxon-matching", {
skip_on_cran()
genera <- c("Perdix", "Cinclus", "Struthio")
expect_warning(tr <- tol_induced_subtree(ott_ids = c(102710, 267845, 292466)))
expect_true(all(strip_ott_ids(tr$tip.label) %in% genera))
})
############################################################################
## tol_node_info ##
############################################################################
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
tol_info <- tol_node_info(ott_id = 81461)
tol_lin <- tol_node_info(ott_id = 81461, include_lineage = TRUE)
tol_mono <- tol_node_info(ott_id = 962396)
}
test_that("tol node info.", {
skip_on_cran()
expect_true(all(names(tol_info) %in%
c(
"node_id", "num_tips", "partial_path_of", "query",
"source_id_map", "supported_by", "synth_id",
"taxon", "terminal"
)))
expect_true(inherits(tol_info, "tol_node"))
})
### methods ---------------------------------------------------------------------
test_that("tol_node tax_rank method", {
skip_on_cran()
expect_true(inherits(
tax_rank(tol_info),
c("otl_tax_rank", "list")
))
expect_equal(tax_rank(tol_info)[[1]], "class")
})
test_that("tol_node ott_id method", {
skip_on_cran()
expect_true(inherits(
ott_id(tol_info),
c("otl_ott_id", "list")
))
expect_equal(ott_id(tol_info)[[1]], 81461)
expect_equal(names(ott_id(tol_info)), "Aves")
})
test_that("tol_node tax_sources", {
skip_on_cran()
expect_true(inherits(
tax_sources(tol_info),
c("otl_tax_sources", "list")
))
expect_true(any(grepl("worms", tax_sources(tol_info)[[1]])))
expect_equal(names(tax_sources(tol_info)), "Aves")
})
test_that("tol_node unique_name", {
skip_on_cran()
expect_true(inherits(
unique_name(tol_info),
c("otl_unique_name", "list")
))
expect_equal(unique_name(tol_info)[[1]], "Aves")
expect_equal(names(unique_name(tol_info)), "Aves")
})
test_that("tol_node tax_name", {
skip_on_cran()
expect_true(inherits(
tax_name(tol_info),
c("otl_name", "list")
))
expect_equal(tax_name(tol_info)[[1]], "Aves")
expect_equal(names(tax_name(tol_info)), "Aves")
})
test_that("tol_node source_list method", {
skip_on_cran()
expect_true(inherits(source_list(tol_info), "data.frame"))
expect_true(all(names(source_list(tol_info)) %in%
c("study_id", "tree_id", "git_sha")))
})
test_that("tol_node tol_lineage", {
skip_on_cran()
expect_error(tol_lineage(tol_info), "needs to be created")
expect_true(inherits(tol_lineage(tol_lin), "data.frame"))
expect_true(nrow(tol_lineage(tol_lin)) > 1)
expect_true(all(names(tol_lineage(tol_lin)) %in% c(
"node_id",
"num_tips",
"is_taxon"
)))
expect_true(all(grepl("^(ott|mrca)", tol_lineage(tol_lin)[["node_id"]])))
})
test_that("tol_node tax_lineage", {
skip_on_cran()
expect_error(tax_lineage(tol_info), "needs to be created")
expect_true(inherits(tax_lineage(tol_lin), "data.frame"))
expect_true(nrow(tax_lineage(tol_lin)) > 1)
expect_true(all(names(tax_lineage(tol_lin)) %in% c(
"rank",
"name",
"unique_name",
"ott_id"
)))
expect_true(any(grepl("no rank", tax_lineage(tol_lin)[["rank"]])))
expect_true(any(grepl("cellular organisms", tax_lineage(tol_lin)[["name"]])))
})
### ott_id() --------------------------------------------------------------------
test_that("taxonomy_taxon_info with ott_id for tol_info", {
skip_on_cran()
expect_equivalent(
ott_id(tol_mono),
ott_id(taxonomy_taxon_info(ott_id(tol_mono)))
)
})
test_that("taxonomy_subtree with ott_id for tol_info", {
skip_on_cran()
tt <- taxonomy_subtree(ott_id = ott_id(tol_mono))
expect_true(length(tt[["tip_label"]]) > 10)
expect_true(length(tt[["edge_label"]]) > 7)
})
test_that("tol_node_info with ott_id for tol_info", {
skip_on_cran()
expect_equivalent(
ott_id(tol_mono),
ott_id(tol_node_info(ott_id(tol_mono)))
)
})
test_that("tol_subtree with ott_id for tol_info", {
skip_on_cran()
expect_warning(
tt <- tol_subtree(ott_id = ott_id(tol_mono)),
"Dropping"
)
expect_true(inherits(tt, "phylo"))
expect_true(length(tt$tip.label) > 1)
expect_true(length(tt$node.label) > 1)
})
test_that("tol_mrca with ott_id for tol_info", {
skip_on_cran()
expect_equivalent(
ott_id(tol_mono),
ott_id(tol_mrca(ott_id(tol_mono)))
)
})
test_that("tol_induced_subtree with ott_id for tol_info", {
skip_on_cran()
expect_error(
tol_induced_subtree(ott_id(tol_mono)),
"least two valid"
)
})
test_that("taxonomy_mrca with ott_id for tol_info", {
skip_on_cran()
expect_equivalent(
ott_id(tol_mono),
ott_id(taxonomy_mrca(ott_id(tol_mono)))
)
})
rotl/tests/testthat/test-api-tnrs.R 0000644 0001762 0000144 00000004007 14441553346 017103 0 ustar ligges users context("tnrs API")
############################################################################
## .tnrs_match_names ##
############################################################################
test_that("names argument is provided for .tnrs_match_names", {
skip_on_cran()
expect_error(
.tnrs_match_names(NULL, NULL, TRUE, NULL, FALSE),
"must supply"
)
})
test_that("names argument is character for .tnrs_match_names", {
skip_on_cran()
expect_error(
.tnrs_match_names(TRUE, NULL, TRUE, NULL, FALSE),
"character"
)
})
test_that("names and ids have the same lengths for .tnrs_match_names", {
skip_on_cran()
expect_error(
.tnrs_match_names("Felis", NULL, TRUE, c("abc", "def"), FALSE),
"same length"
)
})
test_that("ids must be character for .tnrs_match_names", {
skip_on_cran()
expect_error(
.tnrs_match_names("Felis", NULL, TRUE, TRUE, FALSE),
"character"
)
})
test_that("do_approximate_matching is logical for .tnrs_match_names", {
skip_on_cran()
expect_error(
.tnrs_match_names("Felis", NULL, "true", NULL, FALSE),
"logical"
)
})
test_that("include_suppressed is logical for .tnrs_match_names", {
skip_on_cran()
expect_error(
.tnrs_match_names("Felis", NULL, TRUE, NULL, "true"),
"logical"
)
})
test_that("context_name is character for .tnrs_match_names", {
skip_on_cran()
expect_error(
.tnrs_match_names("Felis", TRUE, TRUE, NULL, FALSE, TRUE),
"character"
)
})
############################################################################
## .tnrs_infer_context ##
############################################################################
test_that("names is not NULL for .tnrs_infer_context", {
skip_on_cran()
expect_error(
.tnrs_infer_context(NULL),
"Must supply"
)
})
test_that("names is character for .tnrs_infer_context", {
skip_on_cran()
expect_error(
.tnrs_infer_context(TRUE),
"character"
)
})
rotl/tests/testthat/test-api-tol.R 0000644 0001762 0000144 00000004331 14441553346 016713 0 ustar ligges users context("Tree of Life API")
############################################################################
## .tol_about ##
############################################################################
test_that("include_source_list is logical for .tol_about", {
skip_on_cran()
expect_error(
.tol_about("true"),
"logical"
)
})
############################################################################
## .tol_mrca ##
############################################################################
test_that("neither ott_ids nor node_ids are NULL for .tol_mrca", {
skip_on_cran()
expect_error(
.tol_mrca(NULL),
"Must provide"
)
})
############################################################################
## .tol_subtree ##
############################################################################
test_that("ott_id is not NULL", {
skip_on_cran()
expect_error(
.tol_subtree(ott_id = NULL, node_id = NULL),
"Must provide"
)
})
############################################################################
## .tol_induced_subtree ##
############################################################################
test_that("ott_ids is not NULL", {
skip_on_cran()
expect_error(
.tol_induced_subtree(ott_ids = NULL),
"Must provide"
)
})
test_that("NAs are not accepted for ott_ids", {
skip_on_cran()
expect_error(
.tol_induced_subtree(ott_ids = c(123, NA, 456)),
"NAs are not allowed"
)
})
####################
## .tol_node_info ##
####################
test_that("include_lineage must be logical with .tol_node_info", {
skip_on_cran()
expect_error(
.tol_node_info(ott_id = "ott_123", include_lineage = "123"),
"logical"
)
})
test_that("ott_id must be a numeric with .tol_node_info", {
skip_on_cran()
expect_error(
.tol_node_info(ott_id = "test"),
"look like numbers"
)
})
test_that("node_id must be a character with .tol_node_info", {
skip_on_cran()
expect_error(
.tol_node_info(node_id = 123),
"must look like"
)
})
rotl/tests/testthat/test-studies.R 0000644 0001762 0000144 00000045212 14441553346 017031 0 ustar ligges users if (FALSE) {
context("test of studies")
############################################################################
## studies_properties ##
############################################################################
test_that("studies_properties is a list with 2 elements (if breaks, need to update documentation)", {
skip_on_cran()
expect_true(all(names(studies_properties() %in% c("tree_properties", "study_properties"))))
})
############################################################################
## get_study ##
############################################################################
test_that("get_study returns an error when asking for a study that doesn't exist", {
skip_on_cran()
expect_error(get_study("tt_666666"))
})
test_that("get_study generates a phylo object", {
skip_on_cran()
tr <- get_study("pg_719", object_format = "phylo")
expect_true(inherits(tr, "multiPhylo"))
expect_equal(length(tr), 3)
expect_true(length(tr[[1]]$tip.label) > 1)
})
test_that("get_study returns an error if file is specied but file_format is not", {
skip_on_cran()
expect_error(
get_study("pg_719", file = "test"),
"must be specified"
)
})
test_that("get_study generates a nexml object", {
skip_on_cran()
tr <- get_study("pg_719", object_format = "nexml")
expect_true(inherits(tr, "nexml"))
})
test_that("get_study generates a newick file", {
skip_on_cran()
ff <- tempfile()
tr <- get_study("pg_719", file_format = "newick", file = ff)
expect_true(tr)
expect_true(grepl("^\\(", readLines(ff, n = 1, warn = FALSE)))
})
test_that("get_study generates a nexus file", {
skip_on_cran()
ff <- tempfile()
tr <- get_study("pg_719", file_format = "nexus", file = ff)
expect_true(tr)
expect_true(grepl("^#NEXUS", readLines(ff, n = 1, warn = FALSE)))
})
test_that("get_study generates a nexml file", {
skip_on_cran()
ff <- tempfile()
tr <- get_study("pg_719", file_format = "nexml", file = ff)
expect_true(tr)
expect_true(grepl("^<\\?xml", readLines(ff, n = 1, warn = FALSE)))
})
test_that("get_study generates a json file", {
skip_on_cran()
ff <- tempfile()
tr <- get_study("pg_719", file_format = "json", file = ff)
expect_true(tr)
expect_true(grepl("^\\{", readLines(ff, n = 1, warn = FALSE)))
})
############################################################################
## get_study_tree ##
############################################################################
test_that("get_study_tree returns error when tree doesn't exist", {
skip_on_cran()
expect_error(get_study_tree("2655", "tree5555"))
})
test_that("get_study_tree returns error when study doesn't exist", {
skip_on_cran()
expect_error(get_study_tree("5555555", "tree555555"))
})
test_that("get_study_tree generates nexus file", {
skip_on_cran()
ff <- tempfile(fileext = ".nex")
tt <- get_study_tree("pg_1144", "tree2324",
file_format = "nexus",
file = ff
)
expect_true(tt)
expect_true(grepl("^#NEXUS", readLines(ff, n = 1, warn = FALSE)))
})
test_that("get_study_tree generates newick file", {
skip_on_cran()
ff <- tempfile(fileext = ".tre")
tt <- get_study_tree("pg_1144", "tree2324",
file_format = "newick",
file = ff
)
expect_true(tt)
expect_true(grepl("^\\(", readLines(ff, n = 1, warn = FALSE)))
})
test_that("get_study_tree generates json file", {
skip_on_cran()
ff <- tempfile(fileext = ".json")
tt <- get_study_tree("pg_1144", "tree2324",
file_format = "json",
file = ff
)
expect_true(tt)
expect_true(grepl("^\\{", readLines(ff, n = 1, warn = FALSE)))
})
test_that("get_study_tree returns a phylo object", {
skip_on_cran()
tt <- get_study_tree("pg_1144", "tree2324", object_format = "phylo")
expect_true(inherits(tt, "phylo"))
expect_true(length(tt$tip.label) > 1)
})
### Test types of labels with phylo objects
test_that("get_study_tree returns a phylo object and ott_id for tip labels", {
skip_on_cran()
tt <- get_study_tree("pg_1144", "tree2324",
object_format = "phylo",
tip_label = "ott_id"
)
expect_true(inherits(tt, "phylo"))
expect_true(length(tt$tip.label) > 1)
expect_true(grepl("^[0-9]+$", tt$tip.label[1]))
})
test_that("get_study_tree returns a phylo object and ott_taxon_names for tip labels", {
skip_on_cran()
tt <- get_study_tree("pg_1144", "tree2324",
object_format = "phylo",
tip_label = "ott_taxon_name"
)
expect_true(inherits(tt, "phylo"))
expect_true(length(tt$tip.label) > 1)
expect_true(sum(!grepl("^[A-Za-z]+(_[a-z]+)?$", tt$tip.label)) < 3)
})
test_that("get_study_tree returns a phylo object and original labels for tip labels", {
skip_on_cran()
tt <- get_study_tree("pg_1144", "tree2324",
object_format = "phylo",
tip_label = "original_label"
)
expect_true(inherits(tt, "phylo"))
expect_true(length(tt$tip.label) > 1)
expect_equal(sum(!grepl("^[A-Za-z]+_[a-z]+$", tt$tip.label)), 45)
})
### Test types of labels with files (skipping json for now because there is no good way of doing it)
test_that("get_study_tree returns an error if file is given but file format is not", {
skip_on_cran()
expect_error(
get_study_tree(study_id = "pg_1144", tree_id = "tree2324", file = "test"),
"must be specified"
)
})
test_that("get_study_tree returns nexus file and ott_id for tip labels", {
skip_on_cran()
ff <- tempfile(fileext = ".nex")
tt <- get_study_tree("pg_1144", "tree2324",
file_format = "nexus",
tip_label = "ott_id", file = ff
)
expect_true(tt)
tr <- rncl::read_nexus_phylo(ff)
expect_true(length(tr$tip.label) > 1)
expect_true(grepl("^[0-9]+$", tr$tip.label[1]))
})
test_that("get_study_tree returns a phylo object and ott_taxon_names for tip labels", {
skip_on_cran()
ff <- tempfile(fileext = ".tre")
tt <- get_study_tree("pg_1144", "tree2324",
file_format = "newick",
tip_label = "ott_taxon_name", file = ff
)
expect_true(tt)
tr <- rncl::read_newick_phylo(ff)
expect_true(length(tr$tip.label) > 1)
expect_true(sum(!grepl("^[A-Za-z]+(_[a-z]+)?$", tr$tip.label)) < 3)
})
############################################################################
## get_study_subtree ##
############################################################################
test_that("get_study_subtree returns an error when study_id doesn't exist", {
skip_on_cran()
expect_error(get_study_subtree("pg_55555", "tree55555", subtree_id = "node555555"))
})
test_that("get_study_subtree returns an error when tree_id doesn't exist", {
skip_on_cran()
expect_error(get_study_subtree("pg_1144", "tree55555", subtree_id = "node555555"))
})
test_that("get_study_subtree returns an error when the subtree_id is invalid", {
skip_on_cran()
expect_error(get_study_subtree("pg_1144", "tree2324", "foobar"))
})
test_that("get_study_subtree returns a phylo object", {
skip_on_cran()
tt <- get_study_subtree("pg_420", "tree522",
subtree_id = "ingroup",
object_format = "phylo"
)
sub_tt <- get_study_subtree("pg_420", "tree522",
subtree_id = "node208580",
object_format = "phylo"
)
expect_true(inherits(tt, "phylo"))
expect_true(length(tt$tip.label) > 1)
expect_true(inherits(sub_tt, "phylo"))
expect_true(length(sub_tt$tip.label) > 1)
expect_true(length(tt$tip.label) > length(sub_tt$tip.label))
})
test_that("get_study_subtree fails if file name is given but no file format", {
skip_on_cran()
expect_error(get_study_subtree("pg_420", "tree522",
subtree_id = "ingroup",
file = "test"
), "must be specified")
})
test_that("get_study_subtree returns a nexus file", {
skip_on_cran()
ff <- tempfile(fileext = ".nex")
tt <- get_study_subtree("pg_420", "tree522",
subtree_id = "ingroup",
file_format = "nexus", file = ff
)
expect_true(tt)
expect_true(grepl("^#NEXUS", readLines(ff, n = 1, warn = FALSE)))
})
test_that("get_study_subtree returns a newick file", {
skip_on_cran()
ff <- tempfile(fileext = ".tre")
tt <- get_study_subtree("pg_420", "tree522",
subtree_id = "ingroup",
file_format = "newick", file = ff
)
expect_true(tt)
expect_true(grepl("^\\(", readLines(ff, n = 1, warn = FALSE)))
})
test_that("get_study_subtree can deduplicate labels", {
skip_on_cran()
expect_warning(
get_study_subtree(
study_id = "pg_710", tree_id = "tree1277",
tip_label = "ott_taxon_name",
subtree_id = "ingroup", deduplicate = TRUE
),
"and have been modified"
)
})
test_that("get_study_subtree fails with duplicate labels", {
skip_on_cran()
expect_error(
get_study_subtree(
study_id = "pg_710", tree_id = "tree1277",
tip_label = "ott_taxon_name",
subtree_id = "ingroup", deduplicate = FALSE
),
"has already been encountered"
)
})
############################################################################
## get_study_meta ##
############################################################################
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
sm <- get_study_meta("pg_719")
}
test_that("get_study meta returns a study_meta object", {
skip_on_cran()
expect_true(inherits(sm, "study_meta"))
})
test_that("get_tree_ids method for study_meta", {
skip_on_cran()
expect_equal(get_tree_ids(sm), c("tree1294", "tree1295", "tree1296"))
})
test_that("get_publication method for study_meta", {
skip_on_cran()
expect_equal(attr(get_publication(sm), "DOI"), "http://dx.doi.org/10.1600/036364411X605092")
})
test_that("candidate_for_synth method for study_meta", {
skip_on_cran()
expect_true(candidate_for_synth(sm) %in% get_tree_ids(sm))
})
test_that("get_study_year method for study_meta", {
skip_on_cran()
expect_equal(get_study_year(sm), 2011)
})
############################################################################
## tol_about ##
############################################################################
test_that("tol_about returns class tol_summary", {
skip_on_cran()
expect_true(inherits(tol_about(), "tol_summary"))
})
test_that("study_about", {
skip_on_cran()
ta <- source_list(tol_about(TRUE))
expect_true(inherits(ta, "data.frame"))
expect_true(nrow(ta) > 100)
expect_equal(names(ta), c("study_id", "tree_id", "git_sha"))
})
############################################################################
## studies_find_studies ##
############################################################################
test_that("single study detailed=TRUE", {
skip_on_cran()
res <- studies_find_studies(
property = "ot:studyId",
value = "ot_248", detailed = TRUE
)
expect_true(inherits(res, "data.frame"))
expect_true(inherits(res, "matched_studies"))
expect_true(all(names(res) %in% c(
"study_ids", "n_trees", "tree_ids",
"candidate", "study_year", "title",
"study_doi"
)))
expect_true(nrow(res) >= 1L)
expect_equal(res[["study_ids"]], "ot_248")
expect_equal(res[["n_trees"]], "1")
expect_equal(res[["candidate"]], "Tr76302")
expect_equal(res[["study_year"]], "2014")
expect_equal(res[["study_doi"]], "http://dx.doi.org/10.1016/j.cub.2014.06.060")
expect_equal(res[["title"]], "'Phylogenomic Resolution of the Class Ophiuroidea Unlocks a Global Microfossil Record'")
expect_true(length(attr(res, "metadata")) > 0)
expect_true(length(attr(res, "found_trees")) > 0)
})
test_that("single study detailed=FALSE", {
skip_on_cran()
res <- studies_find_studies(
property = "ot:studyId",
value = "ot_248", detailed = FALSE
)
expect_true(inherits(res, "data.frame"))
expect_true(inherits(res, "study_ids"))
expect_true(inherits(res, "matched_studies"))
expect_match(attr(res, "found_trees"), "list of the trees associated")
expect_equal(names(res), "study_ids")
expect_equal(res[1, 1], "ot_248")
expect_equal(nrow(res), 1L)
expect_equal(ncol(res), 1L)
expect_true(length(attr(res, "metadata")) > 0)
expect_true(length(attr(res, "found_trees")) > 0)
})
test_that("multiple studies detailed=TRUE", {
skip_on_cran()
res <- studies_find_studies(
property = "ot:focalCladeOTTTaxonName",
value = "mammalia", detailed = TRUE
)
expect_true(inherits(res, "data.frame"))
expect_true(inherits(res, "matched_studies"))
expect_true(all(names(res) %in% c(
"study_ids", "n_trees", "tree_ids",
"candidate", "study_year",
"title", "study_doi"
)))
expect_true(nrow(res) >= 8L)
expect_true(length(attr(res, "metadata")) > 0)
expect_true(length(attr(res, "found_trees")) > 0)
})
test_that("multiple studies detailed=FALSE", {
skip_on_cran()
res <- studies_find_studies(
property = "ot:focalCladeOTTTaxonName",
value = "mammalia", detailed = FALSE
)
expect_true(inherits(res, "study_ids"))
expect_true(inherits(res, "matched_studies"))
expect_true(inherits(res, "data.frame"))
expect_equal(ncol(res), 1L)
expect_true(nrow(res) >= 8)
expect_equal(names(res), "study_ids")
expect_true(length(attr(res, "metadata")) > 0)
expect_true(length(attr(res, "found_trees")) > 0)
})
############################################################################
## studies_find_trees ##
############################################################################
test_that("studies_find_trees single study detailed=FALSE", {
skip_on_cran()
res <- studies_find_trees(
property = "ot:studyId",
value = "ot_248", detailed = FALSE
)
expect_true(inherits(res, "data.frame"))
expect_true(inherits(res, "matched_studies"))
expect_match(attr(res, "found_trees")[[1]], "Tr76302")
expect_equal(names(res), c(
"study_ids",
"n_matched_trees",
"match_tree_ids"
))
expect_equal(res[1, 1], "ot_248")
expect_equal(nrow(res), 1L)
expect_equal(ncol(res), 3L)
expect_true(length(attr(res, "metadata")) > 0)
expect_true(length(attr(res, "found_trees")) > 0)
})
test_that("studies_find_trees single study detailed=TRUE", {
skip_on_cran()
res <- studies_find_trees(
property = "ot:studyId",
value = "ot_248", detailed = TRUE
)
expect_true(inherits(res, "data.frame"))
expect_true(inherits(res, "matched_studies"))
expect_equal(names(res), c(
"study_ids", "n_trees",
"tree_ids", "candidate",
"study_year", "title",
"study_doi",
"n_matched_trees",
"match_tree_ids"
))
expect_equal(nrow(res), 1L)
expect_equal(res[["study_ids"]], "ot_248")
expect_equal(res[["n_trees"]], "1")
expect_equal(res[["candidate"]], "Tr76302")
expect_equal(res[["study_year"]], "2014")
expect_equal(res[["study_doi"]], "http://dx.doi.org/10.1016/j.cub.2014.06.060")
expect_equal(res[["title"]], "'Phylogenomic Resolution of the Class Ophiuroidea Unlocks a Global Microfossil Record'")
expect_equal(res[["tree_ids"]], "Tr76302")
expect_true(length(attr(res, "metadata")) > 0)
expect_true(length(attr(res, "found_trees")) > 0)
})
test_that("studies_find_trees multiple studies detailed=TRUE", {
skip_on_cran()
res <- studies_find_trees(
property = "ot:ottTaxonName",
value = "Echinodermata", detailed = TRUE
)
expect_true(inherits(res, "data.frame"))
expect_true(inherits(res, "matched_studies"))
expect_equal(names(res), c(
"study_ids", "n_trees",
"tree_ids", "candidate",
"study_year", "title",
"study_doi",
"n_matched_trees",
"match_tree_ids"
))
expect_true(nrow(res) >= 5L)
expect_true(length(attr(res, "metadata")) > 0)
expect_true(length(attr(res, "found_trees")) > 0)
})
test_that("studies_find_trees multiple studies detailed=FALSE", {
skip_on_cran()
res <- studies_find_trees(
property = "ot:ottTaxonName",
value = "Echinodermata", detailed = FALSE
)
expect_true(inherits(res, "data.frame"))
expect_true(inherits(res, "matched_studies"))
expect_equal(names(res), c(
"study_ids",
"n_matched_trees",
"match_tree_ids"
))
expect_true(nrow(res) >= 5L)
expect_true(length(attr(res, "metadata")) > 0)
expect_true(length(attr(res, "found_trees")) > 0)
})
############################################################################
## list_trees ##
############################################################################
test_that("list_trees with studies_find_studies and detailed = FALSE", {
skip_on_cran()
expect_match(
list_trees(studies_find_studies(
property = "ot:focalCladeOTTTaxonName",
value = "Aves", detailed = FALSE
)),
"If you want to get a list of the trees associated with the studies"
)
})
test_that("list_trees with studies_find_studies and detailed = TRUE", {
skip_on_cran()
res <- studies_find_studies(
property = "ot:focalCladeOTTTaxonName",
value = "mammalia", detailed = TRUE
)
expect_true(inherits(list_trees(res), "list"))
expect_true(length(list_trees(res)) >= 8)
expect_true(sum(names(list_trees(res)) %in% c(
"pg_2647", "ot_308",
"pg_2812", "ot_109",
"pg_2582", "pg_1428",
"ot_755", "pg_2550"
)) >= 8)
})
test_that("list_trees with studies_find_trees and detailed=FALSE", {
skip_on_cran()
res <- studies_find_trees(
property = "ot:ottTaxonName",
value = "Echinodermata", detailed = FALSE
)
lt <- list_trees(res)
expect_true(inherits(lt, "list"))
expect_true(length(names(lt)) >= 5L)
expect_true(all(sapply(lt, length) >= 1L))
})
test_that("list_trees with studies_find_trees and detailed=TRUE", {
skip_on_cran()
res <- studies_find_trees(
property = "ot:ottTaxonName",
value = "Echinodermata", detailed = TRUE
)
lt <- list_trees(res)
expect_true(inherits(lt, "list"))
expect_true(length(names(lt)) >= 5L)
expect_true(all(sapply(lt, length) >= 1L))
})
}
rotl/tests/testthat/test-taxonomy.R 0000644 0001762 0000144 00000027361 14441553346 017234 0 ustar ligges users context("taxonomy")
############################################################################
## taxonomy about ##
############################################################################
test_that("taxonomy_about is a list", {
skip_on_cran()
tt <- taxonomy_about()
expect_true(inherits(tt, "list"))
})
test_that("taxonomy_about has the names listed in documentation (if it breaks update documentation)", {
skip_on_cran()
tt <- taxonomy_about()
expect_true(all(names(tt) %in% c("weburl", "author", "name", "source", "version")))
})
############################################################################
## taxon Info ##
############################################################################
test_that("taxonomy taxon info", {
skip_on_cran()
tid <- 515698
tt <- taxonomy_taxon_info(tid)
expect_equal(tt[[1]][["ott_id"]], tid)
expect_true(inherits(tt, "taxon_info"))
})
test_that("taxonomy with include_lineage=TRUE", {
skip_on_cran()
tt <- taxonomy_taxon_info(515698, include_lineage = TRUE)
expect_true(exists("lineage", tt[[1]]))
expect_true(length(tt[[1]]$lineage) > 1)
})
test_that("taxonomy with include_lineage=FALSE", {
skip_on_cran()
tt <- taxonomy_taxon_info(515698, include_lineage = FALSE)
expect_false(exists("lineage", tt[[1]]))
})
test_that("taxonomy with include_terminal_descendants=TRUE", {
skip_on_cran()
tt <- taxonomy_taxon_info(515698, include_terminal_descendants = TRUE)
expect_true(exists("terminal_descendants", tt[[1]]))
expect_true(length(tt[[1]][["terminal_descendants"]]) > 1)
})
test_that("taxonomy with include_terminal_descendants=FALSE", {
skip_on_cran()
tt <- taxonomy_taxon_info(515698, include_terminal_descendants = FALSE)
expect_false(exists("terminal_descendants", tt[[1]]))
})
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
tid <- c(957430, 337928, 631176)
tax_info <- taxonomy_taxon_info(tid)
}
test_that("taxonomy_taxon tax_rank method", {
skip_on_cran()
expect_true(inherits(
tax_rank(tax_info),
c("otl_tax_rank", "list")
))
expect_equal(
names(tax_rank(tax_info)),
c(
"Actinopyga", "Acanthaster",
"Garrettia (genus in Opisthokonta)"
)
)
expect_equal(
unlist(unname(tax_rank(tax_info))),
rep("genus", 3)
)
})
test_that("taxonomy_taxon ott_taxon_name method", {
skip_on_cran()
expect_true(inherits(
tax_name(tax_info),
c("otl_tax_info", "list")
))
expect_equal(
names(tax_name(tax_info)),
c(
"Actinopyga", "Acanthaster",
"Garrettia (genus in Opisthokonta)"
)
)
expect_equal(
unlist(unname(tax_name(tax_info))),
c("Actinopyga", "Acanthaster", "Garrettia")
)
})
test_that("taxonomy_taxon synonyms method", {
skip_on_cran()
expect_true(inherits(
synonyms(tax_info),
c("otl_synonyms", "list")
))
expect_equal(
names(synonyms(tax_info)),
c(
"Actinopyga", "Acanthaster",
"Garrettia (genus in Opisthokonta)"
)
)
expect_true(all(c("Diamema", "Centrechinus") %in%
synonyms(tax_info)[[3]]))
})
test_that("taxonomy_taxon is_suppressed method", {
skip_on_cran()
expect_true(inherits(
is_suppressed(tax_info),
c("otl_is_suppressed", "list")
))
expect_equal(
names(is_suppressed(tax_info)),
c(
"Actinopyga", "Acanthaster",
"Garrettia (genus in Opisthokonta)"
)
)
expect_equal(
unlist(unname(is_suppressed(tax_info))),
c(FALSE, FALSE, FALSE)
)
})
test_that("taxonomy_taxon flags method", {
skip_on_cran()
expect_true(inherits(
flags(tax_info),
c("otl_flags", "list")
))
expect_equal(
names(flags(tax_info)),
c(
"Actinopyga", "Acanthaster",
"Garrettia (genus in Opisthokonta)"
)
)
expect_equal(
unlist(unname(flags(tax_info))),
NULL
)
})
test_that("higher taxonomy method", {
skip_on_cran()
expect_error(tax_lineage(tax_info), "needs to be created")
lg <- tax_lineage(taxonomy_taxon_info(tid, include_lineage = TRUE))
expect_true(inherits(lg, "list"))
expect_true(inherits(lg[[1]], "data.frame"))
expect_true(all(names(lg[[1]]) %in% c("rank", "name", "unique_name", "ott_id")))
expect_true(any(grepl("no rank", lg[[1]][["rank"]])))
expect_true(any(grep("life", lg[[1]][["name"]])))
})
### ott_id() --------------------------------------------------------------------
test_that("taxonomy_taxon_info with ott_id for tax_info", {
skip_on_cran()
expect_equivalent(
ott_id(tax_info),
ott_id(taxonomy_taxon_info(ott_id(tax_info)))
)
})
test_that("taxonomy_subtree with ott_id for tax_info", {
skip_on_cran()
expect_error(
taxonomy_subtree(ott_id = ott_id(tax_info)),
"supply one"
)
})
test_that("tol_node_info with ott_id for tax_info", {
skip_on_cran()
expect_error(
tol_node_info(ott_id(tax_info)),
"provide a single"
)
})
test_that("tol_subtree with ott_id for tax_info", {
skip_on_cran()
expect_error(
tol_subtree(ott_id = ott_id(tax_info)),
"provide a single"
)
})
test_that("tol_mrca with ott_id for tax_info", {
skip_on_cran()
expect_equivalent(
list("Euleutheroza" = 317277),
ott_id(tol_mrca(ott_id(tax_info)))
)
})
test_that("tol_induced_subtree with ott_id for tax_info", {
skip_on_cran()
expect_warning(
expect_true(inherits(
tol_induced_subtree(ott_id(tax_info)),
"phylo"
))
)
})
test_that("taxonomy_mrca with ott_id for tax_info", {
skip_on_cran()
expect_equivalent(
list("Euleutheroza" = 317277),
ott_id(taxonomy_mrca(ott_id(tax_info)))
)
})
test_that("ott_id subset works", {
skip_on_cran()
expect_true(inherits(ott_id(tax_info), "otl_ott_id"))
expect_true(inherits(ott_id(tax_info)[1], "otl_ott_id"))
expect_true(!is.null(names(ott_id(tax_info))))
})
############################################################################
## taxon subtree ##
############################################################################
test_that("taxonomy subtree raw output", {
skip_on_cran()
tt <- taxonomy_subtree(515698, output_format = "raw")
expect_true(inherits(tt, "list"))
expect_identical(names(tt), "newick")
})
test_that("taxonomy subtree returns warning if file is provided with something else than newick output", {
skip_on_cran()
expect_warning(
taxonomy_subtree(515698, output_format = "raw", file = "/foo/bar"),
"ignored"
)
})
test_that("taxonomy subtree writes a 'valid' newick file", {
skip_on_cran()
ff <- tempfile(fileext = ".tre")
tt <- taxonomy_subtree(515698, output_format = "newick", file = ff)
expect_true(tt)
expect_true(grepl("^\\(", readLines(ff, n = 1, warn = FALSE)))
})
test_that("taxonomy subtree returns a valid newick string", {
skip_on_cran()
tt <- taxonomy_subtree(515698, output_format = "newick")
expect_true(inherits(ape::read.tree(text = tt), "phylo"))
})
test_that("taxonomy subtree returns a valid phylo object", {
skip_on_cran()
tt <- taxonomy_subtree(515698, output_format = "phylo")
expect_true(inherits(tt, "phylo"))
})
test_that("taxonomy subtree returns valid internal node names", {
skip_on_cran()
tt <- taxonomy_subtree(515698, output_format = "taxa")
expect_true(inherits(tt, "list"))
expect_equal(length(tt), 2)
expect_equal(length(tt$tip_label), 32)
expect_equal(length(tt$edge_label), 2)
})
test_that("taxonomy subtree works if taxa has only 1 descendant", {
skip_on_cran()
tt <- taxonomy_subtree(ott_id = 3658331, output_format = "taxa")
expect_true(inherits(tt, "list"))
expect_equal(length(tt), 2)
expect_true(inherits(tt$tip_label, "character"))
})
############################################################################
## taxonomic MRCA ##
############################################################################
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
tax_mrca <- taxonomy_mrca(ott_ids = c(515698, 590452, 643717))
tax_mrca_mono <- taxonomy_mrca(ott_ids = c(79623, 962377))
}
test_that("taxonomic most recent common ancestor", {
skip_on_cran()
expect_true(inherits(tax_mrca, "taxon_mrca"))
expect_true(inherits(tax_mrca, "list"))
})
test_that("mrca tax_rank method", {
skip_on_cran()
expect_equal(
tax_rank(tax_mrca)[1],
list("Asterales" = "order")
)
})
test_that("mrca tax_name method", {
skip_on_cran()
expect_equal(
tax_name(tax_mrca)[1],
list("Asterales" = "Asterales")
)
})
test_that("mrca ott_id method", {
skip_on_cran()
expect_equivalent(
ott_id(tax_mrca)[1],
list("Asterales" = 1042120)
)
expect_true(inherits(ott_id(tax_mrca), "otl_ott_id"))
})
test_that("mrca unique_name method", {
skip_on_cran()
expect_equal(
unique_name(tax_mrca)[1],
list("Asterales" = "Asterales")
)
expect_true(inherits(
unique_name(tax_mrca),
"otl_unique_name"
))
})
test_that("mrca tax_sources method", {
skip_on_cran()
## issue with their taxonomy
skip("need to fixed upstream")
expect_equal(
tax_sources(tax_mrca)[1],
list(
"Asterales" =
c(
"ncbi:4209", "worms:234044",
"gbif:414", "irmng:10011"
)
)
)
expect_true(inherits(
tax_sources(tax_mrca),
"otl_tax_sources"
))
})
test_that("mrca is_suppressed method", {
skip_on_cran()
expect_true(inherits(
is_suppressed(tax_mrca),
c("otl_is_suppressed", "list")
))
expect_equal(
is_suppressed(tax_mrca)[1],
list("Asterales" = FALSE)
)
})
test_that("mrca flags method", {
skip_on_cran()
expect_true(inherits(
flags(tax_mrca),
c("otl_flags", "list")
))
expect_equal(
flags(tax_mrca)[1],
list("Asterales" = NULL)
)
})
### ott_id() --------------------------------------------------------------------
test_that("taxonomy_taxon_info with ott_id for tax_mrca", {
skip_on_cran()
expect_equivalent(
ott_id(tax_mrca_mono),
ott_id(taxonomy_taxon_info(ott_id(tax_mrca_mono)))
)
})
test_that("taxonomy_subtree with ott_id for tax_mrca", {
skip_on_cran()
tt <- taxonomy_subtree(ott_id = ott_id(tax_mrca_mono))
expect_true(length(tt[["tip_label"]]) > 10)
expect_true(length(tt[["edge_label"]]) > 1)
})
test_that("tol_node_info with ott_id for tax_mrca", {
skip_on_cran()
expect_equivalent(
ott_id(tax_mrca_mono),
ott_id(tol_node_info(ott_id(tax_mrca_mono)))
)
})
test_that("tol_subtree with ott_id for tax_mrca", {
skip_on_cran()
expect_warning(
tt <- tol_subtree(ott_id = ott_id(tax_mrca_mono)),
"Dropping"
)
expect_true(inherits(tt, "phylo"))
expect_true(length(tt$tip.label) > 1)
expect_true(length(tt$node.label) > 1)
})
test_that("tol_mrca with ott_id for tax_mrca", {
skip_on_cran()
expect_equivalent(
ott_id(tax_mrca_mono),
ott_id(tol_mrca(ott_id(tax_mrca_mono)))
)
})
test_that("tol_induced_subtree with ott_id for tax_mrca", {
skip_on_cran()
expect_error(
tol_induced_subtree(ott_id(tax_mrca_mono)),
"least two valid"
)
})
test_that("taxonomy_mrca with ott_id for tax_mrca", {
skip_on_cran()
expect_equivalent(
ott_id(tax_mrca_mono),
ott_id(taxonomy_mrca(ott_id(tax_mrca_mono)))
)
})
test_that("ott_id subset works", {
skip_on_cran()
expect_true(inherits(ott_id(tax_mrca_mono), "otl_ott_id"))
expect_true(inherits(ott_id(tax_mrca_mono)[1], "otl_ott_id"))
expect_true(!is.null(names(ott_id(tax_mrca_mono))))
})
### is_in_tree() ---------------------------------------------------------------
if (identical(Sys.getenv("NOT_CRAN"), "true")) {
spp <- c("Tyrannosaurus rex", "Velociraptor", "Fabaceae", "Solanaceae")
ot_names <- tnrs_match_names(spp)
ot_ids <- ott_id(ot_names)
}
test_that("test is_in_tree", {
skip_on_cran()
in_tree <- is_in_tree(ot_ids)
expect_equal(sum(in_tree), 4)
expect_true(all(names(in_tree) %in% spp))
})
rotl/tests/testthat/test-deduplicate_labels.R 0000644 0001762 0000144 00000003131 14441553346 021150 0 ustar ligges users tr_string <- "
((A,A),A 1); ((B.1,B,C),B);
((D,D_1),D.1);
((('A 1','A 1'),A.1),'A 1');
((('A A A','A A A'),A.1),'A 1');
((((A_1:0.1,B__2:0.1)cats:0.1,(A_1:0.1,A_1:0.1)dogs:0.1)mammals:0.1):0.1)fur:0.1;
"
file_dup <- tempfile()
cat(tr_string, file = file_dup, sep = "\n")
############################################################################
## parse_newick ##
############################################################################
context("parse_newick")
test_that("parse newick works correctly", {
prsed_str <- parse_newick(file_dup)
expect_true(is.character(prsed_str))
expect_equal(length(prsed_str), 6L)
})
############################################################################
## deduplicate_labels ##
############################################################################
context("deduplicate_labels")
test_that("deduplicate labels works on made up example", {
expect_warning(
dedup_tr <- deduplicate_labels(file_dup),
"Some tip labels were duplicated"
)
expect_true(file.exists(dedup_tr))
expect_warning(phylo_tr <- rncl::read_newick_phylo(file = dedup_tr), "Dropping singleton")
expect_true(inherits(phylo_tr, "multiPhylo"))
expect_equal(phylo_tr[[6]]$tip.label, c("A_1_1", "B__2", "A_1_2", "A_1"))
})
test_that("deduplicate labels works on a OTL study", {
skip_on_cran()
expect_warning(
get_study_tree(study_id = "pg_710", tree_id = "tree1277", tip_label = "ott_taxon_name"),
"Some tip labels were duplicated"
)
})
unlink(file_dup)
rotl/tests/testthat/test-api-studies.R 0000644 0001762 0000144 00000013540 14441553346 017577 0 ustar ligges users context("studies API tests")
###########################
## .studies_find_studies ##
###########################
test_that("argument verbose needs to be logical for .studies_find_studies", {
skip_on_cran()
expect_error(
.studies_find_studies(NULL, NULL, "123", FALSE),
"logical"
)
})
test_that("argument exact needs to be logical for .studies_find_studies", {
skip_on_cran()
expect_error(
.studies_find_studies(NULL, NULL, TRUE, "123"),
"logical"
)
})
test_that("argument property needs to be character for .studies_find_studies", {
skip_on_cran()
expect_error(
.studies_find_studies(123, NULL, TRUE, TRUE),
"character"
)
})
test_that("argument value needs to be character for .studies_find_studies", {
skip_on_cran()
## there is an error but not because of the argument "value" is
## character, it looks like a number so it's OK. Failure is
## because of the value doesn't exist.
expect_error(
.studies_find_studies("test", "123", TRUE, TRUE),
"Study property test is unknown"
)
})
test_that("both property & value need to be provided for .studies_find_studies", {
skip_on_cran()
expect_error(
.studies_find_studies("test", NULL, TRUE, TRUE),
"Must supply"
)
})
test_that("both property & value need to be provided for .studies_find_studies", {
skip_on_cran()
expect_error(
.studies_find_studies(NULL, "test", TRUE, TRUE),
"Must supply"
)
})
###########################
## .studies_find_trees ##
###########################
test_that("argument verbose needs to be logical for .studies_find_trees", {
skip_on_cran()
expect_error(
.studies_find_trees(NULL, NULL, "123", FALSE),
"logical"
)
})
test_that("argument exact needs to be logical for .studies_find_trees", {
skip_on_cran()
expect_error(
.studies_find_trees(NULL, NULL, TRUE, "123"),
"logical"
)
})
test_that("argument property needs to be character for .studies_find_trees", {
skip_on_cran()
expect_error(
.studies_find_trees(123, NULL, TRUE, TRUE),
"character"
)
})
test_that("argument value needs to be character for .studies_find_trees", {
skip_on_cran()
## there is an error but not because of the argument "value" is
## character, it looks like a number so it's OK. Failure is
## because of the value doesn't exist.
expect_error(.studies_find_trees("test", "123", TRUE, TRUE))
})
test_that("both property & value need to be provided for .studies_find_trees", {
skip_on_cran()
expect_error(
.studies_find_trees("test", NULL, TRUE, TRUE),
"Must supply"
)
})
test_that("both property & value need to be provided for .studies_find_trees", {
skip_on_cran()
expect_error(
.studies_find_trees(NULL, "test", TRUE, TRUE),
"Must supply"
)
})
test_that("exact works as intended", {
skip_on_cran()
expect_equal(length(.studies_find_studies("ot:focalCladeOTTTaxonName",
"felidae",
exact = TRUE
)$matched_studies), 0)
})
test_that("exact works as intended", {
skip_on_cran()
expect_true(length(.studies_find_studies("ot:focalCladeOTTTaxonName",
"Felidae",
exact = TRUE
)$matched_studies) >= 1)
})
############################################################################
## .get_study ##
############################################################################
test_that("study_id isn't NULL for .get_study", {
skip_on_cran()
expect_error(
.get_study(NULL, "test"),
"Must supply"
)
})
test_that("study_id is character for .get_study", {
skip_on_cran()
expect_error(
.get_study(TRUE, "test"),
"character"
)
})
############################################################################
## .get_study_tree ##
############################################################################
test_that("study_id isn't NULL for .get_study_tree", {
skip_on_cran()
expect_error(
.get_study_tree(NULL, NULL),
"Must supply"
)
})
test_that("study_id isn't NULL for .get_study_tree", {
skip_on_cran()
expect_error(
.get_study_tree("123", NULL),
"Must supply"
)
})
test_that("study_id isn't NULL for .get_study_tree", {
skip_on_cran()
expect_error(
.get_study_tree(NULL, "123"),
"Must supply"
)
})
test_that("study_id is character for .get_study", {
skip_on_cran()
expect_error(
.get_study_tree(TRUE, "test"),
"character"
)
})
test_that("study_id is character for .get_study", {
skip_on_cran()
expect_error(
.get_study_tree("test", TRUE),
"character"
)
})
############################################################################
## .get_study_subtree ##
############################################################################
test_that("study_id isn't NULL for .get_study_subtree", {
skip_on_cran()
expect_error(
.get_study_subtree(NULL, NULL, NULL),
"Must supply"
)
})
test_that("tree_id isn't NULL for .get_study_subtree", {
skip_on_cran()
expect_error(
.get_study_subtree("123", NULL, "123"),
"Must supply"
)
})
test_that("subtree_id isn't NULL for .get_study_subtree", {
skip_on_cran()
expect_error(
.get_study_subtree(NULL, "123", "123"),
"Must supply"
)
})
test_that("study_id isn't NULL for .get_study_subtree", {
skip_on_cran()
expect_error(
.get_study_subtree("123", "123", NULL),
"Must supply"
)
})
test_that("study_id is character for .get_study", {
skip_on_cran()
expect_error(
.get_study_subtree(TRUE, "test", "test"),
"character"
)
})
test_that("tree_id is character for .get_study", {
skip_on_cran()
expect_error(
.get_study_subtree("test", TRUE, "test"),
"character"
)
})
test_that("subtree_id is character for .get_study", {
skip_on_cran()
expect_error(
.get_study_subtree("test", "test", TRUE),
"character"
)
})
rotl/tests/testthat/test-API.R 0000644 0001762 0000144 00000013455 14441553346 015766 0 ustar ligges users ####
## Making use of the shared OpenTree testing architecture
####
## The R, Python and Ruby wrappers for the Open Tree share a very similar design,
## allowing them to make use of a single test suite for the low-level functions
## (thus, the tests both checkvan individual library works as expected, and that
## the different libraries stay in line with each other).
##
## This file pulls the current version of the test from a github repo
## (https://github.com/OpenTreeOfLife/shared-api-tests) and translates the json
## files into tests that run in testthat. This takes a considerable amount of
## infrastructure so I'll briefly described the rational here.
##
## The JSON test-specificaton is defined at the github repo linked above, to
## translate these tests I have created custom testthat expectation-functionals
## (contains(), (key_has_value()... ). Because many of the test blocks in the
## JSON files have multiple expectiatoins (i.e. many key-value pairs for
## test_equals) there are functions starting with `test_` that run an entire
## test block for a given expectation. Since many of these tests require
## translation between R-objects and JSON encoded strings there is a set of
## convienence functions to automate that step and a function "test_map" that
## returns the appropriate test_* function for r given JSON test block.
##
## Finally, testthat_json_test uses the above functions to runs an entire test
## from a JSON object, and run_shared_tests() runs every tests in a JSON file.
# functionals that start with a response
contains <- function(key_name) {
function(x) {
expectation(key_name %in% names(x), sprintf("Missing key name: %s", key_name))
}
}
key_has_value <- function(key, value) {
function(x) {
if (length(value) == 0) {
expectation(
length(x[[key]]) == 0,
paste("Key", key, "is not empty")
)
}
else if (length(value) == 1) {
expectation(
x[[key]] == value,
paste("Key", key, "doesn't have value", value)
)
}
else {
expectation(
all(x[[key]] %in% value),
paste("Key", key, "doesn't contain all of", value)
)
}
}
}
value_is_longer_than <- function(key, len) {
function(x) {
expectation(
length(x[[key]]) > len,
paste("Value for key", key, "is shorter than", len)
)
}
}
value_is_error <- function(key_name) {
function(x) {
expectation(
x[[key_name]] == "error",
sprintf("Key %s is not 'error'", key_name)
)
}
}
## Functions to test entire test blocks with the above expectations
test_contains <- function(response, test_block) {
key_names <- test_block[, 1]
sapply(key_names, function(k) expect_that(response, contains(k)))
}
test_equals <- function(response, test_block) {
kv_pairs <- sapply(test_block, "[[", 1)
for (i in 1:length(kv_pairs)) {
expect_that(response, key_has_value(kv_pairs[[1]], kv_pairs[[2]]))
}
}
test_of_type <- function(response, test_block) {
rtype <- type_map(test_block[[1]])
expect_that(response, is_a(rtype))
}
test_deep_equals <- function(response, test_block) {
cat("*")
expect_true(TRUE)
}
test_length_greater_than <- function(response, test_block) {
vl_pairs <- sapply(test_block, "[[", 1)
apply(vl_pairs, 2, function(v) {
expect_that(response, value_is_longer_than(v[[1]], v[[2]]))
})
}
test_contains_error <- function(response, test_block) {
errs <- test_block[, 1]
sapply(errs, function(e) expect_that(reponse, contains_error(e)))
}
## convience functions
obj_map <- function(input) {
if (is.character(input) & length(input) == 1) {
switch(tolower(input),
"true" = TRUE,
"false" = FALSE,
"null" = NULL,
input
)
}
else {
input
}
}
json_to_r <- function(test_input) {
if (length(test_input) == 0) {
return(test_input)
}
return(lapply(test_input, obj_map))
}
type_map <- function(json_type) {
switch(json_type,
"dict" = "list",
stop(sprintf("unknown json type in testing file: %s", json_type))
)
}
test_map <- function(test_type) {
switch(test_type,
"contains" = test_contains,
"equals" = test_equals,
"deep_equals" = test_deep_equals,
"error" = stop("Error tests should be handled first"),
"length_greater_than" = test_length_greater_than,
"of_type" = test_of_type,
stop(sprintf("Unkown error type in JSON test: %s", test_type))
)
}
make_request <- function(json_test) {
test_fxn <- paste0(".", json_test$test_function)
do.call(what = test_fxn, args = json_to_r(json_test$test_input))
}
testthat_json_test <- function(test_obj, test_name) {
tests_to_run <- names(test_obj[[test_name]]$tests)
if (length(tests_to_run) == 1) {
if (grepl("error", tests_to_run)) {
expect_error(make_request(test_obj[[test_name]]))
}
}
else {
response <- make_request(test_obj[[test_name]])
for (i in 1:length(tests_to_run)) {
test_block <- test_obj[[test_name]]$tests[[tests_to_run[i]]]
test_fxn <- test_map(tests_to_run[i])
test_fxn(response, test_block)
}
}
}
run_shared_test <- function(json_obj) {
all_tests <- names(json_obj)
for (i in 1:length(all_tests)) {
test_that(all_tests[i], {
skip_on_cran()
testthat_json_test(json_obj, all_tests[i])
})
}
}
## if (identical(Sys.getenv("NOT_CRAN"), "true")) {
## base_url <- "https://raw.githubusercontent.com/OpenTreeOfLife/shared-api-tests/master/"
## apis <- c("graph_of_life",
## "studies",
## "taxonomy",
## "tree_of_life",
## "tnrs"
## )
## for(i in 1:length(apis)){
## context( paste(apis[i], "API") )
## test_text <- httr::GET(paste0(base_url, apis[i], ".json"))
## test_description <- jsonlite::fromJSON(httr::content(test_text))
## run_shared_test(test_description)
## }
## }
rotl/tests/tree_of_life.json 0000644 0001762 0000144 00000007056 14441553346 015732 0 ustar ligges users {
"test_mrca_normal_input": {
"test_function": "tol_mrca",
"test_input": {"ott_ids":[412129, 536234]},
"tests": {
"of_type":
["dict","Response is of wrong type"]
,
"equals": [
[["nearest_taxon_mrca_rank","'superorder'"],"Fails that nearest_taxon_mrca_rank contains superorder"]
],
"contains": [
["nearest_taxon_mrca_ott_id","Doesn't contain nearest_taxon_mrca_ott_id"]
]
}
},
"test_mrca_empty_list_input": {
"test_function": "tol_mrca",
"test_input": {"ott_ids":[]},
"tests": {
"error": [
["ValueError","Return wrong kind of error, or did return error"]
]
}
},
"test_mrca_empty_list_input_two": {
"test_function": "tol_mrca",
"test_input": {"ott_ids":[],
"node_ids":[]},
"tests": {
"error": [
["ValueError","Return wrong kind of error, or did return error"]
]
}
},
"test_mrca_non_existing_node": {
"test_function": "tol_mrca",
"test_input": {"ott_ids":[4259824365942365972436598732]},
"tests": {
"error": [
["OpenTreeService.OpenTreeError","Return wrong kind of error, or did return error"]
]
}
},
"test_mrca_non_existing_empty": {
"test_function": "tol_mrca",
"test_input": "null",
"tests": {
"error": [
["ValueError","Return wrong kind of error, or did return error"]
]
}
},
"test_subtree_demo": {
"test_function": "tol_subtree",
"test_input": {"ott_id":3599390},
"tests": {
"of_type":
["dict","Response is of wrong type"]
,
"contains": [
["newick","Doesn't contain a newick string"]
]
}
},
"test_subtree_null": {
"test_function": "tol_subtree",
"test_input": {},
"tests": {
"error": [
["ValueError","Return wrong kind of error, or did return error"]
],
"of_type": ["jfdsm"]
}
},
"test_induced_tree_good": {
"test_function": "tol_induced_tree",
"test_input": {"ott_ids":[292466, 501678, 267845, 666104, 316878, 102710, 176458]},
"tests": {
"of_type":
["dict","Response is of wrong type"]
,
"contains": [
["subtree","Doesn't contain a subtree string"]
]
}
},
"test_induced_tree_null": {
"test_function": "tol_induced_tree",
"test_input": {},
"tests": {
"error": [
["ValueError","Return wrong kind of error, or did return error"]
],
"of_type": ["something"]
}
},
"test_about": {
"test_function": "tol_about",
"test_input": {},
"tests": {
"contains": [
["root_taxon_name","Output doesn't contain root_taxon_name"],
["num_source_studies","Output doesn't contain num_source_studies"],
["taxonomy_version","Output doesn't contain taxonomy_version"],
["root_ott_id","Output doesn't contain root_ott_id"],
["num_tips","Output doesn't contain num_tips"]
]
}
}
}
rotl/vignettes/ 0000755 0001762 0000144 00000000000 14442555441 013252 5 ustar ligges users rotl/vignettes/meta-analysis.Rmd 0000644 0001762 0000144 00000052032 14442034213 016454 0 ustar ligges users ---
title: "Using the Open Tree synthesis in a comparative analysis"
author: "David Winter"
date: "2023-06-13"
output:
rmarkdown::html_vignette:
css: vignette.css
vignette: >
%\VignetteIndexEntry{Using the Open Tree synthesis in a comparative analysis}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
%\VignetteEncoding{UTF-8}
---
## Phylogenetic Comparative Methods
The development of phylogenetic comparative methods has made phylogenies and
important source of data in fields as diverse as ecology, genomic and medicine.
Comparative methods can be used to investigate patterns in the evolution of
traits or the diversification of lineages. In other cases a phylogeny is treated
as a "nuisance parameter", allowing with the autocorrelation created by the shared
evolutionary history of the different species included to be controlled for.
In many cases finding a tree that relates the species for which trait data are
available is a rate-limiting step in such comparative analyses. Here we show
how the synthetic tree provided by Open Tree of Life (and made available in R via
`rotl`) can help to fill this gap.
## A phylogenetic meta-analysis
To demonstrate the use of `rotl` in a comparative analysis, we will partially
reproduce the results of [Rutkowska _et al_ 2014](https://doi.org/10.1111/jeb.12282).
Very briefly, this study is a meta-analysis summarising the results of multiple
studies testing for systematic differences in the size of eggs which contain
male and female offspring. Such a difference might mean that birds invest more
heavily in one sex than the other.
Because this study involves data from 51 different species, Rutkowska _et al_
used a phylogenetic comparative approach to account for the shared evolutionary
history among some of the studied-species.
### Gather the data
If we are going to reproduce this analysis, we will first need to gather the
data. Thankfully, the data is available as supplementary material from the
publisher's website. We provide a copy of this data with the package:
```r
library(rotl)
```
```r
## This dataset is available from the publisher's study website:
egg_data <- read.csv(system.file("extdata", "egg.csv", package = "rotl"),
stringsAsFactors = FALSE
)
## }
head(egg_data)
```
```
## animal Spp Lndim Measure Neggs
## 1 Zonotrichia_leucophrys White-crowned sparrow 0.000000000 volume 294
## 2 Passer_domesticus House sparrow 0.009407469 volume 149
## 3 Serinus_canaria Canary 0.000000000 volume 52
## 4 Turdus_merula European blackbird 0.021189299 volume 82
## 5 Agelaius_phoeniceus Red-winged blackbird 0.218316086 volume 394
## 6 Quiscalus_mexicanus Great-tailed grackle 0.281894985 mass 822
## Nclutches ESr Type StudyID Year D EN Zr
## 1 73 0.14004594 stat Mead1987 1987 3.421918 85.91673 0.14097244
## 2 31 0.11175203 stat Cordero2000 2000 4.045161 36.83413 0.11222075
## 3 21 0.49679140 stat Leitner2006 2006 2.180952 23.84279 0.54503712
## 4 54 0.38598540 stat Martyka2010 2010 1.414815 57.95812 0.40707397
## 5 106 0.07410136 raw Weatherhead1985 1985 3.173585 124.14982 0.07423744
## 6 205 0.05178834 raw Teather1989 1989 3.407805 241.21099 0.05183471
## VZr
## 1 0.012060292
## 2 0.029555954
## 3 0.047978211
## 4 0.018195675
## 5 0.008254242
## 6 0.004197959
```
The most important variable in this dataset is `Zr`, which is a [normalized
effect size](https://en.wikipedia.org/wiki/Fisher_transformation) for difference
,in size between eggs that contain males and females. Values close to zero come
from studies that found the sex of an egg's inhabitant had little effect in its size,
while large positive or negative values correspond to studies with substantial
sex biases (towards males and females respectively). Since this is a
meta-analysis we should produce the classic [funnel plot](https://en.wikipedia.org/wiki/Funnel_plot)
with effects-size on the y-axis and precision (the inverse of the sample
standard error) on the x-axis. Here we calculate precision from the sample
variance (`Vzr`):
```r
plot(1 / sqrt(egg_data$VZr), egg_data$Zr,
pch = 16,
ylab = "Effect size (Zr)",
xlab = "Precision (1/SE)",
main = "Effect sizes for sex bias in egg size among 51 brid species"
)
```

In order to use this data later on we need to first convert it to a standard
`data.frame`. We can also convert the `animal` column (the species names) to
lower case, and remove the underscores in their names, which will make it easier to match names later on:
```r
egg_data <- as.data.frame(egg_data)
## Convert taxon names to lower case
egg_data$animal <- tolower(egg_data$animal)
## Let's remove the underscores (_) from the taxon names
egg_data$animal <- gsub("_", " ", egg_data$animal)
```
### Find the species in OTT
We can use the OTL synthesis tree to relate these species. To do so we first need to
find Open Tree Taxonomy (OTT) IDs for each species. We can do that with the
Taxonomic Name Resolution Service function `tnrs_match_names`:
```r
taxa <- tnrs_match_names(unique(egg_data$animal), context = "Animals")
```
```
## Warning in tnrs_match_names(unique(egg_data$animal), context = "Animals"):
## partial argument match of 'context' to 'context_name'
```
```r
head(taxa)
```
```
## search_string unique_name approximate_match ott_id
## 1 zonotrichia leucophrys Zonotrichia leucophrys FALSE 265553
## 2 passer domesticus Passer domesticus FALSE 745175
## 3 serinus canaria Serinus canaria FALSE 464865
## 4 turdus merula Turdus merula FALSE 568572
## 5 agelaius phoeniceus Agelaius phoeniceus FALSE 226605
## 6 quiscalus mexicanus Quiscalus mexicanus FALSE 743411
## is_synonym flags number_matches
## 1 FALSE 1
## 2 FALSE 1
## 3 FALSE sibling_higher 1
## 4 FALSE 1
## 5 FALSE 1
## 6 FALSE 1
```
All of these species are in OTT, but a few of them go by different names in the
Open Tree than we have in our data set. Because the tree `rotl` fetches
will have Open Tree names, we need to create a named vector that maps the names
we have for each species to the names Open Tree uses for them:
```r
taxon_map <- structure(taxa$search_string, names = taxa$unique_name)
```
Now we can use this map to retrieve "data set names" from "OTT names":
```r
taxon_map["Anser caerulescens"]
```
```
## Anser caerulescens
## "chen caerulescens"
```
### Get a tree
Now we can get the tree. There are really too many tips here to show nicely, so
we will leave them out of this plot
```r
tr <- tol_induced_subtree(ott_id(taxa)[is_in_tree(ott_id(taxa))])
```
```
## Warning in collapse_singles(tr, show_progress): Dropping singleton nodes
## with labels: mrcaott246ott5481, mrcaott246ott7145, mrcaott246ott928360,
## mrcaott246ott1858, mrcaott246ott2907, mrcaott246ott3600042, mrcaott246ott7113,
## Passeriformes ott1041547, mrcaott246ott3212, mrcaott246ott428578,
## mrcaott246ott44866, mrcaott246ott5929, mrcaott246ott32658,
## mrcaott246ott310390, mrcaott246ott176461, mrcaott246ott22325,
## mrcaott246ott10351, mrcaott246ott193904, mrcaott246ott5934, mrcaott246ott1566,
## mrcaott1566ott3598440, mrcaott1566ott496009, mrcaott1566ott59716,
## mrcaott1566ott32651, mrcaott1566ott24297, mrcaott1566ott45312,
## mrcaott1566ott22300, mrcaott22300ott35350, mrcaott22300ott547548,
## mrcaott22300ott909199, mrcaott22300ott67150, mrcaott22300ott130294,
## mrcaott22300ott3598245, mrcaott22300ott416087, mrcaott22300ott629342,
## mrcaott22300ott416089, mrcaott22300ott107840, mrcaott364210ott451069,
## mrcaott364210ott3598839, mrcaott3598839ott5341363, mrcaott19467ott431648,
## mrcaott19467ott252687, mrcaott19467ott401023, mrcaott19467ott233446,
## mrcaott19467ott168078, mrcaott19467ott1046624, mrcaott19467ott161293,
## mrcaott19467ott46396, mrcaott46396ott46398, mrcaott46398ott168083,
## mrcaott168083ott431676, mrcaott2175ott35326, mrcaott2175ott968664,
## mrcaott2175ott259082, mrcaott2175ott59905, mrcaott2175ott2224,
## mrcaott2224ott366470, mrcaott3364ott310375, mrcaott3364ott3370,
## mrcaott4083ott35042, mrcaott4083ott370807, mrcaott4083ott469177,
## mrcaott4083ott18592, mrcaott4083ott139823, mrcaott4083ott11712,
## mrcaott4083ott95949, Erythrura ott465905, mrcaott24017ott389884,
## mrcaott24017ott24025, mrcaott24025ott596763, mrcaott24025ott453058,
## mrcaott24025ott141501, mrcaott141501ott966119, mrcaott141501ott865472,
## mrcaott141501ott389883, mrcaott105913ott311555, mrcaott311555ott1082386,
## mrcaott311555ott708327, mrcaott708327ott966122, mrcaott4088ott8371,
## mrcaott4088ott5616, mrcaott5616ott28339, mrcaott5616ott6023,
## mrcaott6023ott243614, mrcaott6023ott101225, mrcaott6023ott125079,
## mrcaott125079ott463026, mrcaott125079ott765405, Zonotrichia (genus in
## domain Eukaryota) ott789032, mrcaott125079ott265547, mrcaott125079ott265554,
## mrcaott5620ott254662, mrcaott5620ott29804, mrcaott29804ott449580,
## mrcaott29804ott449562, mrcaott29804ott86894, mrcaott29804ott93045,
## mrcaott93045ott264496, mrcaott264496ott264500, mrcaott264500ott3597163,
## mrcaott264500ott283668, Quiscalus ott743410, mrcaott283673ott673386,
## mrcaott283673ott741944, mrcaott283673ott735243, mrcaott213448ott213452,
## mrcaott213448ott1009279, mrcaott213448ott213451, mrcaott213454ott430627,
## mrcaott430627ott498751, mrcaott430627ott617797, mrcaott430627ott3597159,
## mrcaott99175ott364331, Xanthocephalus ott364336, mrcaott6366ott28332,
## mrcaott6366ott88283, mrcaott6366ott341465, mrcaott6366ott157599,
## mrcaott6366ott178457, mrcaott6366ott405215, mrcaott6366ott238142,
## mrcaott6366ott6375, mrcaott6375ott119724, mrcaott6375ott238137,
## mrcaott238137ott328909, mrcaott238137ott464865, Haemorhous ott3601758,
## mrcaott9416ott840030, mrcaott9416ott96148, mrcaott9416ott7068473, Passer
## ott515158, mrcaott9416ott407769, mrcaott9416ott25628, mrcaott9416ott407764,
## mrcaott9416ott68955, mrcaott9416ott73636, mrcaott1488ott72472,
## mrcaott1488ott63797, mrcaott1488ott284404, mrcaott1488ott107463,
## mrcaott1488ott17016, mrcaott1488ott44217, mrcaott1488ott16185,
## mrcaott16185ott274931, Hirundinidae ott897681, mrcaott16185ott67916,
## mrcaott67916ott67921, mrcaott67916ott368059, mrcaott67916ott67920,
## Delichon ott922719, mrcaott107476ott177058, mrcaott107476ott271376,
## mrcaott107476ott337752, mrcaott337752ott7661935, mrcaott337752ott337762,
## mrcaott337752ott7068616, mrcaott2375ott73144, mrcaott2375ott124085,
## mrcaott2375ott71358, mrcaott2375ott814750, mrcaott2375ott61147,
## mrcaott84656ott123763, mrcaott123763ott728471, mrcaott123763ott258794,
## mrcaott4820ott409116, mrcaott4820ott17162, mrcaott4820ott20998,
## mrcaott4820ott20989, mrcaott4820ott58860, mrcaott4820ott23690,
## mrcaott4820ott20996, mrcaott4820ott11462, mrcaott4820ott140440,
## mrcaott4820ott197505, mrcaott4820ott75978, mrcaott4820ott11315,
## mrcaott4820ott5933, mrcaott5933ott60465, mrcaott5933ott25637,
## mrcaott25637ott199843, mrcaott25637ott473431, mrcaott25637ott686166,
## mrcaott25637ott111993, mrcaott25637ott183621, mrcaott183621ott501241,
## mrcaott501241ott3598010, mrcaott501241ott597018, mrcaott686165ott686168,
## mrcaott60456ott662804, mrcaott60456ott75990, Pica ott776480, Falconiformes
## ott212187, Falconidae ott212186, mrcaott47588ott225286, mrcaott47588ott748842,
## mrcaott47588ott201377, mrcaott201377ott773020, Cerchneis ott3596159,
## mrcaott179290ott352521, mrcaott179290ott624976, mrcaott179290ott624973,
## mrcaott179290ott624974, mrcaott179290ott432111, mrcaott5272ott92263,
## mrcaott5272ott24121, Scolopacidae ott887699, mrcaott24121ott217797,
## mrcaott24121ott45306, mrcaott24121ott654830, mrcaott24121ott214779,
## mrcaott24121ott651066, mrcaott651066ott1090732, mrcaott7639ott306220,
## mrcaott7639ott57833, mrcaott7639ott383929, mrcaott7639ott279504,
## mrcaott7639ott47401, mrcaott7639ott341047, mrcaott7639ott234666,
## mrcaott7639ott341034, mrcaott7639ott285543, Sterna ott16767,
## mrcaott285543ott341030, mrcaott285543ott738509, mrcaott285543ott966606,
## mrcaott285543ott966604, mrcaott22965ott738512, mrcaott22965ott80679,
## mrcaott22965ott558955, mrcaott22965ott154126, mrcaott22965ott241571,
## mrcaott22965ott282132, mrcaott22965ott414141, mrcaott22965ott704174,
## mrcaott22965ott704175, mrcaott22965ott324050, mrcaott22965ott353849,
## mrcaott22965ott75913, mrcaott75913ott335736, mrcaott306645ott450107,
## mrcaott425206ott887691, mrcaott425206ott515355, mrcaott119599ott993041,
## mrcaott119599ott509055, mrcaott698969ott4947414, mrcaott147723ott219032,
## Stercorariidae ott168297, Stercorarius ott742632, mrcaott742640ott742641,
## mrcaott57823ott57827, mrcaott57823ott242771, mrcaott57823ott112937,
## mrcaott112937ott129402, mrcaott112937ott454019, mrcaott112937ott242776,
## mrcaott242776ott313115, mrcaott242776ott704464, mrcaott242776ott331994,
## mrcaott331994ott413796, mrcaott9830ott86672, mrcaott9830ott90560,
## mrcaott9830ott324158, mrcaott9830ott55044, mrcaott9830ott285638,
## mrcaott9830ott117726, Sulidae ott452462, mrcaott170197ott403772, Sula ott160486,
## mrcaott170197ott5859716, mrcaott170197ott429615, mrcaott429615ott1030312,
## Procellariiformes ott452461, mrcaott18206ott31011, mrcaott31011ott71459,
## Diomedeidae ott85277, mrcaott71459ott320282, Phoebastria ott941509,
## mrcaott320282ott320284, Sphenisciformes ott494366, Spheniscidae ott494367,
## mrcaott60413ott3600120, mrcaott60413ott4130813, mrcaott60413ott4130835,
## mrcaott60413ott4130830, mrcaott60413ott3600127, mrcaott60413ott4130831,
## mrcaott60413ott3600124, mrcaott60413ott3600128, mrcaott60413ott3600129,
## mrcaott60413ott4130819, mrcaott60413ott4130817, mrcaott60413ott60417,
## mrcaott60413ott3600131, mrcaott60413ott917663, Eudyptes ott494364,
## mrcaott82219ott116946, mrcaott116946ott219197, mrcaott134466ott494361,
## Pygoscelis ott494365, mrcaott134466ott783352, mrcaott5021ott198671,
## mrcaott5021ott75792, Cuculiformes ott212171, mrcaott75792ott212172,
## mrcaott75792ott3601282, mrcaott75792ott119216, mrcaott119216ott212175,
## mrcaott119216ott169265, mrcaott169265ott550039, mrcaott169265ott462546,
## mrcaott462546ott3596355, mrcaott462546ott1050027, Cuculus ott1041429,
## mrcaott549514ott7068132, mrcaott549514ott3596308, mrcaott549514ott3596307,
## mrcaott549514ott3596306, mrcaott549514ott792626, mrcaott17146ott57819,
## Columbiformes ott363030, mrcaott17146ott45505, mrcaott45505ott50388,
## mrcaott45505ott506098, mrcaott45505ott51607, mrcaott51607ott277822,
## mrcaott51607ott67614, mrcaott51607ott244134, Columba ott938415,
## mrcaott51607ott277817, mrcaott277817ott320359, mrcaott320359ott493986,
## mrcaott320359ott767317, mrcaott320359ott921832, mrcaott320359ott938416,
## Galliformes ott837585, mrcaott4765ott6520194, mrcaott4765ott109888,
## mrcaott4765ott75785, mrcaott4765ott104461, mrcaott4765ott151684,
## mrcaott4765ott54193, mrcaott4765ott49319, mrcaott4765ott3596087,
## mrcaott4765ott415487, mrcaott4765ott51354, mrcaott4765ott446490, Tetraoninae
## ott999677, mrcaott4765ott55929, mrcaott4765ott539045, mrcaott4765ott234824,
## Centrocercus ott728081, mrcaott53700ott572162, mrcaott53700ott466627,
## mrcaott53700ott309383, mrcaott53700ott102722, mrcaott102722ott137547, Phasianus
## ott102718, mrcaott49310ott102705, mrcaott49310ott153554, mrcaott153554o
```
```r
plot(tr, show.tip.label = FALSE)
```
There are a few things to note here. First, the tree has no branch lengths.
At present this is true for the whole of the Open Tree synthetic tree. Some
comparative methods require either branch lengths or an ultrametric tree. Before
you can use one of those methods you will need to get a tree with branch
lengths. You could try looking for published trees made available by the Open
Tree with `studies_find_trees`. Alternatively, you could estimate branch lengths
from the toplogy of a phylogeny returned by `tol_induced_subtree`, perhaps by
downloading DNA sequences from the NCBI with `rentrez` or "hanging" the tree on
nodes of known-age using penalized likelihood method in `ape::chronos`.
In this case, we will use only the topology of the tree as input to our
comparative analysis, so we can skip these steps.
Second, the tip labels contain OTT IDs, which means they will not perfectly
match the species names in our dataset or the taxon map that we created earlier:
```r
tr$tip.label[1:4]
```
```
## [1] "Ficedula_albicollis_ott107840" "Luscinia_svecica_ott274225"
## [3] "Turdus_merula_ott568572" "Sturnus_unicolor_ott366470"
```
Finally, the tree contains node labels for those nodes that match a higher taxonomic
group, and empty character vectors (`""`) for all other nodes. Some
comparative methods either do no expect node labels at all, or require all
labeled nodes to have a unique name (meaning multiple "empty" labels will cause
and error).
We can deal with all these details easily. `rotl` provides the convenience
function `strip_ott_ids` to remove the extra information from the tip labels.
With the IDs removed, we can use our taxon map to replace the tip labels in the tree
with the species names from dataset.
```r
otl_tips <- strip_ott_ids(tr$tip.label, remove_underscores = TRUE)
tr$tip.label <- taxon_map[ otl_tips ]
```
Finally, we can remove the node labels by setting the `node.label` attribute of
the tree to `NULL`.
```r
tr$node.label <- NULL
```
```r
egg_data <- egg_data[egg_data$animal %in% tr$tip.label, ]
```
### Perform the meta-analysis
Now we have data and a tree, and we know the names in the tree match the ones in
the data. It's time to do the comparative analysis. Rutkowska _et al_. used `MCMCglmm`, a
Bayesian MCMC approach to fitting multi-level models,to perform their meta-analysis,
and we will do the same. Of course, to properly analyse these data you would
take some care in deciding on the appropriate priors to use and inspect the
results carefully. In this case, we are really interested in using this as a
demonstration, so we will just run a simple model.
Specifically we sill fit a model where the only variable that might explain the
values of `Zr` is the random factor `animal`, which corresponds to the
phylogenetic relationships among species. We also provide `Zvr` as the measurement
error variance, effectively adding extra weight to the results of more powerful
studies. Here's how we specify and fit that model with `MCMCglmm`:
```r
set.seed(123)
if (require(MCMCglmm, quietly = TRUE)) {
pr <- list(
R = list(V = 1, nu = 0.002),
G = list(G1 = list(V = 1, nu = 0.002))
)
model <- MCMCglmm(Zr ~ 1,
random = ~animal,
pedigree = tr,
mev = egg_data$VZr,
prior = pr,
data = egg_data,
verbose = FALSE
)
} else {
model <- readRDS(file = system.file("extdata", "mcmcglmm_model.rds", package = "rotl"))
}
```
```
## Warning in inverseA(pedigree = pedigree, scale = scale, nodes = nodes): no
## branch lengths: compute.brlen from ape has been used
```
```
## Warning in sing.rm$coef: partial match of 'coef' to 'coefficients'
```
```
## Warning in x$n: partial match of 'n' to 'nu'
## Warning in x$n: partial match of 'n' to 'nu'
## Warning in x$n: partial match of 'n' to 'nu'
## Warning in x$n: partial match of 'n' to 'nu'
## Warning in x$n: partial match of 'n' to 'nu'
## Warning in x$n: partial match of 'n' to 'nu'
```
Now that we have a result we can find out how much phylogenetic signal exists
for sex-biased differences in egg-size. In a multi-level model we can use variance
components to look at this, specifically the proportion of the total variance
that can be explained by phylogeny is called the phylogenetic reliability, _H_. Let's
calculate the _H_ for this model:
```r
var_comps <- colMeans(model$VCV)
var_comps["animal"] / sum(var_comps)
```
```
## animal
## 0.00283581
```
It appears there is almost no phylogenetic signal to the data.
The relationships among species explain much less that one percent of the total
variance in the data. If you were wondering, Rutkowska _et al_. report a similar result,
even after adding more predictors to their model most of the variance in `Zr`
was left unexplained.
## What other comparative methods can I use in R?
Here we have demonstrated just one comparative analysis that you might
do in R. There are an ever-growing number of packages that allow an
ever-growing number of analysis to performed in R. Some "classics"
like ancestral state reconstruction, phylogenetic independent
contrasts and lineage through time plots are implemented in
`ape`. Packages like `phytools`, `caper` and `diversitree` provide
extensions to these methods. The [CRAN Phylogenetics
Taskview](https://github.com/bomeara/PhylogeneticsTaskView/blob/main/Phylogenetics.md)
gives a good idea of the diversity of packages and analyses that can
be completed in R (note that this links to a draft of the next version
of the Taskview as it is currently unavailable from CRAN).
rotl/vignettes/fig-vignettes-unnamed-chunk-8-1.png 0000644 0001762 0000144 00000045022 14442034217 021565 0 ustar ligges users PNG
IHDR 'j pHYs ~ IDATxw@7 ɔ A(ދjպW:uOG՟uQRW⬃!{f0Fs(*>7ϽOB# m |^ A F , X= 4z `9h r A F , X= 4z `9h r A F , X= 4z `9h r A F , X= 4z `9h r A F , X= 4z `9h r A F , X= 4z `9h r A F , X= 4z `9h r у椲R[[[UUUEE媪ȍ7.\&ߵkW@@gϞٳg!._cǎ;57pAQ.,99y۶m{H\z[ӧ[ZZ:tY]](
uuuN*H((;%ICNAI6mJKKe2.e2YJJ[#`<::C]tI~L&k
X[egg4(''G'77w 7nr$bذafff_hQ~~>xҥ"(--{.\rUUUUUU#G\n]-w7p}@@3dɒ3g111wqqWUUb33ڵ>Ν;ݻwtttDcL䔜Ӕ{{XXXc puu]bEǎnZEmذRSSsbX~"˗/аr劵Aii)Ƹа\yŚA,+NH/*)/͛={ZZZ8q>?ڵ+_x|NQQQA`RMLLLqqaNN=߾}_~ɒ%Ew'hh(㬬,cc㰰0$[JD||L&{葺
Hֽ388xvnnVvvT*-((Wbjj%!**K鰾уG,a,XdzzzD"ƍ1>{dDDEQgϖJ}ϟ4iZ@GGG,_~n|͚5Nę3g:thҤIG~cI53.cS^ba555pBzzD"Q#LLL233ߺwwffffeeW___ެ 8|SEqqqNRRRd w6YfȐ! \R__!I
A0'B"O><vpp "22200_\\,x<^ll3O9H$7oApX__߆L>udGGGPzѣG+!!ޞl... (OBLd} P> M&1)/F^Ù:uQ
joo*'33SUUU(*So8p`DDWmll(RSSCEGGϞ=[([ZZ҃1˗/1b|BƝOM]h***v|||444d2Y^^^\\V\nRRR߾}1 _JB===zs=zhƟҮ];zKu릪3bĈN^[[KwaD4|pqqqtӦMCQ""**jӦMʓ5$ɸ 1EQ,,+++22555***x"AkllbWYTTg-s83gά\288c###cbb|&}n@ѥK`$/_lll-HLLL?N#L&sttLLLJG%ԩSR.##IIIjjj-"I111d:uJOOׯ_AYfСIٳիWR>D"166z*I?F~~$qޚ^2)/F0!$I㯿R#̙/u(H$FFFRtݻw͵zX,$I1EQÇDc >4z?utt<==1~T*}Y%ƸH `###555{1577J?=z!CF۽{q^^IC&?~P(;vbå(jر