Perform quality control on matrices based on read depth per cell and feature prevalence
qc_matrix.RdThis function applies quality control filtering to matrices in a MarchR project or dataset.
It filters out cells with low read depth and features expressed in too few cells,
then stores the QC metrics for later use. The function is a wrapper around
run_matrix_qc that integrates with MarchR objects and maintains cell alignment.
Arguments
- proj
(MarchRProject or MarchRDataset) The project or dataset containing the matrix to QC.
- assay_name
(character) The name of the matrix/assay to perform QC on. If not provided, will use smart selection when only one assay is present.
- read_depth
(numeric) Minimum read depth threshold for cell filtering. Cells with fewer reads than this threshold will be removed. Default is 1000.
- min_cells_per_feature
(numeric) Minimum number of cells that must express each feature for the feature to be retained. Features expressed in fewer cells will be removed. Default is 3.
- dataset_name
(character) For MarchRProject only. The name of the dataset containing the matrix. If not provided, will use smart selection when only one dataset is present.
- ...
Additional arguments passed to methods.
Value
The input object with the specified matrix filtered and QC metrics stored.
For MarchRDataset: Returns the dataset with filtered matrix in matrices slot
and QC metrics in qc_matrices slot.
For MarchRProject: Returns the project with the specified dataset updated.
Details
The function performs the following steps:
Calculates read depth (total counts) per cell
Filters out cells below the
read_depththresholdCounts the number of cells expressing each feature (non-zero values)
Filters out features expressed in fewer than
min_cells_per_featurecellsUpdates the matrix with only passing cells and features
Stores QC metrics for later retrieval with
get_matrix_qcValidates cell alignment across matrices and fragments
The QC metrics include per-cell statistics (such as read depth) and per-feature statistics
(such as number of cells expressing each feature), which can be visualized using
plot_knee to assess the filtering thresholds.
See also
run_matrix_qc for the underlying QC function
get_matrix_qc for retrieving stored QC metrics
plot_knee for visualizing read depth distributions
Examples
# Create a demo project with unfiltered data
project <- MarchRProject()
demo_mat <- BPCells::get_demo_mat(subset = FALSE, filter_qc = FALSE)
project <- add_matrix(project, demo_mat, dataset_name = "demo", mat_name = "RNA")
# Perform quality control with different thresholds
project_qc <- qc_matrix(project,
dataset_name = "demo",
assay_name = "RNA",
read_depth = 1000,
min_cells_per_feature = 3)
# Retrieve QC metrics
qc_metrics <- get_matrix_qc(project_qc, dataset_name = "demo", assay_name = "RNA")
head(qc_metrics)
#> # A tibble: 6 × 2
#> cellName readDepth
#> <chr> <dbl>
#> 1 demo#AAACAGCCAAACAACA-1 2
#> 2 demo#AAACAGCCAAACATAG-1 1
#> 3 demo#AAACAGCCAAACCCTA-1 0
#> 4 demo#AAACAGCCAAACCTTG-1 1
#> 5 demo#AAACAGCCAAACGCGA-1 2
#> 6 demo#AAACAGCCAAACGGGC-1 2
# Plot knee curve to visualize filtering threshold
plot_knee(qc_metrics)