Aggregates read counts in replicate samples by calculating the mean abundances of OTU's.
amp_merge_replicates(data, merge_var, round = NULL)
amp_mergereplicates(data, merge_var, round = NULL)(required) Data list as loaded with amp_load().
Variable in the sample metadata that defines the sample groups, see examples.
If the read counts in data$abund are integers, any decimals present after merging will be rounded either "up" or "down". Make sure this makes sense if the read counts have been normalised, as it may result in 0's, 1's, and 2's everywhere. (default: NULL)
An object of class ampvis2
# load data
d <- amp_load(ampvis2::example_otutable, ampvis2::example_metadata)
d
#> ampvis2 object with 3 elements.
#> Summary of OTU table:
#> Samples OTUs Total#Reads Min#Reads Max#Reads Median#Reads
#> 8 10 32246 2522 5451 3839
#> Avg#Reads
#> 4030.75
#>
#> Assigned taxonomy:
#> Kingdom Phylum Class Order Family Genus Species
#> 10(100%) 10(100%) 10(100%) 10(100%) 10(100%) 10(100%) 1(10%)
#>
#> Metadata variables: 4
#> SampleID, Plant, Date, Year
# add a grouping variable to the sample metadata defining the groups of sample replicates
d$metadata$group <- c("group1", "group1", "group2", "group2", "group3", "group4", NA, NA)
d$metadata
#> SampleID Plant Date Year group
#> 16SAMP_3893 16SAMP_3893 Aalborg E 2014-02-06 2014 group1
#> 16SAMP_3913 16SAMP_3913 Aalborg E 2014-07-03 2014 group1
#> 16SAMP_3941 16SAMP_3941 Aalborg E 2014-08-19 2014 group2
#> 16SAMP_3946 16SAMP_3946 Aalborg E 2014-11-13 2014 group2
#> 16SAMP_3953 16SAMP_3953 Aalborg W 2014-02-04 2014 group3
#> 16SAMP_4591 16SAMP_4591 Aalborg W 2014-05-05 2014 group4
#> 16SAMP_4597 16SAMP_4597 Aalborg W 2014-08-18 2014 <NA>
#> 16SAMP_4603 16SAMP_4603 Aalborg W 2014-11-12 2014 <NA>
# merge by "group" rounding up the resulting values
dmerged <- amp_mergereplicates(d,
merge_var = "group",
round = "up"
)
dmerged$metadata
#> group Plant Date Year
#> group1 group1 Aalborg E 2014-02-06 2014
#> group2 group2 Aalborg E 2014-08-19 2014
#> group3 group3 Aalborg W 2014-02-04 2014
#> group4 group4 Aalborg W 2014-05-05 2014
#> 16SAMP_4597 16SAMP_4597 Aalborg W 2014-08-18 2014
#> 16SAMP_4603 16SAMP_4603 Aalborg W 2014-11-12 2014
dmerged
#> ampvis2 object with 3 elements.
#> Summary of OTU table:
#> Samples OTUs Total#Reads Min#Reads Max#Reads Median#Reads
#> 6 10 25623 3106 5451 4215
#> Avg#Reads
#> 4270.5
#>
#> Assigned taxonomy:
#> Kingdom Phylum Class Order Family Genus Species
#> 10(100%) 10(100%) 10(100%) 10(100%) 10(100%) 10(100%) 1(10%)
#>
#> Metadata variables: 4
#> group, Plant, Date, Year