Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Quality control and doublet detection

Filter 5,025 peripheral blood mononuclear cells (PBMCs) from a healthy human donor, the 10x Genomics 5k PBMC dataset, in two ways: with automatic bounds set from the spread of each QC measure, and with the manual thresholds of the PBMC analysis. Then check which cell types each filter removes, and score doublets among the cells that pass the manual thresholds. The automatic bounds keep 4,331 cells and the manual thresholds 3,948. The two filters disagree at both ends of the count range: the manual thresholds remove 415 cells that the automatic bounds keep, mostly monocytes above the cap of 15,000 counts, and the automatic bounds remove 32 cells that the manual thresholds keep, among them 9 of the 12 platelets that pass the manual thresholds. Doublet scoring calls 18 of the 3,948 cells doublets, 8 of them in the CD14 monocyte cluster.

Each filter saves its result as a cell selection: an artifact that records which cells pass, together with the inputs and parameters that produced it. Filters leave the counts and the cell table unchanged, so every filter here starts from the same input cells and the counts are imported once.

Import the counts

The counts come from the 10x Genomics dataset “5k Peripheral blood mononuclear cells (PBMCs) from a healthy donor (v3 chemistry)”, released under CC BY 4.0. The file holds only the barcodes that Cell Ranger called as cells. An unfiltered droplet matrix needs cell calling first, as the cell calling tutorial shows. The RNA pipeline recipe, ds.pipeline.rna, which runs the whole RNA analysis in one call, calls and filters cells in the same run with cell_calling=True. The example writes its store to a temporary directory; use a project directory to keep it.

DataStore has 5025 (5025) cells with 1 assays: RNA Cell metadata: 'I', 'ids', 'names', 'RNA_nCounts', 'RNA_nFeatures', 'RNA_percentMito', 'RNA_percentRibo', 'sourceRow' RNA assay has 33538 features and following metadata: 'I', 'ids', 'names', 'dropOuts', 'feature_type', 'genome', 'nCells'

Started: 2026-11-18T00:16:04.667011Z | Wall time: 13.740 s

Opening a new store computes four QC columns for every cell: its total counts (RNA_nCounts), its detected genes (RNA_nFeatures), and the percentages of its counts from mitochondrial genes (RNA_percentMito) and from ribosomal protein genes (RNA_percentRibo). The first open also removes every cell with 10 or fewer detected genes from the cell key I, the boolean column marking the cells that analyses use by default. No cell here has so few genes, so I keeps all 5,025 cells.

Inspect the QC distributions

Freeze the cells of I into a cell selection, a fixed copy that later changes to I do not affect, and use it as the input of every filter below. Then summarize and plot the four columns:

RNA_nCountsRNA_nFeaturesRNA_percentMitoRNA_percentRibo
min502.038.00.00.7
25%6079.01816.07.017.1
50%7803.02171.08.428.3
75%10210.02645.010.537.6
max46913.06160.096.852.2
Four violin plots of the 5,025 input PBMCs, one per QC column, with quartile lines and each cell drawn as a point. Counts per cell center near 7,800, with a long upper tail to about 47,000 and a small bulge of cells below about 2,500. Detected genes per cell center near 2,200, with an upper tail to about 6,200 and a bulge of cells with fewer than 1,000 genes. The mitochondrial share centers near 8% with a thin tail to about 97%. The ribosomal protein share has two main modes, near 17% and 38%, a smaller third mode near 3%, and no long upper tail.

Started: 2026-11-18T00:16:18.411326Z | Wall time: 1.009 s

Half of the cells have between 6,079 and 10,210 counts and between 1,816 and 2,645 detected genes. Filters act on the tails around that core. Counts reach 46,913, six times the median of 7,803. Both the count and the gene violins have a bulge of cells below their main body, down to 502 counts and 38 genes. The mitochondrial share has a median of 8.4% and a thin tail up to 96.8%: a damaged cell loses cytoplasmic RNA through its broken membrane but keeps the transcripts inside its mitochondria, so its mitochondrial share rises. The ribosomal protein share has no long upper tail; it has two main modes, one on each side of its median of 28.3%, and a smaller third mode near 3%.

