Skip to content

Commit 488989d

Browse files
Merge pull request nf-core#92 from heylf/dev
Couple of fixes
2 parents ff0aaa6 + 653ee24 commit 488989d

File tree

8 files changed

+103
-35
lines changed

8 files changed

+103
-35
lines changed

conf/modules.config

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,25 @@ process {
138138
path: { "${params.outdir}/cellpose" },
139139
mode: params.publish_dir_mode,
140140
]
141-
ext.args = { "--pretrained_model nuclei --diameter 9 --channel_axis 0 --save_flows" }
141+
ext.args = { "--diameter 9 --channel_axis 0 --save_flows" }
142+
}
143+
144+
// with new version of cellpose you can do --output_name cell_masks
145+
withName: CELLPOSE_CELLS {
146+
publishDir = [
147+
path: { "${params.outdir}/cellpose_cells" },
148+
mode: params.publish_dir_mode,
149+
]
150+
ext.args = { "--diameter 9 --channel_axis 0 --save_flows" }
151+
}
152+
153+
// with new version of cellpose you can do --output_name nucleus_masks
154+
withName: CELLPOSE_NUCLEI {
155+
publishDir = [
156+
path: { "${params.outdir}/cellpose_nuclei" },
157+
mode: params.publish_dir_mode,
158+
]
159+
ext.args = { "--diameter 9 --channel_axis 0 --save_flows" }
142160
}
143161

144162
}

