File: api-taxonomy.R

package info (click to toggle)
r-cran-rotl 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,384 kB
  • sloc: sh: 9; makefile: 5
file content (70 lines) | stat: -rw-r--r-- 2,191 bytes parent folder | download | duplicates (2)
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
##' @importFrom httr content
## Summary information about the OpenTree Taxonomy (OTT)
.taxonomy_about <- function(...) {
  res <- otl_POST(path = "/taxonomy/about", body = list(), ...)
  res
}


##' @importFrom jsonlite unbox
##' @importFrom httr content
## Information about an OpenTree Taxonomy (OTT) taxon
.taxonomy_taxon_info <- function(ott_id = NULL,
                                 include_children = FALSE,
                                 include_lineage = FALSE,
                                 include_terminal_descendants = FALSE,
                                 ...) {
  ott_id <- check_ott_ids(ott_id)

  if (length(ott_id) > 1) {
    stop("Must only supply one ", sQuote("ott_id"), " argument")
  }

  check_is_flag(include_children)
  check_is_flag(include_lineage)
  check_is_flag(include_terminal_descendants)

  q <- list(
    ott_id = jsonlite::unbox(ott_id),
    include_children = jsonlite::unbox(include_children),
    include_lineage = jsonlite::unbox(include_lineage),
    include_terminal_descendants = jsonlite::unbox(include_terminal_descendants)
  )
  res <- otl_POST(path = "/taxonomy/taxon_info", body = q, ...)
  res
}


##' @importFrom jsonlite unbox
##' @importFrom httr content
## Get a subtree from the OpenTree Taxonomy (OTT) taxonomic tree
.taxonomy_subtree <- function(ott_id = NULL, label_format = NULL, ...) {
  ott_id <- check_ott_ids(ott_id)

  if (length(ott_id) > 1) {
    stop("Must only supply one ", sQuote("ott_id"), " argument")
  }

  q <- list(ott_id = jsonlite::unbox(ott_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 = "/taxonomy/subtree", body = q, ...)
  res
}


##' @importFrom httr content
## Get the most recent common ancestor (MRCA) from nodes in the OpenTree Taxonomy (OTT)
.taxonomy_mrca <- function(ott_ids = NULL, ...) {
  ott_ids <- check_ott_ids(ott_ids)
  q <- list(ott_ids = ott_ids)
  res <- otl_POST(path = "/taxonomy/mrca", body = q, ...)
  res
}