data: a data.frame in "wide" format, with samples in either columns or rows. This data.frame should not include any data besides abundance values per sample, per taxonomic unit. Additional data (e.g. taxonomy details) should be added afterwards.
sample_names: a vector with the name of all samples.
samples_in: a vector specifying the location of the samples. It can either be "cols" (default) if samples are in columns, or "rows" if samples are in rows.
...: additional arguments
Returns
An abundance table in long format, compatible with dplyr pipes and ulrb package functions.
Details
This function guarantees that the abundance table includes one column with sample ID's and one column with abundance.
Common species table formats
There are two common formats for abundance tables:
samples as rows and taxa as columns;
taxa as rows and samples as columns.
However, both formats are not tidy/long, because they include several columns with the same variable. They are in a "wide format" instead of a "long format".
This function re-organizes samples and taxa so that there is a single column with the samples ID's and another with the abundance scores. Extra columns are allowed.
Examples
library(dplyr)#sample_names <- c("ERR2044662","ERR2044663","ERR2044664","ERR2044665","ERR2044666","ERR2044667","ERR2044668","ERR2044669","ERR2044670")# Example for samples in cols and with additional data availableprepare_tidy_data(nice, sample_names = sample_names, samples_in ="cols")# Example for samples in rows# Select columns with samples from nicenice_rows <- nice %>% select(all_of(sample_names))# Change columns to rowsnice_rows <- nice_rows %>% t()%>% as.data.frame()# Turn colnames into phylogenetic units IDcolnames(nice_rows)<- paste0("OTU_", seq_along(colnames(nice_rows)))prepare_tidy_data(nice_rows, sample_names = sample_names, samples_in ="rows")