8
8
import typing as ty
9
9
import inspect
10
10
import click
11
- import pytest
12
-
11
+ import warnings
13
12
14
13
15
14
class FSLConverter :
@@ -32,8 +31,7 @@ class FSLConverter:
32
31
]
33
32
34
33
35
- def __init__ (self , interface_name ,
36
- interface_spec_file = Path (os .path .dirname (__file__ )) / "../specs/fsl_conv_param.yml" ):
34
+ def __init__ (self , interface_name , interface_spec_file ):
37
35
self .interface_name = interface_name
38
36
with interface_spec_file .open () as f :
39
37
self .interface_spec = yaml .safe_load (f )[self .interface_name ]
@@ -414,16 +412,53 @@ def string_formats(self, argstr, name):
414
412
return argstr_new
415
413
416
414
415
+ FSL_MODULES = ['aroma' , 'dti' , 'epi' , 'fix' , 'maths' , 'model' , 'possum' , 'preprocess' , 'utils' ]
417
416
418
417
@click .command ()
419
- @click .option ("-i" , "--interface_name" , required = True ,
420
- help = "name of the interface (name used in Nipype, e.g. BET)" )
421
- @click .option ("-m" , "--module_name" , required = True , help = "name of the module (e.g. preprocess)" )
418
+ @click .option ("-i" , "--interface_name" , required = True , default = "all" ,
419
+ help = "name of the interface (name used in Nipype, e.g. BET) or all (default)"
420
+ "if all is used all interfaces from the spec file will be created" )
421
+ @click .option ("-m" , "--module_name" , required = True , help = f"name of the module from the list { FSL_MODULES } " )
422
422
def create_pydra_spec (interface_name , module_name ):
423
- converter = FSLConverter (interface_name = interface_name )
423
+ if module_name not in FSL_MODULES :
424
+ raise Exception (f"module name { module_name } not available;"
425
+ f"should be from the list { FSL_MODULES } " )
426
+
427
+ spec_file = Path (os .path .dirname (__file__ )) / f"../specs/fsl_{ module_name } _param.yml"
428
+ if not spec_file .exists ():
429
+ raise Exception (f"the specification file doesn't exist for the module { module_name } ,"
430
+ f"create the specification file in { spec_file .parent } " )
431
+
432
+ def all_interfaces (module ):
433
+ nipype_module = getattr (fsl , module )
434
+ all_specs = [el for el in dir (nipype_module ) if "InputSpec" in el ]
435
+ all_interf = [el .replace ("InputSpec" , "" ) for el in all_specs ]
436
+
437
+ # interfaces in the spec file
438
+ with open (spec_file ) as f :
439
+ spec_interf = yaml .safe_load (f ).keys ()
440
+
441
+ if set (all_interf ) - set (spec_interf ):
442
+ warnings .warn (f"some interfaces are not in the spec file: "
443
+ f"{ set (all_interf ) - set (spec_interf )} , "
444
+ f"and pydra interfaces will not be created for them" )
445
+ return spec_interf
446
+
447
+ if interface_name == "all" :
448
+ interface_list = all_interfaces (module_name )
449
+ elif interface_name in all_interfaces (module_name ):
450
+ interface_list = [interface_name ]
451
+ else :
452
+ raise Exception (f"interface_name has to be 'all' "
453
+ f"or a name from the list { all_interfaces (module_name )} " )
454
+
424
455
dirname_interf = Path (__file__ ).parent .parent / f"pydra/tasks/fsl/{ module_name } "
425
456
dirname_interf .mkdir (exist_ok = True )
426
- converter .pydra_specs (write = True , dirname = dirname_interf )
457
+
458
+ for interface_el in interface_list :
459
+ converter = FSLConverter (interface_name = interface_el ,
460
+ interface_spec_file = Path (os .path .dirname (__file__ )) / "../specs/fsl_preprocess_param.yml" )
461
+ converter .pydra_specs (write = True , dirname = dirname_interf )
427
462
428
463
if __name__ == '__main__' :
429
464
create_pydra_spec ()
0 commit comments