% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/preprocess.R
\name{filter_mags}
\alias{filter_mags}
\title{Filter MAGs by coverage and prevalence}
\usage{
filter_mags(count_table, coverage_table, min_coverage = 0.3, min_samples = 50L)
}
\arguments{
\item{count_table}{A data.frame of read counts with MAGs as rows and
samples as columns.}

\item{coverage_table}{A data.frame of covered-fraction values with the
same dimensions and names as \code{count_table}.}

\item{min_coverage}{Numeric; minimum covered fraction to retain a
count.}

\item{min_samples}{Integer; minimum number of samples in which a MAG
must be present after coverage masking.}
}
\value{
A data.frame of filtered counts (MAGs as rows, samples as
columns).
}
\description{
Applies two filtering steps from the preprocessing pipeline:
\enumerate{
\item \strong{Coverage masking:} Binarises the coverage table at \code{min_coverage}
and multiplies element-wise with the count table, zeroing out counts
for MAG-sample pairs with insufficient genome coverage.
\item \strong{Prevalence filter:} Retains only MAGs present (non-zero after
masking) in at least \code{min_samples} samples.
}
}
\note{
The original \verb{02_Preprocessing.Rmd} referenced \code{count_table_cov}
on line 111, but the variable was actually \code{count_table_cov_stats}
(line 105).
This function eliminates that confusion.
}
\examples{
data(fancy_tiny_counts)
data(fancy_tiny_coverage)
filt <- filter_mags(fancy_tiny_counts, fancy_tiny_coverage)
dim(filt)

}
