11"""Command-line interface."""
2- import re
32from typing import Sequence
43from typing import Union
54
65import click
76
8- from zerodose .run_abnormality import create_abnormality_maps
9- from zerodose .run_synthesize import synthesize_baselines
7+ from zerodose .pipeline import create_abnormality_maps
8+ from zerodose .pipeline import normalize_to_pet
9+ from zerodose .pipeline import run_full
10+ from zerodose .pipeline import synthesize_baselines
11+ from zerodose .utils import _create_output_fname
1012
1113
1214@click .group ()
@@ -79,50 +81,48 @@ def main() -> None:
7981 Useful if the input images already are in MNI space""" ,
8082)
8183
84+ outputspace_option = click .option (
85+ "--space" ,
86+ "outputspace" ,
87+ type = click .Choice (
88+ [
89+ "mr" ,
90+ "pet" ,
91+ ]
92+ ),
93+ default = "mr" ,
94+ help = "Which space to " ,
95+ )
96+
8297
8398@main .command ()
8499@mri_option
85100@mask_option
86101@sbpet_output_option
87102@verbose_option
88103@device_option
89- @no_registration_option
90104def syn (
91105 mri_fnames : Sequence [str ],
92106 mask_fnames : Sequence [str ],
93107 out_fnames : Union [Sequence [str ], None ] = None ,
94108 verbose : bool = True ,
95109 device : str = "cuda:0" ,
96- no_registration : bool = False ,
97110) -> None :
98111 """Synthesize baseline PET images."""
99112 if out_fnames is None or len (out_fnames ) == 0 :
100113 out_fnames = [
101- _create_output_fname (mri_fname , suffix = "_sb " ) for mri_fname in mri_fnames
114+ _create_output_fname (mri_fname , suffix = "_sbraw " ) for mri_fname in mri_fnames
102115 ]
103116
104- do_registration = not no_registration
105117 synthesize_baselines (
106118 mri_fnames ,
107119 mask_fnames ,
108120 out_fnames ,
109121 verbose = verbose ,
110122 device = device ,
111- do_registration = do_registration ,
112123 )
113124
114125
115- def _create_output_fname (mri_fname , suffix = "_sb" , file_type = ".nii.gz" ):
116- """Create output filename from input filename."""
117- out_fname = mri_fname
118- if out_fname .endswith (".nii.gz" ):
119- out_fname = re .sub (".nii.gz$" , "" , out_fname )
120- if out_fname .endswith (".nii" ):
121- out_fname = re .sub (".nii$" , "" , out_fname )
122- out_fname += suffix + file_type
123- return out_fname
124-
125-
126126pet_option = click .option (
127127 "-p" ,
128128 "--pet" ,
@@ -149,6 +149,14 @@ def _create_output_fname(mri_fname, suffix="_sb", file_type=".nii.gz"):
149149 multiple = True ,
150150)
151151
152+ no_resample_mask_option = click .option (
153+ "--no-resample-mask" ,
154+ "no_resample_mask" ,
155+ is_flag = True ,
156+ default = False ,
157+ help = "Print verbose output." ,
158+ )
159+
152160
153161@pet_option
154162@sbpet_option
@@ -179,3 +187,180 @@ def abn(
179187 verbose = verbose ,
180188 device = device ,
181189 )
190+
191+
192+ no_resample_sbpet_option = click .option (
193+ "--no-resample-sbpet" ,
194+ "no_resample_sbpet" ,
195+ is_flag = True ,
196+ default = False ,
197+ help = "Print verbose output." ,
198+ )
199+
200+
201+ @pet_option
202+ @sbpet_option
203+ @mask_option
204+ @abn_output_option
205+ @verbose_option
206+ @device_option
207+ @main .command ()
208+ def norm (
209+ pet_fnames : Sequence [str ],
210+ sbpet_fnames : Sequence [str ],
211+ mask_fnames : Sequence [str ],
212+ out_fnames : Union [Sequence [str ], None ] = None ,
213+ verbose : bool = False ,
214+ device : str = "cuda:0" ,
215+ ):
216+ """Normalize sbPET images to PET images."""
217+ if out_fnames is None or len (out_fnames ) == 0 :
218+ out_fnames = [
219+ _create_output_fname (pet_name , suffix = "_sb" ) for pet_name in pet_fnames
220+ ]
221+
222+ normalize_to_pet (
223+ pet_fnames = pet_fnames ,
224+ sbpet_fnames = sbpet_fnames ,
225+ mask_fnames = mask_fnames ,
226+ out_fnames = out_fnames ,
227+ verbose = verbose ,
228+ device = device ,
229+ )
230+
231+
232+ no_image_option = click .option (
233+ "--no-image" ,
234+ "no_image" ,
235+ is_flag = True ,
236+ default = False ,
237+ help = "Print verbose output." ,
238+ )
239+
240+ mri_option_single = click .option (
241+ "-i" ,
242+ "--mri" ,
243+ "mri_fname" ,
244+ type = click .Path (exists = True ),
245+ required = True ,
246+ )
247+ mask_option_single = click .option (
248+ "-m" ,
249+ "--mask" ,
250+ "mask_fname" ,
251+ type = click .Path (exists = True ),
252+ required = True ,
253+ )
254+
255+ pet_option_single = click .option (
256+ "-p" ,
257+ "--pet" ,
258+ "pet_fname" ,
259+ type = click .Path (exists = True ),
260+ required = False ,
261+ )
262+
263+ sbpet_output_option_single = click .option (
264+ "-os" ,
265+ "--out-sbpet" ,
266+ "out_sbpet" ,
267+ type = click .Path (),
268+ required = False ,
269+ )
270+
271+ abn_output_option_single = click .option (
272+ "-oa" ,
273+ "--out-abn" ,
274+ "out_abn" ,
275+ type = click .Path (),
276+ required = False ,
277+ )
278+
279+ img_output_option_single = click .option (
280+ "-oi" ,
281+ "--out-img" ,
282+ "out_img" ,
283+ type = click .Path (),
284+ required = False ,
285+ )
286+
287+ no_abnormality_option = click .option (
288+ "--no-abn" ,
289+ "no_abnormality" ,
290+ is_flag = True ,
291+ default = False ,
292+ help = "Print verbose output." ,
293+ )
294+
295+ no_normalization_option = click .option (
296+ "--no-norm" ,
297+ "no_normalization" ,
298+ is_flag = True ,
299+ default = False ,
300+ help = "Print verbose output." ,
301+ )
302+
303+ no_image_option = click .option (
304+ "--no-img" ,
305+ "no_image" ,
306+ is_flag = True ,
307+ default = False ,
308+ help = "Print verbose output." ,
309+ )
310+
311+
312+ @mri_option_single
313+ @mask_option_single
314+ @pet_option_single
315+ @sbpet_output_option_single
316+ @abn_output_option_single
317+ @img_output_option_single
318+ @no_registration_option
319+ @no_abnormality_option
320+ @no_normalization_option
321+ @no_image_option
322+ @verbose_option
323+ @device_option
324+ @outputspace_option
325+ @main .command ()
326+ def run (
327+ mri_fname ,
328+ mask_fname ,
329+ pet_fname ,
330+ out_sbpet ,
331+ out_abn ,
332+ out_img ,
333+ no_registration ,
334+ no_abnormality ,
335+ no_normalization ,
336+ no_image ,
337+ verbose ,
338+ device ,
339+ outputspace ,
340+ ):
341+ """Run full pipeline."""
342+ do_registration = not no_registration
343+ do_abnormality = not no_abnormality
344+ do_normalization = not no_normalization
345+ do_image = not no_image
346+
347+ if out_sbpet is None :
348+ out_sbpet = _create_output_fname (pet_fname , suffix = "_sb" )
349+ if out_abn is None :
350+ out_abn = _create_output_fname (pet_fname , suffix = "_abn" )
351+
352+ run_full (
353+ mri_fname = mri_fname ,
354+ mask_fname = mask_fname ,
355+ out_sbpet = out_sbpet ,
356+ pet_fname = pet_fname ,
357+ out_abn = out_abn ,
358+ out_img = out_img ,
359+ do_registration = do_registration ,
360+ do_abnormality = do_abnormality ,
361+ do_normalization = do_normalization ,
362+ do_image = do_image ,
363+ verbose = verbose ,
364+ device = device ,
365+ outputspace = outputspace ,
366+ )
0 commit comments