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.

Integrating datasets by merging

To analyse cells from several datasets together, first place their compatible assays in one datastore. DataStoreMerge aligns features, carries metadata, and records which source each cell came from. The expression values are unchanged by the merge. Batch correction, when appropriate, is a separate step; this page builds and inspects the uncorrected dataset.

Load compatible source stores

The control and interferon beta stimulated Kang PBMC stores use the same RNA feature space. These prepared stores contain cells with author-provided cell-type labels. Their I columns mark the cells that passed quality control.

Started: 2026-10-11T18:54:46.173170Z | Wall time: 5.383 s

Download the stimulated sample from the same repository.

Started: 2026-10-11T18:54:51.559564Z | Wall time: 3.814 s

Open both source stores before checking their axes.

Started: 2026-10-11T18:54:55.376524Z | Wall time: 5.552 s

Confirm assay type, cell counts, and feature counts before merging. DataStoreMerge validates the feature axes and requires every source to declare the same assay type, which the merged assay keeps; matching gene symbols alone do not establish compatible genome builds or quantification conventions.

sourceassaycellsactive cellsfeatures
0ctrlRNAassay8487848635635
1stimRNAassay101111011135635

Started: 2026-10-11T18:55:00.930984Z | Wall time: 0.024 s

Merge counts and metadata

names supplies the source labels, source_column names their metadata column, and prepend_text keeps imported metadata names distinct from columns authored in the merged store. reset_cell_filter=False copies each source’s I values into the merged store. Cells marked False are still present in the counts and metadata, but remain outside the active selection. A merge never replaces a store that a DataStore has opened, even with overwrite=True, so this example writes into a new temporary folder each time it runs.

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' RNA assay has 35635 features and following metadata: 'I', 'ids', 'names', 'dropOuts', 'nCells'

Started: 2026-10-11T18:55:00.957803Z | Wall time: 15.629 s

sample_id records the source label. Columns imported from the sources keep the orig_ prefix so their origin remains explicit. RNA_I marks the cells that the merged RNA assay measured; every cell here comes from an RNA source, so it is True for all of them. When a source lacks an assay, or measured only some of its cells with it, the merged <assay>_I column keeps that per-cell membership. Operations that read that assay’s values then refuse the cells it did not measure, whose counts are zero-filled, and merged.select_measured_cells("<assay>", cell_selection=...) keeps the measured ones; here it returns the selection unchanged, because RNA measured every cell.

The merged active population contains labelled cells from both sources.

cellscell_types
sample_id
ctrl848613
stim1011113

Started: 2026-10-11T18:55:16.589498Z | Wall time: 0.039 s

Inspect a prepared joint analysis

The merge is complete. To see what these datasets look like together, open the catalog’s prepared merged store. It uses the same merge recipe and already contains PCA, clustering, and UMAP computed without batch correction. This is a separate store from merged, so the following plots do not run an analysis on the store you just created. The saved example run is named docs_default.

['analysis_cell_selection', 'ann_index', 'cluster_selection', 'clusters', 'connectivity_map', 'embedding_initialization', 'feature_universe', 'highly_variable_features', 'input_cell_selection', 'leiden_1.0', 'neighbors', 'normalized', 'pca', 'umap']

Started: 2026-10-11T18:55:16.631321Z | Wall time: 5.088 s

The saved run links each output name to its stored artifact. Its cell selection and metadata stay fixed even if the datastore’s live metadata changes later.

Compare the source labels, the authors’ cell types, and the newly computed clusters on the same UMAP. Agreement between the latter two is useful context when interpreting source separation.

Three UMAP panels show merged control and stimulated samples, imported cell-type labels, and newly computed clusters on the same coordinates. Several cell-type regions separate by sample.

Started: 2026-10-11T18:55:21.721555Z | Wall time: 3.204 s

A table of proportions shows whether each Leiden cluster contains cells from both sources.

sourcectrlstim
cluster
10.0040.996
20.0060.994
30.0080.992
40.4430.557
50.0020.998
60.0020.998
70.9740.026
80.0100.990
90.4290.571
100.3550.645
110.0050.995
120.5120.488
130.5710.429
140.9970.003
150.9930.007
160.4160.584
170.9880.012
180.9980.002
190.9710.029
200.9940.006

Started: 2026-10-11T18:55:24.928027Z | Wall time: 0.143 s

The stimulated sample received interferon beta, and PBMC cell types do not all respond identically to that treatment. Source-associated structure can therefore include biological response as well as technical variation.

The next page, Correcting batch effects with Harmony, uses a different dataset with measured sequencing batches to compare an uncorrected analysis with Harmony. It also introduces metrics for batch mixing. Keep uncorrected counts for condition-level differential expression.