Sums up all OTU read counts at the chosen taxonomic level. Used internally in many ampvis2 functions, but can also be used separately for custom purposes.
aggregate_abund(
abund,
tax,
tax_aggregate = "OTU",
tax_add = NULL,
calcSums = TRUE,
format = "long"
)
The OTU abundance table from an ampvis2 object (ampvis2obj$abund
)
The OTU abundance table from an ampvis2 object (ampvis2obj$tax
)
Aggregate (sum) OTU's to a specific taxonomic level. (default: "OTU"
)
Add additional (higher) taxonomic levels to the taxonomy string. The OTU's will be aggregated to whichever level of the tax_aggregate
and tax_add
vectors is the lowest. (default: NULL
)
Whether to include the sums of read counts for each sample and taxonomic group. (default: TRUE
)
Output format, "long"
or "abund"
. "abund"
corresponds to that of a read counts table with samples as columns and the aggregated taxa as rows.
A data.table.
data("AalborgWWTPs")
aggregated <- aggregate_abund(
AalborgWWTPs$abund,
AalborgWWTPs$tax,
tax_aggregate = "Genus",
tax_add = "Phylum",
format = "long",
calcSums = TRUE
)
#> 4202 OTUs (out of 9430) with no assigned taxonomy at Genus level were removed before aggregating OTUs
aggregated
#> Key: <Display, Sample>
#> Display Sample Abundance Sum
#> <char> <char> <num> <num>
#> 1: p__Acidobacteria; g__Acidobacterium 16S-AMP-1098 0 0
#> 2: p__Acidobacteria; g__Acidobacterium 16S-AMP-1099 0 0
#> 3: p__Acidobacteria; g__Acidobacterium 16S-AMP-1100 0 0
#> 4: p__Acidobacteria; g__Acidobacterium 16S-AMP-1101 0 0
#> 5: p__Acidobacteria; g__Acidobacterium 16S-AMP-1107 0 0
#> ---
#> 350272: p__Verrucomicrobia; g__uncultured 16SAMP-748 0 29
#> 350273: p__Verrucomicrobia; g__uncultured 16SAMP-748 0 29
#> 350274: p__Verrucomicrobia; g__uncultured 16SAMP-748 1 29
#> 350275: p__Verrucomicrobia; g__uncultured 16SAMP-748 0 29
#> 350276: p__Verrucomicrobia; g__uncultured 16SAMP-748 4 29