Filter with automatic bounds

qc.auto_filter sets each bound three median absolute deviations (MADs) from the median of the input cells. The MAD is the median distance of the values from their median, scaled to match the standard deviation of normally distributed values; unlike the standard deviation, it barely moves when extreme cells are added. Counts and detected genes get a lower and an upper bound, computed on log1p values, and the two percentages get an upper bound only. The filter warns when its bounds remove more than half of the cells, or when the bounds on counts or genes miss a second population of cells, such as a separate group above the upper bound; both happen when the empty droplets of an unfiltered matrix set the bounds. The filter returns an ArtifactRef, a reference to the saved selection: ds.artifacts.load reads which cells it keeps, and ds.artifacts.inspect reads the bounds that it resolved.

Cells kept: 4331 of 5025; removed: 694 (13.8%)
lowhighremoved belowremoved above
RNA_nCounts2476.224584.643768
RNA_nFeatures947.14975.044935
RNA_percentMitonone15.80571
RNA_percentRibonone73.900

Started: 2026-11-18T00:16:19.423575Z | Wall time: 0.109 s

The automatic bounds keep 4,331 of the 5,025 cells and remove 694 (13.8%). Because the bounds on counts and genes are set on log1p values, each pair sits the same factor below and above the median: 2,476 and 24,585 counts lie 3.2-fold below and above the median of 7,803, and 947 and 4,975 genes 2.3-fold below and above the median of 2,171. The lower bounds remove 437 and 449 cells and the mitochondrial bound of 15.8% removes 571; these add up to more than twice the 694 removed cells, so most removed cells fail two or three of these bounds at once. The upper bounds remove only the 68 and 35 most extreme cells, and the ribosomal bound of 73.9% lies above every cell.

Filter with manual thresholds

The PBMC analysis keeps cells with more than 1,000 and fewer than 15,000 counts, more than 500 and fewer than 4,000 detected genes, and a mitochondrial share above 0% and below 15%. qc.filter applies such thresholds to cell columns. Its bounds are exclusive, like those of qc.auto_filter: lows=[500] removes a cell with exactly 500 genes, which scanpy’s filter_cells(min_genes=500) keeps. Pass keep_bounds=True for inclusive bounds. Apply the thresholds to the same input cells and draw both sets of bounds on the violins:

Cells kept: 3948 of 5025; removed: 1077 (21.4%)
lowhighremoved belowremoved above
RNA_nCounts100015000139458
RNA_nFeatures5004000206255
RNA_percentMito0151603
The same four violin plots with the manual thresholds as solid lines and the automatic bounds as dashed lines. The manual caps of 15,000 counts and 4,000 genes sit well below the automatic upper bounds of about 24,600 counts and 4,975 genes, and the automatic lower bounds of about 2,500 counts and 950 genes sit above the manual floors of 1,000 counts and 500 genes. The mitochondrial bounds of 15% and 15.8% nearly coincide, the manual floor of 0% lies at the bottom of that panel, and the automatic ribosomal bound of 73.9% lies above every cell.

Started: 2026-11-18T00:16:19.535286Z | Wall time: 0.742 s

The manual thresholds keep 3,948 of the 5,025 cells and remove 1,077 (21.4%). The 15% mitochondrial threshold removes the most cells, 603, and the cap of 15,000 counts the next most, 458. Because bounds are exclusive, the mitochondrial floor of 0% removes the one cell without mitochondrial counts. On the violins, the manual cap of 15,000 counts cuts through the upper shoulder of the counts distribution, while the automatic upper bound of 24,585 sits in its thin tail; the two mitochondrial bounds nearly coincide.

Compare the two filters

Label each input cell by the filters that keep it, count the cells of each outcome with their median QC values, and plot counts against the mitochondrial share and against detected genes:

