Skip to content

Commit 0c353e7

Browse files
Merge pull request nf-core#98 from khersameesh24/dev
Changes to spatialdata handling based on coordinate space
2 parents b4e4926 + afc1b4c commit 0c353e7

File tree

15 files changed

+109
-47
lines changed

15 files changed

+109
-47
lines changed

modules/local/ficture/model/main.nf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ process FICTURE {
1919
script:
2020
def args = task.ext.args ?: ''
2121
def prefix = task.ext.prefix ?: "${meta.id}"
22-
def features = features ? "--in-feature ${features}": ""
22+
def features_list = features ? "--in-feature ${features}": ""
2323

2424
"""
2525
ficture run_together \\
2626
--in-tsv ${transcripts} \\
2727
--in-minmax ${coordinate_minmax} \\
28-
${features} \\
28+
${features_list} \\
2929
--out-dir results \\
3030
--train-width 12,18 \\
3131
--n-factor 6,12 \\

modules/local/spatialdata/write/main.nf

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

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

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ def main():
1313
output_path = "."
1414
outputfolder = "${outputfolder}"
1515
segmented_object = "${segmented_object}"
16+
coordinate_space = "${coordinate_space}"
1617

17-
cells_as_circles=True
18+
cells_as_circles=False
1819
cells_boundaries=False
1920
nucleus_boundaries=False
2021
cells_labels=False
@@ -32,7 +33,19 @@ def main():
3233
cells_labels=True
3334
nucleus_labels=True
3435
else:
35-
cells_as_circles=False
36+
cells_as_circles = False
37+
38+
# set sd variables based on the coordinate space
39+
if ( coordinate_space == "pixels" ):
40+
cells_labels = True
41+
nucleus_labels = True
42+
43+
if ( coordinate_space == "microns" ):
44+
cells_labels = False
45+
cells_boundaries = True
46+
nucleus_boundaries = False
47+
nucleus_labels = False
48+
cells_as_circles = False
3649

3750
format = "${params.format}"
3851
if ( format == "xenium" ):

nextflow.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ dag {
270270

271271
manifest {
272272
name = 'nf-core/spatialxe'
273-
author = """Florian Heyl""" // The author field is deprecated from Nextflow version 24.10.0, use contributors instead
274273
contributors = [
275274
[
276275
name: 'Sameesh Kher',

subworkflows/local/baysor_run_prior_segmentation_mask/main.nf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ workflow BAYSOR_RUN_PRIOR_SEGMENTATION_MASK {
2727
ch_htmls = Channel.empty()
2828

2929
ch_redefined_bundle = Channel.empty()
30+
ch_coordinate_space = Channel.value("microns")
3031

3132
// filter transcripts.parquet based on thresholds
3233
if ( params.filter_transcripts ) {
@@ -72,7 +73,7 @@ workflow BAYSOR_RUN_PRIOR_SEGMENTATION_MASK {
7273
[],
7374
ch_just_segmentation,
7475
ch_polygons2d,
75-
"microns"
76+
ch_coordinate_space
7677
)
7778
ch_versions = ch_versions.mix( XENIUMRANGER_IMPORT_SEGMENTATION.out.versions )
7879

@@ -84,6 +85,8 @@ workflow BAYSOR_RUN_PRIOR_SEGMENTATION_MASK {
8485
polygons2d = ch_polygons2d // channel: [ ["segmentation_polygons_2d.json"] ]
8586
htmls = ch_htmls // channel: [ ["*.html"] ]
8687

88+
coordinate_space = ch_coordinate_space // channel: [ "microns" ]
89+
8790
redefined_bundle = ch_redefined_bundle // channel: [ val(meta), "redefined-xenium-bundle" ]
8891

8992
versions = ch_versions // channel: [ versions.yml ]

subworkflows/local/baysor_run_transcripts_parquet/main.nf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ workflow BAYSOR_RUN_TRANSCRIPTS_PARQUET {
2828
ch_htmls = Channel.empty()
2929

3030
ch_redefined_bundle = Channel.empty()
31+
ch_coordinate_space = Channel.value("microns")
3132

3233

3334
// generate splits
@@ -102,7 +103,7 @@ workflow BAYSOR_RUN_TRANSCRIPTS_PARQUET {
102103
[],
103104
ch_segmentation_csv,
104105
ch_polygons2d,
105-
"microns"
106+
ch_coordinate_space
106107
)
107108
ch_versions = ch_versions.mix( XENIUMRANGER_IMPORT_SEGMENTATION.out.versions )
108109

@@ -114,6 +115,8 @@ workflow BAYSOR_RUN_TRANSCRIPTS_PARQUET {
114115
polygons2d = ch_polygons2d // channel: [ ["segmentation_polygons_2d.json"] ]
115116
htmls = ch_htmls // channel: [ ["*.html"] ]
116117

118+
coordinate_space = ch_coordinate_space // channel: [ ["microns"] ]
119+
117120
redefined_bundle = ch_redefined_bundle // channel: [ val(meta), "redefined-xenium-bundle" ]
118121

119122
versions = ch_versions // channel: [ versions.yml ]

subworkflows/local/cellpose_baysor_import_segmentation/main.nf

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ workflow CELLPOSE_BAYSOR_IMPORT_SEGMENTATION {
2424
ch_image = Channel.empty()
2525
ch_polygons = Channel.empty()
2626
ch_segmentation = Channel.empty()
27+
ch_transcripts = Channel.empty()
2728
ch_filtered_transcripts = Channel.empty()
2829
ch_cellpose_cells_mask = Channel.empty()
2930
ch_cellpose_nuclei_mask = Channel.empty()
3031
ch_cellpose_cells_cells = Channel.empty()
3132
ch_cellpose_nuclei_cells = Channel.empty()
3233
ch_cellpose_cells_flows = Channel.empty()
3334
ch_cellpose_nuclei_flows = Channel.empty()
35+
ch_coordinate_space = Channel.value("microns")
3436

3537
cellpose_model = params.cellpose_model ? (Channel.fromPath(params.cellpose_model, checkIfExists: true)) : []
3638

@@ -98,30 +100,35 @@ workflow CELLPOSE_BAYSOR_IMPORT_SEGMENTATION {
98100
ch_versions = ch_versions.mix ( BAYSOR_PREPROCESS_TRANSCRIPTS.out.versions )
99101

100102
ch_filtered_transcripts = BAYSOR_PREPROCESS_TRANSCRIPTS.out.transcripts_parquet
103+
ch_transcripts = ch_filtered_transcripts
101104

105+
} else {
106+
107+
ch_transcripts = ch_transcripts_parquet
102108
}
103109

104110
// run baysor with cellpose results
105111
if ( params.nucleus_segmentation_only ) {
106112

107113
// run baysor with nuclei mask
108-
BAYSOR_RUN ( ch_filtered_transcripts, ch_cellpose_nuclei_mask, ch_config, 30 )
114+
BAYSOR_RUN ( ch_transcripts, ch_cellpose_nuclei_mask, ch_config, 30 )
109115
ch_versions = ch_versions.mix ( BAYSOR_RUN.out.versions )
110116

111117
} else if ( params.cell_segmentation_only ) {
112118

113119
// run baysor with cell mask
114-
BAYSOR_RUN ( ch_filtered_transcripts, ch_cellpose_cells_mask, ch_config, 30 )
120+
BAYSOR_RUN ( ch_transcripts, ch_cellpose_cells_mask, ch_config, 30 )
115121
ch_versions = ch_versions.mix ( BAYSOR_RUN.out.versions )
116122

117123
} else {
118124

119125
// run baysor with cell mask
120-
BAYSOR_RUN ( ch_filtered_transcripts, [], ch_config, 30 )
126+
BAYSOR_RUN ( ch_transcripts, [], ch_config, 30 )
121127
ch_versions = ch_versions.mix ( BAYSOR_RUN.out.versions )
122128

123129
}
124130

131+
125132
// run import-segmentation with baysor outs
126133
ch_segmentation = BAYSOR_RUN.out.segmentation.map {
127134
_meta, segmentation -> return [ segmentation ]
@@ -136,7 +143,7 @@ workflow CELLPOSE_BAYSOR_IMPORT_SEGMENTATION {
136143
[],
137144
ch_segmentation,
138145
ch_polygons,
139-
"microns"
146+
ch_coordinate_space
140147
)
141148
ch_versions = ch_versions.mix ( XENIUMRANGER_IMPORT_SEGMENTATION.out.versions )
142149

@@ -152,6 +159,8 @@ workflow CELLPOSE_BAYSOR_IMPORT_SEGMENTATION {
152159
segmentation_mask = ch_segmentation // channel: [ val(meta), [ *segmentation.csv ] ]
153160
polygons = ch_polygons // channel: [ val(meta), [ *polygons.json ] ]
154161

162+
coordinate_space = ch_coordinate_space // channel: [ val("microns") ]
163+
155164
redefined_bundle = XENIUMRANGER_IMPORT_SEGMENTATION.out.bundle // channel: [ val(meta), ["redefined-xenium-bundle"] ]
156165

157166
versions = ch_versions // channel: [ versions.yml ]

subworkflows/local/cellpose_resolift_morphology_ome_tif/main.nf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ workflow CELLPOSE_RESOLIFT_MORPHOLOGY_OME_TIF {
2424
ch_cellpose_nuclei_cells = Channel.empty()
2525
ch_cellpose_cells_flows = Channel.empty()
2626
ch_cellpose_nuclei_flows = Channel.empty()
27+
ch_coordinate_space = Channel.value("pixels")
2728

2829
cellpose_model = params.cellpose_model ? (Channel.fromPath(params.cellpose_model, checkIfExists: true)) : []
2930

@@ -82,7 +83,7 @@ workflow CELLPOSE_RESOLIFT_MORPHOLOGY_OME_TIF {
8283
[],
8384
[],
8485
[],
85-
""
86+
ch_coordinate_space
8687
)
8788
ch_versions = ch_versions.mix( XENIUMRANGER_IMPORT_SEGMENTATION.out.versions )
8889

@@ -95,7 +96,7 @@ workflow CELLPOSE_RESOLIFT_MORPHOLOGY_OME_TIF {
9596
ch_cellpose_cells_mask,
9697
[],
9798
[],
98-
""
99+
ch_coordinate_space
99100
)
100101
ch_versions = ch_versions.mix( XENIUMRANGER_IMPORT_SEGMENTATION.out.versions )
101102
}
@@ -109,6 +110,8 @@ workflow CELLPOSE_RESOLIFT_MORPHOLOGY_OME_TIF {
109110
nuclei_flows = ch_cellpose_nuclei_flows // channel: [ val(meta), [ "*flows.tif" ] ]
110111
nuclei_cells = ch_cellpose_nuclei_cells // channel: [ val(meta), [ "*seg.npy" ] ]
111112

113+
coordinate_space = ch_coordinate_space // channel: [ ["pixels"] ]
114+
112115
redefined_bundle = XENIUMRANGER_IMPORT_SEGMENTATION.out.bundle // channel: [ val(meta), ["redefined-xenium-bundle"] ]
113116

114117
versions = ch_versions // channel: [ versions.yml ]

subworkflows/local/proseg_preset_proseg2baysor/main.nf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ workflow PROSEG_PRESET_PROSEG2BAYSOR {
1717
main:
1818

1919
ch_versions = Channel.empty()
20+
ch_coordinate_space = Channel.value("microns")
2021

2122
// run parquet-to-csv
2223
PARQUET_TO_CSV ( ch_transcripts_parquet, ".gz" )
@@ -43,7 +44,7 @@ workflow PROSEG_PRESET_PROSEG2BAYSOR {
4344
[],
4445
ch_metadata,
4546
ch_polygons,
46-
"microns"
47+
ch_coordinate_space
4748
)
4849
ch_versions = ch_versions.mix( XENIUMRANGER_IMPORT_SEGMENTATION.out.versions )
4950

@@ -53,6 +54,7 @@ workflow PROSEG_PRESET_PROSEG2BAYSOR {
5354

5455
xr_polygons = PROSEG2BAYSOR.out.xr_polygons // channel: [ val(meta), [ "xr-cell-polygons.geojson" ] ]
5556
xr_metadata = PROSEG2BAYSOR.out.xr_metadata // channel: [ [ "xr-transcript-metadata.csv" ] ]
57+
coordinate_space = ch_coordinate_space // channel: [ "microns" ]
5658

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

subworkflows/local/segger_create_train_predict/main.nf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ workflow SEGGER_CREATE_TRAIN_PREDICT {
2121
ch_versions = Channel.empty()
2222
ch_redefined_bundle = Channel.empty()
2323
ch_segger_transcripts = Channel.empty()
24+
ch_coordinate_space = Channel.value("pixels")
2425

2526
// create dataset
2627
SEGGER_CREATE_DATASET ( ch_basedir )
@@ -52,12 +53,13 @@ workflow SEGGER_CREATE_TRAIN_PREDICT {
5253
_meta, transcripts -> return [ transcripts ]
5354
}
5455

56+
5557
// replace transcripts.parquet in xenium bundle
56-
ch_updated_bundle = ch_bundle.map { fobj ->
57-
if (fobj.name == 'transcripts.parquet') {
58+
ch_updated_bundle = ch_bundle.map { fileobj ->
59+
if (fileobj.name == 'transcripts.parquet') {
5860
ch_segger_transcripts.val
5961
} else {
60-
fobj
62+
fileobj
6163
}
6264
}
6365

@@ -70,7 +72,7 @@ workflow SEGGER_CREATE_TRAIN_PREDICT {
7072
[],
7173
[],
7274
[],
73-
"pixel"
75+
ch_coordinate_space
7476
)
7577
ch_redefined_bundle = XENIUMRANGER_IMPORT_SEGMENTATION.out.bundle
7678

@@ -84,6 +86,8 @@ workflow SEGGER_CREATE_TRAIN_PREDICT {
8486
benchmarks = SEGGER_PREDICT.out.benchmarks // channel: [ val(meta), [ benchmarks ] ]
8587
segger_transcripts = ch_segger_transcripts // channel: [ [ transcripts.parquet ] ]
8688

89+
coordinate_space = ch_coordinate_space // channel: [ ["pixels"] ]
90+
8791
redefined_bundle = ch_redefined_bundle // channel: [ val(meta), ["redefined-xenium-bundle"] ]
8892

8993
versions = ch_versions // channel: [ versions.yml ]

0 commit comments

Comments
 (0)