% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/filter_asv.R
\name{filter.asv}
\alias{filter.asv}
\title{Filter ASV count matrix by library size (samples) and prevalence (features)}
\usage{
filter.asv(
  S.counts,
  min.lib = 1000,
  prev.prop = 0.05,
  min.count = 2,
  min.rel = NULL,
  min.feat.total = NULL,
  verbose = TRUE
)
}
\arguments{
\item{S.counts}{Numeric matrix (samples x features) of nonnegative counts.}

\item{min.lib}{Integer. Minimum library size (row sum of counts) to keep a sample. Default: 1000.}

\item{prev.prop}{Numeric in (0,1]. Minimum fraction of samples where a feature must be present.
Default: 0.05.}

\item{min.count}{Integer (>=1) or NULL. Reads to call "present" (ignored if \code{min.rel} set). Default: 2.}

\item{min.rel}{Numeric in (0,1) or NULL. Relative abundance to call "present" (overrides \code{min.count}). Default: NULL.}

\item{min.feat.total}{Integer (>=0) or NULL. Optional minimum total reads across all samples per feature. Default: NULL.}

\item{verbose}{Logical. Print keep/drop summaries. Default: TRUE.}
}
\value{
A list with elements:
\describe{
\item{counts}{Filtered count matrix (samples x features).}
\item{rel}{Row-normalized relative-abundance matrix.}
\item{kept.sample.idx}{Kept sample indices (original order).}
\item{kept.feature.idx}{Kept feature indices (original order).}
\item{prevalence}{Per-feature prevalence counts for kept features.}
\item{thresholds}{List of thresholds actually used.}
}
}
\description{
Filters an ASV \strong{count} matrix by:
(1) removing samples with library size below \code{min.lib};
(2) keeping features (taxa) that are "present" in at least
\code{ceiling(prev.prop * nrow(S.counts))} samples, where presence is
defined by either \code{min.count} (counts) or \code{min.rel} (relative).
After feature filtering, zero-total samples are dropped and a row-normalized
relative-abundance matrix is returned alongside the filtered counts.
}
\details{
Sample filtering is applied on raw counts first. Prevalence is computed on the
post-sample-filter matrix using either a count or relative rule. A feature is
retained if prevalence \eqn{\ge \lceil \text{prev.prop} \times n_{\text{samples}} \rceil}.
After feature filtering, samples with zero remaining counts are dropped and
the relative matrix \code{rel} is row-normalized.
}
\section{Conventions}{

Dot-delimited names; rows are samples, columns are features. Supply raw counts.
}

\examples{
set.seed(1)
S <- matrix(rpois(100 * 20, lambda = 5), nrow = 100, ncol = 20)
res <- filter.asv(S, min.lib = 50, prev.prop = 0.1, min.count = 2)
dim(res$counts); dim(res$rel)
range(rowSums(res$rel))

}
