A single-cell snapshot of a developing tissue holds cells at many stages of a process at once. Pseudotime orders those cells along the process, so that each gene can be followed from the start to the ends. This page orders 3,696 cells of the embryonic mouse pancreas Bastidas-Ponce et al., 2019 from Ductal cells to the four endocrine types Alpha, Beta, Delta and Epsilon, then finds the genes that change along that order in two ways: by correlating each gene with pseudotime, and by grouping genes with similar profiles into modules.
The order runs from the Ductal cells near 0 (median 0.017), through the endocrine progenitors with high Neurog3 expression in the middle (median 0.559), to the four endocrine types near 1 (medians 0.952 to 0.977). Genes high in all four endocrine types, such as Gnas (r = 0.73), correlate most strongly with pseudotime, while each hormone gene correlates weakly because only one type expresses it. Neurog3 itself does not correlate with pseudotime at all (r = 0.001) because it rises and then falls; grouping genes by profile places it in a module of 1,229 genes that peaks at pseudotime 0.51, where the progenitors sit.
Open the prepared analysis¶
# Work with numeric arrays and tables.
import numpy as np
import pandas as pd
# Run CyteArc analyses, with helpers that pick the cell column and the expression scale that plots color by.
import cytearc
from cytearc.plotting import CellField, NormalizationSpec
# Keep routine logs and progress bars out of the results.
cytearc.configure_output(level="WARNING", progress=False)
# Download the prepared example store.
dataset = cytearc.datasets.connect("cytearc_docs").download_dataset(
name="bastidas-ponce_4K_pancreas-d15_rnaseq",
destination="cytearc_datasets",
zarr=True,
)
# Open the store and its saved RNA analysis.
ds = cytearc.DataStore(f"{dataset}/data.zarr", nthreads=4)
analysis_run = ds.pipeline.open(label="rna")
# Keep the neighbor graph and the full feature selection of the saved analysis.
graph = analysis_run["connectivity_map"]
all_features = analysis_run["feature_universe"]
# Show the store's cells, assays and metadata columns.
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-24T13:04:32.910148Z | Wall time: 9.316 s
The store holds 3,696 cells and 27,998 genes. Its saved rna analysis supplies what the steps below reuse: the neighbor graph, the UMAP and a feature selection that holds every gene. ds.pipeline.open returns that run, and indexing the run by the name of one of its outputs, such as analysis_run["connectivity_map"], returns that output as an artifact reference, a handle to an immutable saved result that later calls take as input. The clusters column holds the cell types that the authors published, not clusters computed by the run. Besides Ductal cells and the Alpha, Beta, Delta and Epsilon endocrine cells, the published types include Pre-endocrine cells and two groups of endocrine progenitors (EP), Ngn3 low EP and Ngn3 high EP, named for their low or high expression of Neurog3, which is also called Ngn3.
Choose the source and the sinks¶
CyteArc’s pseudotime takes the start and the ends of the process as input rather than finding them. It uses population balance analysis Weinreb et al., 2018, which treats the source as where cells enter the process and the sinks as where they leave it, and solves on the neighbor graph for a potential: one value per cell that rises from the source to the sinks. The source and sinks enter as a source-sink vector, which gives each cell a weight: negative weights mark the source, positive weights the sinks, and the weights sum to zero. Here the Ductal cells are the source and the four published endocrine types are the sinks, the same source and sinks that the fate mapping and lineage dynamics tutorials use. The source cells share a total weight of -1 and the sink cells a total of +1, so the two ends weigh the same although they differ in size.
# Read the published cell type of each cell in the analysis.
annotations = ds.cells.fetch("clusters", key="I")
# Name the four candidate endocrine fates.
fates = ["Alpha", "Beta", "Delta", "Epsilon"]
# Mark the source population and the pooled sinks.
source = annotations == "Ductal"
sink = np.isin(annotations, fates)
# Share a total weight of -1 among the source cells and +1 among the sink cells.
source_sink_vector = np.zeros(len(annotations), dtype=float)
source_sink_vector[source] = -1.0 / source.sum()
source_sink_vector[sink] = 1.0 / sink.sum()
# Check the size and the total weight of each end.
pd.DataFrame(
{
"cells": [source.sum(), sink.sum()],
"total weight": [
source_sink_vector[source].sum(),
source_sink_vector[sink].sum(),
],
},
index=["source: Ductal", "sinks: Alpha, Beta, Delta, Epsilon"],
).round(6)| cells | total weight | |
|---|---|---|
| source: Ductal | 916 | -1.0 |
| sinks: Alpha, Beta, Delta, Epsilon | 1284 | 1.0 |
Started: 2026-11-24T13:04:42.226969Z | Wall time: 0.011 s
The source holds 916 Ductal cells and the sinks 1,284 endocrine cells; every other cell has weight 0.
Score pseudotime¶
trajectory.pseudotime solves for the potential on the saved graph and rescales it so that the cell with the lowest potential scores 0 and the cell with the highest scores 1. It scores one connected component of the graph, by default the largest or, with component_policy="sources", the one that holds the most source cells, and marks the cells outside that component as invalid in the valid array of the loaded result. The plot shows pseudotime beside the published cell types; color_by takes the pseudotime artifact reference directly, so the scores need no column in the cell table.
# Score pseudotime with the chosen source and sinks.
pseudotime_ref = ds.trajectory.pseudotime(
graph, ss_vec=pd.Series(source_sink_vector, index=ds.cells.fetch("ids", key="I"))
)
# Load the scores, and count the cells of each connected component of the graph.
pseudotime = ds.trajectory.load_pseudotime(pseudotime_ref)
print(
f"Component sizes: {pseudotime.component_sizes}; "
f"scored cells: {pseudotime.valid.sum()}"
)
# Compare the published cell types with pseudotime on the saved UMAP.
ds.plots.embedding(
layout=analysis_run["umap"],
color_by=[CellField("clusters", label="published cell type"), pseudotime_ref],
sort_values=True,
n_columns=2,
)Component sizes: (3696,); scored cells: 3696

