Parses the pred_metagenome_strat.tsv file produced by PICRUSt2's
--strat_out flag and converts the wide format to tidy long format.
Usage
read_strat_file(file = NULL, data = NULL)
Arguments
- file
Path to the stratified file (.tsv, .txt, .csv, or gzipped variants).
- data
A data.frame already loaded from the stratified file.
If both file and data are provided, data is used.
Value
A tidy data.frame with columns: function_id, taxon,
sample, abundance.
Details
The stratified file has function IDs in the first column, sequence/taxon
IDs in the second column, and sample abundances in the remaining columns
(wide format). This function pivots to long format for downstream analysis.
Function IDs, taxon IDs, and sample column names must be non-empty; sample
column names must also be unique.
Examples
# \donttest{
# From a data.frame
strat_df <- data.frame(
`function` = c("K00001", "K00001", "K00002"),
sequence = c("ASV1", "ASV2", "ASV1"),
S1 = c(10, 5, 8),
S2 = c(12, 3, 7),
check.names = FALSE
)
result <- read_strat_file(data = strat_df)
head(result)
# }