1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
##' @importFrom jsonlite unbox
##' @importFrom httr content
## Summary information about the OpenTree Tree of Life
.tol_about <- function(include_source_list = FALSE, ...) {
check_is_flag(include_source_list)
q <- list(include_source_list = jsonlite::unbox(include_source_list))
res <- otl_POST(path = "tree_of_life/about", body = q, ...)
res
}
##' @importFrom jsonlite unbox
##' @importFrom httr content
## Get summary information about a node in the OpenTree Tree of Life
.tol_node_info <- function(ott_id = NULL, node_id = NULL, include_lineage = FALSE, ...) {
check_is_flag(include_lineage)
if (is.null(ott_id) && is.null(node_id)) {
stop("Must provide either ", sQuote("ott_id"), " or ", sQuote("node_id"))
}
if (!is.null(ott_id) && !is.null(node_id)) {
stop("Must provide either ", sQuote("ott_id"), " or ", sQuote("node_id"), ", not both.")
}
if (!is.null(ott_id)) {
ott_id <- check_ott_ids(ott_id)
if (length(ott_id) != 1) {
stop("Please provide a single ", sQuote("ott_id"), call. = FALSE)
}
q <- list(ott_id = jsonlite::unbox(ott_id), include_lineage = jsonlite::unbox(include_lineage))
} else {
if (!check_valid_node_id(node_id)) {
stop("Argument ", sQuote("node_id"), " must look like \'ott123\' or \'mrcaott123ott456\'.")
}
q <- list(node_id = jsonlite::unbox(node_id), include_lineage = jsonlite::unbox(include_lineage))
}
res <- otl_POST(path = "tree_of_life/node_info", body = q, ...)
res
}
##' @importFrom httr content
## Get the MRCA of a set of nodes
.tol_mrca <- function(ott_ids = NULL, node_ids = NULL, ...) {
if (is.null(ott_ids) && is.null(node_ids)) {
stop("Must provide ", sQuote("ott_ids"), " or ", sQuote("node_ids"), " (or both).")
}
q <- list()
if (!is.null(ott_ids)) {
ott_ids <- check_ott_ids(ott_ids)
q$ott_ids <- ott_ids
}
if (!is.null(node_ids)) {
check_node_ids(node_ids)
q$node_ids <- node_ids
}
res <- otl_POST(path = "tree_of_life/mrca", body = q, ...)
res
}
# ignoring 'include_lineage' for subtree below. arguson only
##' @importFrom jsonlite unbox
##' @importFrom httr content
## Get a subtree from the OpenTree Tree of Life
.tol_subtree <- function(ott_id = NULL, node_id = NULL, label_format = NULL, ...) {
if (is.null(ott_id) && is.null(node_id)) {
stop("Must provide either ", sQuote("ott_id"), " or ", sQuote("node_id"))
}
if (!is.null(ott_id) && !is.null(node_id)) {
stop("Must provide either ", sQuote("ott_id"), " or ", sQuote("node_id"), ", not both.")
}
if (!is.null(ott_id)) {
ott_id <- check_ott_ids(ott_id)
if (length(ott_id) != 1) {
stop("Please provide a single ", sQuote("ott_id"))
}
q <- list(ott_id = jsonlite::unbox(ott_id))
} else {
if (!check_valid_node_id(node_id)) {
stop("Argument ", sQuote("node_id"), " must look like \'ott123\' or \'mrcaott123ott456\'.")
}
q <- list(node_id = jsonlite::unbox(node_id))
}
if (!is.null(label_format)) {
if (!check_label_format(label_format)) {
stop(
sQuote("label_format"), " must be one of: ", sQuote("name"), ", ",
sQuote("id"), ", or ", sQuote("name_and_id")
)
}
q$label_format <- jsonlite::unbox(label_format)
}
res <- otl_POST(path = "tree_of_life/subtree", body = q, ...)
res
}
##' @importFrom httr content
## Get an induced subtree from the OpenTree Tree of Life from a set of nodes
.tol_induced_subtree <- function(ott_ids = NULL, node_ids = NULL, label_format = NULL, ...) {
if (is.null(ott_ids) && is.null(node_ids)) {
stop("Must provide ", sQuote("ott_ids"), " or ", sQuote("node_ids"), " (or both).")
}
q <- list()
if (!is.null(label_format)) {
if (!check_label_format(label_format)) {
stop(
sQuote("label_format"), " must be one of: ", sQuote("name"), ", ",
sQuote("id"), ", or ", sQuote("name_and_id")
)
}
q$label_format <- jsonlite::unbox(label_format)
}
if (!is.null(ott_ids)) {
ott_ids <- check_ott_ids(ott_ids)
q$ott_ids <- ott_ids
}
if (!is.null(node_ids)) {
check_node_ids(node_ids)
q$node_ids <- node_ids
}
if ((length(ott_ids) + length(node_ids)) < 2) {
stop("At least two valid ", sQuote("ott_ids"), " or ", sQuote("node_ids"), " must be provided.")
}
res <- otl_POST("tree_of_life/induced_subtree", body = q, ...)
res
}
|