Diagonal integration: [RNA, ATAC]¶
Diagonal integration combines RNA and ATAC measured in different cells, with no pairing between them. If your RNA and ATAC come from the same cells, as in 10x Multiome, use the vertical tutorial. This tutorial runs iNMF and online_iNMF on D27mini, the RNA and ATAC of 3,000 cells of the benchmark dataset D27 with the pairing left out, then on data in your own format.
Most diagonal methods read ATAC as gene-activity scores, made beforehand with a tool such as Signac or ArchR. GLUE and Seurat_v5 read the peak matrix, and MultiMAP and Seurat_v3 need both. The folder layout lists each method's ATAC files.
iNMF and online_iNMF run on Linux, Windows and macOS (Apple silicon). Or open in Colab: sections 1 to 4 take about 6 minutes there.
1. Install¶
pip may then print a note about restarting the kernel: no restart is needed, because the pins keep the numpy and pandas already installed.
import numpy, pandas
pins = f"numpy=={numpy.__version__} pandas=={pandas.__version__}"
%pip install -q "multibench-sc>=0.7.4" {pins}
Note: you may need to restart the kernel to use updated packages.
2. Download the data and the environments¶
mtb.data.fetch downloads D27mini (15 MB) once. mtb.env.install downloads the environments for iNMF and online_iNMF. On Linux the download is 0.9 GB. On Windows it is 0.3 GB. On macOS it is 0.7 GB.
import multibench as mtb
import pandas as pd
pd.set_option("display.max_columns", None) # show every column of the tables
mtb.data.fetch("D27mini")
METHODS = ["iNMF", "online_iNMF"]
envs = mtb.env.install(METHODS)
downloading D27mini (15 MB) ...
3. Run the methods¶
run runs each method on D27mini and scores its output. The clustering metrics score how well the embedding's clusters and neighbourhoods match the cell types, and how separate the clusters are. The batch metrics measure how well the RNA and ATAC cells mix. The classification scores measure how well the cell types learned on one of them are predicted in the other. Higher is better for every metric.
Details
params={"Method": {"key": value}} sets a method's parameters, and mtb.params_for lists them.
mtb.load_run("out/D27mini") reloads these results later.
res = mtb.run("D27mini", "diagonal", methods=METHODS, out_dir="out/D27mini")
res.summary
[run] iNMF (diagonal/D27mini) ... [run] -> scored (17.0s) ARI 0.467 [run] online_iNMF (diagonal/D27mini) ... [run] -> scored (8.5s) ARI 0.465
| method | status | ARI | NMI | ASW | iASW | iF1 | cLISI | ASW_batch | ARI_batch | NMI_batch | GC | iLISI | OCA | ACA | Spec | Sens | F1 | run_sec | caveat | reason | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | iNMF | scored | 0.4672 | 0.6538 | 0.7145 | 0.7254 | 0.5909 | 0.9846 | 0.8036 | 0.9993 | 0.9816 | 0.8860 | 0.8308 | 0.7507 | 0.6154 | 0.9780 | 0.6154 | 0.5964 | 17.0 | ||
| 1 | online_iNMF | scored | 0.4652 | 0.6185 | 0.6725 | 0.6788 | 0.5646 | 0.9679 | 0.7769 | 1.0000 | 0.9996 | 0.8945 | 0.6918 | 0.7168 | 0.6148 | 0.9754 | 0.6148 | 0.5973 | 8.5 |
4. Plot¶
res.plot() draws the scores as a bubble table. Circle size ranks the rows within each column and colour shows the value scaled per column, so a small gap can look large. res.summary has the values.
Details
Metrics are grouped by family: blue for clustering, green for batch correction, pink for classification. Each family starts with an Overall bar: each row's mean rank over the family's metrics, scaled so that the lowest gets the shortest bar.
A column with fewer than two different values is drawn grey. A figure of one method is grey everywhere.
res.plot()
5. Your own data¶
Your data needs raw RNA counts in one .h5ad file and ATAC in another, with a cell type for each cell in both. online_iNMF needs about 5,000 cells in total.
Recipes cover labels in a CSV file and no labels.
Details: export
labels= needs the column in both files. With cell types for the RNA cells only, leave labels= out and follow the recipe for no labels.
The next cell writes two small example files, my_rna.h5ad and my_atac.h5ad, from 90% of the RNA profiles and 90% of the ATAC profiles of D27mini. Skip it for your own data.
mtb.data.write_example("D27mini")
wrote my_rna.h5ad: 2,700 cells. RNA counts in X, cell types in obs["celltype"]. wrote my_atac.h5ad: 2,700 cells. ATAC gene-activity scores in X, cell types in obs["celltype"].
Read your files. For your own data, change every file name marked # <-. On Colab, upload the files first: click the folder icon on the left, then the upload icon.
import anndata as ad
rna = ad.read_h5ad("my_rna.h5ad") # <- your RNA file
atac = ad.read_h5ad("my_atac.h5ad") # <- your ATAC file, other cells
print(rna)
print(atac)
AnnData object with n_obs × n_vars = 2700 × 2500
obs: 'celltype'
layers: None (.X)
AnnData object with n_obs × n_vars = 2700 × 2500
obs: 'celltype'
layers: None (.X)
Write the dataset folder. Change each name in quotes marked # <- to one the printout above lists for your files, with its prefix, as "obs:celltype".
NAME = "MYDIAG_RNA_ATAC" # <- a new name for your own data
mtb.io.export_dataset(rna, "mydata/" + NAME,
rna="X", # <- where the RNA counts are:
# "X" or "layer:counts"
atac=atac, # the ATAC file, values in X
atac_kind="gene_activity", # <- or "peak"
labels="obs:celltype", # <- the column in both files
category="diagonal", overwrite=True)
mtb.scan("mydata/" + NAME, "diagonal", methods=METHODS)
[scan] 2 of 2 methods have their input files in MYDIAG_RNA_ATAC. 2 of 2 can run on this computer. MYDIAG_RNA_ATAC holds RNA and ATAC. [scan] Cells per file: rna.h5 2,700, atac_gas.h5 2,700.
| method | modalities | runnable | reason | env | caveat | |
|---|---|---|---|---|---|---|
| 0 | iNMF | rna+atac_gas | True | scmb_r | ||
| 1 | online_iNMF | rna+atac_gas | True | scmb_r |
mine = mtb.run("mydata/" + NAME, "diagonal", methods=METHODS,
out_dir="out/" + NAME)
mine.summary
[run] iNMF (diagonal/MYDIAG_RNA_ATAC) ... [run] -> scored (18.1s) ARI 0.494 [run] online_iNMF (diagonal/MYDIAG_RNA_ATAC) ... [run] -> scored (12.5s) ARI 0.406
| method | status | ARI | NMI | ASW | iASW | iF1 | cLISI | ASW_batch | ARI_batch | NMI_batch | GC | iLISI | OCA | ACA | Spec | Sens | F1 | run_sec | caveat | reason | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | iNMF | scored | 0.4940 | 0.6647 | 0.6625 | 0.6985 | 0.6068 | 0.9771 | 0.8458 | 0.9999 | 0.9982 | 0.9350 | 0.8271 | 0.7641 | 0.5809 | 0.9789 | 0.5809 | 0.5539 | 18.1 | ||
| 1 | online_iNMF | scored | 0.4055 | 0.6065 | 0.6148 | 0.6338 | 0.5260 | 0.9630 | 0.8130 | 0.9995 | 0.9995 | 0.8774 | 0.6939 | 0.6974 | 0.5940 | 0.9745 | 0.5940 | 0.5621 | 12.5 |
mine.plot()
6. Stored results¶
The package ships stored results for 11 methods on D28. load_results reads them and mtb.plot.bubble draws them, without running anything.
Details
There are no stored results for D27mini. D28 is another benchmark dataset of the same task.
stored = mtb.load_results("diagonal", dataset="D28")
mtb.plot.bubble(stored)
7. Every method of this task¶
14 methods run this task. This notebook runs them all. Its 8 environments download 13.9 GB on a computer without a GPU and 13.2 GB on one with a GPU.
Troubleshooting¶
res.summary[res.summary.status != "scored"] lists each method that failed or was skipped. Its reason column ends with the method's error output.
Details
| symptom | fix |
|---|---|
| a method fails on a small dataset | mtb.scan names what the method needs from the data's size in its caveat column |
| batch metrics use the wrong batches | res.rescore(batch=...), with one batch per cell, scores again without running the methods |
Next steps¶
- Run a method, Score an embedding, Load and plot results and Discover methods.
- Look at an embedding draws a method's embedding as a UMAP.
- The interactive explorer has the full benchmark's rankings, with no install needed.