Skip to content

Commit 46b65e9

Browse files
committed
collated all parcellations to a single directory before returning
1 parent 857cc65 commit 46b65e9

File tree

3 files changed

+40
-98
lines changed

3 files changed

+40
-98
lines changed

specs/australian-imaging-service/mri/human/neuro/t1w/preprocess.yaml

Lines changed: 4 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ commands:
108108
column_defaults:
109109
datatype: medimage/nifti-gz # medimage/dicom-series # the default
110110
outputs: # List the outputs generated by the pipeline
111+
parcellations:
112+
field: parcellations
113+
datatype: medimage-mrtrix3/image-format+directory-of # MIME-type or "MIME-like" format
114+
help: generated parcellation images # description of field presented in UI
111115
vis_image_fsl:
112116
field: vis_image_fsl
113117
datatype: medimage-mrtrix3/image-format-gz # MIME-type or "MIME-like" format
@@ -132,98 +136,6 @@ commands:
132136
field: ftt_image_hsvs
133137
datatype: medimage-mrtrix3/image-format-gz # MIME-type or "MIME-like" format
134138
help: 5tt image HSVS # description of field presented in UI
135-
aparca2009s:
136-
field: aparca2009s
137-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
138-
help: aparca2009s parcellation image
139-
aparc:
140-
field: aparc
141-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
142-
help: aparc parcellation image
143-
desikan:
144-
field: desikan
145-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
146-
help: desikan parcellation image
147-
destrieux:
148-
field: destrieux
149-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
150-
help: destrieux parcellation image
151-
economo:
152-
field: economo
153-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
154-
help: economo parcellation image
155-
glasser360:
156-
field: glasser360
157-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
158-
help: glasser360 parcellation image
159-
hcpmmp1:
160-
field: hcpmmp1
161-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
162-
help: hcpmmp1 parcellation image
163-
schaefer100:
164-
field: schaefer100
165-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
166-
help: schaefer100 parcellation image
167-
schaefer1000:
168-
field: schaefer1000
169-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
170-
help: schaefer1000 parcellation image
171-
schaefer200:
172-
field: schaefer200
173-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
174-
help: schaefer200 parcellation image
175-
schaefer300:
176-
field: schaefer300
177-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
178-
help: schaefer300 parcellation image
179-
schaefer400:
180-
field: schaefer400
181-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
182-
help: schaefer400 parcellation image
183-
schaefer500:
184-
field: schaefer500
185-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
186-
help: schaefer500 parcellation image
187-
schaefer600:
188-
field: schaefer600
189-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
190-
help: schaefer600 parcellation image
191-
schaefer700:
192-
field: schaefer700
193-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
194-
help: schaefer700 parcellation image
195-
schaefer800:
196-
field: schaefer800
197-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
198-
help: schaefer800 parcellation image
199-
schaefer900:
200-
field: schaefer900
201-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
202-
help: schaefer900 parcellation image
203-
vosdewael100:
204-
field: vosdewael100
205-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
206-
help: vosdewael100 parcellation image
207-
vosdewael200:
208-
field: vosdewael200
209-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
210-
help: vosdewael200 parcellation image
211-
vosdewael300:
212-
field: vosdewael300
213-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
214-
help: vosdewael300 parcellation image
215-
vosdewael400:
216-
field: vosdewael400
217-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
218-
help: vosdewael400 parcellation image
219-
yeo17:
220-
field: Yeo17
221-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
222-
help: Yeo17 parcellation image
223-
yeo7:
224-
field: Yeo7
225-
datatype: medimage-mrtrix3/image-format # MIME-type or "MIME-like" format
226-
help: Yeo7 parcellation image
227139
parameters:
228140
parcellation:
229141
datatype: field/text # Format of the field

src/australianimagingservice/mri/human/neuro/t1w/preprocess.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@
1010
FivettGen_Freesurfer,
1111
FivettGen_Fsl,
1212
)
13-
from fileformats.generic import Directory
13+
from fileformats.generic import Directory, DirectoryOf
1414
from fileformats.medimage import NiftiGz
15+
from fileformats.medimage_mrtrix3 import ImageFormat as Mif
1516
from pydra.tasks.fastsurfer.latest import Fastsurfer
17+
from pydra.engine.task import FunctionTask
18+
from pydra.engine.specs import BaseSpec
1619
from pathlib import Path
1720
import os
1821

1922
os.environ["SUBJECTS_DIR"] = ""
2023

2124

22-
def preprocess(
25+
def single_parc(
2326
parcellation: str,
2427
freesurfer_home: Path,
2528
mrtrix_lut_dir: Path,
@@ -1033,7 +1036,7 @@ def join_task_catalogue(
10331036
] # List of different parcellations
10341037

10351038

1036-
def preprocess_all_parcs(
1039+
def all_parcs(
10371040
freesurfer_home: Path,
10381041
mrtrix_lut_dir: Path,
10391042
cache_dir: Path,
@@ -1055,6 +1058,28 @@ def preprocess_all_parcs(
10551058
cache_dir=cache_dir,
10561059
)
10571060

1061+
def collate_parcs(out_dir: Path, **parcs: Mif) -> DirectoryOf[Mif]: # type: ignore[type-arg]
1062+
for name, parc in parcs.values():
1063+
parc.copy(out_dir, new_stem=name)
1064+
return DirectoryOf[Mif](out_dir) # type: ignore[no-any-return,type-arg,misc]
1065+
1066+
wf.add(
1067+
FunctionTask(
1068+
collate_parcs,
1069+
name="collate_parcs",
1070+
input_spec=SpecInfo(
1071+
name="CollateParcsInputs",
1072+
bases=(BaseSpec,),
1073+
fields=[(p, Mif) for p in parcellation_list],
1074+
),
1075+
output_spec=SpecInfo(
1076+
name="CollateParcsOutputs",
1077+
bases=(BaseSpec,),
1078+
fields=[("out_dir", DirectoryOf[Mif])], # type: ignore[misc]
1079+
),
1080+
)
1081+
)
1082+
10581083
for parcellation in parcellation_list:
10591084

10601085
wf.add(
@@ -1071,8 +1096,13 @@ def preprocess_all_parcs(
10711096
)
10721097
)
10731098

1074-
wf.set_output([(parcellation, getattr(wf, parcellation).lzout.parc_image)])
1099+
setattr(
1100+
wf.collate_parcs.inputs,
1101+
parcellation,
1102+
getattr(wf, parcellation).lzout.parc_image,
1103+
)
10751104

1105+
wf.set_output(("parcellations", wf.collate_parcs.lzout.out_dir))
10761106
wf.set_output(("vis_image_fsl", wf.desikan.lzout.vis_image_fsl))
10771107
wf.set_output(("ftt_image_fsl", wf.desikan.lzout.ftt_image_fsl))
10781108
wf.set_output(("vis_image_freesurfer", wf.desikan.lzout.vis_image_freesurfer))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from australianimagingservice.mri.human.neuro.t1w.preprocess import preprocess
1+
from australianimagingservice.mri.human.neuro.t1w.preprocess import all_parcs
22

33

44
def test_t1w_preprocess():
5-
preprocess()
5+
all_parcs()

0 commit comments

Comments
 (0)