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.

Merging datasets

Merge two single-cell RNA-seq count stores into one store and analyze their cells together. The data come from the Kang et al. experiment: human peripheral blood mononuclear cells (PBMCs) from eight lupus patients, cultured for 6 hours with or without interferon beta (IFN-beta). The cells of each condition were pooled and captured as one sample. The merged store holds 18,597 cells that passed quality control, measured on 35,635 genes, and each cell carries one of 13 annotated cell types stored with the data. Without batch correction, 14 of the 18 Leiden clusters draw at least 90% of their cells from one sample. In each of the 13 cell types, interferon-stimulated genes such as ISG15 are detected in a larger share of stimulated cells than of control cells and reach higher mean levels.

Download and open the source stores

Each source store holds one sample: its RNA counts, the annotated cell type of each cell in cluster_labels, and an I column that marks the active cells, those that passed quality control and that analyses use by default.

cellsactive cellsfeatures
sample
ctrl8487848635635
stim101111011135635

Started: 2026-11-24T13:25:43.151545Z | Wall time: 18.845 s

All 10,111 stimulated cells and 8,486 of the 8,487 control cells are active, and both stores measure 35,635 RNA features.

Plan the merge

DataStoreMerge writes a new store that holds the cells of several source stores. It matches features across the sources by their IDs, and each merged assay must have the same assay type, such as RNA, in every source. The settings below name the sources ctrl and stim (names) and store each cell’s source name in a new sample_id column (source_column). prepend_text="orig" adds the prefix orig_ to each copied cell column, and reset_cell_filter=False keeps each source’s I values instead of activating every cell. Creating the merge writes nothing, and plan() reports the cells and features that the merge would write.

typecellsfeaturesshare of features in both samples
assay
RNARNA18598356351.0

Started: 2026-11-24T13:26:01.997378Z | Wall time: 0.210 s

Every feature is found in both samples, so the share is 1.0, and the merged store will hold all 18,598 cells. When sources identify the same genes with different ID schemes, such as Ensembl IDs in one and gene symbols in the other, few features match and the share falls. Pass feature_key="names" to match features by name instead: the merged store then uses the names as feature IDs and sums the counts of features that share a name within one source.

Write the merged store

dump() writes the merged counts and cell metadata. A merge does not replace a store that has been opened as a DataStore, even with overwrite=True, so this page writes into a new temporary folder on each run. Use a permanent path for your own data.

DataStore has 18597 (18598) cells with 1 assays: RNA Cell metadata: 'I', 'ids', 'names', 'RNA_I', 'RNA_nCounts', 'RNA_nFeatures', 'RNA_percentMito', 'RNA_percentRibo', 'orig_RNA_UMAP1', 'orig_RNA_UMAP2', 'orig_RNA_clusters', 'orig_RNA_leiden_cluster', 'orig_cluster_labels', 'sample_id', 'sourceRow' RNA assay has 35635 features and following metadata: 'I', 'ids', 'names', 'dropOuts', 'nCells'

Started: 2026-11-24T13:26:02.208416Z | Wall time: 8.508 s

The merged store holds 18,598 cells, of which 18,597 are active: reset_cell_filter=False left the one control cell that failed quality control inactive. sample_id holds each cell’s source, and the copied columns carry the orig_ prefix, so orig_cluster_labels holds the annotated cell types. RNA_I marks the cells that the merged RNA assay measured, here every cell. When a source lacks an assay, the merge writes zeros for that source’s cells and leaves their <assay>_I value False. Analyses of that assay then refuse those cells, and merged.select_measured_cells("<assay>") returns a cell selection without them.

cellscell_types
sample_id
ctrl848613
stim1011113

Started: 2026-11-24T13:26:10.717495Z | Wall time: 0.010 s

The merged store keeps each sample’s active cells, 8,486 control and 10,111 stimulated, and both samples contain all 13 annotated cell types.