cellsmedian RNA_nCountsmedian RNA_nFeaturesmedian RNA_percentMitomedian RNA_percentRibo
Kept by both39167903.02190.08.232.6
Removed by both6622041.0760.029.35.5
Removed only by manual thresholds41517427.03950.07.519.4
Removed only by automatic bounds321913.5814.510.314.1
Removed only by manual thresholds, with 15,000 counts or more: 388
Two scatter plots of the 5,025 input PBMCs against counts per cell on a log scale: left the mitochondrial share of counts, right detected genes on a log scale. Light gray cells are kept by both filters, dark gray cells removed by both, orange cells removed only by the manual thresholds and blue cells only by the automatic bounds; solid lines mark the manual thresholds and dashed lines the automatic bounds. Dark gray cells fill the corner of few counts and a high mitochondrial share and the far right beyond 24,585 counts, orange cells form a band between 15,000 and 24,585 counts with a low mitochondrial share, and blue cells lie between the manual and automatic lower bounds, from about 1,000 to 2,500 counts.

Started: 2026-11-18T00:16:20.279887Z | Wall time: 0.674 s

Both filters keep 3,916 cells and both remove 662. Most of the 662 are damaged cells in the corner of few counts and a high mitochondrial share: their median counts are 2,041 and their median mitochondrial share 29.3%, against 7,903 and 8.2% for the cells that both filters keep. Their median ribosomal protein share is 5.5%, against 32.6%, so these damaged cells form the small third mode of the ribosomal violin. The filters disagree at the two ends of the count range. The manual thresholds remove 415 cells that the automatic bounds keep: their median is 17,427 counts, and 388 of them have 15,000 counts or more. The automatic bounds remove 32 cells that the manual thresholds keep, all of them between the manual floors and the automatic lower bounds on counts or genes.

To see which cell types each filter removes, save each cell’s outcome as a cell column and compare the lineage markers of the PBMC analysis across the four groups. Dot size is the share of a group’s cells that detect a gene, and color is its mean expression, standardized across the groups:

groupKept by bothRemoved by bothRemoved only by manual thresholdsRemoved only by automatic bounds
feature
LST135208447
S100A824177150
FCGR3A157343
CD3D6320303
IL7R5435279
PPBP14128
PF403028
Dot plot of 13 lineage markers, grouped as monocyte, B-cell, T-cell, NK-cell, pDC-like and platelet markers along the columns, across the four filter outcomes along the rows. Dot size is the share of cells that detect the gene, and color is mean expression standardized across the four rows. The cells removed only by the manual thresholds have the largest dots for the monocyte markers LST1, S100A8 and FCGR3A, and the cells kept by both the largest dots for the T-cell markers CD3D and IL7R. The cells removed only by the automatic bounds have the only sizable dots for the platelet markers PPBP and PF4, and medium dots for LST1 and S100A8, with the brightest S100A8 color of the four rows.

Started: 2026-11-18T00:16:20.957000Z | Wall time: 0.884 s

The cells that only the manual thresholds remove are mostly monocytes: 84% of them detect the monocyte marker LST1 and 71% S100A8, against 35% and 24% of the cells that both filters keep, while the T-cell marker CD3D falls from 63% to 30%. Monocytes hold more RNA than lymphocytes, so a fixed cap on counts removes them first. The 32 cells that only the automatic bounds remove are a mix: 28% of them detect the platelet markers PPBP and PF4, against at most 1% of the cells that both filters keep, and about half detect the monocyte markers LST1 and S100A8. Removing cells by type changes the composition that every later analysis sees, so check which populations a threshold removes before accepting it.

Filter within each sample

Pooled bounds penalize a sample sequenced less deeply than the others: its cells sit low in the pooled distribution, so the lower bounds remove more of them. With sample_column, qc.auto_filter computes the bounds within each sample instead. This dataset is one sample, so the call below does not run here:

# Compute the bounds within each sample of a sample_id column.
sample_selection = ds.qc.auto_filter(
    cell_selection=qc_cell_selection,
    sample_column="sample_id",
)

