read_strat_file: Read PICRUSt2 stratified abundance file

View source: R/taxa_contribution.R

read_strat_fileR Documentation

Read PICRUSt2 stratified abundance file

Description

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, or .csv).

data

A data.frame already loaded from the stratified file. If both file and data are provided, data is used.

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.

Value

A tidy data.frame with columns: function_id, taxon, sample, abundance.

Examples


# 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)



ggpicrust2 documentation built on April 10, 2026, 5:06 p.m.