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.

Compare biological conditions across donors

Test whether gamma-delta T cells from people with rheumatoid arthritis (RA) express six interferon-response, cytokine, cytotoxicity, and effector-memory genes differently from those of matched controls. The data are human peripheral blood mononuclear cells (PBMCs) from the Binvignat cohort, in which 18 RA donors are each matched to a control donor and the samples were sequenced in three batches Binvignat et al., 2024. Select 1,386 gamma-delta T cells of these 36 donors from 108,717 cells, test the six genes with a paired Wilcoxon signed-rank test on donor means, then sum each donor’s raw counts into a pseudobulk profile and export the profiles, with the paired design, for a genome-wide count model such as DESeq2 or edgeR.

No gene differs significantly between the conditions: the smallest p-value, 0.14 for ISG15, becomes 0.69 after correction for the six tests. For S100A4, GZMA, and ISG15, batch 3 holds the highest donor means and the largest within-pair differences, so its pairs weigh most in the tests of these genes. In most batch-3 pairs, S100A4 and GZMA are lower in the RA donor. For the count model, requiring 20 gamma-delta T cells from both donors of a pair keeps 8 of the 18 pairs, only 2 of them from batch 3.

Both analyses treat the donor, not the cell, as the replicate. Cells from one person share that person’s genotype, disease activity, treatment, and sample handling, so the 1,386 cells are not 1,386 independent observations. A test that counted cells as replicates would mistake differences between individual donors for an effect of disease and report p-values far smaller than 36 donors can support, an error called pseudoreplication.

Prepare the source data

The code downloads the published H5AD file once, checks that raw/X has the published numbers of cells and genes and that its sampled values are whole counts, converts the counts to a local Zarr store within a 6 GiB memory budget, and mounts that store: selections and test results then go to a temporary analysis store, while the counts stay in the reusable source. The first run needs network access; later runs reuse both files. The Harmony batch correction tutorial describes the dataset and its three sequencing batches, and uses the same files.

Started: 2026-11-18T00:15:55.744999Z | Wall time: 3.296 s

{'count matrix': 'raw/X', 'cells': 108717, 'genes': 21648, 'integer counts': True}

Started: 2026-11-18T00:15:59.043849Z | Wall time: 1.842 s

Started: 2026-11-18T00:16:00.889111Z | Wall time: 21.387 s

{'cells': 108717, 'genes': 21648}

Started: 2026-11-18T00:16:22.278321Z | Wall time: 3.533 s

Select gamma-delta T cells from matched pairs

The publication labels gamma-delta T cells yd T cells in fine_annot and numbers the matched RA-control pairs in pair_index_CW. The selection keeps the gamma-delta T cells that carry a pair number, and snapshot_cell_selection freezes them, returning a reference to an immutable record of exactly these cells. The test, the donor means, and the pseudobulk below all read that reference, so every result describes the same cells. The donor design keeps one row per donor with its condition, pair, and batch, and every pair must hold one control and one RA donor.

gamma-delta T cells 1424 without a pair number 38 selected cells 1386 donors 36 matched pairs 18 dtype: int64

Started: 2026-11-18T00:16:25.814795Z | Wall time: 0.263 s

Of the 1,424 gamma-delta T cells, 1,386 carry a pair number. The other 38 belong to Control07_1_C_F, the control of pair 7 and the donor that the Harmony batch correction tutorial follows through all three sequencing batches: only its batch-1 cells carry the pair number, so every donor enters the comparison from one batch. The 36 donors form 18 pairs, so the tests below have at most 18 replicates, one per pair. In every pair but one, both donors were sequenced in the same batch:

diseasepair_index_CWbatch
donor_id
Control16_1_C_Fnormal222
RA22_1_C_Frheumatoid arthritis223

Started: 2026-11-18T00:16:26.080609Z | Wall time: 0.015 s

Pair 22 matches a control from batch 2 with an RA donor from batch 3, so its difference mixes disease with batch, and the paired test has no batch term to separate them.

Test six genes on paired donor means

The six genes cover effector cytokines (IFNG, TNF), interferon-stimulated genes (IFIT2, ISG15), the cytotoxic protease granzyme A (GZMA), and S100A4, a calcium-binding protein of effector and memory T cells. CellField("disease") names the cell column that holds the conditions, and groups picks the two conditions and their order. StudyDesign names the column that identifies donors (sample_by) and the column that matches them in pairs (pair_by). With these, compare.test scales each cell’s counts to 1,000 in total, averages each gene over each donor’s cells, takes the difference between the two donors of each pair, and runs a two-sided Wilcoxon signed-rank test on those differences. Benjamini-Hochberg correction covers the six genes together. The result is saved in the analysis store, and a repeated call with the same inputs reuses it.

