Skip to contents

This function applies quality control filtering to fragments in a MarchR project or dataset. It filters out cells with low fragment counts and low TSS enrichment scores, and stores the QC metrics for later use. The function is a wrapper around run_fragment_qc that integrates with MarchR objects and maintains cell alignment.

Usage

# S3 method for class 'MarchRDataset'
qc_fragments(
  proj,
  frags_name = character(0),
  gene_annotations,
  blacklist,
  n_frags = 1000,
  tss_enrichment = 10
)

# S3 method for class 'MarchRProject'
qc_fragments(
  proj,
  dataset_name = character(0),
  frags_name = character(0),
  gene_annotations = NULL,
  blacklist = NULL,
  n_frags = 1000,
  tss_enrichment = 10
)

Arguments

proj

(MarchRProject or MarchRDataset) The project or dataset containing the fragments to QC.

frags_name

(character) The name of the fragments to perform QC on. If not provided, will use smart selection when only one fragment set is present.

gene_annotations

(data.frame) Gene annotation data frame with transcript information. For MarchRProject, if NULL, will use annotations from the project genome. Required columns depend on the underlying BPCells requirements.

blacklist

(data.frame) Blacklisted genomic regions data frame. For MarchRProject, if NULL, will use blacklist from the project genome. Required columns depend on the underlying BPCells requirements.

n_frags

(numeric) Minimum fragment count threshold for cell filtering. Cells with fewer than this many fragments will be removed. Default is 1000.

tss_enrichment

(numeric) Minimum TSS enrichment threshold for cell filtering. Cells with TSS enrichment below this threshold will be removed. Default is 10. Note: TSS enrichment is computed by BPCells::qc_scATAC, which uses a narrower flanking window than ArchR's TSSEnrichment. Scores from the two tools may not be directly comparable.

dataset_name

(character) For MarchRProject only. The name of the dataset containing the fragments. 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 fragments filtered and QC metrics stored. For MarchRDataset: Returns the dataset with filtered fragments in fragments slot and QC metrics in qc_frags slot. For MarchRProject: Returns the project with the specified dataset updated.

Details

The function performs the following steps:

  1. Calculates fragment count per cell

  2. Calculates TSS enrichment scores per cell using gene annotations

  3. Filters out cells below the n_frags and tss_enrichment thresholds

  4. Updates the fragments with only passing cells

  5. Stores QC metrics for later retrieval with get_fragment_qc

  6. Validates cell alignment across matrices and fragments

For MarchRProject objects, gene annotations and blacklist can be automatically retrieved from the project genome if they have been previously set using set_gene_annotations and set_blacklist.

The QC metrics include per-cell statistics such as fragment counts and TSS enrichment, which can be visualized using plot_tss_scatter to assess the filtering thresholds.

See also

run_fragment_qc for the underlying QC function get_fragment_qc for retrieving stored QC metrics plot_tss_scatter for visualizing fragment QC distributions set_gene_annotations for setting project gene annotations set_blacklist for setting project blacklist

Examples

if (FALSE) { # \dontrun{
# Create a demo project with fragments
project <- create_example_project()

# Create gene annotations and blacklist (format depends on BPCells requirements)
gene_annot <- data.frame(
  chr = "chr1",
  start = seq(1000, 10000, 1000),
  end = seq(1500, 10500, 1000),
  strand = rep(c("+", "-"), length.out = 10),
  gene_id = paste0("gene_", 1:10),
  gene_name = paste0("GENE", 1:10)
)

blacklist <- data.frame(
  chr = "chr2",
  start = 1000,
  end = 2000
)

# Perform quality control with annotations
project_qc <- qc_fragments(project, 
                           dataset_name = "dataset_1", 
                           frags_name = "fragments",
                           gene_annotations = gene_annot,
                           blacklist = blacklist,
                           n_frags = 500,
                           tss_enrichment = 5)

# Retrieve QC metrics
qc_metrics <- get_fragment_qc(project_qc, dataset_name = "dataset_1", frags_name = "fragments")
head(qc_metrics)

# Plot TSS enrichment vs fragment count
plot_tss_scatter(qc_metrics)
} # }