Analyze the merged cells together

pipeline.rna runs CyteArc’s RNA recipe on the merged store and returns a PipelineRun, the durable record of each stage’s saved result. The settings below select 2,000 highly variable genes, reduce them to 25 principal components, connect each cell to its 21 nearest neighbors, embed the graph with UMAP, and cluster it with Leiden at resolution 1.0. No stage corrects for the sample, so the result shows how far the two samples differ.

The run analyzes the 18,597 active cells as they are (filtering=False), because each source’s I column already records which cells passed quality control. It skips cell-cycle scoring, doublet scoring, and marker ranking, which this comparison does not use. Doublets form within one capture, so when merged samples still need doublet scores, pass doublets={"sample_column": "sample_id"} to score each sample separately. snapshot_columns copies sample_id and orig_cluster_labels into run.cells, the run’s cell view, which keeps their values from the start of the run next to the run’s clusters and UMAP coordinates. The plots and the cluster table below read that view.

Started: 2026-11-24T13:26:10.728512Z | Wall time: 39.881 s

Color the joint UMAP by sample, by annotated cell type, and by Leiden cluster.

Three UMAP panels of the 18,597 merged cells, each with its legend beside it. Left, colored by sample (ctrl blue, stim orange): control and stimulated cells occupy separate regions; the monocytes and dendritic cells form a stimulated group at the top right and a control group at the bottom right, and the T-cell and B-cell regions on the left each divide into a stimulated side above and a control side below. Middle, colored by the 13 annotated cell types: T and NK cells lie on the left, B cells at the lower center, and monocytes and dendritic cells on the right. In both monocyte groups, CD14 monocytes form the large body, CD16 monocytes a smaller group above the stimulated group and to the right of the control group, and dendritic cells a thin strip between the two groups. Right, colored by the 18 Leiden clusters, numbered on the plot: three clusters make up each monocyte group, one each for the CD14 monocytes, the CD16 monocytes and the dendritic cells of the group's sample.

Started: 2026-11-24T13:26:50.610804Z | Wall time: 0.766 s

Control and stimulated cells occupy separate regions of the UMAP. Monocytes and dendritic cells form a stimulated group at the top right and a control group at the bottom right, and within each group the CD16 monocytes and the dendritic cells sit apart from the CD14 monocytes. The T-cell and B-cell regions each divide into a control side and a stimulated side. Count each cluster’s cells by sample and by annotated cell type to measure the split.

14 of 18 clusters draw at least 90% of their cells from one sample
cells% stimulatedmain cell type% of cluster
cluster
1292499.7CD 14 Mono86
227590.3CD 14 Mono89
3217999.8CD4 naive T91
419381.1CD4 naive T84
5140299.4CD4 Memory T72
612193.0CD4 Memory T70
7119799.2CD8 T52
88899.2B67
988999.7B82
1070098.9CD16 Mono100
116020.2CD16 Mono97
125602.9NK65
1352753.1T activated86
142495.2DC86
1520559.5Mk96
1617099.4DC94
1711263.4pDC99
187657.9Eryth97

Started: 2026-11-24T13:26:51.379585Z | Wall time: 0.028 s

Of the 18 clusters, 14 draw at least 90% of their cells from one sample. Six cell types each split into a control cluster and a stimulated cluster: the CD14 and CD16 monocytes, the dendritic cells, the CD4 naive and CD4 memory T cells, and the B cells. Stimulated cells fill a cluster in which 52% are CD8 T cells, and control cells one in which 65% are NK cells. The four clusters that mix the samples hold 53.1% to 63.4% stimulated cells, around the stimulated sample’s share of all cells (10,111 of 18,597). Their main types are activated T cells, megakaryocytes, plasmacytoid dendritic cells, and erythrocytes. Both samples contain every cell type, so the single-sample clusters reflect a change in expression rather than a cell type that only one sample has.

Compare interferon-stimulated genes and monocyte markers between samples

