14
14
BaseInterfaceInputSpec , TraitedSpec , SimpleInterface ,
15
15
traits , InputMultiPath , File
16
16
)
17
+ from ...utils .filemanip import split_filename
17
18
18
19
19
- class ACMInputSpec (BaseInterfaceInputSpec ):
20
+ class ActivationCountInputSpec (BaseInterfaceInputSpec ):
20
21
in_files = InputMultiPath (File (exists = True ), mandatory = True ,
21
22
desc = 'input file, generally a list of z-stat maps' )
22
23
threshold = traits .Float (1.65 , usedefault = True ,
23
24
desc = 'binarization threshold. A z-value of 1.65 '
24
25
'corresponds to a two-sided test of p<.10' )
25
26
26
27
27
- class ACMOutputSpec (TraitedSpec ):
28
+ class ActivationCountOutputSpec (TraitedSpec ):
28
29
out_file = File (exists = True , desc = 'output activation count map' )
29
30
acm_pos = File (exists = True , desc = 'positive activation count map' )
30
31
acm_neg = File (exists = True , desc = 'negative activation count map' )
31
32
32
33
33
- class ACM (SimpleInterface ):
34
+ class ActivationCount (SimpleInterface ):
34
35
"""
35
36
Calculate a simple Activation Count Maps
36
37
37
38
Adapted from: https://github.com/poldracklab/CNP_task_analysis/\
38
39
blob/61c27f5992db9d8800884f8ffceb73e6957db8af/CNP_2nd_level_ACM.py
39
40
"""
40
- input_spec = ACMInputSpec
41
- output_spec = ACMOutputSpec
41
+ input_spec = ActivationCountInputSpec
42
+ output_spec = ActivationCountOutputSpec
42
43
43
44
def _run_interface (self , runtime ):
44
45
allmaps = nb .concat_images (self .inputs .in_files ).get_data ()
@@ -48,19 +49,20 @@ def _run_interface(self, runtime):
48
49
axis = 3 , dtype = np .float32 )
49
50
acm_diff = acm_pos - acm_neg
50
51
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
58
55
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' ])
65
67
66
68
return runtime
0 commit comments