Filter cells based on the number of genes, counts, and mitochondrial reads.
filter_cells.RdFiltering runs in two stages, and the log records how many cells each one removed.
Usage
filter_cells(
x,
num_mads = 3,
min_genes = 500,
max_genes = NULL,
min_counts = NULL,
max_counts = NULL,
max_mt = 10,
min_cells = 50,
log_file = NULL
)Arguments
- x
A tibble with metadata (default method) or a Seurat object (Seurat method). Must have
detected_genes/total_countscolumns, as added byinitialize_seurat_object().- num_mads
Median absolute deviations for the outlier stage.
NULLskips the stage.- min_genes
Minimum number of genes per cell.
NULLfor no cutoff.- max_genes
Maximum number of genes per cell.
NULLfor no cutoff.- min_counts
Minimum number of counts per cell.
NULLfor no cutoff.- max_counts
Maximum number of counts per cell.
NULLfor no cutoff.- max_mt
Maximum percentage of mitochondrial reads per cell.
NULLfor no cutoff.- min_cells
Minimum number of cells that must survive filtering. Below this, filtering
stop()s rather than handing back an object too small to analyze meaningfully.NULLskips the check.- log_file
Log file.
Value
Filtered data. The Seurat method also writes a pre-filtering QC
violin plot (via plot_metrics_distribution()) and the unfiltered
metadata (via save_metadata(), as metadata-unfiltered.csv.gz), plus
the post-filtering QC plots (via plot_metrics_distribution() and
plot_metrics_correlations()) to the working directory.
Details
Outlier removal. Cells further than
num_madsmedian absolute deviations from the median number of genes or counts are dropped. The median and MAD are computed on the log scale and the bounds back-transformed, which suits these right-skewed counts.num_mads = NULLskips it.Fixed cutoffs.
min_genes/max_genes/min_counts/max_countsare applied to whatever survived stage 1, thenmax_mt. Each is skipped whenNULL, so out of the box onlymin_genes(500) andmax_mt(10) do anything.
Applying the fixed cutoffs second makes them a quality floor the data-driven bounds cannot undercut: a wide or contaminated distribution can put the MAD bound below 500 genes, and those cells are still removed. All cutoffs are inclusive.
Genes that are no longer detected in any of the retained cells are dropped, since filtering cells leaves them as all-zero rows.