A sample with fewer cells than min_cells_per_sample, 20 by default, keeps all of them, with a warning, because its bounds cannot be estimated reliably. The RNA recipe takes the same option, as ds.pipeline.rna(filtering={"sample_column": "sample_id"}). With cell hashing, the recipe’s hashing stage keeps the cells of exactly one hashtag and computes the bounds within each hashtag unless filtering names a sample_column, as the HTO demultiplexing tutorial shows.

Filter imported QC columns

qc.auto_filter gives each metric a policy: which bounds apply, and whether they are computed on log1p or raw values. The columns that CyteArc wrote get the policies used above. A QC column imported from another tool gets its policy from the end of its name, with a warning: a name ending in nCounts or nFeatures is treated as counts, one ending in percentMito or percentRibo as a percentage, and any other name gets two-sided bounds on raw values. Scanpy’s total_counts and pct_counts_mt fall in the last group, so set their policies with metric_policies. To show the call, export 500 input cells with scanpy’s column names and import them into a new store:

total_countspct_counts_mt
014882.07.653541
17882.012.040091
210334.05.893168
37650.07.032680
46205.07.912973

Started: 2026-11-18T00:16:21.844526Z | Wall time: 2.965 s

Imported cells kept: 432 of 500
transformbound_directionlowhigh
total_countslog1ptwo_sided3049.219976.0
pct_counts_mtidentityuppernone14.9

Started: 2026-11-18T00:16:24.813329Z | Wall time: 0.124 s

The bounds, 3,049 to 19,976 counts and a mitochondrial share below 14.9%, keep 432 of the 500 cells. They differ from the bounds of all 5,025 input cells, 2,476 to 24,585 counts and 15.8%, because the median and MAD of a random sample of 500 cells differ from those of the full input. A policy with bound_direction="lower" removes only low-count cells and leaves the high-count cells for review, and metric_policies also applies within each sample of a sample_column.

Measure other gene families

The mitochondrial and ribosomal percentages count the genes whose names match ^MT- and ^RPS|^RPL|^MRPS|^MRPL, ignoring case; the ribosomal pattern matches ribosomal protein genes, not ribosomal RNA. Features named by Ensembl IDs match neither pattern, so check a store’s feature names before reading a zero percentage. Both columns are computed when a store is first opened, replacing any imported column of the same name, and stay fixed: a later open with a different mito_pattern or ribo_pattern raises an error. For another gene family, select its genes and compute their share of each cell’s counts with qc.feature_percentage, which saves the shares as a result rather than as a cell column. Most genes whose names start with HSP encode heat-shock proteins, which rise in stressed cells:

Genes selected: 34
count 3948.00 mean 0.33 std 0.13 min 0.00 25% 0.24 50% 0.31 75% 0.40 max 1.53 Name: HSP genes (% of counts), dtype: float64

Started: 2026-11-18T00:16:24.940530Z | Wall time: 0.478 s

The 34 genes with the HSP prefix take a median of 0.31% of the counts of a cell that passes the manual thresholds, and at most 1.53%, about five times the median. To filter on such a percentage, pass the result to ds.select_cells with a high bound. Excluding gene families from the highly variable genes is a separate choice, covered in the feature selection tutorial.

Score doublets

A doublet is a droplet that captured two cells, so one barcode holds the RNA of both. A doublet of two cell types can show the markers of both and look like a cell state of its own; a doublet of two cells of one type looks like one cell with more RNA.

CyteArc scores doublets as Scrublet does Wolock et al., 2019. Scoring simulates doublets by adding the counts of two cells of the same sample and gives each cell the probability that it is a doublet from the share of simulated doublets among its nearest neighbors in PCA space; the methods page gives the details. Doublets form only within one capture, so name each cell’s 10x channel or lane with doublets={"sample_column": ...} when cells come from several; this dataset is one capture. qc.doublets takes a neighbor graph, onto whose PCA it projects the simulated doublets, and the graph’s clusters, so run the RNA recipe on the cells that pass the manual thresholds, with the settings of the PBMC analysis: 500 highly variable genes, 15 principal components and Leiden resolution 0.5, without cell-cycle scoring or markers. The recipe takes the selection as cells, analyzes exactly those cells and returns a PipelineRun. Indexing the run by an output name, as in doublet_run["doublets"], returns a reference to that saved result, and doublet_run.cells reads per-cell values of the run, such as each cell’s cluster and doublet call:

