metacoder (version 0.1.3)

filter_taxa: Filter taxa with a list of conditions

Description

Filter taxa in a taxmap object with a list of conditions. Any column name that appears in taxon_data(.data) can be used as if it was a vector on its own. See filter for inspiration and more information.

Usage

filter_taxa(.data, ..., subtaxa = FALSE, supertaxa = FALSE,
  taxonless = FALSE, reassign_obs = TRUE, reassign_taxa = TRUE,
  invert = FALSE)

Arguments

.data
...

One or more filtering conditions. This can be one of three things:

character

One or more taxon_ids

integer

One or more indexes of taxon_data

logical

A TRUE/FALSE vector of length equal to the number of rows in taxon_data

Any column name that appears in taxon_data(.data) can be used as if it was a vector on its own.

subtaxa

(logical of length 1) If TRUE, include subtaxa of taxa passing the filter.

supertaxa

(logical of length 1) If TRUE, include supertaxa of taxa passing the filter.

taxonless

(logical of length 1) If TRUE, include observations even if the taxon they are assigned to is filtered out. observation assigned to removed taxa will be assigned to NA. See the reassign option below for further complications.

reassign_obs

(logical of length 1) If TRUE, observations assigned to removed taxa will be reassigned to the closest supertaxon that passed the filter. If there are no supertaxa of such an observation that passed the filter, they will be filtered out if taxonless is TRUE.

reassign_taxa

(logical of length 1) If TRUE, subtaxa of removed taxa will be reassigned to the closest supertaxon that passed the filter.

invert

(logical of length 1) If TRUE, do NOT include the selection. This is different than just replacing a == with a != because this option negates the selection after taking into account the subtaxa and supertaxa options. This is useful for removing a taxon and all its subtaxa for example.

Value

An object of type taxmap

See Also

Other dplyr-like functions: arrange_obs, arrange_taxa, filter_obs, mutate_obs, mutate_taxa, sample_frac_obs, sample_frac_taxa, sample_n_obs, sample_n_taxa, select_obs, select_taxa, transmute_obs, transmute_taxa

Examples

Run this code
# NOT RUN {
# Remove singleton taxa, but reassign singletons to supertaxa that pass filter
filter_taxa(unite_ex_data_3, n_obs > 1)
# Remove singleton taxa and associated seqeuence data
filter_taxa(unite_ex_data_3, n_obs > 1, taxonless = FALSE, reassign_obs = FALSE)
# Subset to a single taxon and its subtaxa
filter_taxa(unite_ex_data_3, name == "Basidiomycota", subtaxa = TRUE)
# Remove a taxon and its subtaxa
filter_taxa(unite_ex_data_3, name == "Basidiomycota", subtaxa = TRUE, invert = TRUE)
# Remove taxa, reassigning supertaxa and subtaxa 
filter_taxa(unite_ex_data_3, unite_rank != "p")

# }

Run the code above in your browser using DataCamp Workspace