The dot plot below shows three interferon-stimulated genes and four monocyte markers in each annotated cell type of each sample. One of the markers, IFITM3, is itself an interferon-stimulated gene.

Dot plot with one row for each of the 13 annotated cell types in each sample, 26 rows in all, and seven gene columns: the interferon-stimulated genes ISG15, IFIT3, and MX1, and the monocyte markers CD14, S100A8, FCGR3A, and IFITM3. Dot size gives the percent of cells in which the gene is detected, and color gives the mean log-normalized expression, from dark purple at 0 to yellow at the highest mean. Every stimulated row has larger, brighter dots for the three interferon-stimulated genes than the matching control row: teal to yellow for ISG15, brightest in stimulated CD14 monocytes, CD16 monocytes, and dendritic cells, and blue to teal for IFIT3 and MX1. Control rows have mostly small, dark purple dots, with a mid-sized ISG15 dot for CD16 monocytes. Among the monocyte markers, CD14 dots are large in control CD14 and CD16 monocytes and shrink after stimulation, S100A8 is largest in control CD14 monocytes, FCGR3A is largest in CD16 monocytes of both samples, and IFITM3 is larger in every stimulated row than in the matching control row, largest and teal in stimulated monocytes and dendritic cells.

Started: 2026-11-24T13:26:51.408656Z | Wall time: 0.648 s

In each of the 13 cell types, ISG15, IFIT3, and MX1 are detected in a larger share of stimulated cells than of control cells and reach higher mean levels. ISG15 is highest in stimulated monocytes and dendritic cells. A response shared by every cell type is consistent with the split that most clusters follow, in which stimulated and control cells of the same type fall into different clusters. The monocyte markers differ between the samples as well. The dot plot returns the values it draws in marker_plot.tables["aggregate"], and the table below takes from it the percent of monocytes and dendritic cells in which each gene is detected.

ISG15CD14S100A8FCGR3AIFITM3
cell typesample
CD 14 Monoctrl3177864322
stim100235329100
CD16 Monoctrl5568388866
stim100201687100
DCctrl3421261515
stim100101514100

Started: 2026-11-24T13:26:52.057847Z | Wall time: 0.006 s

ISG15 is detected in 100% of stimulated monocytes and dendritic cells, against 31% to 55% of their control counterparts. In the control sample, S100A8 is detected in fewer CD16 monocytes than CD14 monocytes (38% against 86%), while FCGR3A (88% against 43%), IFITM3 (66% against 22%), and ISG15 (55% against 31%) are detected in more. After stimulation, CD14 monocytes shift toward that CD16 profile in three of these four genes: S100A8 falls to 53% of cells, and IFITM3 and ISG15 rise to 100%. FCGR3A, which encodes CD16, falls from 43% to 29% instead, and CD14 itself falls from 77% to 23%. Dendritic cells gain IFITM3 in the same way, from 15% to 100%.

These shifts matter when stimulated cells are labeled from control cells. The reference mapping and label transfer tutorial labels these stimulated cells from their nearest cells in the control sample, and nearly all stimulated CD14 monocytes and dendritic cells receive the CD16 monocyte label. The nearest control cells of the stimulated CD14 monocytes are the few monocytes with the strongest interferon response, and those cells carry the CD16 monocyte label.

Choose the next step

Each condition was captured separately, so the split between the samples combines the interferon response with any technical difference between the two captures, and this design cannot separate the two. Correcting the embedding for sample_id would pull the two samples together and hide the response in the embedding along with any technical difference; the counts, which the correction leaves unchanged, keep both. The Harmony batch correction tutorial corrects technical batches with Harmony and measures how well they mix, and the reference mapping and label transfer tutorial labels these stimulated cells from a reference built on the control cells. The donor-level comparisons tutorial tests differences between conditions across donors, which needs each cell’s donor; these stores pool the eight patients and carry no donor column.