metacoder (version 0.1.3)

taxonomic_sample: Recursivly sample a set of taxonomic assignments

Description

Recursivly sample a set of observations with taxonomic assignments and an associated taxonomy.

Usage

taxonomic_sample(taxmap_data, max_counts = c(), min_counts = c(),
  max_children = c(), min_children = c(), obs_filters = list(),
  subtaxa_filters = list(), stop_conditions = list(), ...)

Arguments

taxmap_data

(An object of type taxmap)

max_counts

(numeric) A named vector that defines that maximum number of observations in for each level specified. The names of the vector specifies that level each number applies to. If more than the maximum number of observations exist for a given taxon, it is randomly subsampled to this number.

min_counts

(numeric) A named vector that defines that minimum number of observations in for each level specified. The names of the vector specifies that level each number applies to.

max_children

(numeric) A named vector that defines that maximum number of subtaxa per taxon for each level specified. The names of the vector specifies that level each number applies to. If more than the maximum number of subtaxa exist for a given taxon, they are randomly subsampled to this number of subtaxa.

min_children

(numeric) A named vector that defines that minimum number of subtaxa in for each level specified. The names of the vector specifies that level each number applies to.

obs_filters

(list of function(observations, id)) A list of functions that take a data structure containing the information of multiple observations and a taxon id. Returns a object of the same type with some of the observations potentially removed.

subtaxa_filters

(list of function(observations, id)) A list of functions that take a data structure containing the information of multiple subtaxa IDs and the current taxon id. Returns a object of the same type with some of the subtaxa potentially removed. If a function returns NULL, then no observations for the current taxon are returned.

stop_conditions

(list of function(id)) A list of functions that take the current taxon id. If any of the functions return TRUE, the observations for the current taxon are returned rather than looking for observations of subtaxa, stopping the recursion.

...

Additional parameters are passed to all of the function options.

Value

Returns an object of type taxmap

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
#Plot data before subsampling
heat_tree(unite_ex_data_3,
          node_size = n_obs,
          node_color = n_obs,
          node_label = n_obs)
     
# Subsampling
subsampled <- taxonomic_sample(unite_ex_data_3,
                               max_counts = c("4" = 20, "7" = 5),
                               min_counts = c("7" = 3))
     
# Remove unobserved taxa and plot
heat_tree(subset(subsampled, n_obs > 0, unobserved = FALSE),
          node_size = n_obs,
          node_color = n_obs,
          node_label = n_obs)
# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace