Skip to contents

Extracts the n most abundant Amplicon Sequence Variants (ASVs) from a sample or group of samples, optionally including their taxonomic classification.

Usage

prof.fn(id, S, bm.tx = NULL, n.prof = 5, k.neighbors = 1, verbose = FALSE)

Arguments

id

Character string or numeric index identifying the sample in the abundance matrix S. If character, must match a row name in S.

S

Numeric matrix of ASV abundances with samples in rows and ASVs in columns. Row names should contain sample identifiers and column names should contain ASV identifiers.

bm.tx

Optional named vector containing taxonomic classifications for ASVs. Names must match column names in S. If NULL, only abundances are returned.

n.prof

Integer specifying the number of most abundant ASVs to report. Default is 5.

k.neighbors

Integer specifying the number of nearest neighbors to include in abundance calculations. Default is 1 (only target sample). If greater than 1, returns mean abundances across the k nearest neighbors of the target sample (including the target itself).

verbose

Logical indicating whether to print the resulting profile matrix. Default is FALSE.

Value

A matrix with one column containing abundance values (rounded to 2 significant figures). If bm.tx is provided, additional columns contain taxonomic information. Row names are ASV identifiers.

Details

When k.neighbors > 1, the function uses k-nearest neighbors based on Euclidean distance in the abundance space to compute mean abundances. This can help smooth profiles in sparse data.

Examples

# Create example data
S <- matrix(runif(100), nrow = 10, ncol = 10)
rownames(S) <- paste0("Sample", 1:10)
colnames(S) <- paste0("ASV", 1:10)

# Extract profile for first sample
prof <- prof.fn("Sample1", S, n.prof = 3)

# With taxonomy
taxonomy <- paste0("Taxon", 1:10)
names(taxonomy) <- colnames(S)
prof_with_tax <- prof.fn(1, S, bm.tx = taxonomy, n.prof = 3, verbose = TRUE)