Vertical integration: RNA + ADT + ATAC¶
Vertical integration combines modalities measured in the same cells. This tutorial is for RNA, surface protein and ATAC from the same cells. It runs Matilda and UINMF on D22mini, 3,000 cells of the benchmark dataset D22, and then on data in your own format.
Matilda and UINMF run on Linux and macOS (Apple silicon), and UINMF has no Windows environment. On Windows, open this notebook 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 D22mini (8 MB) once. mtb.env.install downloads the environments for Matilda and UINMF. On Linux the download is 1.5 GB on a computer without a GPU and 4.0 GB on one with a GPU. On macOS it is 1.0 GB.
import multibench as mtb
mtb.data.fetch("D22mini")
METHODS = ["Matilda", "UINMF"]
envs = mtb.env.install(METHODS)
downloading D22mini (8 MB) ...
3. Run the methods¶
run runs each method on D22mini 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/D22mini") reloads these results later.
res = mtb.run("D22mini", "vertical", methods=METHODS, out_dir="out/D22mini")
res.summary
[run] Matilda (vertical/D22mini) ... [run] -> scored (12.5s) ARI 0.414 [run] UINMF (vertical/D22mini) ... [run] -> scored (17.3s) ARI 0.338
| method | status | ARI | NMI | ASW | iASW | iF1 | cLISI | run_sec | caveat | reason | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Matilda | scored | 0.4137 | 0.7317 | 0.5706 | 0.5986 | 0.6832 | 0.9922 | 12.5 | ||
| 1 | UINMF | scored | 0.3380 | 0.6623 | 0.5672 | 0.5605 | 0.5282 | 0.9952 | 17.3 |
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 counts for RNA and protein (ADT) in one .h5ad file, an ATAC peak matrix of the same cells in another, and a cell type for each cell.
Recipes cover a 10x .h5 file, labels in a CSV file, no labels and several donors or samples.
Details: export
The example keeps the protein names in adata.uns["protein_names"]. A DataFrame in adata.obsm["protein"] brings its own names in its columns.
The next cell writes two small example files, my_file.h5ad and my_atac.h5ad, from 60% of the cells of D22mini. Skip it for your own data.
mtb.data.write_example("D22mini")
wrote my_file.h5ad: 1,800 cells. RNA counts in X, protein counts in obsm["protein"], cell types in obs["celltype"]. wrote my_atac.h5ad: 1,800 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
adata = ad.read_h5ad("my_file.h5ad") # <- your RNA and protein file
atac = ad.read_h5ad("my_atac.h5ad") # <- your ATAC file, the same cells
print(adata)
print(atac)
AnnData object with n_obs × n_vars = 1800 × 1000
obs: 'celltype'
uns: 'protein_names'
obsm: 'protein'
layers: None (.X)
AnnData object with n_obs × n_vars = 1800 × 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" or "obsm:protein".
NAME = "MYTRI" # <- a new name for your own data
mtb.io.export_dataset(adata, "mydata/" + NAME,
rna="X", # <- where the RNA counts are:
# "X" or "layer:counts"
adt="obsm:protein", # <- where the proteins (ADT) are
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 MYTRI. 2 of 2 can run on this computer. MYTRI holds RNA, ADT and ATAC. [scan] Cells per file: rna.h5 1,800, adt.h5 1,800, atac.h5 1,800, atac_peak.h5 1,800.
| method | modalities | runnable | reason | env | caveat | |
|---|---|---|---|---|---|---|
| 0 | Matilda | rna+adt+atac | True | matilda | ||
| 1 | UINMF | rna+adt+atac | True | scmb_r |
mine = mtb.run("mydata/" + NAME, "vertical", methods=METHODS,
out_dir="out/" + NAME)
mine.summary
[run] Matilda (vertical/MYTRI) ... [run] -> scored (8.8s) ARI 0.358 [run] UINMF (vertical/MYTRI) ... [run] -> scored (15.4s) ARI 0.298
| method | status | ARI | NMI | ASW | iASW | iF1 | cLISI | run_sec | caveat | reason | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Matilda | scored | 0.3585 | 0.7115 | 0.5655 | 0.5925 | 0.6477 | 0.9881 | 8.8 | ||
| 1 | UINMF | scored | 0.2984 | 0.6480 | 0.5838 | 0.5884 | 0.5330 | 0.9902 | 15.4 |
mine.plot()
6. Every method of this task¶
5 methods run this task. This notebook runs them all. Its 5 environments download 12.7 GB on a computer without a GPU and 18.5 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.