Skill Tracer
Skills › Knowledge Work Plugins › single-cell-rna-qc

single-cell-rna-qc

skill · 175 lines · Apache-2.0 · bio-research/skills/single-cell-rna-qc/SKILL.md

The facts

Its description

Performs quality control on single-cell RNA-seq data (.h5ad or .h5 files) using scverse best practices with MAD-based filtering and comprehensive visualizations. Use when users request QC analysis, filtering low-quality cells, assessing data quality, or following scverse/scanpy best practices for single-cell analysis.

The description the agent reads to decide when to use it.

From its settingsline 3

When it starts

A person working with single-cell RNA-seq data asks for quality control on it — filtering low-quality cells, assessing data quality, or following scverse/scanpy best practices on .h5ad or .h5 files. The description is the only thing the agent sees, so any request that pairs single-cell data with QC, filtering, or scverse/scanpy practice would pull it in.

Things a person might say (the model's guesses)

  • “Can you run QC on my single-cell RNA-seq data? The file is filtered_feature_bc_matrix.h5.”
  • “Filter out the low-quality cells from this .h5ad file and show me the before/after plots.”
  • “What are the scverse best practices for mitochondrial filtering in single-cell data?”

A model's summary of when it is used.

A model's reading

Runs scripts

scripts/qc_analysis.py, python3 scripts/qc_analysis.py, scripts/qc_core.py, scripts/qc_plotting.py

Scripts the text names. Found by matching words, so treat them as pointers.

Found by matching wordsline 27 line 30 line 32 line 78

Files it mentions

scripts/qc_analysis.py, scripts/qc_core.py, scripts/qc_plotting.py, references/scverse_qc_guidelines.md

Files the text names, such as ones to read or write. Found by matching words, so treat them as pointers.

Found by matching wordsline 27 line 78 line 158

What leads to it

Other skills that hand off to this one, call it, require it or offer it instead, as a model read them.

A model's reading

Licence

Apache-2.0, from bio-research/skills/single-cell-rna-qc/LICENSE.txt

The terms its author shares it under, which let it be shown here.

Other files in this skill (5) Close

The text

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1---
2name: single-cell-rna-qc
3description: Performs quality control on single-cell RNA-seq data (.h5ad or .h5 files) using scverse best practices with MAD-based filtering and comprehensive visualizations. Use when users request QC analysis, filtering low-quality cells, assessing data quality, or following scverse/scanpy best practices for single-cell analysis.
4---
5
6# Single-Cell RNA-seq Quality Control
7
8Automated QC workflow for single-cell RNA-seq data following scverse best practices.
9

Single-Cell RNA-seq Quality Control

Automated QC workflow for single-cell RNA-seq data following scverse best practices.

Raw lines 1 to 9
10## When to Use This Skill
12Use when users:
13- Request quality control or QC on single-cell RNA-seq data
14- Want to filter low-quality cells or assess data quality
15- Need QC visualizations or metrics
16- Ask to follow scverse/scanpy best practices
17- Request MAD-based filtering or outlier detection
19**Supported input formats:**
20- `.h5ad` files (AnnData format from scanpy/Python workflows)
21- `.h5` files (10X Genomics Cell Ranger output)
23**Default recommendation**: Use Approach 1 (complete pipeline) unless the user has specific custom requirements or explicitly requests non-standard filtering logic.

When to Use This Skill

Use when users:

  • Request quality control or QC on single-cell RNA-seq data
  • Want to filter low-quality cells or assess data quality
  • Need QC visualizations or metrics
  • Ask to follow scverse/scanpy best practices
  • Request MAD-based filtering or outlier detection

Supported input formats:

  • .h5ad files (AnnData format from scanpy/Python workflows)
  • .h5 files (10X Genomics Cell Ranger output)

Default recommendation: Use Approach 1 (complete pipeline) unless the user has specific custom requirements or explicitly requests non-standard filtering logic.

Raw lines 10 to 24
25## Approach 1: Complete QC Pipeline (Recommended for Standard Workflows)
27For standard QC following scverse best practices, use the convenience script `scripts/qc_analysis.py`:
29```bash
30python3 scripts/qc_analysis.py input.h5ad
31# or for 10X Genomics .h5 files:
32python3 scripts/qc_analysis.py raw_feature_bc_matrix.h5
33```
35The script automatically detects the file format and loads it appropriately.
37**When to use this approach:**
38- Standard QC workflow with adjustable thresholds (all cells filtered the same way)
39- Batch processing multiple datasets
40- Quick exploratory analysis
41- User wants the "just works" solution
43**Requirements:** anndata, scanpy, scipy, matplotlib, seaborn, numpy
45**Parameters:**
47Customize filtering thresholds and gene patterns using command-line parameters:
48- `--output-dir` - Output directory
49- `--mad-counts`, `--mad-genes`, `--mad-mt` - MAD thresholds for counts/genes/MT%
50- `--mt-threshold` - Hard mitochondrial % cutoff
51- `--min-cells` - Gene filtering threshold
52- `--mt-pattern`, `--ribo-pattern`, `--hb-pattern` - Gene name patterns for different species
54Use `--help` to see current default values.
56**Outputs:**
58All files are saved to `<input_basename>_qc_results/` directory by default (or to the directory specified by `--output-dir`):
59- `qc_metrics_before_filtering.png` - Pre-filtering visualizations
60- `qc_filtering_thresholds.png` - MAD-based threshold overlays
61- `qc_metrics_after_filtering.png` - Post-filtering quality metrics
62- `<input_basename>_filtered.h5ad` - Clean, filtered dataset ready for downstream analysis
63- `<input_basename>_with_qc.h5ad` - Original data with QC annotations preserved
65If copying outputs for user access, copy individual files (not the entire directory) so users can preview them directly.

Approach 1: Complete QC Pipeline (Recommended for Standard Workflows)

For standard QC following scverse best practices, use the convenience script scripts/qc_analysis.py:

python3 scripts/qc_analysis.py input.h5ad
# or for 10X Genomics .h5 files:
python3 scripts/qc_analysis.py raw_feature_bc_matrix.h5

The script automatically detects the file format and loads it appropriately.

When to use this approach:

  • Standard QC workflow with adjustable thresholds (all cells filtered the same way)
  • Batch processing multiple datasets
  • Quick exploratory analysis
  • User wants the "just works" solution

Requirements: anndata, scanpy, scipy, matplotlib, seaborn, numpy

Parameters:

Customize filtering thresholds and gene patterns using command-line parameters:

  • --output-dir - Output directory
  • --mad-counts, --mad-genes, --mad-mt - MAD thresholds for counts/genes/MT%
  • --mt-threshold - Hard mitochondrial % cutoff
  • --min-cells - Gene filtering threshold
  • --mt-pattern, --ribo-pattern, --hb-pattern - Gene name patterns for different species

Use --help to see current default values.

Outputs:

All files are saved to <input_basename>_qc_results/ directory by default (or to the directory specified by --output-dir):

  • qc_metrics_before_filtering.png - Pre-filtering visualizations
  • qc_filtering_thresholds.png - MAD-based threshold overlays
  • qc_metrics_after_filtering.png - Post-filtering quality metrics
  • <input_basename>_filtered.h5ad - Clean, filtered dataset ready for downstream analysis
  • <input_basename>_with_qc.h5ad - Original data with QC annotations preserved

If copying outputs for user access, copy individual files (not the entire directory) so users can preview them directly.

Raw lines 25 to 66
Reads a file scripts/qc_analysis.py :27
Runs code python3 scripts/qc_analysis.py :30
67### Workflow Steps
69The script performs the following steps:
711. **Calculate QC metrics** - Count depth, gene detection, mitochondrial/ribosomal/hemoglobin content
722. **Apply MAD-based filtering** - Permissive outlier detection using MAD thresholds for counts/genes/MT%
733. **Filter genes** - Remove genes detected in few cells
744. **Generate visualizations** - Comprehensive before/after plots with threshold overlays

Workflow Steps

The script performs the following steps:

  1. Calculate QC metrics - Count depth, gene detection, mitochondrial/ribosomal/hemoglobin content
  2. Apply MAD-based filtering - Permissive outlier detection using MAD thresholds for counts/genes/MT%
  3. Filter genes - Remove genes detected in few cells
  4. Generate visualizations - Comprehensive before/after plots with threshold overlays
Raw lines 67 to 75
76## Approach 2: Modular Building Blocks (For Custom Workflows)
78For custom analysis workflows or non-standard requirements, use the modular utility functions from `scripts/qc_core.py` and `scripts/qc_plotting.py`:
80```python
81# Run from scripts/ directory, or add scripts/ to sys.path if needed
82import anndata as ad
83from qc_core import calculate_qc_metrics, detect_outliers_mad, filter_cells
84from qc_plotting import plot_qc_distributions # Only if visualization needed
86adata = ad.read_h5ad('input.h5ad')
87calculate_qc_metrics(adata, inplace=True)
88# ... custom analysis logic here
89```
91**When to use this approach:**
92- Different workflow needed (skip steps, change order, apply different thresholds to subsets)
93- Conditional logic (e.g., filter neurons differently than other cells)
94- Partial execution (only metrics/visualization, no filtering)
95- Integration with other analysis steps in a larger pipeline
96- Custom filtering criteria beyond what command-line params support
98**Available utility functions:**
100From `qc_core.py` (core QC operations):
101- `calculate_qc_metrics(adata, mt_pattern, ribo_pattern, hb_pattern, inplace=True)` - Calculate QC metrics and annotate adata
102- `detect_outliers_mad(adata, metric, n_mads, verbose=True)` - MAD-based outlier detection, returns boolean mask
103- `apply_hard_threshold(adata, metric, threshold, operator='>', verbose=True)` - Apply hard cutoffs, returns boolean mask
104- `filter_cells(adata, mask, inplace=False)` - Apply boolean mask to filter cells
105- `filter_genes(adata, min_cells=20, min_counts=None, inplace=True)` - Filter genes by detection
106- `print_qc_summary(adata, label='')` - Print summary statistics
108From `qc_plotting.py` (visualization):
109- `plot_qc_distributions(adata, output_path, title)` - Generate comprehensive QC plots
110- `plot_filtering_thresholds(adata, outlier_masks, thresholds, output_path)` - Visualize filtering thresholds
111- `plot_qc_after_filtering(adata, output_path)` - Generate post-filtering plots
113**Example custom workflows:**
115**Example 1: Only calculate metrics and visualize, don't filter yet**
116```python
117adata = ad.read_h5ad('input.h5ad')
118calculate_qc_metrics(adata, inplace=True)
119plot_qc_distributions(adata, 'qc_before.png', title='Initial QC')
120print_qc_summary(adata, label='Before filtering')
121```
123**Example 2: Apply only MT% filtering, keep other metrics permissive**
124```python
125adata = ad.read_h5ad('input.h5ad')
126calculate_qc_metrics(adata, inplace=True)
128# Only filter high MT% cells
129high_mt = apply_hard_threshold(adata, 'pct_counts_mt', 10, operator='>')
130adata_filtered = filter_cells(adata, ~high_mt)
131adata_filtered.write('filtered.h5ad')
132```
134**Example 3: Different thresholds for different subsets**
135```python
136adata = ad.read_h5ad('input.h5ad')
137calculate_qc_metrics(adata, inplace=True)
139# Apply type-specific QC (assumes cell_type metadata exists)
140neurons = adata.obs['cell_type'] == 'neuron'
141other_cells = ~neurons
143# Neurons tolerate higher MT%, other cells use stricter threshold
144neuron_qc = apply_hard_threshold(adata[neurons], 'pct_counts_mt', 15, operator='>')
145other_qc = apply_hard_threshold(adata[other_cells], 'pct_counts_mt', 8, operator='>')
146```

Approach 2: Modular Building Blocks (For Custom Workflows)

For custom analysis workflows or non-standard requirements, use the modular utility functions from scripts/qc_core.py and scripts/qc_plotting.py:

# Run from scripts/ directory, or add scripts/ to sys.path if needed
import anndata as ad
from qc_core import calculate_qc_metrics, detect_outliers_mad, filter_cells
from qc_plotting import plot_qc_distributions  # Only if visualization needed

adata = ad.read_h5ad('input.h5ad')
calculate_qc_metrics(adata, inplace=True)
# ... custom analysis logic here

When to use this approach:

  • Different workflow needed (skip steps, change order, apply different thresholds to subsets)
  • Conditional logic (e.g., filter neurons differently than other cells)
  • Partial execution (only metrics/visualization, no filtering)
  • Integration with other analysis steps in a larger pipeline
  • Custom filtering criteria beyond what command-line params support

Available utility functions:

From qc_core.py (core QC operations):

  • calculate_qc_metrics(adata, mt_pattern, ribo_pattern, hb_pattern, inplace=True) - Calculate QC metrics and annotate adata
  • detect_outliers_mad(adata, metric, n_mads, verbose=True) - MAD-based outlier detection, returns boolean mask
  • apply_hard_threshold(adata, metric, threshold, operator='>', verbose=True) - Apply hard cutoffs, returns boolean mask
  • filter_cells(adata, mask, inplace=False) - Apply boolean mask to filter cells
  • filter_genes(adata, min_cells=20, min_counts=None, inplace=True) - Filter genes by detection
  • print_qc_summary(adata, label='') - Print summary statistics

From qc_plotting.py (visualization):

  • plot_qc_distributions(adata, output_path, title) - Generate comprehensive QC plots
  • plot_filtering_thresholds(adata, outlier_masks, thresholds, output_path) - Visualize filtering thresholds
  • plot_qc_after_filtering(adata, output_path) - Generate post-filtering plots

Example custom workflows:

Example 1: Only calculate metrics and visualize, don't filter yet

adata = ad.read_h5ad('input.h5ad')
calculate_qc_metrics(adata, inplace=True)
plot_qc_distributions(adata, 'qc_before.png', title='Initial QC')
print_qc_summary(adata, label='Before filtering')

Example 2: Apply only MT% filtering, keep other metrics permissive

adata = ad.read_h5ad('input.h5ad')
calculate_qc_metrics(adata, inplace=True)

# Only filter high MT% cells
high_mt = apply_hard_threshold(adata, 'pct_counts_mt', 10, operator='>')
adata_filtered = filter_cells(adata, ~high_mt)
adata_filtered.write('filtered.h5ad')

Example 3: Different thresholds for different subsets

adata = ad.read_h5ad('input.h5ad')
calculate_qc_metrics(adata, inplace=True)

# Apply type-specific QC (assumes cell_type metadata exists)
neurons = adata.obs['cell_type'] == 'neuron'
other_cells = ~neurons

# Neurons tolerate higher MT%, other cells use stricter threshold
neuron_qc = apply_hard_threshold(adata[neurons], 'pct_counts_mt', 15, operator='>')
other_qc = apply_hard_threshold(adata[other_cells], 'pct_counts_mt', 8, operator='>')
Raw lines 76 to 147
Reads a file scripts/qc_core.py :78
Reads a file scripts/qc_plotting.py :78
148## Best Practices
1501. **Be permissive with filtering** - Default thresholds intentionally retain most cells to avoid losing rare populations
1512. **Inspect visualizations** - Always review before/after plots to ensure filtering makes biological sense
1523. **Consider dataset-specific factors** - Some tissues naturally have higher mitochondrial content (e.g., neurons, cardiomyocytes)
1534. **Check gene annotations** - Mitochondrial gene prefixes vary by species (mt- for mouse, MT- for human)
1545. **Iterate if needed** - QC parameters may need adjustment based on the specific experiment or tissue type

Best Practices

  1. Be permissive with filtering - Default thresholds intentionally retain most cells to avoid losing rare populations
  2. Inspect visualizations - Always review before/after plots to ensure filtering makes biological sense
  3. Consider dataset-specific factors - Some tissues naturally have higher mitochondrial content (e.g., neurons, cardiomyocytes)
  4. Check gene annotations - Mitochondrial gene prefixes vary by species (mt- for mouse, MT- for human)
  5. Iterate if needed - QC parameters may need adjustment based on the specific experiment or tissue type
Raw lines 148 to 155
156## Reference Materials
158For detailed QC methodology, parameter rationale, and troubleshooting guidance, see `references/scverse_qc_guidelines.md`. This reference provides:
159- Detailed explanations of each QC metric and why it matters
160- Rationale for MAD-based thresholds and why they're better than fixed cutoffs
161- Guidelines for interpreting QC visualizations (histograms, violin plots, scatter plots)
162- Species-specific considerations for gene annotations
163- When and how to adjust filtering parameters
164- Advanced QC considerations (ambient RNA correction, doublet detection)
166Load this reference when users need deeper understanding of the methodology or when troubleshooting QC issues.

Reference Materials

For detailed QC methodology, parameter rationale, and troubleshooting guidance, see references/scverse_qc_guidelines.md. This reference provides:

  • Detailed explanations of each QC metric and why it matters
  • Rationale for MAD-based thresholds and why they're better than fixed cutoffs
  • Guidelines for interpreting QC visualizations (histograms, violin plots, scatter plots)
  • Species-specific considerations for gene annotations
  • When and how to adjust filtering parameters
  • Advanced QC considerations (ambient RNA correction, doublet detection)

Load this reference when users need deeper understanding of the methodology or when troubleshooting QC issues.

Raw lines 156 to 167
168## Next Steps After QC
170Typical downstream analysis steps:
171- Ambient RNA correction (SoupX, CellBender)
172- Doublet detection (scDblFinder)
173- Normalization (log-normalize, scran)
174- Feature selection and dimensionality reduction
175- Clustering and cell type annotation

Next Steps After QC

Typical downstream analysis steps:

  • Ambient RNA correction (SoupX, CellBender)
  • Doublet detection (scDblFinder)
  • Normalization (log-normalize, scran)
  • Feature selection and dimensionality reduction
  • Clustering and cell type annotation
Raw lines 168 to 175

From anthropics/knowledge-work-plugins at 2574e29, 2026-10-27. Skills read by DeepSeek V4.1 Flash on 2026-11-04. Summary and techniques by Claude Opus 5.5 on 2026-11-06.