1414 BaseInterfaceInputSpec , TraitedSpec , SimpleInterface ,
1515 traits , InputMultiPath , File
1616)
17+ from ...utils .filemanip import split_filename
1718
1819
19- class ACMInputSpec (BaseInterfaceInputSpec ):
20+ class ActivationCountInputSpec (BaseInterfaceInputSpec ):
2021 in_files = InputMultiPath (File (exists = True ), mandatory = True ,
2122 desc = 'input file, generally a list of z-stat maps' )
2223 threshold = traits .Float (1.65 , usedefault = True ,
2324 desc = 'binarization threshold. A z-value of 1.65 '
2425 'corresponds to a two-sided test of p<.10' )
2526
2627
27- class ACMOutputSpec (TraitedSpec ):
28+ class ActivationCountOutputSpec (TraitedSpec ):
2829 out_file = File (exists = True , desc = 'output activation count map' )
2930 acm_pos = File (exists = True , desc = 'positive activation count map' )
3031 acm_neg = File (exists = True , desc = 'negative activation count map' )
3132
3233
33- class ACM (SimpleInterface ):
34+ class ActivationCount (SimpleInterface ):
3435 """
3536 Calculate a simple Activation Count Maps
3637
3738 Adapted from: https://github.com/poldracklab/CNP_task_analysis/\
3839 blob/61c27f5992db9d8800884f8ffceb73e6957db8af/CNP_2nd_level_ACM.py
3940 """
40- input_spec = ACMInputSpec
41- output_spec = ACMOutputSpec
41+ input_spec = ActivationCountInputSpec
42+ output_spec = ActivationCountOutputSpec
4243
4344 def _run_interface (self , runtime ):
4445 allmaps = nb .concat_images (self .inputs .in_files ).get_data ()
@@ -48,19 +49,20 @@ def _run_interface(self, runtime):
4849 axis = 3 , dtype = np .float32 )
4950 acm_diff = acm_pos - acm_neg
5051
51- nii = nb .load (self .inputs .in_files [0 ])
52- self ._results ['out_file' ] = os .path .join (
53- runtime .cwd , 'acm_diff.nii.gz' )
54- self ._results ['acm_pos' ] = os .path .join (
55- runtime .cwd , 'acm_pos.nii.gz' )
56- self ._results ['acm_neg' ] = os .path .join (
57- runtime .cwd , 'acm_neg.nii.gz' )
52+ template_fname = self .inputs .in_files [0 ]
53+ ext = split_filename (template_fname )[2 ]
54+ fname_fmt = os .path .join (runtime .cwd , 'acm_{}' + ext ).format
5855
59- nb .Nifti1Image (
60- acm_diff , nii .affine , nii .header ).to_filename (self ._results ['out_file' ])
61- nb .Nifti1Image (
62- acm_pos , nii .affine , nii .header ).to_filename (self ._results ['acm_pos' ])
63- nb .Nifti1Image (
64- acm_neg , nii .affine , nii .header ).to_filename (self ._results ['acm_neg' ])
56+ self ._results ['out_file' ] = fname_fmt ('diff' )
57+ self ._results ['acm_pos' ] = fname_fmt ('pos' )
58+ self ._results ['acm_neg' ] = fname_fmt ('neg' )
59+
60+ img = nb .load (template_fname )
61+ img .__class__ (acm_diff , img .affine , img .header ).to_filename (
62+ self ._results ['out_file' ])
63+ img .__class__ (acm_pos , img .affine , img .header ).to_filename (
64+ self ._results ['acm_pos' ])
65+ img .__class__ (acm_neg , img .affine , img .header ).to_filename (
66+ self ._results ['acm_neg' ])
6567
6668 return runtime
0 commit comments