Started: 2026-11-24T13:04:42.238765Z | Wall time: 0.704 s
All 3,696 cells form one connected component, so every cell is scored. On the UMAP, pseudotime rises from the Ductal and Ngn3 low EP cells on the right, along the arc of Ngn3 high EP cells across the top, to the Pre-endocrine cells and the four endocrine types on the left.
# Summarize the scores within each published cell type, in order of the median.
scored = pd.DataFrame({"cell type": annotations, "pseudotime": pseudotime.values})
(
scored[pseudotime.valid]
.groupby("cell type")["pseudotime"]
.describe()[["count", "25%", "50%", "75%"]]
.sort_values("50%")
.round(3)
.astype({"count": int})
)| count | 25% | 50% | 75% | |
|---|---|---|---|---|
| cell type | ||||
| Ductal | 916 | 0.009 | 0.017 | 0.022 |
| Ngn3 low EP | 262 | 0.021 | 0.036 | 0.073 |
| Ngn3 high EP | 642 | 0.386 | 0.559 | 0.636 |
| Pre-endocrine | 592 | 0.828 | 0.890 | 0.929 |
| Epsilon | 142 | 0.933 | 0.952 | 0.967 |
| Delta | 70 | 0.953 | 0.957 | 0.957 |
| Alpha | 481 | 0.968 | 0.975 | 0.979 |
| Beta | 591 | 0.965 | 0.977 | 0.990 |
Started: 2026-11-24T13:04:42.944088Z | Wall time: 0.012 s
The medians follow the published stages in order: Ductal 0.017, Ngn3 low EP 0.036, Ngn3 high EP 0.559 and Pre-endocrine 0.890, then Epsilon 0.952, Delta 0.957, Alpha 0.975 and Beta 0.977. Ngn3 low EP cells score almost as low as Ductal cells, so the graph barely separates the two. Ngn3 high EP cells spread across the middle of the range, with quartiles at 0.386 and 0.636, so the ordering places most of the transition from progenitor to endocrine cell within this population. Pseudotime measures position on the graph, not elapsed time: the gap between two populations need not match how long the transition takes.
Find genes that change along pseudotime¶
trajectory.markers computes Pearson’s correlation r between pseudotime and each gene’s expression, normalized for library size without a log transform, over the scored cells, and adjusts the p-values for the false discovery rate over the tested genes Benjamini & Hochberg, 1995. Genes expressed in fewer than 10 cells (min_cells) are not tested and have no p-value.
# Correlate each gene's expression with pseudotime across the scored cells.
marker_ref = ds.trajectory.markers(pseudotime_ref, features=all_features, min_cells=10)
markers = ds.trajectory.load_markers(marker_ref)
# Keep the tested genes and rank them from the most positive correlation down.
tested = markers.table.dropna(subset=["p_value_adjusted"]).set_index("feature_name")
tested["rank"] = tested["r_value"].rank(ascending=False).astype(int)
significant = (tested["p_value_adjusted"] < 0.05).sum()
print(
f"{len(tested):,} of {len(markers.table):,} genes tested; "
f"{significant:,} with an adjusted p-value below 0.05"
)
# Show the ten strongest positive and the ten strongest negative correlations.
pd.concat(
{
"increasing": tested["r_value"].nlargest(10).reset_index(),
"decreasing": tested["r_value"].nsmallest(10).reset_index(),
},
axis=1,
).round(2)13,821 of 27,998 genes tested; 9,388 with an adjusted p-value below 0.05
| increasing | decreasing | |||
|---|---|---|---|---|
| feature_name | r_value | feature_name | r_value | |
| 0 | Gnas | 0.73 | Spp1 | -0.83 |
| 1 | Aplp1 | 0.73 | Rpl13 | -0.82 |
| 2 | Cpe | 0.73 | Rps19 | -0.81 |
| 3 | Fam183b | 0.67 | Rps8 | -0.81 |
| 4 | Hmgn3 | 0.64 | Dbi | -0.80 |
| 5 | Bex2 | 0.62 | Rpl32 | -0.78 |
| 6 | Pcsk1n | 0.62 | Rps4x | -0.78 |
| 7 | Ubb | 0.60 | Rpl12 | -0.77 |
| 8 | Rap1b | 0.60 | Rps2 | -0.75 |
| 9 | Scgn | 0.59 | Mgst1 | -0.75 |
Started: 2026-11-24T13:04:42.956591Z | Wall time: 1.327 s
Of the 27,998 genes, 13,821 reach the 10-cell minimum and are tested, and 9,388 of those have an adjusted p-value below 0.05. Gnas, Aplp1 and Cpe correlate most strongly, each with r = 0.73, and three of the top ten, Cpe, Pcsk1n and Scgn, take part in processing and secreting hormones. The strongest negative correlations are those of Spp1 (r = -0.83), which the ductal epithelium expresses, seven ribosomal protein genes (r = -0.82 to -0.75), Dbi and Mgst1.
The hormone genes of the four endocrine types, Gcg (Alpha), Ins1 (Beta), Sst (Delta) and Ghrl (Epsilon), are missing from the top of the list. The table looks them up, with Neurog3:
# Look up Neurog3 and the hormone gene of each endocrine type.
lookup = tested.loc[
["Neurog3", "Gcg", "Ins1", "Sst", "Ghrl"],
["r_value", "p_value_adjusted", "rank"],
]
# Round r, and show each adjusted p-value to two significant digits.
lookup.round({"r_value": 3}).assign(
p_value_adjusted=lookup["p_value_adjusted"].map("{:.2g}".format)
)| r_value | p_value_adjusted | rank | |
|---|---|---|---|
| feature_name | |||
| Neurog3 | 0.001 | 0.97 | 7821 |
| Gcg | 0.224 | 2.4e-42 | 587 |
| Ins1 | 0.181 | 1.3e-27 | 902 |
| Sst | 0.089 | 1.7e-07 | 2565 |
| Ghrl | 0.141 | 3.7e-17 | 1400 |
Started: 2026-11-24T13:04:44.284672Z | Wall time: 0.004 s
The hormone genes correlate weakly with pseudotime, from r = 0.089 for Sst at rank 2,565 of 13,821 to r = 0.224 for Gcg at rank 587, and Neurog3 does not correlate at all (r = 0.001, adjusted p-value 0.97). Sst’s weak correlation still has an adjusted p-value of : across 3,696 cells, weak trends reach significance, so r, not the p-value, says how closely a gene follows pseudotime. Mapping each gene beside pseudotime shows why the hormone genes and Neurog3 correlate weakly, with Gnas for comparison:
# Map pseudotime beside the log1p expression of these genes and of Gnas.
ds.plots.embedding(
layout=analysis_run["umap"],
color_by=[pseudotime_ref, "Neurog3", "Gcg", "Ins1", "Sst", "Ghrl", "Gnas"],
normalization=NormalizationSpec(transform="log1p"),
n_columns=4,
)
Started: 2026-11-24T13:04:44.289556Z | Wall time: 0.609 s
Each hormone gene is confined to its own endocrine type. A pooled pseudotime puts all four types at the end of one axis, so each hormone gene is off in most late cells, which keeps its correlation low, while Gnas, high in all four types, correlates strongly. The hormones of the two smallest types correlate least: Sst of the 70 Delta cells (r = 0.089) and Ghrl of the 142 Epsilon cells (r = 0.141). Neurog3 is high along the arc of Ngn3 high EP cells, where pseudotime is in the middle of its range, and low on both sides, so it has no overall trend for a correlation to find. The modules below find transient genes such as Neurog3.
Group genes into expression modules¶
Correlation finds steady trends and misses genes that peak partway. trajectory.aggregation instead builds a profile of each gene along pseudotime and groups genes with similar profiles into modules:
It sorts the scored cells by pseudotime, smooths each gene’s normalized expression with a centered rolling mean over 200 cells (
window_size), and standardizes it.It splits the sorted cells into 50 bins (
chunk_size) that each hold the same number of cells, and averages each gene within each bin.It drops the genes whose mean normalized expression does not exceed
min_expor whose smoothed profile is flat, which leaves 12,455 genes, fewer than the 13,821 that the correlation tested.It clusters a nearest-neighbor graph of the profiles into 10 modules (
n_clusters), numbered in order of the median of their genes’ peak bins.
In the heatmap, each row is a gene, each column a bin, and the bar below gives each bin’s mean pseudotime.
# Smooth each gene along pseudotime, average it in bins, and group the genes into modules.
modules_ref = ds.trajectory.aggregation(
pseudotime_ref,
features=all_features,
window_size=200,
chunk_size=50,
n_clusters=10,
)
# Draw each gene's standardized profile, with genes grouped by module.
ds.plots.pseudotime_heatmap(aggregation=modules_ref)
Started: 2026-11-24T13:04:44.900974Z | Wall time: 5.981 s
The modules form a staircase: the modules of the Ductal start, 1 to 4, are high in the first third of the columns, the Neurog3 module, 5, in a narrow band where pseudotime climbs through the middle of its range, modules 6 and 7 at the center of the heatmap and just after it, and modules 8 to 10, among them the modules of Sst, Ins1 and Gcg, in its last third. Module 2 is the exception: its genes dip across the middle columns and sit above their mean on both sides. Because every bin holds the same number of cells, the columns follow cell counts rather than pseudotime: the Ductal and Ngn3 low EP cells, a third of all cells, fill the first third of the columns, the Ngn3 high EP and Pre-endocrine cells fill the middle third, across which pseudotime climbs through most of its range, and the four endocrine types fill the last third.
To read a module, rank its genes by membership: the correlation of a gene’s profile with its module’s average profile. The next cells compute membership for every gene and summarize each module by its size, the pseudotime at which its average profile peaks, its five most typical genes, those of highest membership, and the genes named above that it holds.
# Load each gene's binned profile and module.
modules = ds.trajectory.load_aggregation(modules_ref)
genes = pd.DataFrame({"gene": modules.feature_names, "module": modules.feature_clusters})
print(f"{len(genes):,} genes in {genes['module'].nunique()} modules")
# Label each bin with its cells' mean pseudotime, splitting the sorted scores as the aggregation does.
ordered = np.sort(pseudotime.values[pseudotime.valid])
bins = np.array_split(ordered, modules.data.shape[1])
profiles = pd.DataFrame(modules.data.compute(), columns=[b.mean() for b in bins])
# Average each module's profiles, and score each gene by its correlation with the average.
module_profiles = profiles.groupby(genes["module"]).mean()
genes["membership"] = [
np.corrcoef(profile, module_profiles.loc[module])[0, 1]
for profile, module in zip(profiles.to_numpy(), genes["module"])
]12,455 genes in 10 modules
Started: 2026-11-24T13:04:50.883375Z | Wall time: 0.494 s
# Summarize each module: its size, where its average peaks, its most typical genes and the genes discussed above.
typical = genes.sort_values("membership", ascending=False).groupby("module")["gene"]
named = ["Spp1", "Neurog3", "Gcg", "Ins1", "Sst", "Ghrl", "Gnas"]
discussed = genes[genes["gene"].isin(named)]
pd.DataFrame(
{
"genes": genes.groupby("module").size(),
"peak pseudotime": module_profiles.idxmax(axis=1).round(2),
"most typical genes": typical.agg(lambda names: ", ".join(names[:5])),
"genes discussed above": discussed.groupby("module")["gene"].agg(", ".join),
}
).fillna("")| genes | peak pseudotime | most typical genes | genes discussed above | |
|---|---|---|---|---|
| module | ||||
| 1 | 956 | 0.00 | Lsm2, Cdca7l, Ptn, Dctpp1, Shmt1 | |
| 2 | 1055 | 0.00 | Polr2f, Hprt, Elovl6, Mvb12a, Pgm2 | |
| 3 | 1305 | 0.02 | Epn3, Ggt1, Bst2, Spp1, Decr1 | Spp1 |
| 4 | 1066 | 0.03 | Grb7, Clic1, Pld1, Rdx, Palld | |
| 5 | 1229 | 0.51 | Tead2, Cdk4, Mex3a, Mospd1, Magoh | Neurog3 |
| 6 | 1595 | 0.79 | Gtf2b, Nipbl, Bckdha, Cyth2, Serping1 | Ghrl |
| 7 | 604 | 0.90 | Gm43861, Vdr, Pgf, Med25, Ddc | |
| 8 | 1522 | 0.98 | Gabarapl2, Srp14, Rundc3a, Pnmal2, Tmed8 | |
| 9 | 1341 | 0.95 | 1700007K13Rik, Cbarp, Sirt3, Nmt2, Rap1b | Sst, Gnas |
| 10 | 1782 | 1.00 | Gns, Slc16a12, 2410015M20Rik, Ush1c, Abcc8 | Ins1, Gcg |
Started: 2026-11-24T13:04:51.378287Z | Wall time: 0.009 s
Modules 1 and 2 peak first, at the start of the order, and module 1 counts Shmt1 and Dctpp1, two genes of nucleotide metabolism, among its most typical genes. The Spp1 module, module 3, peaks at 0.02 among the Ductal cells. The Neurog3 module, module 5 with 1,229 genes, peaks at 0.51, where the Ngn3 high EP cells sit: the transient progenitor program that correlation missed forms a module of its own. The hormone genes fall into the late modules, in the order of their cell types’ medians: Sst, with Gnas, into module 9, which peaks at 0.95 (Delta median 0.957), and Gcg and Ins1 into module 10, which peaks at 1.00 (Alpha median 0.975, Beta 0.977). Ghrl, the hormone of the Epsilon cells (median 0.952), joins module 6, whose average peaks earlier, at 0.79, before most Pre-endocrine cells. The numbering follows the median of the genes’ own peaks, so the peaks of the module averages can fall out of order: module 8, whose genes stay above their mean from the middle of the order on, comes before the Sst module although its average peaks later, at 0.98 against 0.95. The five most typical genes of the other modules point to no single process.
The modules depend on three settings: a narrower window_size keeps brief peaks and more noise, more bins (chunk_size) resolve the order more finely, and a larger n_clusters splits the profiles into more modules. Before interpreting a module, change one setting at a time and check that the module persists.
Follow each lineage separately¶
The fate mapping tutorial computes each cell’s probability of reaching each endocrine type from the same source and sinks, and the lineage dynamics tutorial weighs cells by those probabilities to follow genes that change in one lineage only, such as the hormone genes. The lineage curves tutorial fits a curve to each lineage, and its validation checks rescore one lineage on its own subgraph, test the direction without a source and find the cells that follow no lineage.
- 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
- Weinreb, C., Wolock, S., Tusi, B. K., Socolovsky, M., & Klein, A. M. (2018). Fundamental limits on dynamic inference from single-cell snapshots. Proceedings of the National Academy of Sciences, 115(10). 10.1073/pnas.1714723115
- Benjamini, Y., & Hochberg, Y. (1995). Controlling the False Discovery Rate: A Practical and Powerful Approach to Multiple Testing. Journal of the Royal Statistical Society Series B: Statistical Methodology, 57(1), 289–300. 10.1111/j.2517-6161.1995.tb02031.x