Combine datasets¶
Combine merges two or more files into one dataset, with a sample column naming each cell's source. Use it when you want one clustering, one differential expression test or one figure across samples: timepoints of a tissue, replicates, or several sections of one slide.
Where to find it
File → Combine datasets… (or File → Load… and switch the dialog's mode toggle to Combine)
How it works¶
Skopia reads every input, keeps the genes they all share, and stacks the cells. What happens to coordinates depends on what the inputs carry:
| Inputs | Mode | Coordinates in the result |
|---|---|---|
| Every input has spatial coordinates | spatial |
Sections placed left to right along x, separated by a gap; only X_spatial is kept in .obsm |
| Anything else (at least one input without coordinates) | concat |
Rows concatenated, no geometry invented; .obsm arrays present in every input are kept, one-sided ones dropped |
An input counts as spatial when its .obsm holds the array named by uns['skopia_spatial_key'], or else spatial, or else X_spatial (checked in that order), with at least two columns.
In spatial mode each section's x coordinates are shifted so it starts where the previous one ended, plus a gap. The gap is a percentage of the mean section width (default 5%). Per-file PCA and UMAP are dropped in this mode because they were computed on different gene spaces; run PCA and UMAP again on the combined data.
In concat mode, an embedding every input shares (a common X_pca, say) survives, so the combined dataset opens with something to look at. An embedding only some inputs have cannot describe the combined cells, so it is dropped.
In both modes, each input's .raw, .varm, .obsp and .uns are dropped.
Which genes survive¶
Only genes present in every input survive (the intersection of the .var indices). If no gene is shared, the combine is refused. A common cause is that the files use different identifiers, Ensembl IDs in one and symbols in another; load each file, pick the same identifier column with the Gene IDs: select in the Genes panel, export it as .h5ad, and combine the exports (The Genes panel).
Cell names¶
Cell names are made unique by appending the sample label: a cell AAACCTG-1 from the input labeled hind becomes AAACCTG-1-hind.
Run it¶
- Open File → Combine datasets….
- Click files in the browser to add them to the list. Every format File → Load… accepts works here, in any mixture:
.h5ad, 10x.h5, Visium HDfeature_slice.h5, Seurat.rds, 10x matrix folders and*_matrix.mtx(.gz)trios (Load your data). You need at least two. - Edit each file's label if you want. The label becomes that file's value in the
samplecolumn; it defaults to the dataset's name (filename without extension, folder name, or trio prefix). Duplicate labels get a numeric suffix. - For spatial inputs, set Gap: (percentage of mean section width, 0 to 50, default 5). It is ignored in concat mode.
- Open Columns to keep and review what happens to each
.obsand.varcolumn (next section). - Choose Load into: (New dataset to keep what is already loaded).
- Click Combine N sections (the button counts the files in the list, spatial or not).
The combined dataset behaves like any other: color by sample, run preprocessing and clustering on it, or compare samples with differential expression.
Choose which columns survive¶
Inputs often share column names that do not share meaning. Two files each carrying seurat_clusters from independent clusterings are the dangerous case: cluster 3 in one has nothing to do with cluster 3 in the other, and pooling them into one column invents a comparison nobody made. Columns to keep lists every .obs and .var column across the inputs before anything is combined, shows which datasets carry each one, and lets you decide. Reading the columns does not load the expression matrices, so the list appears quickly even for large files.
Cell (.obs) columns¶
| Choice | Result |
|---|---|
| one column | One column under the original name; each cell keeps its own value |
| one per dataset | One column per input, named <column>__<label>, empty for the other inputs' cells |
| drop | Not carried into the combined dataset |
| Same as → another column | Pools this column into the other one, under the other column's name |
Each row has a suggested default. Hover the row to see the reason; a choice you change away from the suggestion is outlined in amber.
How Skopia suggests a default:
| Column | Default | Why |
|---|---|---|
| Held by only one input | one column | Nothing to collide with |
| Kinds differ between inputs (labels in one, numbers in another) | one per dataset | Types differ across datasets |
Per-cell measurement (float, or integer with more than 50 distinct values), e.g. nCount_RNA, percent.mt |
one column | A measurement means the same thing in every dataset |
| Integer with 50 or fewer distinct values | one per dataset | Looks like ids (clusters stored as integers), not a measurement |
| Label column whose vocabularies overlap: labels shared by every holder, divided by all labels seen, is at least 0.5 | one column | One annotation scheme applied to each file; the row shows the count, e.g. 8/9 labels shared |
Label column whose labels are all ids (0, 1.0, C3, cl12) |
one per dataset | Cluster ids overlap by construction and mean nothing across files |
| Any other label column | one per dataset | Labels from independent analyses are not comparable |
The 0.5 overlap threshold is a judgment call: two annotations of one scheme on different tissues share most names, rarely all. One input whose labels differ sharply from the rest pulls the overlap down, which errs toward keeping columns apart.
Same labels under two names¶
When the same annotation is called celltype in one file and cell_type in another, the select offers a Same as group listing the other label columns it could be pooled with, with the label overlap for each. Candidates that look like the same scheme (named labels sharing at least half the union) are marked likely and listed first. Choosing one writes a single column under the target's name.
Skopia refuses, with a message:
- chains (pooling
aintobwhilebis pooled intoc; poolaintocinstead), - a pair where one input holds both columns, since its cells would have two values,
- a label column pooled with a numeric one,
- pooling anything into
sample.
Gene (.var) columns¶
Genes are shared after the intersection, so Skopia can compare a .var column's values directly instead of guessing.
| Choice | Result | Default when |
|---|---|---|
| one copy | One column, taken from the first input that has it | Identical in every input (gene_symbol, say), or held by one input |
| one per dataset | <column>__<label> per input |
Values differ (highly_variable, moranI) |
| drop | Not carried over | Never by default |
The comparison is made over the shared genes only, since the others are dropped anyway.
Name collisions¶
A split column never overwrites an existing one. If an input already has x__A, the split of x for input A becomes x__A_1. The sample column is always written and cannot be dropped, split or pooled.
What it writes¶
| Where | What |
|---|---|
obs['sample'] |
Categorical, one category per input label, in input order |
.obs |
The columns kept under your policy (merged, <column>__<label>, or pooled under a Same as target) |
.var |
Shared genes only; .var columns kept under your policy |
obsm['X_spatial'] |
Spatial mode: the laid-out coordinates |
.obsm |
Concat mode: every array all inputs shared |
uns['skopia_combine'] |
mode (spatial or concat), labels, and the resolved obs_policy, var_policy and obs_merge_into, including every default Skopia filled in |
Because uns['skopia_combine'] records the resolved policy, an exported combined file says what was done to it.
Tips and pitfalls¶
Re-run the analysis on the combined data
The combined dataset starts without the per-file graphs and analysis results (.obsp, .uns), and in spatial mode without per-file embeddings. Normalization and log state carry over in the matrix but not the scanpy records of them. Check the matrix's scale in the Source dropdown (Expression scale detection) before you normalize again.
Inputs must be on the same scale
Combine stacks the matrices as they are. If one file holds raw counts and another log-normalized values, the combined .X mixes them and every downstream result is wrong. Bring the inputs to the same scale first.
Spatial sections that do not touch
The gap keeps sections apart in the plot, but a spatial neighbor graph built later by distance alone can still link cells across a small gap. Use the sample column as the section column when you build spatial neighbors (Spatial neighbors and autocorrelation), so no edge crosses between sections.
Menu text
The menu's subtitle still reads "Place 2+ ST h5ads left-to-right" and the button counts "sections". Combine accepts non-spatial inputs and every loadable format; the wording predates that.
Related¶
- Datasets, split view and compare: hold datasets side by side without merging them
- The .obs manager: merge, rename or drop columns after combining
- Sections and territories
- Load your data
- What Skopia writes to AnnData