Transforms any ampvis2 object into a long data frame (data.table) to facilitate custom data analysis. Only the elements OTU counts (data$abund), taxonomy (data$tax), and metadata (data$metadata) are used, not phylogenetic tree or DNA sequences.

amp_export_long(
  data,
  metadata_vars = colnames(data$metadata),
  tax_levels = colnames(data$tax)
)

Arguments

data

(required) Data list as loaded with amp_load.

metadata_vars

A character vector of sample metadata variables to include from data$metadata, or NULL. The first column (sample IDs) will always be included. Default includes all.

tax_levels

A character vector of taxonomic levels to include from data$tax, or NULL. The OTU column will always be included. Default includes all.

Value

A data.table in long format.

Author

Kasper Skytte Andersen ksa@bio.aau.dk

Thomas Yssing Michaelsen tym@bio.aau.dk

Examples

# load minimal example data
d <- amp_load(example_otutable, example_metadata)

# transform d into a long-format data frame
d_long <- amp_export_long(d, metadata_vars = "Date", tax_levels = c("OTU", "Genus"))

# print the data frame (data.table)
d_long
#>        SampleID    OTU count       Date                       Genus
#>          <char> <char> <int>     <POSc>                      <char>
#>  1: 16SAMP_3893  OTU_1    23 2014-02-06    g__Candidatus Amarilinum
#>  2: 16SAMP_3893  OTU_2   675 2014-02-06             g__Tetrasphaera
#>  3: 16SAMP_3893  OTU_3   780 2014-02-06    g__Candidatus Microthrix
#>  4: 16SAMP_3893  OTU_4   272 2014-02-06            g__Dechloromonas
#>  5: 16SAMP_3893  OTU_5   560 2014-02-06 g__Candidatus Villogracilis
#>  6: 16SAMP_3893  OTU_6   906 2014-02-06             g__Trichococcus
#>  7: 16SAMP_3893  OTU_7   297 2014-02-06    g__Candidatus Microthrix
#>  8: 16SAMP_3893  OTU_8    28 2014-02-06               g__Nitrospira
#>  9: 16SAMP_3893  OTU_9     0 2014-02-06                g__QEDR3BF09
#> 10: 16SAMP_3893 OTU_10   373 2014-02-06                     g__MK04
#> 11: 16SAMP_3913  OTU_1    15 2014-07-03    g__Candidatus Amarilinum
#> 12: 16SAMP_3913  OTU_2   565 2014-07-03             g__Tetrasphaera
#> 13: 16SAMP_3913  OTU_3   733 2014-07-03    g__Candidatus Microthrix
#> 14: 16SAMP_3913  OTU_4   233 2014-07-03            g__Dechloromonas
#> 15: 16SAMP_3913  OTU_5   339 2014-07-03 g__Candidatus Villogracilis
#> 16: 16SAMP_3913  OTU_6   766 2014-07-03             g__Trichococcus
#> 17: 16SAMP_3913  OTU_7   218 2014-07-03    g__Candidatus Microthrix
#> 18: 16SAMP_3913  OTU_8     8 2014-07-03               g__Nitrospira
#> 19: 16SAMP_3913  OTU_9     0 2014-07-03                g__QEDR3BF09
#> 20: 16SAMP_3913 OTU_10   256 2014-07-03                     g__MK04
#> 21: 16SAMP_3941  OTU_1   273 2014-08-19    g__Candidatus Amarilinum
#> 22: 16SAMP_3941  OTU_2   331 2014-08-19             g__Tetrasphaera
#> 23: 16SAMP_3941  OTU_3   405 2014-08-19    g__Candidatus Microthrix
#> 24: 16SAMP_3941  OTU_4  1434 2014-08-19            g__Dechloromonas
#> 25: 16SAMP_3941  OTU_5   509 2014-08-19 g__Candidatus Villogracilis
#> 26: 16SAMP_3941  OTU_6   133 2014-08-19             g__Trichococcus
#> 27: 16SAMP_3941  OTU_7   418 2014-08-19    g__Candidatus Microthrix
#> 28: 16SAMP_3941  OTU_8   155 2014-08-19               g__Nitrospira
#> 29: 16SAMP_3941  OTU_9     9 2014-08-19                g__QEDR3BF09
#> 30: 16SAMP_3941 OTU_10    19 2014-08-19                     g__MK04
#> 31: 16SAMP_3946  OTU_1    51 2014-11-13    g__Candidatus Amarilinum
#> 32: 16SAMP_3946  OTU_2   411 2014-11-13             g__Tetrasphaera
#> 33: 16SAMP_3946  OTU_3   199 2014-11-13    g__Candidatus Microthrix
#> 34: 16SAMP_3946  OTU_4   256 2014-11-13            g__Dechloromonas
#> 35: 16SAMP_3946  OTU_5   598 2014-11-13 g__Candidatus Villogracilis
#> 36: 16SAMP_3946  OTU_6   390 2014-11-13             g__Trichococcus
#> 37: 16SAMP_3946  OTU_7   130 2014-11-13    g__Candidatus Microthrix
#> 38: 16SAMP_3946  OTU_8    72 2014-11-13               g__Nitrospira
#> 39: 16SAMP_3946  OTU_9     0 2014-11-13                g__QEDR3BF09
#> 40: 16SAMP_3946 OTU_10   415 2014-11-13                     g__MK04
#> 41: 16SAMP_3953  OTU_1   127 2014-02-04    g__Candidatus Amarilinum
#> 42: 16SAMP_3953  OTU_2   430 2014-02-04             g__Tetrasphaera
#> 43: 16SAMP_3953  OTU_3  1346 2014-02-04    g__Candidatus Microthrix
#> 44: 16SAMP_3953  OTU_4   736 2014-02-04            g__Dechloromonas
#> 45: 16SAMP_3953  OTU_5   223 2014-02-04 g__Candidatus Villogracilis
#> 46: 16SAMP_3953  OTU_6   232 2014-02-04             g__Trichococcus
#> 47: 16SAMP_3953  OTU_7  1354 2014-02-04    g__Candidatus Microthrix
#> 48: 16SAMP_3953  OTU_8   156 2014-02-04               g__Nitrospira
#> 49: 16SAMP_3953  OTU_9    19 2014-02-04                g__QEDR3BF09
#> 50: 16SAMP_3953 OTU_10    43 2014-02-04                     g__MK04
#> 51: 16SAMP_4591  OTU_1   190 2014-05-05    g__Candidatus Amarilinum
#> 52: 16SAMP_4591  OTU_2   780 2014-05-05             g__Tetrasphaera
#> 53: 16SAMP_4591  OTU_3  1114 2014-05-05    g__Candidatus Microthrix
#> 54: 16SAMP_4591  OTU_4  1338 2014-05-05            g__Dechloromonas
#> 55: 16SAMP_4591  OTU_5   145 2014-05-05 g__Candidatus Villogracilis
#> 56: 16SAMP_4591  OTU_6  1458 2014-05-05             g__Trichococcus
#> 57: 16SAMP_4591  OTU_7   198 2014-05-05    g__Candidatus Microthrix
#> 58: 16SAMP_4591  OTU_8   101 2014-05-05               g__Nitrospira
#> 59: 16SAMP_4591  OTU_9    25 2014-05-05                g__QEDR3BF09
#> 60: 16SAMP_4591 OTU_10   102 2014-05-05                     g__MK04
#> 61: 16SAMP_4597  OTU_1   220 2014-08-18    g__Candidatus Amarilinum
#> 62: 16SAMP_4597  OTU_2   699 2014-08-18             g__Tetrasphaera
#> 63: 16SAMP_4597  OTU_3  1630 2014-08-18    g__Candidatus Microthrix
#> 64: 16SAMP_4597  OTU_4  1224 2014-08-18            g__Dechloromonas
#> 65: 16SAMP_4597  OTU_5   212 2014-08-18 g__Candidatus Villogracilis
#> 66: 16SAMP_4597  OTU_6   560 2014-08-18             g__Trichococcus
#> 67: 16SAMP_4597  OTU_7   283 2014-08-18    g__Candidatus Microthrix
#> 68: 16SAMP_4597  OTU_8   151 2014-08-18               g__Nitrospira
#> 69: 16SAMP_4597  OTU_9    58 2014-08-18                g__QEDR3BF09
#> 70: 16SAMP_4597 OTU_10    73 2014-08-18                     g__MK04
#> 71: 16SAMP_4603  OTU_1    83 2014-11-12    g__Candidatus Amarilinum
#> 72: 16SAMP_4603  OTU_2   820 2014-11-12             g__Tetrasphaera
#> 73: 16SAMP_4603  OTU_3   112 2014-11-12    g__Candidatus Microthrix
#> 74: 16SAMP_4603  OTU_4   564 2014-11-12            g__Dechloromonas
#> 75: 16SAMP_4603  OTU_5  1619 2014-11-12 g__Candidatus Villogracilis
#> 76: 16SAMP_4603  OTU_6   287 2014-11-12             g__Trichococcus
#> 77: 16SAMP_4603  OTU_7   116 2014-11-12    g__Candidatus Microthrix
#> 78: 16SAMP_4603  OTU_8    25 2014-11-12               g__Nitrospira
#> 79: 16SAMP_4603  OTU_9     0 2014-11-12                g__QEDR3BF09
#> 80: 16SAMP_4603 OTU_10   138 2014-11-12                     g__MK04
#>        SampleID    OTU count       Date                       Genus