1+ import argparse
12import copy
23import json
34import pathlib as pl
@@ -119,17 +120,17 @@ class PipelineCombination:
119120 pipeline_id : str
120121 pipeline_perturb_id : str
121122 step : PipelineStep
122- connectivity_method : str
123- use_nuisance_correction : bool
123+ # connectivity_method: str
124+ # use_nuisance_correction: bool
124125
125126 def name (self , pipeline_num : int ) -> str :
126127 return (
127128 f"p{ pipeline_num :03d} _"
128129 f"base-{ filesafe (self .pipeline_id )} _"
129130 f"perturb-{ filesafe (self .pipeline_perturb_id )} _"
130131 f"step-{ filesafe (self .step .name )} _"
131- f"conn-{ filesafe (self .connectivity_method )} _"
132- f"nuisance-{ filesafe (str (self .use_nuisance_correction ))} "
132+ # f"conn-{filesafe(self.connectivity_method)}_"
133+ # f"nuisance-{filesafe(str(self.use_nuisance_correction))}"
133134 )
134135
135136 def filename (self , pipeline_num : int ) -> str :
@@ -143,15 +144,15 @@ def iter_pipeline_combis() -> Generator[PipelineCombination, Any, None]:
143144 for pipeline_id in PIPELINE_NAMES .keys ():
144145 for pipeline_perturb_id in PIPELINE_NAMES .keys ():
145146 for step in PIPELINE_STEPS :
146- for connectivity_method in CONNECTIVITY_METHODS :
147- for nuisance_method in NUISANCE_METHODS :
148- yield PipelineCombination (
149- pipeline_id = pipeline_id ,
150- pipeline_perturb_id = pipeline_perturb_id ,
151- step = step ,
152- connectivity_method = connectivity_method ,
153- use_nuisance_correction = nuisance_method ,
154- )
147+ # for connectivity_method in CONNECTIVITY_METHODS:
148+ # for nuisance_method in NUISANCE_METHODS:
149+ yield PipelineCombination (
150+ pipeline_id = pipeline_id ,
151+ pipeline_perturb_id = pipeline_perturb_id ,
152+ step = step ,
153+ # connectivity_method=connectivity_method,
154+ # use_nuisance_correction=nuisance_method,
155+ )
155156
156157
157158def iter_pipeline_combis_no_duplicates () -> Generator [PipelineCombination , Any , None ]:
@@ -241,30 +242,30 @@ def generate_pipeline_from_combi(
241242 index = ["timeseries_extraction" , "run" ],
242243 value = True ,
243244 )
244- multi_set (
245- pipeline .config ,
246- index = ["timeseries_extraction" , "connectivity_matrix" , "using" ],
247- value = aslist (combi .connectivity_method ),
248- )
245+ # multi_set(
246+ # pipeline.config,
247+ # index=["timeseries_extraction", "connectivity_matrix", "using"],
248+ # value=aslist(combi.connectivity_method),
249+ # )
249250 multi_set (
250251 pipeline .config ,
251252 index = ["timeseries_extraction" , "connectivity_matrix" , "measure" ],
252253 value = aslist ("Pearson" ),
253254 )
254255
255256 # Set nuisance method
256- # Using regressors for calculations
257- multi_set (
258- pipeline .config ,
259- index = ["nuisance_corrections" , "2-nuisance_regression" , "run" ],
260- value = aslist (combi .use_nuisance_correction ),
261- )
262- # Generating regressors (opposed to ingressing them)
263- multi_set (
264- pipeline .config ,
265- index = ["nuisance_corrections" , "2-nuisance_regression" , "create_regressors" ],
266- value = combi .use_nuisance_correction ,
267- )
257+ # # Using regressors for calculations
258+ # multi_set(
259+ # pipeline.config,
260+ # index=["nuisance_corrections", "2-nuisance_regression", "run"],
261+ # value=aslist(combi.use_nuisance_correction),
262+ # )
263+ # # Generating regressors (opposed to ingressing them)
264+ # multi_set(
265+ # pipeline.config,
266+ # index=["nuisance_corrections", "2-nuisance_regression", "create_regressors"],
267+ # value=combi.use_nuisance_correction,
268+ # )
268269
269270 # Deactivate all other derivatives than connectomes
270271 _config_deactivate_derivatives (pipeline )
@@ -281,15 +282,48 @@ def generate_pipeline_from_combi(
281282 value = True ,
282283 )
283284
285+ # Dont run Freesurfer recon_all
286+ multi_set (
287+ pipeline .config ,
288+ index = ["surface_analysis" , "freesurfer" , "run_reconall" ],
289+ value = False ,
290+ )
291+
292+ # Dont run any connectivity stuff
293+ multi_del (
294+ pipeline .config ,
295+ index = ["timeseries_extraction" , "connectivity_matrix" ],
296+ )
297+
298+ # Hardcode freesurfer ingress dir
299+ multi_set (
300+ pipeline .config ,
301+ index = ["pipeline_setup" , "freesurfer_dir" ],
302+ value = "/ocean/projects/med220004p/trogers1/many_pipelines/freesurfer/outputs/ABCD_all_subjects" ,
303+ )
304+
284305 # Set pipeline name
285306 pipeline .set_name (combi .name (pipeline_num ))
286307
287308 return pipeline
288309
289310
290- def main () -> None :
311+ def main (force = False ) -> None :
291312 """Main entry point for the CLI"""
292313
314+ # Delete build and dist directories if force is True
315+ if force :
316+ dir_dist = pl .Path ("dist" )
317+ dir_build = pl .Path ("build" )
318+
319+ if dir_dist .exists ():
320+ print (f"Force option enabled: Removing { dir_dist } " )
321+ shutil .rmtree (dir_dist )
322+
323+ if dir_build .exists ():
324+ print (f"Force option enabled: Removing { dir_build } " )
325+ shutil .rmtree (dir_build )
326+
293327 checkout_sha = CPAC_SHA
294328 cpac_version_hash = b64_urlsafe_hash (checkout_sha )
295329
@@ -342,6 +376,159 @@ def main() -> None:
342376 print (f"> Generating { filename } " )
343377
344378 combined = generate_pipeline_from_combi (pipeline_num , combi , configs )
379+
380+ if (
381+ combi .pipeline_id == "ABCD"
382+ and combi .pipeline_perturb_id == "CCS"
383+ and combi .step .name == "Functional Registration"
384+ ) or (
385+ combi .pipeline_id == "CCS"
386+ and combi .pipeline_perturb_id == "ABCD"
387+ and combi .step .name == "Functional Masking"
388+ ):
389+ # See text related to search term "apply_func_mask_in_native_space: false" in
390+ # https://docs.google.com/document/d/1WyARU5wkkAd9VrT24Tc7xJWJf7CIGO29PY0IM4tdGgQ/edit?tab=t.0
391+ # todo: sanity check
392+ multi_set (
393+ combined .config ,
394+ index = ["functional_preproc" , "func_masking" , "apply_func_mask_in_native_space" ],
395+ value = True ,
396+ )
397+
398+ # if (
399+ # combi.pipeline_id == "CCS"
400+ # and combi.pipeline_perturb_id == "ABCD"
401+ # and combi.step.name == "Functional Masking"
402+ # #and combi.use_nuisance_correction == True
403+ # ):
404+ # # See text related to search term "use_priors" and "lateral_ventricles_mask" in
405+ # # https://docs.google.com/document/d/1WyARU5wkkAd9VrT24Tc7xJWJf7CIGO29PY0IM4tdGgQ/edit?tab=t.0
406+ # # todo: sanity check
407+ # multi_set(
408+ # combined.config,
409+ # index=["segmentation", "tissue_segmentation", "FSL-FAST", "use_priors", "run"],
410+ # value=False,
411+ # )
412+ # multi_set(
413+ # combined.config,
414+ # index=["nuisance_corrections", "2-nuisance_regrtession", "lateral_ventricles_mask"],
415+ # value=None,
416+ # )
417+
418+ if (
419+ combi .pipeline_id == "ABCD"
420+ and combi .pipeline_perturb_id == "RBC"
421+ and combi .step .name == "Structural Registration"
422+ ):
423+ # See text related to search term "overwrite transform" in
424+ # https://docs.google.com/document/d/1WyARU5wkkAd9VrT24Tc7xJWJf7CIGO29PY0IM4tdGgQ/edit?tab=t.0
425+ # todo: sanity check
426+ multi_set (
427+ combined .config ,
428+ index = ["registration_workflows" , "anatomical_registration" , "overwrite_transform" , "run" ],
429+ value = True ,
430+ )
431+
432+ if (
433+ (
434+ combi .pipeline_id == "ABCD"
435+ and combi .pipeline_perturb_id == "RBC"
436+ and combi .step .name == "Functional Registration"
437+ )
438+ or (
439+ combi .pipeline_id == "ABCD"
440+ and combi .pipeline_perturb_id == "fMRIPrep"
441+ and combi .step .name == "Functional Registration"
442+ )
443+ or (
444+ combi .pipeline_id == "RBC"
445+ and combi .pipeline_perturb_id == "ABCD"
446+ and combi .step .name == "Functional Masking"
447+ )
448+ ):
449+ # See text related to search term "Anatomical_Resampled to CCS_Anatomical_Refined" in
450+ # https://docs.google.com/document/d/1WyARU5wkkAd9VrT24Tc7xJWJf7CIGO29PY0IM4tdGgQ/edit?tab=t.0
451+ # todo: sanity check
452+ multi_set (
453+ combined .config ,
454+ index = ["functional_preproc" , "func_masking" , "using" ],
455+ value = ["CCS_Anatomical_Refined" ], # string list, change from ["Anatomical_Resampled"]
456+ )
457+
458+ if (
459+ combi .pipeline_id == "ABCD"
460+ and combi .pipeline_perturb_id == "fMRIPrep"
461+ and combi .step .name == "Structural Registration"
462+ ) or (
463+ combi .pipeline_id == "CCS"
464+ and combi .pipeline_perturb_id == "ABCD"
465+ and combi .step .name == "Structural Masking"
466+ ):
467+ # See text related to search term "registration: using: ANTS" in
468+ # https://docs.google.com/document/d/1WyARU5wkkAd9VrT24Tc7xJWJf7CIGO29PY0IM4tdGgQ/edit?tab=t.0
469+ # todo: sanity check
470+ multi_set (
471+ combined .config ,
472+ index = ["registration_workflows" , "anatomical_registration" , "registration" , "using" ],
473+ value = ["FSL" ], # string list, change from ["ANTS"]
474+ )
475+ multi_set (
476+ combined .config ,
477+ index = ["registration_workflows" , "anatomical_registration" , "overwrite_transform" , "run" ],
478+ value = True ,
479+ )
480+
481+ if (
482+ combi .pipeline_id == "RBC"
483+ and combi .pipeline_perturb_id == "ABCD"
484+ and combi .step .name == "Functional Masking"
485+ ) and (
486+ combi .pipeline_id == "fMRIPrep"
487+ and combi .pipeline_perturb_id == "ABCD"
488+ and combi .step .name == "Structural Masking"
489+ ):
490+ # See text related to search term "overwrite transform" in
491+ # https://docs.google.com/document/d/1WyARU5wkkAd9VrT24Tc7xJWJf7CIGO29PY0IM4tdGgQ/edit?tab=t.0
492+ # todo: sanity check
493+ multi_set (
494+ combined .config ,
495+ index = ["registration_workflows" , "anatomical_registration" , "overwrite_transform" , "run" ],
496+ value = True ,
497+ )
498+
499+ if (
500+ combi .pipeline_id == "RBC"
501+ and combi .pipeline_perturb_id == "CCS"
502+ and combi .step .name == "Structural Registration"
503+ ):
504+ # See text related to search term "overwrite transform" in
505+ # https://docs.google.com/document/d/1WyARU5wkkAd9VrT24Tc7xJWJf7CIGO29PY0IM4tdGgQ/edit?tab=t.0
506+ # todo: sanity check
507+ multi_set (
508+ combined .config ,
509+ index = ["registration_workflows" , "anatomical_registration" , "registration" , "using" ],
510+ value = ["ANTS" ], # string list, change from ["FSL"]
511+ )
512+
513+ if (
514+ combi .pipeline_id == "fMRIPrep"
515+ and combi .pipeline_perturb_id == "CCS"
516+ and combi .step .name == "Structural Registration"
517+ ) and (
518+ combi .pipeline_id == "RBC"
519+ and combi .pipeline_perturb_id == "CCS"
520+ and combi .step .name == "Structural Registration"
521+ ):
522+ multi_del (
523+ combined .config ,
524+ index = ["registration_workflows" , "anatomical_registration" , "overwrite_transform" , "using" ],
525+ )
526+ multi_set (
527+ combined .config ,
528+ index = ["registration_workflows" , "anatomical_registration" , "registration" , "using" ],
529+ value = ["ANTS" ], # string list, change from ["FSL"]
530+ )
531+
345532 combined .file = dir_gen / filename
346533
347534 # Let CPAC check if it is a valid config
@@ -364,5 +551,13 @@ def main() -> None:
364551 )
365552
366553
554+ def cli ():
555+ parser = argparse .ArgumentParser (description = "Your script description" )
556+ parser .add_argument ("-f" , "--force" , action = "store_true" , help = "Force execution without prompts" )
557+ args = parser .parse_args ()
558+
559+ main (force = args .force )
560+
561+
367562if __name__ == "__main__" :
368- main ()
563+ cli ()
0 commit comments