Predicted doublets: 18 of 3948 cells
Median counts: 10,519 in the predicted doublets, 7,876 in the other cells
cellspredicted doubletsremoved by automatic boundsmedian genesmedian ribosomal protein counts (%)
cluster
11249081966.039.7
27048152988.516.4
3559102345.033.8
4364102227.026.2
5289302269.016.9
6256401928.530.8
7239102290.033.2
8151002187.039.6
955001808.036.5
1030002428.525.9
1125003396.014.3
1215003365.023.4
131209695.01.4

Started: 2026-11-18T00:16:25.421560Z | Wall time: 147.869 s

The run calls 18 of the 3,948 cells doublets. The predicted doublets carry more RNA: their median of 10,519 counts is 1.3 times the 7,876 of the other cells. The run’s cells and settings are those of the PBMC analysis, which names its 12 clusters from their markers. Clustering depends on the order of the cells in the store, and the two stores hold the cells in different orders, so this run finds 13 clusters. Six of them match cell types of that page in size: cluster 2 its 704 CD14 monocytes, clusters 6 and 7 together its 495 B cells, and clusters 11, 12 and 13 its 25 CD16 monocytes, 15 pDC-like cells and 12 platelets. The other seven together match its 2,697 T and NK cells. In the layout below, clusters 5 and 10 sit at the lower end of the region that these seven form, where that page draws its NK cells, and clusters 1, 3, 4, 8 and 9 above them, where it draws its T cells. Cluster 2 holds 8 of the 18 predicted doublets and cluster 6 holds 4; no cluster is made of doublets.

The table also explains the two main modes of the ribosomal protein share and the cells that only the automatic bounds remove. The ribosomal protein share follows cell type: its median is 14.3% to 16.9% in the monocyte and NK clusters 2, 5 and 11 and 33.8% to 39.7% in T-cell clusters 1, 3, 8 and 9, so these cells form the modes near 17% and 38% of its violin, while T-cell cluster 4 sits between them, at 26.2%. The platelets of cluster 13 have a median of 695 detected genes, below the automatic lower bound of 947, so the automatic bounds remove 9 of the 12 platelets. The other cells that only the automatic bounds remove are 15 of the 704 cells of CD14 monocyte cluster 2 and 8 of the 1,249 cells of T-cell cluster 1.

Plot the clusters beside the doublet scores:

Two UMAP panels of the 3,948 PBMCs that pass the manual thresholds. Left: cells colored by the 13 Leiden clusters, with each cluster's number on the data; the T-cell clusters 1, 3, 4, 8 and 9 form a connected group on the left that ends in the NK clusters 5 and 10 at the bottom, monocyte cluster 2 forms a separate group on the right with the small cluster 11 beside it, B-cell clusters 6 and 7 form a group at the top, and the small clusters 12 and 13 sit apart at the top right. Right: the same cells colored by doublet score from 0 to 0.7, with the highest scores drawn on top; nearly all cells score low, and most of the few high-scoring cells sit inside clusters 2 and 6.

Started: 2026-11-18T00:18:53.293518Z | Wall time: 0.537 s

Most of the highest scores sit inside clusters 2 and 6 rather than between clusters. The threshold that turns scores into calls comes from the simulated doublets: those of two cells of one type look like singlets and score low, those of two types score high, and the threshold is the minimum between the two modes of their scores. Plot the scores of the simulated doublets and of the cells, with the threshold as a dashed line:

Two histograms of doublet scores with the threshold of 0.340 as a dashed vertical line. Left: the 7,896 simulated doublets, with a mode below 0.1 and tall spikes of high scores near 0.36, 0.44, 0.54 and 0.7, the tallest at 0.7. Right: the 3,948 cells on a logarithmic count axis, almost all below 0.2, with 18 cells above the threshold, 10 of them at 0.7.