n_pairsstatisticp_valuep_value_adjusted
gene
IFNG1839.01.0000001.0000
IFIT21826.00.8784821.0000
TNF1857.00.8647051.0000
GZMA1863.00.3465500.6931
ISG151813.00.1394140.6931
S100A41835.00.2719480.6931

Started: 2026-11-18T00:16:26.097912Z | Wall time: 2.590 s

No gene passes an adjusted p-value of 0.05. ISG15 has the smallest p-value, 0.14, and correction for the six tests brings GZMA, ISG15, and S100A4 to the same adjusted value, 0.69.

See which way each pair moves

The test reports p-values but not the direction of each pair. compare.compute_bulk with aggr_type="mean" returns the donor means that the test compared, as a BulkProfiles record: profiles holds one row per gene and one column per donor, and columns holds n_cells, the number of cells behind each column. These means reproduce the test’s p-values, and comparing each RA donor with its control gives the direction of every pair.

RA higherRA lowerzero in both
gene
IFNG576
IFIT2648
TNF873
GZMA8100
ISG15468
S100A4774

Started: 2026-11-18T00:16:28.690861Z | Wall time: 1.877 s

No gene moves consistently: depending on the gene, the RA donor is higher in 4 to 8 pairs and lower in 4 to 10. Many pairs hold no counts at all: for IFIT2 and ISG15, neither donor of 8 pairs has a single count in its gamma-delta T cells. The n_pairs column of the test table counts all 18 pairs, but the signed-rank test leaves out pairs whose difference is zero, so it tests ISG15 on 10 pairs, 6 lower and 4 higher in RA.

Each line below joins the two donors of one pair and takes the color of the batch they were sequenced in:

Six panels, one per gene (IFNG, IFIT2, TNF, GZMA, ISG15, S100A4), plot the mean expression of each donor's gamma-delta T cells in counts per 1,000, with the control donor of each of the 18 matched pairs at left and its RA donor at right, joined by a line colored by batch: green for batch 1, orange-red for batch 2, violet for batch 3, and dashed dark gray for the one pair whose donors were sequenced in two batches. Panel titles give the paired Wilcoxon p-values, from 0.14 (adjusted 0.69) for ISG15 to 1.00 for IFNG. S100A4, GZMA, and ISG15 reach high means only in batch-3 donors, up to 3.3 counts per 1,000 for S100A4, while batch-1 and batch-2 donors stay below 0.3. Most batch-3 lines for S100A4 and GZMA fall from control to RA, and the dashed pair rises against them, from about 0.2 to 1.5 for S100A4. In the IFNG, IFIT2, and TNF panels, lines run both up and down.

Started: 2026-11-18T00:16:30.571110Z | Wall time: 0.811 s

S100A4, GZMA, and ISG15 reach high donor means only in batch 3 (violet), where most S100A4 and GZMA lines fall from control to RA. In batches 1 and 2, both donors of most pairs sit near zero for S100A4 and ISG15, while TNF runs higher there than in batch 3. Pair 22 (dashed) climbs from its batch-2 control to its batch-3 RA donor for S100A4 and GZMA, matching the gap between those batches rather than the fall seen in most batch-3 pairs. The table compares the batches:

donorsmedian counts per cellIFNGIFIT2TNFGZMAISG15S100A4
batch
114311.00.000.00.040.120.000.00
27245.00.000.00.070.100.000.08
315817.50.070.00.000.510.141.74

Started: 2026-11-18T00:16:31.384538Z | Wall time: 0.026 s

Batch 3 differs from the other two batches in both depth and expression. Its gamma-delta T cells carry a median of 818 counts each, against 311 in batch 1 and 245 in batch 2, and its median donor has 1.74 S100A4 counts per 1,000, against 0.08 or less. Because 17 of the 18 pairs sit within one batch, their differences never compare donors across batches, but the batches do not weigh equally in the test: for S100A4, GZMA, and ISG15, the largest differences come from batch-3 pairs, which take the top ranks of the signed-rank test.

Sum raw counts per donor for a count model