modules/local/spatialdata/write/main.nf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ process SPATIALDATA_WRITE {
77
input:
88
tuple val(meta), path(bundle, stageAs: "*")
99
val(outputfolder)
10+
val(segmented_object)
1011

1112
output:
1213
tuple val(meta), path("${outputfolder}"), emit: spatialdata

modules/local/spatialdata/write/templates/write.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,34 @@ def main():
1212
input_path = "${bundle}"
1313
output_path = "."
1414
outputfolder = "${outputfolder}"
15+
segmented_object = "${segmented_object}"
16+
17+
cells_boundaries=False
18+
nucleus_boundaries=False
19+
cells_labels=False
20+
nucleus_labels=False
21+
22+
if ( segmented_object == 'cells' ):
23+
cells_boundaries=True
24+
cells_labels=True
25+
if ( segmented_object == 'nuclei' ):
26+
nucleus_boundaries=True
27+
nucleus_labels=True
28+
if ( segmented_object == 'cells_and_nuclei' ):
29+
cells_boundaries=True
30+
nucleus_boundaries=True
31+
cells_labels=True
32+
nucleus_labels=True
1533

1634
format = "${params.format}"
17-
1835
if ( format == "xenium" ):
1936
sd_xenium_obj = xenium(
2037
input_path,
2138
cells_as_circles=True,
22-
nucleus_boundaries=True,
39+
cells_boundaries=cells_boundaries,
40+
nucleus_boundaries=nucleus_boundaries,
41+
cells_labels=cells_labels,
42+
nucleus_labels=nucleus_labels,
2343
transcripts=True,
2444
morphology_mip=True,
2545
morphology_focus=True,

modules/nf-core/cellpose/main.nf

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

subworkflows/local/cellpose_resolift_morphology_ome_tif/main.nf

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Run cellpose on the morphology tiff
33
//
44

5-
include { CELLPOSE } from '../../../modules/nf-core/cellpose/main'
5+
include { CELLPOSE as CELLPOSE_CELLS } from '../../../modules/nf-core/cellpose/main'
6+
include { CELLPOSE as CELLPOSE_NUCLEI } from '../../../modules/nf-core/cellpose/main'
67
include { RESOLIFT } from '../../../modules/local/resolift/main'
78
include { XENIUMRANGER_IMPORT_SEGMENTATION } from '../../../modules/nf-core/xeniumranger/import-segmentation/main'
89

@@ -26,24 +27,39 @@ workflow CELLPOSE_RESOLIFT_MORPHOLOGY_OME_TIF {
2627
ch_versions = ch_versions.mix( RESOLIFT.out.versions )
2728

2829
// run cellpose on the enhanced tiff
29-
CELLPOSE ( RESOLIFT.out.enhanced_tiff, cellpose_model )
30+
CELLPOSE_CELLS ( RESOLIFT.out.enhanced_tiff, cellpose_model, 'cells' )
3031
ch_versions = ch_versions.mix( CELLPOSE.out.versions )
3132

33+
CELLPOSE_NUCLEI ( RESOLIFT.out.enhanced_tiff, 'nuclei', 'nuclei' )
34+
ch_versions = ch_versions.mix( CELLPOSE_NUCLEI.out.versions )
35+
3236
} else {
3337

3438
// run cellpose on the original tiff
35-
CELLPOSE ( ch_morphology_image, cellpose_model )
36-
ch_versions = ch_versions.mix( CELLPOSE.out.versions )
39+
CELLPOSE_CELLS ( ch_morphology_image, cellpose_model, 'cells' )
40+
ch_versions = ch_versions.mix( CELLPOSE_CELLS.out.versions )
41+
42+
CELLPOSE_NUCLEI ( ch_morphology_image, 'nuclei', 'nuclei' )
43+
ch_versions = ch_versions.mix( CELLPOSE_NUCLEI.out.versions )
3744
}
3845

3946
// get cellpose segmentation results
40-
cellpose_cells = CELLPOSE.out.cells.map {
47+
cellpose_cells_cells = CELLPOSE_CELLS.out.cells.map {
48+
_meta, cells -> return [ cells ]
49+
}
50+
cellpose_cells_mask = CELLPOSE_CELLS.out.mask.map {
51+
_meta, mask -> return [ mask ]
52+
}
53+
_cellpose_cells_flows = CELLPOSE_CELLS.out.flows.map {
54+
_meta, flows -> return [ flows ]
55+
}
56+
cellpose_nuclei_cells = CELLPOSE_NUCLEI.out.cells.map {
4157
_meta, cells -> return [ cells ]
4258
}
43-
cellpose_mask = CELLPOSE.out.mask.map {
59+
cellpose_nuclei_mask = CELLPOSE_NUCLEI.out.mask.map {
4460
_meta, mask -> return [ mask ]
4561
}
46-
_cellpose_flows = CELLPOSE.out.flows.map {
62+
_cellpose_nuclei_flows = CELLPOSE_NUCLEI.out.flows.map {
4763
_meta, flows -> return [ flows ]
4864
}
4965

@@ -53,7 +69,7 @@ workflow CELLPOSE_RESOLIFT_MORPHOLOGY_OME_TIF {
5369
XENIUMRANGER_IMPORT_SEGMENTATION (
5470
ch_bundle_path,
5571
[],
56-
cellpose_mask,
72+
cellpose_nuclei_mask,
5773
[],
5874
[],
5975
[],
@@ -66,8 +82,8 @@ workflow CELLPOSE_RESOLIFT_MORPHOLOGY_OME_TIF {
6682
XENIUMRANGER_IMPORT_SEGMENTATION (
6783
ch_bundle_path,
6884
[],
69-
cellpose_mask,
70-
cellpose_cells,
85+
cellpose_nuclei_mask,
86+
cellpose_cells_mask,
7187
[],
7288
[],
7389
""
@@ -77,9 +93,12 @@ workflow CELLPOSE_RESOLIFT_MORPHOLOGY_OME_TIF {
7793

7894
emit:
7995

80-
mask = CELLPOSE.out.mask // channel: [ val(meta), [ "*masks.tif" ] ]
81-
flows = CELLPOSE.out.flows // channel: [ val(meta), [ "*flows.tif" ] ]
82-
cells = CELLPOSE.out.cells // channel: [ val(meta), [ "*seg.npy" ] ]
96+
cells_mask = CELLPOSE_CELLS.out.mask // channel: [ val(meta), [ "*masks.tif" ] ]
97+
cells_flows = CELLPOSE_CELLS.out.flows // channel: [ val(meta), [ "*flows.tif" ] ]
98+
cells_cells = CELLPOSE_CELLS.out.cells // channel: [ val(meta), [ "*seg.npy" ] ]
99+
nuclei_mask = CELLPOSE_NUCLEI.out.mask // channel: [ val(meta), [ "*masks.tif" ] ]
100+
nuclei_flows = CELLPOSE_NUCLEI.out.flows // channel: [ val(meta), [ "*flows.tif" ] ]
101+
nuclei_cells = CELLPOSE_NUCLEI.out.cells // channel: [ val(meta), [ "*seg.npy" ] ]
83102

84103
redefined_bundle = XENIUMRANGER_IMPORT_SEGMENTATION.out.bundle // channel: [ val(meta), ["redefined-xenium-bundle"] ]
85104

subworkflows/local/spatialdata_write_meta_merge/main.nf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ include { SPATIALDATA_META } from '../../
1010
workflow SPATIALDATA_WRITE_META_MERGE {
1111

1212
take:
13-
ch_bundle_path // channel: [ val(meta), [ "path-to-xenium-bundle" ] ]
14-
ch_redefined_bundle // channel: [ val(meta), [ "redefined-xenium-bundle" ] ]
13+
ch_bundle_path // channel: [ val(meta), [ "path-to-xenium-bundle" ] ]
14+
ch_redefined_bundle // channel: [ val(meta), [ "redefined-xenium-bundle" ] ]
15+
ch_segmented_object // can be either cells,nuclei,cells_and_nuclei
1516

1617
main:
1718

@@ -20,15 +21,17 @@ workflow SPATIALDATA_WRITE_META_MERGE {
2021
// write spatialdata object from the raw xenium bundle
2122
SPATIALDATA_WRITE_RAW_BUNDLE (
2223
ch_bundle_path,
23-
'spatialdata_raw'
24+
'spatialdata_raw',
25+
ch_segmented_object
2426
)
2527
ch_versions = ch_versions.mix ( SPATIALDATA_WRITE_RAW_BUNDLE.out.versions )
2628

2729

2830
// write spatialdata object after running IMP_SEG
2931
SPATIALDATA_WRITE_REDEFINED_BUNDLE (
3032
ch_redefined_bundle,
31-
'spatialdata_redefined'
33+
'spatialdata_redefined',
34+
ch_segmented_object
3235
)
3336
ch_versions = ch_versions.mix ( SPATIALDATA_WRITE_REDEFINED_BUNDLE.out.versions )
3437

subworkflows/local/utils_nfcore_spatialxe_pipeline/main.nf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,6 @@ def validateInputParameters() {
195195
log.warn "⚠️ Use --nucleus_segmentation_only to enable nucleus segmentation to redefine xenium bundle with import-segmentation module."
196196
}
197197

198-
if ( params.mode == 'image' && params.method == 'baysor' ) {
199-
if ( !params.method_mask ) {
200-
log.error "❌ Error: Missing path to segmentation mask. Image-based segmentation with the `baysor` method requires a segmentation mask with the `--segmentation_mask` option."
201-
exit 1
202-
}
203-
}
204-
205198
}
206199

207200
//

workflows/spatialxe.nf

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,21 @@ workflow SPATIALXE {
241241
// run baysor run with morphology_ome.tif
242242
if ( params.method == 'baysor' ) {
243243

244-
BAYSOR_RUN_PRIOR_SEGMENTATION_MASK (
245-
ch_bundle_path,
246-
ch_transcripts_parquet,
247-
ch_segmentation_mask,
248-
ch_config
249-
)
244+
if ( params.segmentation_mask ) {
245+
BAYSOR_RUN_PRIOR_SEGMENTATION_MASK (
246+
ch_bundle_path,
247+
ch_transcripts_parquet,
248+
ch_segmentation_mask,
249+
ch_config
250+
)
251+
} else {
252+
BAYSOR_RUN_PRIOR_SEGMENTATION_MASK (
253+
ch_bundle_path,
254+
ch_transcripts_parquet,
255+
[],
256+
ch_config
257+
)
258+
}
250259
ch_redefined_bundle = BAYSOR_RUN_PRIOR_SEGMENTATION_MASK.out.redefined_bundle
251260
}
252261

@@ -343,9 +352,12 @@ workflow SPATIALXE {
343352
// run spatialdata modules to generate sd objects in image or coordinate mode
344353
if ( params.mode == 'image' || params.mode == 'coordinate' ) {
345354

355+
ch_segmented_object = Channel.value('cells_and_nuclei')
356+
346357
SPATIALDATA_WRITE_META_MERGE (
347358
ch_bundle_path,
348-
ch_redefined_bundle
359+
ch_redefined_bundle,
360+
ch_segmented_object
349361
)
350362

351363
}

0 commit comments

Comments
 (0)