Vertical integration: RNA + ATAC¶
Vertical integration combines modalities measured in the same cells. This tutorial is for RNA and ATAC, as in 10x Multiome. It runs scMM and VIMCCA on D27mini_vertical, 5,000 cells of the benchmark dataset D27, and then on data in your own format.
Methods run on Linux. scMM has no Windows environment, and scMM and VIMCCA have no macOS environment. On Windows or macOS, open this notebook in Colab: sections 1 to 4 take about 11 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_vertical (24 MB) once. mtb.env.install downloads the environments for scMM and VIMCCA. The download is 1.2 GB.
import multibench as mtb
mtb.data.fetch("D27mini_vertical")
METHODS = ["scMM", "VIMCCA"]
envs = mtb.env.install(METHODS)
downloading D27mini_vertical (24 MB) ... [env] downloading scmb_vimcca 725 MB ... [env] 725 MB of 725 MB (29 MB/s) [env] unpacking scmb_vimcca ...
3. Run the methods¶
run runs each method on D27mini_vertical and scores its output with the scIB metrics. The clustering metrics score how well the embedding's clusters and neighbourhoods match the cell types, and how separate the clusters are. 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_vertical") reloads these results later.
res = mtb.run("D27mini_vertical", "vertical", methods=METHODS,
out_dir="out/D27mini_vertical")
res.summary
[run] VIMCCA (vertical/D27mini_vertical) ... [run] -> scored (18.4s) ARI 0.388 [run] scMM (vertical/D27mini_vertical) ... [run] -> scored (55.1s) ARI 0.276
| method | status | ARI | NMI | ASW | iASW | iF1 | cLISI | run_sec | caveat | reason | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | VIMCCA | scored | 0.3879 | 0.5710 | 0.6248 | 0.6217 | 0.523 | 0.9607 | 18.4 | ||
| 1 | scMM | scored | 0.2762 | 0.4837 | 0.6001 | 0.6045 | 0.389 | 0.8963 | 55.1 |
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. 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, an ATAC matrix of the same cells and a cell type for each cell, as two .h5ad files.
Recipes cover a 10x .h5 file, labels in a CSV file, no labels and several donors or samples.
Details: export
A 10x Multiome MuData goes in with one call. Here the labels are in mdata.obs. For labels in mdata["rna"].obs, write labels="rna:celltype".
mtb.io.export_dataset(mdata, "mydata/" + NAME, rna="rna", atac="atac",
atac_kind="peak", labels="obs:celltype",
category="vertical")
The next cell writes two small example files, my_rna.h5ad and my_atac.h5ad, from 60% of the cells of D27mini_vertical. Skip it for your own data.
mtb.data.write_example("D27mini_vertical")
wrote my_rna.h5ad: 3,000 cells. RNA counts in X, cell types in obs["celltype"]. wrote my_atac.h5ad: 3,000 cells. ATAC peak counts 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, the same cells
print(rna)
print(atac)
AnnData object with n_obs × n_vars = 3000 × 2500
obs: 'celltype'
layers: None (.X)
AnnData object with n_obs × n_vars = 3000 × 5000
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 = "MYMULTIOME" # <- 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, peak counts in X
atac_kind="peak", # the methods here read peaks
labels="obs:celltype", # <- the cell-type column
overwrite=True)
mtb.scan("mydata/" + NAME, "vertical", methods=METHODS)
[scan] 2 of 2 methods have their input files in MYMULTIOME. 2 of 2 can run on this computer. MYMULTIOME holds RNA and ATAC. [scan] Cells per file: rna.h5 3,000, atac.h5 3,000, atac_peak.h5 3,000.
| method | modalities | runnable | reason | env | caveat | |
|---|---|---|---|---|---|---|
| 0 | VIMCCA | rna+atac | True | scmb_vimcca | ||
| 1 | scMM | rna+atac | True | scmb_scmm2 | scMM reads inputs/rna.h5, inputs/atac.h5. mtb.... |
mine = mtb.run("mydata/" + NAME, "vertical", methods=METHODS,
out_dir="out/" + NAME)
mine.summary
[run] VIMCCA (vertical/MYMULTIOME) ... [run] -> scored (13.1s) ARI 0.373 [run] scMM (vertical/MYMULTIOME) ... [run] -> scored (35.5s) ARI 0.317
| method | status | ARI | NMI | ASW | iASW | iF1 | cLISI | run_sec | caveat | reason | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | VIMCCA | scored | 0.3726 | 0.5684 | 0.6130 | 0.6259 | 0.5044 | 0.9515 | 13.1 | ||
| 1 | scMM | scored | 0.3171 | 0.4731 | 0.5729 | 0.5806 | 0.3867 | 0.8883 | 35.5 |
mine.plot()
6. Every method of this task¶
14 methods run this task. This notebook runs them all. Its 13 environments download 31.8 GB on a computer without a GPU and 37.6 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 |
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.