Score the S-phase and G2M-phase gene programs in 3,696 cells of the embryonic mouse pancreas Bastidas-Ponce et al., 2019, assign each cell a cell-cycle phase, and find the cycling populations. Strong S and G2M programs concentrate in three of the 12 computed Leiden clusters, made up mostly of Ductal cells: cluster 7 is 95% G2M, and clusters 8 and 11 are 84% and 89% S. Cluster 7 also holds a small group of 23 Ngn3 high endocrine progenitors (Ngn3 high EP) that includes the cells with the highest S and G2M scores. The Pre-endocrine and hormone-producing clusters are 82% to 96% G1, the phase of cells that express neither program, which includes cells that have left the cycle. Cluster 2, mostly Ductal cells, and clusters 4 and 10, mostly Ngn3 high EP cells, split between G1 and S, but each has a median S score of 0.00, and the scores published with the data call many of these S calls G1.
Open the prepared analysis¶
Download the prepared store and reopen its saved RNA analysis:
# Tabulate the scores and draw the figures.
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from matplotlib import patheffects
import cytearc
from cytearc.plotting import CategoricalScale, CellField
# Keep warnings visible and routine progress messages out of the page.
cytearc.configure_output(level="WARNING", progress=False)
# Download the prepared pancreas store with its saved RNA analysis.
dataset = cytearc.datasets.connect("cytearc_docs").download_dataset(
name="bastidas-ponce_4K_pancreas-d15_rnaseq",
destination="cytearc_datasets",
zarr=True,
)
# Open the store, where scoring saves its result, and reopen the saved analysis and its cells.
ds = cytearc.DataStore(f"{dataset}/data.zarr", nthreads=4)
analysis_run = ds.pipeline.open(label="rna")
analysis_cells = analysis_run["analysis_cell_selection"]
dsDataStore has 3696 (3696) cells with 1 assays: RNA
Cell metadata:
'I', 'ids', 'names', 'G2M_score', 'RNA_UMAP1',
'RNA_UMAP2', 'RNA_clusters', 'RNA_leiden_cluster', 'RNA_nCounts', 'RNA_nFeatures',
'RNA_percentMito', 'RNA_percentRibo', 'S_score', 'clusters', 'clusters_coarse'
RNA assay has 27998 features and following metadata:
'I', 'ids', 'names', 'dropOuts', 'highly_variable_genes',
'nCells'Started: 2026-11-14T15:42:34.159113Z | Wall time: 7.178 s
The cell table, ds.cells, listed above as cell metadata, holds the published annotation: clusters names eight cell types, and S_score and G2M_score are cell-cycle scores published with the data.
ds.pipeline.open(label="rna") reopens the saved run of ds.pipeline.rna, CyteArc’s RNA analysis recipe, without recomputing it. Indexing the run by an output name returns an artifact reference, a handle to one saved result: analysis_cell_selection is a frozen cell selection, the fixed list of cells that the analysis used; umap is the two-dimensional layout of those cells; and clusters holds their Leiden clusters. The run’s clusters and the cell table’s clusters, which the code names CellField("clusters"), hold different labels. Draw both on the saved UMAP to see which published types each computed cluster holds:
# Draw the run's computed clusters beside the published cell types on the saved UMAP.
figure, axes = plt.subplots(1, 2, figsize=(9.5, 4.6), layout="constrained")
for axis, color_by, title in zip(
axes,
(analysis_run["clusters"], CellField("clusters")),
("Computed Leiden clusters", "Published cell types"),
strict=True,
):
ds.plots.embedding(
layout=analysis_run["umap"],
color_by=color_by,
legend_loc="on_data",
target=axis,
show_titles=False,
show=False,
)
axis.set_title(title)
plt.show()
Started: 2026-11-14T15:42:41.339178Z | Wall time: 0.609 s
The Ductal cells and the Ngn3 low endocrine progenitors (Ngn3 low EP) fill the right-hand branch, the Ngn3 high EP cells the arc across the top, and the Pre-endocrine cells and the hormone-producing Alpha, Beta, Delta and Epsilon cells the left side. The 12 Leiden clusters divide the right-hand branch into clusters 2, 7, 8 and 11 and the arc into clusters 4 and 10, and they put a small group of Ngn3 high EP cells beside the arc into cluster 7.
Score the S and G2M programs¶
ds.scores.cell_cycle scores each phase in four steps:
It matches the phase’s marker genes to the assay’s gene names. By default the markers come from CyteArc’s bundled lists,
cytearc.quality_control.s_phase_genesandg2m_phase_genes, which hold Seurat’s 2019 update of the S and G2M markers in human gene symbols. Matching ignores case, so these symbols match mouse genes of the same name, and a marker renamed since the data were annotated matches its previous symbol.It ranks all genes by their mean log-normalized expression over the scored cells and cuts the ranking into bins of genes with similar means;
n_binssets their number.From each bin that holds a marker, it draws control genes at random with a fixed seed,
rand_seed, as many per bin as the shorter marker list holds.It subtracts each cell’s mean control expression from its mean marker expression.
Check which markers match the store’s gene names, with the matching function that the scorer uses:
# Match both bundled marker lists to the store's gene names, as the scorer does.
gene_names = ds.RNA.feats.fetch_all("names")
coverage = {}
for phase_name, markers in (
("S", cytearc.quality_control.s_phase_genes),
("G2M", cytearc.quality_control.g2m_phase_genes),
):
match = cytearc.quality_control.match_gene_names(gene_names, markers)
coverage[phase_name] = {
"markers": len(markers),
"not found": ", ".join(match.unmatched) or "none",
"matched by a previous symbol": ", ".join(
f"{gene} as {name}" for gene, name in match.aliases.items()
)
or "none",
}
pd.DataFrame(coverage).T| markers | not found | matched by a previous symbol | |
|---|---|---|---|
| S | 43 | none | none |
| G2M | 54 | none | PIMREG as Fam64a, JPT1 as Hn1 |
Started: 2026-11-14T15:42:41.951113Z | Wall time: 0.140 s
All 43 S markers and all 54 G2M markers match. Two G2M markers carry newer symbols than the store’s gene names and match by their previous ones: PIMREG as Fam64a and JPT1 as Hn1.
Score the cells of the saved analysis. The call saves each cell’s S score, G2M score and phase as a new cell_cycle artifact and returns its reference. A cell with both scores below zero is G1, and any other cell takes the phase with the higher score, S on a tie:
# Score both programs on the analysis cells; the result is saved as a new artifact.
cell_cycle_ref = ds.scores.cell_cycle(analysis_cells)
# Read the two scores and the assigned phase, one value per cell in the selection's order.
s_score = ds.artifacts.load_values(
cell_cycle_ref, value="s_score", cell_ids=False
).values
g2m_score = ds.artifacts.load_values(
cell_cycle_ref, value="g2m_score", cell_ids=False
).values
phase = ds.artifacts.load_values(cell_cycle_ref, cell_ids=False).values.astype(str)
# Show the first five cells with their scores and phase.
pd.DataFrame({"S score": s_score, "G2M score": g2m_score, "phase": phase}).head()| S score | G2M score | phase | |
|---|---|---|---|
| 0 | -0.024501 | -0.038461 | G1 |
| 1 | 0.020201 | -0.028616 | S |
| 2 | -0.001931 | -0.045212 | G1 |
| 3 | 0.104609 | 0.023677 | S |
| 4 | -0.006316 | -0.020066 | G1 |
Started: 2026-11-14T15:42:42.093742Z | Wall time: 1.829 s
Rows 0, 2 and 4 have both scores below zero, so those cells are G1. Row 1 has a positive S score and a negative G2M score, and row 3 has two positive scores, the higher for S, so both are S.
Find the cycling populations¶
Tabulate the phases within each computed cluster, beside the published cell type that most of the cluster’s cells carry and the median of each score:
# Read the computed clusters and the published cell types in the same cell order as the scores.
cluster = analysis_run.cells.fetch("clusters")
cell_type = ds.artifacts.load_values(
CellField("clusters"), cell_selection=analysis_cells, cell_ids=False
).values
# Give each computed cluster its size, the published type of most of its cells, and its phases.
phases = ["G1", "S", "G2M"]
type_fraction = pd.crosstab(cluster, cell_type, normalize="index")
phase_percent = 100 * pd.crosstab(cluster, phase, normalize="index")[phases]
phase_table = pd.DataFrame(
{
"cells": pd.Series(cluster).value_counts(),
"published cell type": type_fraction.idxmax(axis=1),
"type %": 100 * type_fraction.max(axis=1),
}
).join(phase_percent.add_suffix(" %"))
percent_columns = ["type %", "G1 %", "S %", "G2M %"]
phase_table[percent_columns] = phase_table[percent_columns].round().astype(int)
# Add the median of each score; adding 0.0 prints a median that rounds to -0.00 as 0.00.
for column, values in (("median S", s_score), ("median G2M", g2m_score)):
medians = pd.Series(values).groupby(cluster).median().astype(float)
phase_table[column] = medians.round(2) + 0.0
phase_table = phase_table.sort_index().rename_axis("computed cluster")
phase_table| cells | published cell type | type % | G1 % | S % | G2M % | median S | median G2M | |
|---|---|---|---|---|---|---|---|---|
| computed cluster | ||||||||
| 1 | 552 | Beta | 97 | 95 | 5 | 0 | -0.01 | -0.04 |
| 2 | 544 | Ductal | 77 | 42 | 57 | 1 | 0.00 | -0.04 |
| 3 | 449 | Alpha | 94 | 94 | 6 | 0 | -0.01 | -0.04 |
| 4 | 385 | Ngn3 high EP | 100 | 51 | 49 | 1 | 0.00 | -0.03 |
| 5 | 369 | Pre-endocrine | 84 | 91 | 9 | 0 | -0.01 | -0.04 |
| 6 | 347 | Pre-endocrine | 62 | 82 | 17 | 1 | -0.01 | -0.03 |
| 7 | 227 | Ductal | 67 | 0 | 5 | 95 | 0.02 | 0.16 |
| 8 | 213 | Ductal | 96 | 6 | 84 | 10 | 0.06 | 0.00 |
| 9 | 194 | Epsilon | 70 | 92 | 8 | 0 | -0.01 | -0.05 |
| 10 | 175 | Ngn3 high EP | 58 | 49 | 46 | 5 | 0.00 | -0.04 |
| 11 | 145 | Ductal | 83 | 0 | 89 | 11 | 0.11 | 0.02 |
| 12 | 96 | Delta | 72 | 96 | 4 | 0 | -0.01 | -0.04 |
Started: 2026-11-14T15:42:43.926282Z | Wall time: 0.086 s
Clusters 7, 8 and 11, mostly Ductal cells, are the only clusters with fewer than 10% G1 cells. Cluster 7 is 95% G2M and clusters 8 and 11 are 84% and 89% S; their medians, 0.16 for G2M in cluster 7 and 0.06 and 0.11 for S in clusters 8 and 11, are the only medians of either score above 0.02. The Pre-endocrine clusters 5 and 6 and the hormone-producing clusters 1 (Beta), 3 (Alpha), 9 (Epsilon) and 12 (Delta) are 82% to 96% G1. Cluster 2, mostly Ductal cells, and the Ngn3 high EP clusters 4 and 10 split between G1 and S, with 42% to 51% G1, but each has a median S score of 0.00: many of their S calls rest on S scores close to zero.
Draw the phases on the UMAP, with clusters 7, 8 and 11 numbered, beside a plot of every cell’s S and G2M scores:
# Count the cells of each phase, and give each phase one color in both panels.
phase_counts = pd.Series(phase).value_counts()[phases]
print(
", ".join(
f"{name}: {count:,} cells ({count / len(phase):.0%})"
for name, count in phase_counts.items()
)
)
phase_colors = dict(zip(phases, ("#0072B2", "#009E73", "#E69F00"), strict=True))
figure, (umap_axis, score_axis) = plt.subplots(
1, 2, figsize=(9.5, 4.6), layout="constrained"
)
# Left: color the UMAP by phase and number the clusters with fewer than 10% G1 cells.
ds.plots.embedding(
layout=analysis_run["umap"],
color_by=cell_cycle_ref,
categorical_scale=CategoricalScale(order=tuple(phases), palette=phase_colors),
target=umap_axis,
show_titles=False,
show_legend=False,
show=False,
)
umap = analysis_run.cells.to_pandas_dataframe(["umap_1", "umap_2"])
for cluster_id in phase_table.index[phase_table["G1 %"] < 10]:
x, y = umap[cluster == cluster_id].median()
umap_axis.text(
x,
y,
str(cluster_id),
ha="center",
va="center",
fontsize=11,
fontweight="bold",
path_effects=[patheffects.withStroke(linewidth=3, foreground="white")],
)
umap_axis.set_title("Assigned phase")
# Right: place each cell by its two scores and draw the lines where the phase changes.
for name, color in phase_colors.items():
in_phase = phase == name
score_axis.scatter(
s_score[in_phase],
g2m_score[in_phase],
s=6,
color=color,
edgecolors="white",
linewidths=0.2,
label=name,
rasterized=True,
)
low = min(s_score.min(), g2m_score.min()) - 0.02
high = max(s_score.max(), g2m_score.max()) + 0.02
for x, y in (([0, 0], [low, 0]), ([low, 0], [0, 0]), ([0, high], [0, high])):
score_axis.plot(x, y, color="0.25", linewidth=1)
score_axis.set(
xlim=(low, high),
ylim=(low, high),
aspect="equal",
xlabel="S score",
ylabel="G2M score",
title="Scores and the phase rule",
)
score_axis.legend(title="Phase", loc="lower right", markerscale=3, frameon=False)
plt.show()G1: 2,355 cells (64%), S: 1,067 cells (29%), G2M: 274 cells (7%)