The signed-rank test covers six chosen genes and gives every donor mean the same weight, however many cells it averages. Testing all genes calls for a count model, such as the negative binomial models of DESeq2 and edgeR, fitted to raw counts with the donor as the replicate. With aggr_type="sum", compute_bulk adds each gene’s raw counts over a donor’s selected cells instead of averaging scaled values, so profiles holds one pseudobulk count column per donor, and columns["n_cells"] gives the cells behind each column.

IFNGIFIT2TNFGZMAISG15S100A4n_cells
donor_id
Control01_1_A_M05100015
RA01_1_A_M10010278
Control03_1_C_F00000030
RA03_1_C_F00020010

Started: 2026-11-18T00:16:31.414193Z | Wall time: 1.682 s

The profiles hold one column for each of the 36 donors and cover 13,547 of the 21,648 genes, those with at least one count in the 1,386 cells. With a few hundred counts per cell, the six tested genes are rare even in donors with many cells: the 78 cells of RA01 hold 2 S100A4 counts, and the 30 cells of Control03 hold none of the six genes.

Keep pairs with enough cells in both donors

A pseudobulk profile summed from a few cells measures its donor’s gamma-delta T cells poorly, and the paired design needs both donors of a pair. A pair stays only when both of its donors have at least 20 cells. The bars show both donors of every pair, ordered by the smaller donor:

Grouped bars give the number of gamma-delta T cells from the control (blue) and RA (orange) donor of each of the 18 matched pairs, with the pairs ordered by their smaller donor and a dashed line at the 20-cell minimum. The 10 pairs in the shaded left part have a donor below 20 cells, from 8 cells in pair 17 to 19 cells in pairs 10, 20, and 22, and are dropped. The 8 pairs at right are kept, from pair 4, whose RA donor has exactly 20 cells, to pair 8, with 56 and 84 cells. The largest donor, the RA donor of the dropped pair 20, has 109 cells.

Started: 2026-11-18T00:16:33.099216Z | Wall time: 0.302 s

minimum cells per donor01015202530
batch
1776421
2333221
3764211
two batches111000
all181714853

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

The 20-cell minimum drops 10 pairs and keeps 8. The table shows how fast pairs disappear as the minimum rises, from 18 without a minimum to 14 at 15 cells, 8 at 20, and 5 at 25. The minimum takes most from batch 3, where S100A4, GZMA, and ISG15 reach their highest levels: 2 of its 7 pairs remain at 20 cells. Set the minimum before fitting the model, because a minimum chosen after seeing the results makes the model’s p-values too small. Restrict the design and the counts to the kept pairs, and drop the genes left without counts:

donors 16 matched pairs 8 cells 716 genes with counts 11976 pairs that span two batches 0 dtype: int64

Started: 2026-11-18T00:16:33.421481Z | Wall time: 0.015 s

The 8 kept pairs hold 16 donors and 716 of the 1,386 cells, and 11,976 genes have at least one count in them. Pair 22 is gone, so both donors of every kept pair share a batch, and a pair term in the model also accounts for batch.

Export counts and the donor design

Two CSV files hold the raw counts, one row per gene and one column per donor, and the donor design, one row per donor in the same order, with each donor’s condition, pair, batch, and number of cells. Give a count-model method the raw integer counts, not normalized values: DESeq2 and edgeR estimate library sizes and dispersions from the counts themselves. Fit disease within pairs, with the design ~ pair_index_CW + disease and pair_index_CW read as a factor. CytePool tests pseudobulk profiles like these with limma, edgeR, or DESeq2.

rowscolumns
file
yd_t_cell_raw_counts.csv1197616
yd_t_cell_donor_design.csv164

Started: 2026-11-18T00:16:33.438682Z | Wall time: 0.042 s

References
  1. Binvignat, M., Miao, B. Y., Wibrand, C., Yang, M. M., Rychkov, D., Flynn, E., Nititham, J., Tamaki, W., Khan, U., Carvidi, A., Krueger, M., Niemi, E., Sun, Y., Fragiadakis, G. K., Sellam, J., Mariotti-Ferrandiz, E., Klatzmann, D., Gross, A. J., Ye, C. J., … Sirota, M. (2024). Single-cell RNA-Seq analysis reveals cell subsets and gene signatures associated with rheumatoid arthritis disease activity. JCI Insight, 9(16). 10.1172/jci.insight.178499