Single-cell & spatial omics · open source · MIT

Single-cell and Spatial Omics Toolkit

Open tools I built for my own single-cell and spatial analyses: finding gene programs on the GPU, putting H&E and IF images onto the cells of a Xenium run, and cutting regions out of whole slides for figures. Each one is tested on public data.

Input
Xenium run + stained slidesDAPI image, transcripts; H&E or IF of the same or a neighbouring section
Align
histology_alignStains into the DAPI pixel grid, with a QC grade per fit
Show
qupath-roi-exporterAnnotated regions at chosen magnifications, with scale bars
Input
Cells × genes countsscRNA-seq, snRNA-seq or segmented spatial cells
Find programs
cnmfgpuConsensus NMF on the GPU; shared and private programs across samples
Tools

Three tools, one per job.

Gene programs · Python

cnmfgpu

cNMFPyTorchCUDA · Apple MPS · CPUscRNA-seqspatial

Consensus NMF (cNMF; Kotliar et al., eLife 2019) with the many NMF restarts run as one batch on the GPU. Everything apart from the factorisation is cNMF's own code, so the outputs are ordinary cNMF outputs and agree with the original.

  • On a public 63,000-cell mouse brain section, one k took 2.1 min on a laptop GPU against 21 min with cNMF on 8 processes
  • Checks after the fit: which programs are shared across samples, which are private to one, and which private ones look like a genomic change
  • Benchmarked against cNMF and standard clustering on public datasets
pip install git+https://github.com/osamashiraz/cnmfgpu.git
cnmfgpu overview: counts, batched NMF restarts on the GPU, cNMF consensus, programs and usage, then shared, private and genomic checks across samples.
The method in one picture. From the cnmfgpu repository.
Image alignment · Python

histology_align

XeniumH&EIFOME-TIFFQuPathno GPU

Puts H&E and IF images into the pixel grid of a Xenium run's DAPI image, so what you see or draw on the stain lands on the measured cells. Works for stains of the same section after the run and of a neighbouring section.

  • Same-section H&E agrees with 10x's published alignment to 0.26–0.74 µm (median) on four public sections
  • Every fit gets a QC grade (PASS / CHECK / FAIL) and a QC picture
  • Transforms written for Xenium Explorer and QuPath, with one QuPath project per sample to check each fit by eye
pip install git+https://github.com/osamashiraz/histology_align.git
histology-align demo demo_out
Xenium DAPI, the H&E of the same section and the H&E of a neighbouring section, all put into one pixel grid, on public 10x human breast cancer data.
Public 10x human breast cancer data. From the histology_align repository.
Figures · Groovy + Bash

qupath-roi-exporter

QuPathwhole-slide imagesGeoJSONOME-TIFF

A command-line QuPath tool for publication figures. Give it a whole-slide OME-TIFF (H&E, other stains or IF; tested on H&E) and a GeoJSON of annotations, and it exports a crop around each region at every magnification you ask for.

  • Any set of magnifications, e.g. 10x, 20x, 40x, computed from the image's pixel size
  • Optional ROI outlines and scale bars; optional fixed-radius circles around each annotation
  • Runs QuPath headless and writes a manifest of each crop’s pixel size and field of view, for figure legends
./bin/run_export.sh slide.ome.tiff slide.geojson out/
whole slide + GeoJSON 10x 20x 40x crops per ROI, with scale bars
Schematic drawing; it shows no data.
Principles

How these tools are built.

Public data, rerunnable

Every number and figure in the repositories comes from public datasets and can be rerun from the code.

Checked against a reference

Where a reference exists, each tool is checked against it: cnmfgpu against original cNMF, histology_align against the alignments 10x published. qupath-roi-exporter writes a manifest of every crop's settings.

Runs on a laptop

Apple silicon, CPU or a single GPU. No cluster needed to try them; CLI and Python entry points for batch runs.