Extract taxonomy information from sequence headers

Description

Extracts the taxonomy from metadata (e.g. sequence headers) or parsed sequence data. The location and identity of important information in the input is specified using a regular expression with capture groups and an corresponding key. An object of type taxmap is returned containing the specifed information. Taxa are translated into unique codes if they are not already encoded this way.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
extract_taxonomy(input, ...)

## Default S3 method:
extract_taxonomy(input, key = c("class", "taxon_id", "name",
  "taxon_info", "obs_id", "obs_info"), regex = "(.*)", class_key = c("name",
  "taxon_id", "taxon_info"), class_regex = "(.*)", class_sep = NULL,
  class_rev = FALSE, database = c("none", "ncbi", "itis", "eol", "col",
  "tropicos", "nbn"), allow_na = TRUE, vigilance = c("warning", "error",
  "message", "none"), return_match = FALSE, return_input = FALSE,
  redundant_names = FALSE, verbosity = c("low", "none", "high"), ...)

## S3 method for class 'DNAbin'
extract_taxonomy(input, ...)

## S3 method for class 'list'
extract_taxonomy(input, ...)

Arguments

input

A vector from which to extract taxonomy information or an object of class ape{DNAbin}.

...

Not used.

key

(character) The identity of the capturing groups defined using regex. The length of key must be equal to the number of capturing groups specified in regex. Any names added to the terms will be used as column names in the output. Only "taxon_info" and "obs_info" can be used multiple times. Each term must be one of those decribed below:

taxon_id

A unique numeric id for a taxon for a particular database (e.g. ncbi accession number). Requires an internet connection.

name

The name of a taxon. Not necessarily unique, but are interpretable by a particular database. Requires an internet connection.

taxon_info

Arbitrary taxon info you want included in the output. Can be used more than once.

class

A list of taxa information that consitutes the full taxonomic classification from broad to specific (see class_rev) for a particular database. Individual taxa are separated by the class_sep argument and the information is parsed by the class_regex and class_key arguments.

obs_id

An unique observation (e.g. sequence) identifier for a particular database. Requires an internet connection.

obs_info

Arbitrary observation info you want included in the output. Can be used more than once.

regex

(character; length == 1) A regular expression with capturing groups indicating the locations of relevant information. The identity of the information must be specified using the key argument.

class_key

(character of length 1) The identity of the capturing groups defined using class_iregex. The length of class_key must be equal to the number of capturing groups specified in class_regex. Any names added to the terms will be used as column names in the output. At least "taxon_id" or "name" must be specified. Only "taxon_info" can be used multiple times. Each term must be one of those decribed below:

taxon_id

A unique numeric id for a taxon for a particular database (e.g. ncbi accession number). Requires an internet connection.

name

The name of a taxon. Not necessarily unique, but are interpretable by a particular database. Requires an internet connection.

taxon_info

Arbitrary taxon info you want included in the output. Can be used more than once.

class_regex

(character of length 1) A regular expression with capturing groups indicating the locations of data for each taxon in the class term in the key argument. The identity of the information must be specified using the class_key argument. The class_sep option can be used to split the classification into data for each taxon before matching. If class_sep is NULL, each match of class_regex defines a taxon in the classification.

class_sep

(character of length 1) Used with the class term in the key argument. The character(s) used to separate individual taxa within a classification. After the string defined by the class capture group in regex is split by class_sep, its capture groups are extracted by class_regex and defined by class_key. If NULL, every match of class_regex is used instead with first splitting by class_sep.

class_rev

(logical of length 1) Used with the class term in the key argument. If TRUE, the order of taxon data in a classfication is reversed to be specific to broad.

database

(character of length 1) The name of the database that patterns given in parser will apply to. Valid databases include "ncbi", "itis", "eol", "col", "tropicos", "nbn", and "none". "none" will cause no database to be quired; use this if you want to not use the internet. NOTE: Only "ncbi" has been tested so far.

allow_na

(logical of length 1) If TRUE, any missing data will be represented as NAs in the output. This preserves the correspondance between the input and output values. Missing data can be generated if the regex does not match the input or online queries fail.

vigilance

(character of length 1) Controls the reporting of possible problems, such as missing data and failed online queries (see allow_na). The following values are possible:

"none"

No warnings or errors are generated if the function can complete.

"message"

A message is generated when atypical events occur.

"warning"

Warnings are generated when atypical events occur.

"error"

Errors are generated when atypical events occur, stopping the completion of the function.

return_match

(logical of length 1) If TRUE, include the part of the input matched by regex in the output object.

return_input

(logical of length 1) If TRUE, include the input in the output object.

redundant_names

(logical of length 1) If TRUE, remove any occurrence of the a supertaxon's name at the start of the taxon name. This is useful for removing the redundant genus information in species binomials.

verbosity

(character of length 1) Controls the printing of progress updates. The following values are possible:

"none"

No progress reports are printed

"low"

Minimal progress reports of a fixed length are printed.

"high"

Lots of information is printed depending on the amount of the input.

Value

Returns an object of type taxmap

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
# Extract embedded classifications from UNITE FASTA file offline
file_path <- system.file("extdata", "unite_general_release.fasta", package = "metacoder")
sequences <- ape::read.FASTA(file_path)
unite_ex_data_3 <- extract_taxonomy(sequences,
                                    regex = "^(.*)\\|(.*)\\|(.*)\\|.*\\|(.*)$",
                                    key = c(name = "obs_info", seq_id = "obs_info",
                                            other_id = "obs_info", "class_name"),
                                    database = "none")
# Look up taxonomic data online using sequence ID
unite_ex_data <- extract_taxonomy(sequences,
                                  regex = "^(.*)\\|(.*)\\|(.*)\\|.*\\|(.*)$",
                                key = c(name = "name", seq_id = "obs_id",
                                       other_id = "obs_info", tax_string = "obs_info"))

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.