Learn R Programming

RAM (version 1.2.1.3)

tax.abund: Aggregate OTU Data Based on Taxonomy

Description

This function consumes OTU table(s) and (optionally) a taxonomic rank, then extracts the classification of each OTU at the given taxonomic rank, groups by classification at the given rank, removes all groups with only 0 counts, optionally removes all unclassified groups, sorts groups based on abundance, and then returns the transpose.

Usage

tax.abund(otu1, otu2=NULL, rank=NULL, drop.unclassified=FALSE, top=NULL, count=TRUE, mode="number")

Arguments

otu1
the first OTU table to be used.
otu2
the second OTU table to be used.
rank
a character vector representing a rank. Must be in one of three specific formats (see ?RAM.rank.formatting for help). If omitted, the function will repeat for all seven major taxonomic ranks.
drop.unclassified
logical. Determine whether or not the OTUs labelled "unclassified" or missing classification at the given taxonomic rank should be excluded.
top
the number of groups to select, starting with the most abundant. If NULL, all are selected.
count
logical. Should the actual count of each OTU be shown, or should the relative abundances be shown?
mode
a character vector, one of "percent" or "number". If number, then top many groups will be selected. If percent, then all groups with relative abundance in at least one sample above top will be selected.

Value

The value returned by this function may become nested lists, so for convenience, any nested lists have been given descriptive items names to make accessing its elements simple (see Examples).
  • If otu2 is given:
    • If rank is given: a list containing two data frames (otu1 and otu2 aggregated at the given rank).
    • If rank is not given: a list containing two lists. The first sublist represents otu1, the second otu2. The sublists contain seven data frames, the aggregation of the data at each taxonomic rank (see Examples).
  • If otu2 is not given:
    • If rank is given: a single data frame (otu1 aggregated at the given rank).
    • If rank is not given: a list containing seven data frames (otu1 aggregated at each taxonomic rank).

See Also

RAM.rank.formatting

Examples

Run this code
data(ITS1, ITS2)
# aggregate based on phylum
ITS1.p <- tax.abund(ITS1, rank="p")
# aggregate based on all ranks; ignoring all unclassified OTUs
ITS1.taxa <- tax.abund(ITS1, drop.unclassified=FALSE)
# aggregate for one rank for both ITS1 and ITS2
lst <- tax.abund(ITS1, ITS2, rank="class")
# aggregate for all ranks for both ITS1 and ITS2
lst.all <- tax.abund(ITS1, ITS2)
stopifnot(identical(lst.all$otu1$phylum, ITS1.p))
# get the counts for all genera with relative abundance > 25%
tax.abund(ITS1, rank="g", top=25, mode="percent", count=TRUE)

Run the code above in your browser using DataLab