Skip to contents

Given a samples-by-features matrix X and a subset vertex.ids (either row names or integer row indices), compute for each feature (column) the number k and proportion p of subset rows for which X[row, feature] > eps.

This is useful as a lightweight prevalence/coverage summary within a basin (or any vertex subset) when X contains relative abundances or counts.

Usage

count.feature.carriers(X, vertex.ids, eps = 0, drop.missing = TRUE)

Arguments

X

A numeric matrix (or data.frame coercible to a numeric matrix) with samples/vertices in rows and features (e.g., phylotypes) in columns. Row names are required if vertex.ids is character.

vertex.ids

A vector of row identifiers. May be character (matched to rownames(X)) or numeric/integer (treated as 1-based row indices).

eps

A non-negative numeric threshold. A feature is considered present in a vertex if X > eps. Default is 0.

drop.missing

Logical; if TRUE (default), when vertex.ids is character, silently drop IDs not found in rownames(X). If FALSE, error on any missing IDs.

Value

A data.frame with two columns:

  • k: integer counts of vertices with X > eps

  • p: numeric proportions k / length(vertex.ids.resolved)

Row names correspond to colnames(X).

Examples

if (FALSE) { # \dontrun{
## X: samples x phylotypes matrix
## ids: subset of rownames(X) for a basin/region
prev.df <- count.feature.carriers(X, vertex.ids = ids, eps = 0)
head(prev.df)

## using integer indices
prev.df2 <- count.feature.carriers(X, vertex.ids = c(1L, 5L, 10L), eps = 1e-6)
} # }