Summarize a gene program, such as a pathway, a cell state or a lineage signature, as one score per cell, and compare CyteArc’s two methods for scoring any RNA gene set, WAGGR and AUCell. The data are 3,948 human peripheral blood mononuclear cells (PBMCs) from a healthy donor in the 10x Genomics 5k PBMC dataset (tenx_5K_pbmc_rnaseq), scored for five-gene signatures of T cells, B cells and myeloid cells. Each signature scores highest in its own lineage, with median AUCell scores of 0.84 in T cells, 0.95 in B cells and 0.95 in CD14 monocytes. The B-cell signature also reaches a median AUCell score of 0.55 in CD14 monocytes, which express three of its five genes: the tetraspanin CD37 and the MHC class II antigen-presentation genes CD74 and HLA-DRA.
WAGGR, a weighted aggregate Mompel et al., 2022, averages the library-size-normalized expression of the signature genes, so its score grows with how strongly a cell expresses the program, on a scale set by the abundance of the signature genes rather than capped at 1. AUCell Aibar et al., 2017 ranks each cell’s genes by their counts and scores, from 0 to 1, how many signature genes rank near the top and how high, so the score stops rising once every signature gene ranks near the top. AUCell therefore separates the cells that express a program from those that do not, and WAGGR ranks the expressing cells by how strongly they express it: within the CD14 monocytes, the myeloid AUCell score spans a 1.13-fold range from its 5th to its 95th percentile, and the WAGGR score a 7.37-fold range.
Open the prepared analysis¶
# Import CyteArc and its plot settings, pandas and Matplotlib for tables and figures, and tools for a temporary GMT file.
from pathlib import Path
from tempfile import TemporaryDirectory
import matplotlib.pyplot as plt
import pandas as pd
import cytearc
from cytearc.plotting import CategoricalScale, CellField, ColorScale
# Keep routine logs and progress bars out of the page.
cytearc.configure_output(level="WARNING", progress=False)
# Download the prepared PBMC store, which holds the counts and a saved RNA analysis.
dataset = cytearc.datasets.connect("cytearc_docs").download_dataset(
"tenx_5K_pbmc_rnaseq",
destination="cytearc_datasets",
zarr=True,
)
# Open the store with four threads for scoring, and reopen its saved RNA run.
ds = cytearc.DataStore(f"{dataset}/data.zarr", nthreads=4)
run = ds.pipeline.open(label="rna")
dsDataStore has 3948 (5025) cells with 1 assays: RNA
Cell metadata:
'I', 'ids', 'names', 'RNA_G2M_score', 'RNA_S_score',
'RNA_UMAP1', 'RNA_UMAP2', 'RNA_cell_cycle_phase', 'RNA_clusters', 'RNA_doublet_score',
'RNA_leiden_cluster', 'RNA_nCounts', 'RNA_nFeatures', 'RNA_paris_cluster', 'RNA_percentMito',
'RNA_percentRibo'
RNA assay has 33538 features and following metadata:
'I', 'ids', 'names', 'dropOuts', 'feature_type',
'genome', 'nCells'Started: 2026-11-18T00:15:59.712715Z | Wall time: 12.828 s
The store holds 5,025 cells, and its saved RNA analysis kept the 3,948 that passed quality control. ds.pipeline.open(label="rna") reopens that analysis as a pipeline run, the saved record of one call of the RNA recipe with its cells, settings and results.
Define the gene sets¶
Gene sets are commonly shared as Gene Matrix Transposed (GMT) files, with one set per line: its name, a description and its genes, separated by tabs. cytearc.read_gmt reads a GMT file into a table with one row per gene of each set, where source names the set and target the gene. The next cell writes the three signatures to a temporary GMT file and reads it back. For your own gene sets, pass the path of your GMT file to cytearc.read_gmt:
# Write one tab-separated line per signature: its name, a description, and its genes.
input_directory = TemporaryDirectory()
gmt_path = Path(input_directory.name) / "pbmc_signatures.gmt"
gmt_path.write_text(
"T_cell\tna\tCD3D\tCD3E\tTRAC\tLTB\tIL7R\n"
"B_cell\tna\tMS4A1\tCD79A\tCD37\tCD74\tHLA-DRA\n"
"Myeloid\tna\tLST1\tS100A8\tS100A9\tCTSS\tFCER1G\n",
encoding="utf-8",
)
# Read the file as one row per signature and gene, and list each signature's genes.
gene_sets = cytearc.read_gmt(gmt_path)
gene_sets.groupby("source", sort=False)["target"].agg(", ".join).to_frame("genes")| genes | |
|---|---|
| source | |
| T_cell | CD3D, CD3E, TRAC, LTB, IL7R |
| B_cell | MS4A1, CD79A, CD37, CD74, HLA-DRA |
| Myeloid | LST1, S100A8, S100A9, CTSS, FCER1G |
Started: 2026-11-18T00:16:12.546732Z | Wall time: 0.031 s
The T-cell signature holds CD3D and CD3E of the CD3 complex, the T-cell receptor gene TRAC, the lymphotoxin gene LTB and the interleukin-7 receptor gene IL7R. The B-cell signature holds MS4A1 (CD20), CD79A of the B-cell receptor complex, the tetraspanin CD37, and CD74 and HLA-DRA of MHC class II antigen presentation, a function that B cells share with monocytes and dendritic cells. The myeloid signature holds LST1, the calprotectin genes S100A8 and S100A9, the protease gene CTSS and the Fc receptor gene FCER1G.
Score each cell with WAGGR and AUCell¶
Both methods take the gene sets, the cells to score and the features that the signature genes are matched against. Indexing a run by an output name returns an ArtifactRef, a reference to that saved result: run["analysis_cell_selection"] refers to the frozen selection of the run’s 3,948 analyzed cells, which later edits of the cell table cannot change. ds.features.universe(from_assay="RNA") selects every RNA feature. WAGGR scales each cell’s raw counts to a fixed total, and AUCell ranks the genes within each cell, a ranking that such scaling would not change. AUCell counts only the top 5% of that ranking, so rank every feature: ranking a smaller set, such as the highly variable genes, changes which genes count as top-ranked.
Signature genes are matched to the names of the selected features without regard to case. A gene that matches no feature is dropped without a message, and a gene that matches several, such as a symbol shared by two feature IDs, is dropped with a warning. A signature left with fewer than tmin matched genes is not scored, so check how many genes each signature matched, as the table below does. The default, tmin=5, would drop a five-gene signature that misses one gene, so the next cell sets tmin=3. Each method saves its scores in the store as an artifact, a result kept with a record of the inputs and settings that produced it, and ds.scores.load reads them back:
# Score the analyzed cells against every RNA feature, for signatures with at least 3 matched genes.
cell_selection = run["analysis_cell_selection"]
all_features = ds.features.universe(from_assay="RNA")
waggr = ds.scores.waggr(gene_sets, cell_selection, features=all_features, tmin=3)
aucell = ds.scores.aucell(gene_sets, cell_selection, features=all_features, tmin=3)
# Read both saved results as tables of cells by signatures, in one signature order.
score_sources = ["T_cell", "B_cell", "Myeloid"]
waggr_result = ds.scores.load(waggr, sources=score_sources)
aucell_result = ds.scores.load(aucell, sources=score_sources)
waggr_scores = waggr_result.to_pandas()
aucell_scores = aucell_result.to_pandas()
# Print how many top-ranked genes AUCell counts and the total that WAGGR scales each cell's counts to.
n_up = ds.artifacts.load(aucell).attrs["n_up"]
size_factor = ds.artifacts.load(waggr).attrs["size_factor"]
print(
f"{len(aucell_scores):,} cells scored. AUCell counts the top {n_up:,} of "
f"{ds.RNA.feats.N:,} ranked genes; WAGGR scales each cell's counts to a total of "
f"{size_factor:,.0f}."
)
# Compare the matched genes, median, and maximum of each signature's scores.
pd.DataFrame(
{
"genes matched": pd.Series(waggr_result.source_sizes, index=waggr_result.source_names),
"WAGGR median": waggr_scores.median(),
"WAGGR max": waggr_scores.max(),
"AUCell median": aucell_scores.median(),
"AUCell max": aucell_scores.max(),
}
).round(2)3,948 cells scored. AUCell counts the top 1,677 of 33,538 ranked genes; WAGGR scales each cell's counts to a total of 1,000.
| genes matched | WAGGR median | WAGGR max | AUCell median | AUCell max | |
|---|---|---|---|---|---|
| T_cell | 5 | 0.56 | 2.55 | 0.68 | 0.93 |
| B_cell | 5 | 0.17 | 7.28 | 0.31 | 0.98 |
| Myeloid | 5 | 0.05 | 25.16 | 0.08 | 0.99 |
Started: 2026-11-18T00:16:12.582068Z | Wall time: 19.362 s
All five genes of each signature matched. With all genes weighted equally, as here, a WAGGR score is the mean expression of the signature genes in counts per 1,000 counts of the cell: in the cell with the highest myeloid score, 25.16, the five myeloid genes average 25 counts per 1,000. An AUCell score adds a share for each signature gene that ranks among the cell’s top 1,677 genes: for a five-gene signature, about 0.2 for a gene at the top of the ranking, less for a gene further down, and nothing for a gene below rank 1,677. A score near 1, such as the maxima of 0.93 to 0.99, therefore needs all five genes near the top.
Map the scores on the UMAP¶
Name the broad cell type of each cluster as the PBMC analysis does from marker genes: CD14 monocytes for cluster 2, CD16 monocytes for the 25 cells of cluster 10, and pDC-like cells, which resemble plasmacytoid dendritic cells, for cluster 11. Save the names and the scores as columns of the cell table, and color the run’s UMAP, run["umap"], by them. The AUCell panels share one scale from 0 to 1, and each WAGGR panel has its own:
# Name the broad cell type of each cluster, as the PBMC analysis does from marker genes.
cell_type_by_cluster = {
"1": "T cells",
"2": "CD14 monocytes",
"3": "T cells",
"4": "T cells",
"5": "NK cells",
"6": "B cells",
"7": "B cells",
"8": "T cells",
"9": "NK cells",
"10": "CD16 monocytes",
"11": "pDC-like cells",
"12": "platelets",
}
clusters = run.cells.fetch("clusters").astype(str)
cell_type = pd.Series(clusters).map(cell_type_by_cluster).to_numpy()
# Mark the run's analyzed cells in a column, and save the cell types and scores to those rows, keyed by cell ID.
cell_ids = ds.cells.fetch_all("ids")
ds.cells.insert(
"analyzed", pd.Series(run.cells.fetch_all("I").astype(bool), index=cell_ids), overwrite=True
)
ds.cells.insert(
"pbmc_cell_type",
pd.Series(cell_type, index=run.cells.fetch("ids")),
key="analyzed",
overwrite=True,
)
for method, scores in (("AUCell", aucell_scores), ("WAGGR", waggr_scores)):
# Each score row is indexed by its cell's row in the cell table.
for source in score_sources:
values = pd.Series(scores[source].to_numpy(), index=cell_ids[scores.index])
ds.cells.insert(f"{source} {method}", values, key="analyzed", overwrite=True)
# Give each cell type one color, shared by the UMAP and the scatter plots.
cell_type_colors = {
"T cells": "#0072b2",
"NK cells": "#56b4e9",
"B cells": "#009e73",
"CD14 monocytes": "#e69f00",
"CD16 monocytes": "#d55e00",
"pDC-like cells": "#cc79a7",
"platelets": "#000000",
}
# Lay out cell types and clusters in the first column, AUCell scores in the top row and WAGGR scores in the bottom row.
figure, axes = plt.subplots(2, 4, figsize=(10, 5.4), layout="constrained")
# List the cell types beside their panel, because the smallest populations are too small to carry a label.
ds.plots.embedding(
layout=run["umap"],
color_by=CellField("pbmc_cell_type", label="Cell type"),
categorical_scale=CategoricalScale(order=tuple(cell_type_colors), palette=cell_type_colors),
legend_loc="right",
target=axes[0, 0],
show=False,
)
# Draw the three AUCell scores on one scale from 0 to 1.
ds.plots.embedding(
layout=run["umap"],
color_by=[f"{source} AUCell" for source in score_sources],
color_scale=ColorScale(vmin=0, vmax=1),
target=axes[0, 1:],
show=False,
)
# Label each Leiden cluster on the plot, and draw each WAGGR score on its own scale.
ds.plots.embedding(
layout=run["umap"],
color_by=[run["clusters"], *[f"{source} WAGGR" for source in score_sources]],
legend_loc="on_data",
target=axes[1],
show=False,
)
axes[1, 0].set_title("Leiden cluster", fontsize=axes[0, 0].title.get_fontsize())
plt.show()
Started: 2026-11-18T00:16:31.948992Z | Wall time: 4.273 s
Each signature is brightest over its own lineage: the T-cell signature over the T cells on the left, the B-cell signature over the B cells at the top, and the myeloid signature over the CD14 monocytes on the right. For their own signatures, the B cells and the CD14 monocytes are almost uniformly near the top of the AUCell scale, while their WAGGR scores vary from cell to cell, most visibly for the myeloid signature. The B-cell AUCell panel also colors the monocytes in a middle shade, which the WAGGR panel shows only faintly.
Compare the scores between cell types¶
Take the median of each score in each cell type:
# Compare the median of each score between the cell types.
scores = pd.concat({"AUCell": aucell_scores, "WAGGR": waggr_scores}, axis=1)
medians = scores.groupby(cell_type).median().loc[list(cell_type_colors)]
medians.insert(0, "cells", pd.Series(cell_type).value_counts())
medians.round(2)| cells | AUCell | WAGGR | |||||
|---|---|---|---|---|---|---|---|
| T_cell | B_cell | Myeloid | T_cell | B_cell | Myeloid | ||
| T cells | 2385 | 0.84 | 0.21 | 0.01 | 0.76 | 0.12 | 0.03 |
| NK cells | 312 | 0.07 | 0.19 | 0.18 | 0.05 | 0.15 | 0.18 |
| B cells | 495 | 0.19 | 0.95 | 0.14 | 0.29 | 3.47 | 0.07 |
| CD14 monocytes | 704 | 0.00 | 0.55 | 0.95 | 0.00 | 1.06 | 5.85 |
| CD16 monocytes | 25 | 0.05 | 0.55 | 0.76 | 0.04 | 0.99 | 1.93 |
| pDC-like cells | 15 | 0.06 | 0.57 | 0.33 | 0.04 | 2.30 | 0.26 |
| platelets | 12 | 0.00 | 0.00 | 0.14 | 0.00 | 0.00 | 0.09 |
Started: 2026-11-18T00:16:36.226335Z | Wall time: 0.029 s
Each signature has its highest median in its own population, by both methods. Elsewhere, the AUCell median of the T-cell signature stays at or below 0.19, and that of the myeloid signature at or below 0.33, except in the CD16 monocytes of cluster 10, at 0.76. The B-cell signature also scores in other populations: its AUCell median reaches 0.55 in both monocyte populations and 0.57 in the pDC-like cells, more than half of its 0.95 in B cells, while its WAGGR median in the two monocyte populations, 1.06 and 0.99, is under a third of the B cells’ 3.47. Compare the expression and detection of each B-cell gene in B cells, CD14 monocytes and pDC-like cells:
# Average each B-cell signature gene in counts per 1,000, and find the fraction of cells in which it is detected, in three cell types.
bulk = ds.compare.compute_bulk("pbmc_cell_type", feature_label="name", count_detected=True)
b_cell_genes = gene_sets.loc[gene_sets["source"] == "B_cell", "target"]
populations = ["B cells", "CD14 monocytes", "pDC-like cells"]
pd.concat(
{
"counts per 1,000": bulk.profiles.loc[b_cell_genes, populations],
"fraction detected": bulk.detected_fraction.loc[b_cell_genes, populations],
},
axis=1,
).round(2)| counts per 1,000 | fraction detected | |||||
|---|---|---|---|---|---|---|
| group | B cells | CD14 monocytes | pDC-like cells | B cells | CD14 monocytes | pDC-like cells |
| MS4A1 | 1.11 | 0.01 | 0.01 | 0.99 | 0.03 | 0.07 |
| CD79A | 1.68 | 0.01 | 0.04 | 1.00 | 0.03 | 0.33 |
| CD37 | 2.68 | 0.58 | 0.61 | 1.00 | 0.97 | 1.00 |
| CD74 | 7.24 | 2.54 | 7.90 | 1.00 | 0.99 | 1.00 |
| HLA-DRA | 4.72 | 2.74 | 3.44 | 1.00 | 0.99 | 1.00 |
Started: 2026-11-18T00:16:36.258480Z | Wall time: 1.254 s
CD37, CD74 and HLA-DRA are detected in 97% to 100% of the CD14 monocytes and pDC-like cells, MS4A1 in only 3% and 7%, and CD79A in 3% and 33%. A cell with three of the five genes at the top of its ranking scores about three fifths of the AUCell maximum, and the medians of these populations are 0.55 and 0.57. WAGGR averages expression instead, so the two most abundant genes, CD74 and HLA-DRA, carry most of its score: 2.54 and 2.74 counts per 1,000 in the CD14 monocytes against 0.58 for CD37, and 7.24 and 4.72 in the B cells against 1.11 for MS4A1 and 1.68 for CD79A. The pDC-like cells express CD74 at 7.90 counts per 1,000, more than the B cells do, and reach a WAGGR median of 2.30, two thirds of the B cells’ 3.47. To mark B cells alone, build the signature from genes rarely detected outside B cells, such as MS4A1, which is detected in 99% of the B cells.
Compare WAGGR and AUCell cell by cell¶
Plot the two scores of each cell against each other, one panel per signature:
# Plot AUCell against WAGGR for each cell, one panel per signature, colored by cell type.
figure, axes = plt.subplots(1, 3, figsize=(10, 3.4), sharey=True, layout="constrained")
for axis, source in zip(axes, score_sources, strict=True):
for population, color in cell_type_colors.items():
cells = cell_type == population
axis.scatter(
waggr_scores.loc[cells, source],
aucell_scores.loc[cells, source],
s=4,
alpha=0.5,
color=color,
linewidths=0,
label=population,
)
axis.set_title(f"{source} signature")
axes[0].set(ylabel="AUCell score", ylim=(0, 1))
figure.supxlabel("WAGGR score (mean counts per 1,000)")
# Show one legend for the three panels, with opaque markers.
handles, labels = axes[0].get_legend_handles_labels()
legend = figure.legend(handles, labels, loc="outside right center", frameon=False, markerscale=3)
for handle in legend.legend_handles:
handle.set_alpha(1)
plt.show()
Started: 2026-11-18T00:16:37.517976Z | Wall time: 0.595 s
In each panel, AUCell rises steeply at low WAGGR scores and then levels off, because higher expression cannot lift a gene that already ranks near the top. The CD14 monocytes stay near the top of the AUCell axis for the myeloid signature across WAGGR scores up to 25, and level off near 0.55 for the B-cell signature. For the T-cell signature, the T cells fall into horizontal bands about 0.2 apart, because a cell’s AUCell score depends mostly on how many of the five genes rank near the top. Measure how widely each score spreads within the population its signature marks:
# Measure each method's 5th to 95th percentile spread in the population each signature marks.
marked_population = {"T_cell": "T cells", "B_cell": "B cells", "Myeloid": "CD14 monocytes"}
spread = {}
for source, population in marked_population.items():
spread[source] = {"population": population}
for method, table in (("AUCell", aucell_scores), ("WAGGR", waggr_scores)):
low, high = table.loc[cell_type == population, source].quantile([0.05, 0.95])
spread[source] |= {
f"{method} 5th": low,
f"{method} 95th": high,
f"{method} fold": high / low,
}
pd.DataFrame.from_dict(spread, orient="index").round(2)| population | AUCell 5th | AUCell 95th | AUCell fold | WAGGR 5th | WAGGR 95th | WAGGR fold | |
|---|---|---|---|---|---|---|---|
| T_cell | T cells | 0.52 | 0.91 | 1.75 | 0.40 | 1.34 | 3.34 |
| B_cell | B cells | 0.92 | 0.96 | 1.05 | 2.38 | 4.66 | 1.96 |
| Myeloid | CD14 monocytes | 0.86 | 0.97 | 1.13 | 1.95 | 14.36 | 7.37 |
Started: 2026-11-18T00:16:38.117413Z | Wall time: 0.028 s
WAGGR scores spread more widely than AUCell scores in all three populations. The gap is largest in the CD14 monocytes, 1.13-fold for AUCell against 7.37-fold for WAGGR. The B cells have the narrowest AUCell spread, 1.05-fold between 0.92 and 0.96, and the T cells the widest, 1.75-fold between 0.52 and 0.91, because their scores span the bands of the scatter plot.
Use AUCell to call the cells that express a program, with a cutoff chosen for each signature: the median B-cell score of the CD14 monocytes, 0.55, is above the 5th percentile of the T-cell score in T cells, 0.52, so AUCell scores of different signatures do not compare directly. Use WAGGR to rank cells by how strongly they express a program, and compare WAGGR scores only within one signature: their maxima run from 2.55 for the T-cell signature to 25.16 for the myeloid signature.
Weight genes and transform expression in WAGGR¶
WAGGR reads an optional weight column of the gene-set table: a larger weight gives a gene more influence on the score, and a negative weight subtracts a gene, such as one that the program represses. Without the column, every gene has weight one. The default mode="wmean" divides the weighted sum by the sum of the absolute weights, so the score does not grow with the number of genes in a signature, and mode="wsum" returns the weighted sum. log_transform=True takes the logarithm of the scaled counts plus one before weighting, which reduces the pull of the most abundant genes, such as CD74 in the B-cell signature. WAGGR scores compare only between results with the same mode and transformation. AUCell ignores weights.
To score S-phase and G2/M gene sets and assign each cell a cell-cycle phase, continue with Score cell-cycle activity.
- Badia-i Mompel, P., Vélez Santiago, J., Braunger, J., Geiss, C., Dimitrov, D., Müller-Dott, S., Taus, P., Dugourd, A., Holland, C. H., Ramirez Flores, R. O., & Saez-Rodriguez, J. (2022). decoupleR: ensemble of computational methods to infer biological activities from omics data. Bioinformatics Advances, 2(1). 10.1093/bioadv/vbac016
- Aibar, S., González-Blas, C. B., Moerman, T., Huynh-Thu, V. A., Imrichova, H., Hulselmans, G., Rambow, F., Marine, J.-C., Geurts, P., Aerts, J., van den Oord, J., Atak, Z. K., Wouters, J., & Aerts, S. (2017). SCENIC: single-cell regulatory network inference and clustering. Nature Methods, 14(11), 1083–1086. 10.1038/nmeth.4463