Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Step-by-step guide

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:

  1. Nextflow, version 25.10.4 or later. Follow its installation guide; it is one command.

  2. 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/you
  3. A 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.

samplecycle_numberimage_tilesmarker_sheet
slide011/data/myproject/raw/slide01/cycle01.ome.tiff/data/myproject/sheets/markers_slide01.csv
slide012/data/myproject/raw/slide01/cycle02.ome.tiff/data/myproject/sheets/markers_slide01.csv
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.csv

All 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_numbercycle_numbermarker_namechannel_rolechannel_compartment
11DNA_1dnanuclear
21CD45markermembrane
31PanCKmarkercytoplasm
42DNA_2dnanuclear
52CD3markermembrane
62Ki67markernuclear
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,nuclear

All 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.65

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.yml

What each part means:

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

  1. Read the error Nextflow prints. It names the step that failed and its work folder, a path under work/.

  2. Open that folder and read .command.err: the step’s own error message. .command.out holds its normal output, and .command.sh the exact command that ran.

  3. 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.log in your working folder has the full story.

  4. Fix the cause, and run the same command again with -resume added. 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:

  1. 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.

  2. The stitched image, preprocessing/registration/{sample}.ome.tif, in QuPath or napari.

  3. 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.