Skip to content

Commit 811fe5b

Browse files
committed
manual testing changes
1 parent 49ce4ee commit 811fe5b

File tree

8 files changed

+76
-71
lines changed

8 files changed

+76
-71
lines changed

conf/modules.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ process {
2727
]
2828
}
2929

30+
withName: XENIUMRANGER_RESEGMENT {
31+
publishDir = [
32+
path: "${params.outdir}/xeniumranger/resegment",
33+
mode: params.publish_dir_mode
34+
]
35+
}
36+
3037
withName: XENIUMRANGER_IMPORT_SEGMENTATION {
3138
publishDir = [
3239
path: "${params.outdir}/xeniumranger/import_segementation",

nextflow.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ params {
1818
qupath_polygons = null // polygon segmentation results in GeoJSON format
1919
alignment_csv = null // image alignment file format a 3x3 transformation matrix, where the last row is [0,0,1]
2020
cellpose_model = null // custom cellpose model to use for running or starting training
21+
segmentation_mask = null // prior segmentation mask
2122

2223
// execution specific
2324
sharpen_tiff = false // wether to sharpen the morphology-focus tiff

nextflow_schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
"description": "Model to use for running or starting training.",
5959
"format": "file-path"
6060
},
61+
"segmentation_mask": {
62+
"type": "string",
63+
"description": "Prior segmentation mask from other segmentation methods.",
64+
"format": "file-path"
65+
},
6166
"email": {
6267
"type": "string",
6368
"description": "Email address for completion summary.",

subworkflows/local/baysor_run_morphology_ome_tif/main.nf renamed to subworkflows/local/baysor_run_prior_segmentation_mask/main.nf

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,43 @@ include { BAYSOR_RUN as BAYSOR_RUN_IMAGE } from '../../../modules/local/ba
88
include { XENIUMRANGER_IMPORT_SEGMENTATION } from '../../../modules/nf-core/xeniumranger/import-segmentation/main'
99

1010

11-
workflow BAYSOR_RUN_MORPHOLOGY_OME_TIF {
11+
workflow BAYSOR_RUN_PRIOR_SEGMENTATION_MASK {
1212

1313
take:
1414

15-
ch_bundle_path // channel: [ val(meta), ["path-to-xenium-bundle"] ]
16-
ch_transcripts_csv // channel: [ val(meta), ["path-to-transcripts.csv.gz"] ]
17-
ch_morphology_image // channel: [ val(meta), ["path-to-morphology_focus.tiff"] ]
18-
ch_config // channel: ["path-to-xenium.toml"]
15+
ch_bundle_path // channel: [ val(meta), ["path-to-xenium-bundle"] ]
16+
ch_transcripts_csv // channel: [ val(meta), ["path-to-transcripts.csv.gz"] ]
17+
ch_segmentation_mask // channel: [ ["path-to-prior-segmentation-mask"] ]
18+
ch_config // channel: ["path-to-xenium.toml"]
1919

2020
main:
2121

2222
ch_versions = Channel.empty()
2323

24-
ch_enhanced_tiff = Channel.empty()
2524
ch_segmentation = Channel.empty()
2625
ch_polygons2d = Channel.empty()
2726
ch_htmls = Channel.empty()
2827

2928
ch_redefined_bundle = Channel.empty()
3029
ch_unzipped_transcripts = Channel.empty()
3130

32-
3331
// unzip transcripts.csv.gz
3432
GUNZIP ( ch_transcripts_csv )
3533
ch_versions = ch_versions.mix ( GUNZIP.out.versions )
3634

3735
ch_unzipped_transcripts = GUNZIP.out.gunzip
3836

39-
// sharpen morphology tiff if param `sharpen_tiff` is true
40-
ch_just_image = Channel.empty()
41-
if ( params.sharpen_tiff ) {
42-
43-
RESOLIFT ( ch_morphology_image )
44-
ch_versions = ch_versions.mix( RESOLIFT.out.versions )
45-
46-
ch_enhanced_tiff = RESOLIFT.out.enhanced_tiff
47-
ch_just_image = ch_enhanced_tiff.map {
48-
_meta, image -> return [ image ]
49-
}
50-
51-
} else {
52-
53-
// use the original morphology tiff from the bundle
54-
ch_just_image = ch_morphology_image.map {
55-
_meta, image -> return [ image ]
56-
}
57-
}
58-
5937
// run baysor with morphology.tiff
6038
BAYSOR_RUN_IMAGE (
6139
ch_unzipped_transcripts,
62-
ch_just_image,
40+
ch_segmentation_mask,
6341
ch_config,
6442
30
6543
)
6644
ch_versions = ch_versions.mix( BAYSOR_RUN_IMAGE.out.versions )
6745

6846
ch_segmentation = BAYSOR_RUN_IMAGE.out.segmentation
69-
ch_jus_segmentation = ch_segmentation.map {
47+
ch_just_segmentation = ch_segmentation.map {
7048
_meta, segmentation -> return [ segmentation ]
7149
}
7250
ch_polygons2d = BAYSOR_RUN_IMAGE.out.polygons2d
@@ -78,18 +56,16 @@ workflow BAYSOR_RUN_MORPHOLOGY_OME_TIF {
7856
[],
7957
[],
8058
[],
81-
ch_jus_segmentation,
59+
ch_just_segmentation,
8260
ch_polygons2d,
83-
"pixel"
61+
"microns"
8462
)
8563
ch_versions = ch_versions.mix( XENIUMRANGER_IMPORT_SEGMENTATION.out.versions )
8664

8765
ch_redefined_bundle = XENIUMRANGER_IMPORT_SEGMENTATION.out.bundle
8866

8967
emit:
9068

91-
enhanced_tiff = ch_enhanced_tiff // channel: [ val(meta), ["morphology.tiff"] ]
92-
9369
segmentation = ch_segmentation // channel: [ val(meta), ["segmentation.csv"] ]
9470
polygons2d = ch_polygons2d // channel: [ ["segmentation_polygons_2d.json"] ]
9571
htmls = ch_htmls // channel: [ ["*.html"] ]

subworkflows/local/spatialdata_write_meta_merge/main.nf

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,23 @@ workflow SPATIALDATA_WRITE_META_MERGE {
1818
ch_versions = Channel.empty()
1919

2020
// write spatialdata object from the raw xenium bundle
21-
raw_bundle_path = ch_bundle_path.map { meta, file_path ->
22-
return [ meta, file(file_path) ]
23-
}
2421
SPATIALDATA_WRITE_RAW_BUNDLE (
25-
raw_bundle_path,
22+
ch_bundle_path,
2623
'spatialdata_raw'
2724
)
2825
ch_versions = ch_versions.mix ( SPATIALDATA_WRITE_RAW_BUNDLE.out.versions )
2926

3027

3128
// write spatialdata object after running IMP_SEG
32-
redefined_bundle_path = ch_redefined_bundle.map { meta, file_path ->
33-
return [ meta, file(file_path) ]
34-
}
3529
SPATIALDATA_WRITE_REDEFINED_BUNDLE (
36-
redefined_bundle_path,
30+
ch_redefined_bundle,
3731
'spatialdata_redefined'
3832
)
3933
ch_versions = ch_versions.mix ( SPATIALDATA_WRITE_REDEFINED_BUNDLE.out.versions )
4034

4135

4236
// merge raw & redefined spatialdata objects
43-
ch_just_redefined_bundle = ch_redefined_bundle.map {
37+
ch_just_redefined_bundle = SPATIALDATA_WRITE_REDEFINED_BUNDLE.out.spatialdata.map {
4438
_meta, bundle -> return [ bundle ]
4539
}
4640
SPATIALDATA_MERGE_RAW_REDEFINED (
@@ -67,6 +61,6 @@ workflow SPATIALDATA_WRITE_META_MERGE {
6761
ch_sd_merged = SPATIALDATA_MERGE_RAW_REDEFINED.out.spatialxe_bundle // channel: [ val(meta), "spatialdata_spatialxe" ]
6862
ch_sd_meta = SPATIALDATA_META.out.spatialxe_bundle // channel: [ val(meta), "spatialdata_spatialxe_final" ]
6963

70-
versions = ch_versions // channel: [ versions.yml ]
64+
versions = ch_versions // channel: [ versions.yml ]
7165
}
7266

subworkflows/local/utils_nfcore_spatialxe_pipeline/main.nf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,30 @@ def validateInputParameters() {
152152

153153
if ( params.mode == 'coordinate' && params.segmentation ) {
154154
if ( !params.transcript_seg_methods.contains(params.segmentation) ) {
155-
error "Error: Invalid segmentation method: ${params.segmentation} provided for the `coordinate` based mode. Options: ${params.transcript_seg_methods}"
155+
error "Error: Invalid segmentation method: `${params.segmentation}` provided for the `coordinate` based mode. Options: ${params.transcript_seg_methods}"
156156
}
157157
}
158158

159159
// check if --relabel_genes is true but --gene_panel is not provided
160160
if ( params.relabel_genes && !params.gene_panel ) {
161-
log.warn "Relabel genes is enabled, but gene panel is not provided with the `--gene_panel`. Using `gene_panel.json` in the xenium bundle"
161+
log.warn "Relabel genes is enabled, but gene panel is not provided with the `--gene_panel`. Using `gene_panel.json` in the xenium bundle."
162162
}
163163

164164
// check if --relabel_genes is true but --gene_panel is not provided
165165
if ( params.gene_panel && !params.relabel_genes ) {
166-
log.warn "Gene panel provided, but relabel genes is disabled. Using `gene_panel.json` only to generate metadata"
166+
log.warn "Gene panel provided, but relabel genes is disabled. Using `gene_panel.json` only to generate metadata."
167+
}
168+
169+
// check if segmentation method is xeniumranger and nucleus_ony_segmentation is enabled
170+
if ( params.segmentation == 'xeniumranger' && !params.nucleus_segmentation_only ) {
171+
log.warn "Nucleus segmentation is disabled. Running xeniumranger resegment module to redefine xenium bundle without nucleus segmentation."
172+
log.warn "Use --nucleus_segmentation_only to enable nucleus segmentation to redefine xenium bundle with import-segmentation module."
173+
}
174+
175+
if ( params.mode == 'image' && params.segmentation == 'baysor' ) {
176+
if ( !params.segmentation_mask ) {
177+
error "Error: Missing path to segmentation mask. Image-based segmentation with the `baysor` method requires a segmentation mask with the `--segmentation_mask` option."
178+
}
167179
}
168180

169181
}

subworkflows/local/xeniumranger_resegment_morphology_ome_tif/main.nf

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,44 @@ workflow XENIUMRANGER_RESEGMENT_MORPHOLOGY_OME_TIF {
1313

1414
main:
1515

16-
ch_versions = Channel.empty()
16+
ch_versions = Channel.empty()
17+
ch_redefined_bundle = Channel.empty()
1718

1819
// run resegment with changed config values
1920
XENIUMRANGER_RESEGMENT ( ch_bundle_path )
2021
ch_versions = ch_versions.mix( XENIUMRANGER_RESEGMENT.out.versions )
2122

2223

23-
// run import segmentation to redine
24-
nuclei = XENIUMRANGER_RESEGMENT.out.bundle.map {
25-
_meta, bundle -> return [ bundle + "/cells.zarr.zip" ]
26-
}
27-
cells = XENIUMRANGER_RESEGMENT.out.bundle.map {
24+
// run import segmentation to redine xenium bundle along with nuclear segmentation
25+
cells = XENIUMRANGER_RESEGMENT.out.bundle.map {
2826
_meta, bundle -> return [ bundle + "/cells.zarr.zip" ]
2927
}
3028

31-
XENIUMRANGER_IMPORT_SEGMENTATION (
32-
XENIUMRANGER_RESEGMENT.out.bundle,
33-
[],
34-
nuclei,
35-
cells,
36-
[],
37-
[],
38-
"pixel"
39-
)
40-
ch_versions = ch_versions.mix( XENIUMRANGER_IMPORT_SEGMENTATION.out.versions )
29+
// adjust the nuclear expansion distance without altering nuclei detection
30+
if ( params.nucleus_segmentation_only ) {
31+
32+
XENIUMRANGER_IMPORT_SEGMENTATION (
33+
XENIUMRANGER_RESEGMENT.out.bundle,
34+
[],
35+
cells,
36+
[],
37+
[],
38+
[],
39+
"pixels"
40+
)
41+
ch_versions = ch_versions.mix( XENIUMRANGER_IMPORT_SEGMENTATION.out.versions )
42+
43+
ch_redefined_bundle = XENIUMRANGER_IMPORT_SEGMENTATION.out.bundle
44+
45+
} else {
46+
47+
ch_redefined_bundle = XENIUMRANGER_RESEGMENT.out.bundle
48+
}
4149

4250
emit:
4351

44-
redefined_bundle = XENIUMRANGER_IMPORT_SEGMENTATION.out.bundle // channel: [ val(meta), ["redefined-xenium-bundle"] ]
52+
redefined_bundle = ch_redefined_bundle // channel: [ val(meta), ["redefined-xenium-bundle"] ]
4553

46-
versions = ch_versions // channel: [ versions.yml ]
54+
versions = ch_versions // channel: [ versions.yml ]
4755
}
4856

workflows/spatialxe.nf

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ include { BAYSOR_GENERATE_PREVIEW } from '../subworkflo
2626
include { BAYSOR_RUN_TRANSCRIPTS_CSV } from '../subworkflows/local/baysor_run_transcripts_csv/main'
2727

2828
// image-based segmentation subworklfows
29-
include { BAYSOR_RUN_MORPHOLOGY_OME_TIF } from '../subworkflows/local/baysor_run_morphology_ome_tif/main'
29+
include { BAYSOR_RUN_PRIOR_SEGMENTATION_MASK } from '../subworkflows/local/baysor_run_prior_segmentation_mask/main'
3030
include { CELLPOSE_RESOLIFT_MORPHOLOGY_OME_TIF } from '../subworkflows/local/cellpose_resolift_morphology_ome_tif/main'
3131
include { CELLPOSE_BAYSOR_IMPORT_SEGMENTATION } from '../subworkflows/local/cellpose_baysor_import_segmentation/main'
3232
include { XENIUMRANGER_RESEGMENT_MORPHOLOGY_OME_TIF } from '../subworkflows/local/xeniumranger_resegment_morphology_ome_tif/main'
@@ -100,25 +100,27 @@ workflow SPATIALXE {
100100
def transcripts_csv = file(bundle.replaceFirst(/\/$/, '') + "/transcripts.csv.gz")
101101
return [ meta, transcripts_csv ]
102102
}
103-
// ch_transcripts_csv.view()
104103

105104
// get transcript.parquet from the xenium bundle
106105
ch_transcripts_parquet = ch_samplesheet.map { meta, bundle, _image ->
107106
def transcripts_parquet = file(bundle.replaceFirst(/\/$/, '') + "/transcripts.parquet")
108107
return [ meta, transcripts_parquet ]
109108
}
110-
// ch_transcripts_parquet.view()
111109

112110
// get morphology.ome.tif from the xenium bundle
113111
ch_morphology_image = ch_samplesheet.map { meta, bundle, image ->
114112
def morphology_img = image ? file(image) : file(bundle.replaceFirst(/\/$/, '') + "/morphology.ome.tif")
115113
return [ meta, morphology_img ]
116114
}
117-
// ch_morphology_image.view()
118115

119116
// get baysor xenium config
120117
ch_config = Channel.fromPath("${projectDir}/assets/config/xenium.toml", checkIfExists: true)
121118

119+
// get segmentation mask if provided with --segmentation_mask for the baysor method
120+
if ( params.segmentation_mask ) {
121+
ch_segmentation_mask = Channel.fromPath(params.segmentation_mask, checkIfExists: true)
122+
}
123+
122124
// get gene_panel.json if provided with --gene_panel, sets relabel_genes to true
123125
if (( params.gene_panel )) {
124126

@@ -203,13 +205,13 @@ workflow SPATIALXE {
203205
// run baysor run with morphology_ome.tif
204206
if ( params.segmentation == 'baysor' ) {
205207

206-
BAYSOR_RUN_MORPHOLOGY_OME_TIF (
208+
BAYSOR_RUN_PRIOR_SEGMENTATION_MASK (
207209
ch_bundle_path,
208210
ch_transcripts_csv,
209-
ch_morphology_image,
211+
ch_segmentation_mask,
210212
ch_config
211213
)
212-
ch_redefined_bundle = BAYSOR_RUN_MORPHOLOGY_OME_TIF.out.redefined_bundle
214+
ch_redefined_bundle = BAYSOR_RUN_PRIOR_SEGMENTATION_MASK.out.redefined_bundle
213215
}
214216

215217
// run cellpose on the morphology_ome.tif

0 commit comments

Comments
 (0)