Started: 2026-11-18T00:18:53.833749Z | Wall time: 0.562 s

The high scores take only a few values because a cell’s score depends only on how many of its 90 nearest neighbors are simulated doublets. The samples attribute of the scores records how each sample’s threshold was chosen and what it calls:

cells 3948 simulatedDoublets 7896 adjustedNeighbors 90 threshold 0.340431 thresholdMethod minimum predictedDoublets 18 detectableDoubletFraction 0.359549 estimatedDoubletRate 0.012681 dtype: object
Simulated doublets among the 90 neighbors of a predicted doublet: 87 to 90

Started: 2026-11-18T00:18:54.398726Z | Wall time: 0.016 s

The simulated scores have a valley with more than 5% of the simulated doublets on each side, and the doublet rate that it implies is at most 50%, so the method is minimum. Otherwise Otsu’s threshold is taken, otsu, as long as it implies a doublet rate of at most 50%, as for scores without a valley or a minimum that leaves fewer than 5% on one side. A sample where neither threshold does, such as one cell type alone, whose simulated doublets look like its cells, gets the method none and no threshold, so no line to draw, calls no cell, and the stage warns. The threshold of 0.340 calls a cell a doublet when at least 87 of its 90 nearest neighbors are simulated doublets. Only 36% of the simulated doublets score above the threshold; the others pair two cells similar enough to pass as one. Scrublet’s estimate of the doublet rate divides the share of cells called by that detectable fraction, which gives 1.3%, a third of the 3.9% multiplet rate that the 10x Genomics user guide for v3 chemistry lists for about 5,000 recovered cells. The cap of 15,000 counts removed 458 cells before scoring, and any doublets among them are missing from the estimate.

For your own data, compare the estimate with the rate that the user guide of your kit lists for the number of cells recovered. When the two disagree, or the method is otsu or none, review the histograms and pass a threshold to qc.doublets, or doublets={"threshold": ...} to the RNA recipe. doublet_run.report() lists each sample’s threshold, its method and calls beside the summaries of the run’s other stages.

Keep the singlets

Doublet scoring removes no cells. Select the cells that were not called doublets:

Singlets: 3930

Started: 2026-11-18T00:18:54.416867Z | Wall time: 0.057 s

The 3,930 singlets, the 3,948 scored cells without the 18 predicted doublets, form a new cell selection. ds.select_cells reads one per-cell array of a result, here predicted_doublets, and keeps the cells whose value include lists. For numeric values, low and high set the range to keep: ds.select_cells(doublets, high=0.3, keep_bounds=True) keeps the cells that score at most 0.3. Read per-cell values lists the results and arrays that ds.select_cells reads. Pass the singlets as cells to the RNA recipe, as above, to analyze them.

Filter ATAC cells

Opening a store with an ATAC assay computes each cell’s fragment or cut-site count and the number of peaks with at least one count. The ATAC recipe, ds.pipeline.atac, filters cells on these two columns, then features.prevalent_peaks keeps the peaks with the highest summed TF-IDF values across the remaining cells for LSI and the neighbor graph, as the scATAC-seq tutorial shows. CyteArc does not compute the fraction of reads in peaks (FRiP) or transcription start site (TSS) enrichment; import them as cell metadata from another tool to filter on them.

Filter antibody and multimodal assays

Antibody panels often include isotype controls, which the ADT recipe, ds.pipeline.adt, leaves out of its panel by default: the antibodies whose names contain “isotype”, “control” or “ctrl”, in any case. panel={"exclude": ...} sets another pattern. RNA, ADT and HTO assays share one cell table, so one cell selection serves every assay: ds.pipeline.adt(cells=rna_run) analyzes the cells that an RNA run kept without filtering them again. The HTO demultiplexing tutorial covers hashtag demultiplexing.

References
  1. Wolock, S. L., Lopez, R., & Klein, A. M. (2019). Scrublet: Computational Identification of Cell Doublets in Single-Cell Transcriptomic Data. Cell Systems, 8(4), 281-291.e9. 10.1016/j.cels.2018.11.005