From raw images to a table of cells, on a computing cluster. About ten minutes to read. You type a handful of commands; no programming. Every step links to the page with the details.
1. Get set up¶
You need three things on the cluster, once:
Nextflow, version 25.10.4 or later. Follow its installation guide; it is one command.
The software images the pipeline runs in. The pipeline downloads nothing while it runs, so these must be in place first. Ask whoever maintains the pipeline at your site where they are, and set the folder in your environment, for example in
~/.bashrc:export NXF_SINGULARITY_CACHEDIR=/path/your/admin/gave/youA working folder with space for the results, separate from where your raw images are.
At the MDC, the dropbox can run the pipeline for you instead.
2. Find your images¶
Note the full path of each cycle’s image file, for example
/data/myproject/raw/slide01/cycle01.ome.tiff. Any format the microscope software writes and
Bio-Formats reads works, one file per cycle. Use full paths, starting with /, and no spaces.
3. Write the samplesheet¶
The samplesheet lists your images: one row per cycle. Write it in a spreadsheet and save it as
CSV (comma-separated), for example samplesheet.csv.
| sample | cycle_number | image_tiles | marker_sheet |
|---|---|---|---|
| slide01 | 1 | /data/myproject/raw/slide01/cycle01.ome.tiff | /data/myproject/sheets/markers_slide01.csv |
| slide01 | 2 | /data/myproject/raw/slide01/cycle02.ome.tiff | /data/myproject/sheets/markers_slide01.csv |
sample: a short name for the slide, used in every output file name.cycle_number: 1, 2, 3, … with no gaps.marker_sheet: the sheet you write in the next step, the same on every row of a sample.
The same samplesheet as CSV
sample,cycle_number,image_tiles,marker_sheet
slide01,1,/data/myproject/raw/slide01/cycle01.ome.tiff,/data/myproject/sheets/markers_slide01.csv
slide01,2,/data/myproject/raw/slide01/cycle02.ome.tiff,/data/myproject/sheets/markers_slide01.csvAll columns and rules: Samplesheet.
4. Write the marker sheet¶
The marker sheet names every channel: one row per channel, across all cycles, numbered 1 to N.
| channel_number | cycle_number | marker_name | channel_role | channel_compartment |
|---|---|---|---|---|
| 1 | 1 | DNA_1 | dna | nuclear |
| 2 | 1 | CD45 | marker | membrane |
| 3 | 1 | PanCK | marker | cytoplasm |
| 4 | 2 | DNA_2 | dna | nuclear |
| 5 | 2 | CD3 | marker | membrane |
| 6 | 2 | Ki67 | marker | nuclear |
marker_name: what you want to see in the results. Unique.channel_role:dnafor the nuclear stain,markerfor an antibody. Every cycle needs adnachannel, and it should come first in each cycle.channel_compartment: where the marker sits in the cell. Optional, but it lets the QC check that a marker landed where it should.
The same marker sheet as CSV
channel_number,cycle_number,marker_name,channel_role,channel_compartment
1,1,DNA_1,dna,nuclear
2,1,CD45,marker,membrane
3,1,PanCK,marker,cytoplasm
4,2,DNA_2,dna,nuclear
5,2,CD3,marker,membrane
6,2,Ki67,marker,nuclearAll columns and rules: Marker sheet.
5. Write the settings file¶
The settings go in a small text file, params.yml. This one segments cells with InstanSeg, which
reads every marker and needs only the pixel size of your images in µm:
input: /data/myproject/sheets/samplesheet.csv
outdir: /data/myproject/results
use_instanseg: true
pixel_size: 0.65input: the samplesheet from step 3.outdir: where the results go. The folder is created for you.For a slide larger than a few mm, also set
patch_width_pixel; see patch size.
Other choices, such as Cellpose instead, nuclei as well as cells, or a TMA: Parameters.
6. Start the run¶
On the cluster’s login node, go to your working folder and start a tmux session, so the run
keeps going when you log out:
cd /path/to/my/working/folder
tmux new -s histo
nextflow run CosciaLab/histo -r v3.2.0 \
-profile singularity,size_small,slurm \
-params-file params.ymlWhat each part means:
nextflow run CosciaLab/histo: run this pipeline.-r v3.2.0: this version of it, so a rerun next year gives the same result.-profile singularity,size_small,slurm: run the software in Singularity containers, ask for resources sized for images up to about 50 GB, and send each step to the cluster’s queue. See Profiles; at the MDC addmdc.-params-file params.yml: your settings from step 5.
Leave tmux with Ctrl-b then d; come back with tmux attach -t histo. The cluster setup in
full: Running on the cluster.
7. Watch it run¶
Nextflow prints one line per step, with how many tasks are done. A large slide can take many
hours, much of it waiting in the cluster queue. When it finishes it prints
Pipeline completed successfully.
Nextflow keeps its working files in a work/ folder inside your working folder. Leave it there
until you are happy with the results: it is what lets you resume.
If something fails¶
Read the error Nextflow prints. It names the step that failed and its work folder, a path under
work/.Open that folder and read
.command.err: the step’s own error message..command.outholds its normal output, and.command.shthe exact command that ran.If the run stopped before any step started, the problem is in your sheets or settings. The message names the sample, the sheet and the column.
.nextflow.login your working folder has the full story.Fix the cause, and run the same command again with
-resumeadded. Steps that already finished are reused, so only the failed part runs again.
Keep work/ and the hidden .nextflow/ folder in your working folder: -resume needs both.
More on resuming: Resume a run. Problems visible only in the results,
such as missing cells: Common failures.
Look at the results¶
A finished run is not yet a run that worked: the pipeline never fails on bad quality. Look, in this order:
The QC report,
qc/{sample}_instanseg_qc_report.html. Open it in any browser. Start with “Stitching and registration”, then the segmentation overlay. What each section means: Reports.The stitched image,
preprocessing/registration/{sample}.ome.tif, in QuPath or napari.The cells over the image, in the store
{sample}.zarr. See viewers.
Every file, one by one: Outputs.
Open the results in Python¶
Everything for one sample is in {sample}.zarr. To work with it, install
spatialdata (pip install spatialdata) and read it:
import spatialdata as sd
sdata = sd.read_zarr("results/slide01.zarr")
print(sdata) # every image, outline set and table
adata = sdata.tables["instanseg_table"] # one row per cell
cells = sdata.shapes["instanseg_cells"] # outlines, with the same cell ids
means = adata[:, adata.var["statistic"] == "mean"].to_df() # cells × {marker}_mean
adata.obs[["cell_area", "slide"]] # area in pixels²adata is an AnnData table, ready for scanpy or squidpy. With
Cellpose, the names start with cellpose_. Table names for other runs, and what NaN means in the
table: The store.