Repository navigation
fix: combine all membrane markers for cellSAM segmentation - #31
Merged
mcmero merged 2 commits intoJul 13, 2026
Merged
Conversation
cellSAM previously received only the first matching membrane channel (first-match-and-break in extract_channels), silently discarding any additional markers. Wire COMBINECHANNELS into the CELLSAM_SEGMENT subworkflow (mirroring the SOPA/Cellpose path) so all listed membrane markers are max-combined into a single 'combined_membrane' channel before segmentation. The background-subtraction variant inherits the fix via its call to CELLSAM_SEGMENT. Because cellSAM now only sees the single combined channel, log which channels were combined in combine_channels.py so that information stays visible in the process log. Add multi-membrane nf-test cases to the combinechannels module and the cellsam_segment subworkflow (reusing synthetic_multichannel.tif with CD45:TRITC). Snapshots still need blessing on a GPU node; the existing cellsam_segment / cellsam_segment_wbacksub snapshots also change because COMBINECHANNELS now runs within those workflows. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
This PR is against the
|
mcmero
approved these changes
Jul 13, 2026
mcmero
left a comment
Contributor
There was a problem hiding this comment.
Looks good, I'll merge it to dev.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When running cellSAM whole-cell segmentation, only the first matching
membrane marker was ever used.
extract_channelsinbin/cellsam_segment.pyloops over the
--membrane-channellist andbreaks on the first hit, so anyadditional markers were silently discarded. With a single weak boundary marker,
cellSAM falls back to a nucleus-driven (round) segmentation.
This is inconsistent with the Cellpose/SOPA path, which already runs
COMBINECHANNELSto max-combine all listed membrane markers into one channelbefore segmentation.
Fix
Wire
COMBINECHANNELSinto theCELLSAM_SEGMENTsubworkflow (mirroringsubworkflows/local/sopa_segment/main.nf): all listed membrane markers aremax-combined into a single
combined_membranechannel, and that combined tiffis what feeds both
CELLSAMWCandCELLSAMNUC. The duplicateCOMBINECHANNELScall in the report block is removed (it now runs upstream).
CELLSAM_SEGMENT_WBACKSUBinherits the fix automatically — it background-subtractsthen delegates to
CELLSAM_SEGMENT.Observability
Because cellSAM now only sees the single combined channel (its
Available channels:log no longer shows the source panel),combine_channels.pylogs what it combined to stderr, e.g.:
This benefits the Cellpose path and the report background too, since they share the module.
Tests
combinechannels - multi-membrane combinecase (the module previously hadno multi-membrane coverage — both existing cases use a single channel).
cellsam_segment - multi-membrane combinecase guarding the wiring.tests/data/comet/synthetic_multichannel.tif(CD45:TRITC= two markers);no new test binary.
Validation already run
combine_channels.pyon a synthetic 2-marker array (markers innon-overlapping halves): output is
[DAPI, combined_membrane]withcombined_membrane == max(CD45, Ecad)and not equal to either single marker.-stub-runof the cellSAM path withCD45:Ecad:COMBINECHANNELS -> CELLSAMWC/CELLSAMNUC -> CELLMEASUREMENT -> SEGMENTATIONREPORT,pipeline completed successfully (no double-
COMBINECHANNELSerror).Reviewer checklist — snapshots need blessing on a GPU node
nf-testsnapshots are not included (nonf-test/GPU on the dev box). Before merge, run with--update-snapshotand commit the.snapfiles:modules/local/combinechannels— new case (deterministic, GPU-free)subworkflows/local/cellsam_segment— new case and re-bless the existing case (changed:COMBINECHANNELSnow runs in the workflow → new entry inversions)subworkflows/local/cellsam_segment_wbacksub— re-bless the existing case (same reason)🤖 Generated with Claude Code