Merge any number of ampvis2 objects into a single object.

amp_merge_ampvis2(
  ...,
  by_refseq = TRUE,
  refseq_names = NULL,
  rename_unmatched = TRUE,
  unmatched_prefix = "unmatched"
)

Arguments

...

(required) Any number of ampvis2-class objects to merge

by_refseq

(recommended) Merge by exact matches between DNA reference sequences. The full DNA sequences will then be used as the new names in the output. (default: TRUE)

refseq_names

Path to a FASTA file or a DNAbin class object with sequences whose names will be used as OTU names by exact matches (i.e. same length, 100% sequence identity). (default: NULL)

rename_unmatched

Whether to rename any unmatched sequences or not when refseq_names is provided. (default: TRUE)

unmatched_prefix

Prefix used to name any unmatched sequences when refseq_names is provided. An integer counting from 1 will be appended to this prefix, so for example the 123th unmatched sequence will be named unmatched123, and so on. (default: "unmatched")

Value

An ampvis2-class object

Details

It's important to ensure that the taxonomy for all OTU's across data sets is generated in the exact same way with the same database. When by_refseq = FALSE it's likewise important to ensure that OTU ID's are not arbitrary between data sets and that they are corresponding to the same sequences across data sets (objects). When by_refseq = TRUE the full DNA sequences will be used as the new OTU ID's unless refseq_names is provided.

Currently, phylogenetic trees are not merged. Feel free to contribute.

Examples

data("MiDAS")

# summary of samples from 2010-2012
amp_filter_samples(
  MiDAS,
  Year %in% c("2010", "2011", "2012")
)
#> 488 samples and 2220 OTUs have been filtered 
#> Before: 658 samples and 14969 OTUs
#> After: 170 samples and 12749 OTUs
#> ampvis2 object with 5 elements. 
#> Summary of OTU table:
#>      Samples         OTUs  Total#Reads    Min#Reads    Max#Reads Median#Reads 
#>          170        12749      5308714        18373        42811        31385 
#>    Avg#Reads 
#>     31227.73 
#> 
#> Assigned taxonomy:
#>       Kingdom        Phylum         Class         Order        Family 
#>   12749(100%) 12396(97.23%) 10987(86.18%)  9966(78.17%)   8631(67.7%) 
#>         Genus       Species 
#>   6566(51.5%)      26(0.2%) 
#> 
#> Metadata variables: 5 
#>  SampleID, Plant, Date, Year, Period

# now merge individual objects and verify summary is the same
d_2010 <- amp_filter_samples(
  MiDAS,
  Year %in% "2010"
)
#> 594 samples and 5022 OTUs have been filtered 
#> Before: 658 samples and 14969 OTUs
#> After: 64 samples and 9947 OTUs
d_2011 <- amp_filter_samples(
  MiDAS,
  Year %in% "2011"
)
#> 610 samples and 4989 OTUs have been filtered 
#> Before: 658 samples and 14969 OTUs
#> After: 48 samples and 9980 OTUs
d_2012 <- amp_filter_samples(
  MiDAS,
  Year %in% "2012"
)
#> 600 samples and 4127 OTUs have been filtered 
#> Before: 658 samples and 14969 OTUs
#> After: 58 samples and 10842 OTUs

amp_merge_ampvis2(
  d_2010,
  d_2011,
  d_2012
)
#> ampvis2 object with 5 elements. 
#> Summary of OTU table:
#>      Samples         OTUs  Total#Reads    Min#Reads    Max#Reads Median#Reads 
#>          170        12749      5308714        18373        42811        31385 
#>    Avg#Reads 
#>     31227.73 
#> 
#> Assigned taxonomy:
#>       Kingdom        Phylum         Class         Order        Family 
#>   12749(100%) 12396(97.23%) 10987(86.18%)  9966(78.17%)   8631(67.7%) 
#>         Genus       Species 
#>   6566(51.5%)      26(0.2%) 
#> 
#> Metadata variables: 5 
#>  SampleID, Plant, Date, Year, Period