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.

Tutorial 4: Multiple segmentations

What you will do

Segment the same tissue with two methods, Cellpose and InstanSeg, each finding both cells and nuclei, and compare the two. Use this when you are unsure which method suits your tissue, or when you want nuclei and cytoplasm measured separately.

The data is exemplar-001, as in Tutorial 1. Do that one first: the download, samplesheet and marker sheet are the same.

Choose methods and targets

Pick one or both methods:

You wantSet
Cells from one membrane marker and DNAuse_cellpose: true, cellpose_channels: "CD45 DNA_6", nuclear stain last
Cells from many markers, with Cellposeuse_cellpose: true, use_projection: true; see Many markers
Cells from every marker, no channel choiceuse_instanseg: true, pixel_size in µm per pixel
A second opinionBoth. The QC then compares them

Then the targets. Cells are on by default.

You wantSet
Cellsnothing
Cells, nuclei and cytoplasm, linkedsegment_nuclei: true
Nuclei onlysegment_cells: false, segment_nuclei: true

Every method × target is one more pass over every patch. Two methods with two targets are four segmentations per patch. Nuclei come from a nuclear stain: for Cellpose the last of cellpose_channels, or the projection’s nuclear channel; for InstanSeg the dna channels. More: Methods and targets.

The parameters

Use the samplesheet and marker sheet from Tutorial 1. Save as params.yml:

input: /path/to/exemplars/samplesheet.csv
outdir: /path/to/results/exemplar-001-both

use_cellpose: true
use_projection: true

use_instanseg: true
pixel_size: 0.65

segment_nuclei: true
patch_width_pixel: 1500

Run

nextflow run CosciaLab/histo -r v3.2.0 \
    -profile singularity,size_small,slurm \
    -params-file params.yml

On the MDC cluster add mdc. See Running on the cluster.

What you get

/path/to/results/exemplar-001-both/
├── preprocessing/            as in Tutorial 1
├── exemplar-001.zarr/
│   ├── images/               exemplar-001
│   ├── shapes/               image_patches,
│   │                         cellpose_cells, cellpose_nuclei, cellpose_cytoplasm,
│   │                         instanseg_cells, instanseg_nuclei, instanseg_cytoplasm
│   └── tables/               cellpose_table, instanseg_table; layers nucleus and cytoplasm
├── qc/
│   ├── exemplar-001_cellpose_qc_report.html, exemplar-001_instanseg_qc_report.html
│   ├── exemplar-001_cellpose_qc.json, exemplar-001_instanseg_qc.json
│   ├── exemplar-001_cellpose_qc_images/, exemplar-001_instanseg_qc_images/
│   ├── exemplar-001_comparison.html, exemplar-001_comparison.json
│   └── exemplar-001_projection.png, exemplar-001_projection.json
└── pipeline_info/

Each method has its own table, one row per cell, with marker intensities over the whole cell and, in the layers, over the nucleus and the cytoplasm. See The SpatialData store.

What to check

  1. qc/exemplar-001_projection.png, what Cellpose saw: nuclear in magenta, cell in green. In the JSON, a marker under dominant swamps the others; leave it out with the segmentation column of the marker sheet. See Many markers.

  2. qc/exemplar-001_comparison.html: cell counts, median areas, and the share of cells both methods agree on, with both outlines on the same crops.

  3. “Linking” in each method’s report: cells by number of nuclei, nuclei linked to no cell, and cells their nucleus fills completely (no cytoplasm). See The QC report.

  4. Both sets of outlines over the image; see Viewers.