amp_filter_samples: Subset ampvis2 objects based on sample metadata

View source: R/amp_filter_samples.R

amp_filter_samplesR Documentation

Subset ampvis2 objects based on sample metadata

Description

Subsets the data in ampvis2 objects based on metadata and returns the subsetted object.

Usage

amp_filter_samples(
  data,
  ...,
  minreads = 0,
  rarefy = NULL,
  normalise = FALSE,
  removeAbsentOTUs = TRUE
)

amp_subset_samples(
  data,
  ...,
  minreads = 0,
  rarefy = NULL,
  normalise = FALSE,
  removeAbsentOTUs = TRUE
)

Arguments

data

(required) Data list as loaded with amp_load.

...

Logical expression indicating elements or rows to keep in the metadata. Missing values are treated as FALSE. Passed directly to filter.

minreads

Minimum number of reads pr. sample. Samples below this value will be removed initially. (default: 0)

rarefy

Rarefy species richness to this value by using rrarefy. This is done initially, but after filtering based on the minreads value, if set. (default: NULL)

normalise

(logical) Normalise the OTU read counts to 100 (ie percent) per sample BEFORE the subset. (default: FALSE)

removeAbsentOTUs

(logical) Whether to remove OTU's that may have 0 read abundance in all samples after the subset. (default: TRUE)

Details

The subset is performed on the metadata by subset() and the abundance- and taxonomy tables are then adjusted accordingly.

Value

A modifed ampvis2 object

Preserving relative abundances in a subset of larger data

By default the raw read counts in the abundance matrix are normalised (transformed to percentages) by some plotting functions automatically (for example amp_heatmap, amp_timeseries, and more). This means that the relative abundances shown will be calculated based on the remaining taxa after the subset, not including the removed taxa, if any. To circumvent this, set normalise = TRUE when subsetting with the amp_filter_taxa and amp_filter_samples functions, and then set normalise = FALSE in the plotting function. This will transform the OTU counts to relative abundances BEFORE the subset, and setting normalise = FALSE will skip the transformation in the plotting function, see the example below.

data("MiDAS")
subsettedData <- amp_filter_samples(MiDAS,
                                    Plant %in% c("Aalborg West", "Aalborg East"),
                                    normalise = TRUE
                                    )
amp_heatmap(subsettedData,
            group_by = "Plant",
            tax_aggregate = "Phylum",
            tax_add = "Genus",
            normalise = FALSE
            )

Author(s)

Kasper Skytte Andersen ksa@bio.aau.dk

Mads Albertsen MadsAlbertsen85@gmail.com

References

McMurdie, P.J. & Holmes, S. (2014). Waste not, want not: Why rarefying microbiome data is inadmissible. PLoS Comput Biol 10(4): e1003531. DOI:10.1371/journal.pcbi.1003531

See Also

amp_load, amp_filter_taxa

Examples

# Load example data
data("MiDAS")

# Show a short summary about the data by simply typing the name of the object in the console
MiDAS

# Keep only samples containing Aalborg West or East in the Plant column
MiDASsubset <- amp_filter_samples(MiDAS, Plant %in% c("Aalborg West", "Aalborg East"))

# Summary
MiDASsubset

# Keep only samples containing Aalborg West or East in the Plant column
# and remove the sample "16SAMP-749". Remove any sample(s) with less than 20000 total reads
MiDASsubset2 <- amp_filter_samples(MiDAS,
  Plant %in% c("Aalborg West", "Aalborg East") & !SampleID %in% c("16SAMP-749"),
  minreads = 20000
)

# Summary
MiDASsubset2

MadsAlbertsen/ampvis2 documentation built on Jan. 28, 2024, 7:12 a.m.