Started: 2026-11-14T15:42:44.014150Z | Wall time: 0.345 s
Of the 3,696 cells, 2,355 (64%) are G1, 1,067 (29%) S and 274 (7%) G2M. On the UMAP, the G2M cells of cluster 7 and the S cells of clusters 8 and 11 lie side by side at the bottom of the right-hand branch, and S and G1 cells mix in similar numbers along the rest of the branch and the arc. The small group of Ngn3 high EP cells beside the arc is S along its stalk and G2M at its tip, and a few more G2M cells line the inner edge of the arc. In the score plot, the G1 cells form a compact cloud with both scores slightly below zero. The S cells spread to the right of the vertical line, many of them close to it, and the G2M cells rise above the diagonal, where the G2M score exceeds the S score.
Draw each score on the UMAP to see where each program is strongest:
# Draw each score on the saved UMAP, with the highest-scoring cells on top.
figure, axes = plt.subplots(1, 2, figsize=(9.5, 4.2), layout="constrained")
for axis, values, title in (
(axes[0], s_score, "S score"),
(axes[1], g2m_score, "G2M score"),
):
order = np.argsort(values)
points = axis.scatter(
umap["umap_1"].to_numpy()[order],
umap["umap_2"].to_numpy()[order],
c=values[order],
s=4,
cmap="viridis",
rasterized=True,
)
axis.set(title=title, xticks=[], yticks=[])
axis.spines[["top", "right"]].set_visible(False)
figure.colorbar(points, ax=axis, label=title)
plt.show()
Started: 2026-11-14T15:42:44.360635Z | Wall time: 0.231 s
Within the right-hand branch, the S score is highest in clusters 8 and 11 and the G2M score in cluster 7. The highest values of both scores fall in the small group beside the arc: the S score peaks along its stalk and the G2M score at its tip. Split cluster 7, which holds that group, by published cell type:
# Split cluster 7 by published cell type, with the phases and median scores of each type.
in_cluster_7 = cluster == 7
type_in_cluster_7 = cell_type[in_cluster_7]
split = pd.crosstab(type_in_cluster_7, phase[in_cluster_7]).reindex(
columns=phases, fill_value=0
)
split.insert(0, "cells", split.sum(axis=1))
for column, values in (("median S", s_score), ("median G2M", g2m_score)):
medians = pd.Series(values[in_cluster_7]).groupby(type_in_cluster_7).median()
split[column] = medians.round(2) + 0.0
split.rename_axis(index="published cell type in cluster 7", columns=None).sort_values(
"cells", ascending=False
)| cells | G1 | S | G2M | median S | median G2M | |
|---|---|---|---|---|---|---|
| published cell type in cluster 7 | ||||||
| Ductal | 153 | 0 | 3 | 150 | 0.02 | 0.15 |
| Ngn3 low EP | 50 | 0 | 0 | 50 | 0.01 | 0.18 |
| Ngn3 high EP | 23 | 0 | 8 | 15 | 0.08 | 0.19 |
| Pre-endocrine | 1 | 0 | 0 | 1 | -0.01 | 0.16 |
Started: 2026-11-14T15:42:44.594285Z | Wall time: 0.015 s
Cluster 7 holds 23 Ngn3 high EP cells, which make up nearly all of the small group beside the arc: 8 are S and 15 G2M, with a median S score of 0.08 and a median G2M score of 0.19, against 0.00 and -0.03 in cluster 4, which is 100% Ngn3 high EP. The 153 Ductal and 50 Ngn3 low EP cells of cluster 7 are almost all G2M.
Compare with the published scores¶
Correlate the new scores with the published S_score and G2M_score columns, and assign phases from both with the same rule:
# Correlate the new scores with the published S_score and G2M_score columns of the same cells.
published = {
column: ds.artifacts.load_values(
CellField(column, kind="continuous"),
cell_selection=analysis_cells,
cell_ids=False,
).values
for column in ("S_score", "G2M_score")
}
print(f"S score: Pearson r = {np.corrcoef(s_score, published['S_score'])[0, 1]:.3f}")
print(
f"G2M score: Pearson r = {np.corrcoef(g2m_score, published['G2M_score'])[0, 1]:.3f}"
)
# Apply the same phase rule to the published scores and compare the two calls cell by cell.
published_phase = cytearc.quality_control.assign_cell_cycle_phase(
published["S_score"], published["G2M_score"]
)
print(f"Same phase: {np.mean(published_phase == phase):.1%} of {len(phase):,} cells")
pd.crosstab(
pd.Series(phase, name="phase from the new scores"),
pd.Series(published_phase, name="phase from the published scores"),
margins=True,
margins_name="total",
).reindex(index=[*phases, "total"], columns=[*phases, "total"], fill_value=0)S score: Pearson r = 0.979
G2M score: Pearson r = 0.984
Same phase: 86.1% of 3,696 cells
| phase from the published scores | G1 | S | G2M | total |
|---|---|---|---|---|
| phase from the new scores | ||||
| G1 | 2355 | 0 | 0 | 2355 |
| S | 501 | 560 | 6 | 1067 |
| G2M | 5 | 2 | 267 | 274 |
| total | 2861 | 562 | 273 | 3696 |
Started: 2026-11-14T15:42:44.611255Z | Wall time: 0.069 s
The two sets of scores correlate at r = 0.979 for S and 0.984 for G2M, and their phases agree for 86.1% of the cells. Every cell that the new scores call G1 is G1 by the published scores too, and 267 of the 274 G2M cells are G2M by both. The S calls differ: the published scores call 562 cells S, about half as many as the new scores’ 1,067, and 501 of the new S calls are G1 by the published scores. Count each computed cluster’s S calls and how many of them the published scores call G1:
# Count each computed cluster's S calls and how many of them the published scores call G1.
is_s = phase == "S"
pd.DataFrame(
{
"S calls": pd.Series(cluster[is_s]).value_counts(),
"G1 by the published scores": pd.Series(
cluster[is_s & (published_phase == "G1")]
).value_counts(),
}
).fillna(0).astype(int).sort_index().rename_axis("computed cluster").T| computed cluster | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| S calls | 30 | 312 | 29 | 187 | 32 | 58 | 11 | 179 | 15 | 81 | 129 | 4 |
| G1 by the published scores | 30 | 146 | 24 | 122 | 32 | 51 | 0 | 21 | 13 | 58 | 0 | 4 |
Started: 2026-11-14T15:42:44.682375Z | Wall time: 0.009 s
The published scores call G1 none of the S calls in clusters 7 and 11 and only 21 of the 179 in cluster 8, the clusters with strong cell-cycle programs. They call G1 146 of the 312 S calls in cluster 2, 122 of the 187 in cluster 4 and 58 of the 81 in cluster 10, and nearly all of the few S calls in the Pre-endocrine and hormone-producing clusters, such as all 30 in cluster 1. Many cells have an S score close to zero, as the score plot shows, so a small difference between two sets of scores moves them across the boundary between G1 and S. CyteArc’s scorer matches Scanpy’s on these cells when both use the same control genes (comparisons with other tools). Read an S call whose S score is close to zero as uncertain, and report the continuous scores beside the phases.
Score your own data¶
By default, a ds.pipeline.rna run scores the cell cycle with the same scorer in its cell_cycle stage and keeps the scores and phases as the run’s s_score, g2m_score and cell_cycle_phase cell fields. The saved run on this store was made without that stage, so this page calls the scorer directly; the pipeline reference lists the stage’s settings. A marker that matches no gene name is left out with a warning, and a phase with no match stops the call with an error; to score an assay whose gene names are not symbols, pass your own lists as s_genes and g2m_genes. Each call draws its control genes from the expression bins of the cells it scores, so scores from calls on different cells are not on one scale; score the samples that you want to compare in one call.
Gene-set scoring scores other gene programs in each cell with AUCell and WAGGR, and fate mapping scores how differentiated each of these pancreas cells is with ds.scores.potency.
- Bastidas-Ponce, A., Tritschler, S., Dony, L., Scheibner, K., Tarquis-Medina, M., Salinno, C., Schirge, S., Burtscher, I., Böttcher, A., Theis, F. J., Lickert, H., & Bakhti, M. (2019). Comprehensive single cell mRNA profiling reveals a detailed roadmap for pancreatic endocrinogenesis. Development, 146(12), dev173849. 10.1242/dev.173849