14
14
15
15
import os
16
16
import os .path as op
17
- from distutils import spawn
18
17
19
18
from ...utils .filemanip import (load_json , save_json , split_filename )
20
19
from ..base import (
23
22
24
23
from .base import (
25
24
AFNICommandBase , AFNICommand , AFNICommandInputSpec , AFNICommandOutputSpec ,
26
- Info , no_afni )
25
+ AFNIPythonCommandInputSpec , AFNIPythonCommand , Info , no_afni )
27
26
28
27
29
28
class CentralityInputSpec (AFNICommandInputSpec ):
@@ -47,17 +46,7 @@ class CentralityInputSpec(AFNICommandInputSpec):
47
46
desc = 'Mask the dataset to target brain-only voxels' ,
48
47
argstr = '-automask' )
49
48
50
- class AlignEpiAnatPyInputSpec (CommandLineInputSpec ):
51
- outputtype = traits .Enum ('AFNI' , list (Info .ftypes .keys ()),
52
- desc = 'AFNI output filetype' )
53
- py27_path = File (
54
- desc = 'Path to Python 2.7 executable for running afni python scripts' ,
55
- argstr = '%s ' + spawn .find_executable ('align_epi_anat.py' ),
56
- exists = True ,
57
- #default='/opt/miniconda/envs/py27/bin/python',
58
- mandatory = True ,
59
- position = 0
60
- )
49
+ class AlignEpiAnatPyInputSpec (AFNIPythonCommandInputSpec ):
61
50
in_file = File (
62
51
desc = 'EPI dataset to align' ,
63
52
argstr = '-epi %s' ,
@@ -70,13 +59,14 @@ class AlignEpiAnatPyInputSpec(CommandLineInputSpec):
70
59
mandatory = True ,
71
60
exists = True ,
72
61
copyfile = False )
73
- epi_base = traits .Str (
62
+ epi_base = traits .Either (
63
+ traits .Range (low = 0 ),
64
+ traits .Enum ('mean' , 'median' , 'max' ),
74
65
desc = 'the epi base used in alignment'
75
66
'should be one of (0/mean/median/max/subbrick#)' ,
76
67
mandatory = True ,
77
68
argstr = '-epi_base %s' )
78
69
anat2epi = traits .Bool (
79
- default = True ,
80
70
desc = 'align anatomical to EPI dataset (default)' ,
81
71
argstr = '-anat2epi' )
82
72
epi2anat = traits .Bool (
@@ -86,24 +76,30 @@ class AlignEpiAnatPyInputSpec(CommandLineInputSpec):
86
76
desc = 'save skull-stripped (not aligned)' ,
87
77
argstr = '-save_skullstrip' )
88
78
suffix = traits .Str (
79
+ '_al' ,
89
80
desc = 'append suffix to the original anat/epi dataset to use'
90
81
'in the resulting dataset names (default is "_al")' ,
82
+ usedefault = True ,
91
83
argstr = '-suffix %s' )
92
- epi_strip = traits .Enum (('3dSkullStrip' ,'3dAutomask' ,'None' ),
93
- desc = 'method to mask brain in EPI data'
84
+ epi_strip = traits .Enum (
85
+ ('3dSkullStrip' , '3dAutomask' , 'None' ),
86
+ desc = 'method to mask brain in EPI data'
94
87
'should be one of[3dSkullStrip]/3dAutomask/None)' ,
95
88
argstr = '-epi_strip %s' )
96
- volreg = traits .Enum (('on' ,'off' ),
89
+ volreg = traits .Enum (
90
+ 'on' , 'off' ,
91
+ usedefault = True ,
97
92
desc = 'do volume registration on EPI dataset before alignment'
98
93
'should be \' on\' or \' off\' , defaults to \' on\' ' ,
99
- default = 'on' ,
100
94
argstr = '-volreg %s' )
101
- tshift = traits .Enum (('on' ,'off' ),
95
+ tshift = traits .Enum (
96
+ 'on' , 'off' ,
97
+ usedefault = True ,
102
98
desc = 'do time shifting of EPI dataset before alignment'
103
99
'should be \' on\' or \' off\' , defaults to \' on\' ' ,
104
- default = 'on' ,
105
100
argstr = '-tshift %s' )
106
101
102
+
107
103
class AlignEpiAnatPyOutputSpec (TraitedSpec ):
108
104
anat_al_orig = File (
109
105
desc = "A version of the anatomy that is aligned to the EPI" )
@@ -129,8 +125,8 @@ class AlignEpiAnatPyOutputSpec(TraitedSpec):
129
125
skullstrip = File (
130
126
desc = "skull-stripped (not aligned) volume" )
131
127
132
- class AlignEpiAnatPy (AFNICommand ):
133
- """align EPI to anatomical datasets or vice versa
128
+ class AlignEpiAnatPy (AFNIPythonCommand ):
129
+ """Align EPI to anatomical datasets or vice versa
134
130
This Python script computes the alignment between two datasets, typically
135
131
an EPI and an anatomical structural dataset, and applies the resulting
136
132
transformation to one or the other to bring them into alignment.
@@ -165,48 +161,48 @@ class AlignEpiAnatPy(AFNICommand):
165
161
========
166
162
>>> from nipype.interfaces import afni
167
163
>>> al_ea = afni.AlignEpiAnatPy()
168
- >>> al_ea.inputs.py27_path = "/opt/miniconda/envs/py27/bin/python"
169
164
>>> al_ea.inputs.anat = "structural.nii"
170
165
>>> al_ea.inputs.in_file = "functional.nii"
171
- >>> al_ea.inputs.epi_base = '0'
166
+ >>> al_ea.inputs.epi_base = 0
172
167
>>> al_ea.inputs.epi_strip = '3dAutomask'
173
168
>>> al_ea.inputs.volreg = 'off'
174
169
>>> al_ea.inputs.tshift = 'off'
175
170
>>> al_ea.inputs.save_skullstrip = True
176
171
>>> al_ea.cmdline # doctest: +ALLOW_UNICODE
177
- 'echo "" && /opt/miniconda/envs/py27/ bin/python /root/abin/ align_epi_anat.py -anat structural.nii -epi_base 0 -epi_strip 3dAutomask -epi functional.nii -save_skullstrip -tshift off -volreg off'
172
+ 'python2 /usr/lib/afni/ bin/align_epi_anat.py -anat structural.nii -epi_base 0 -epi_strip 3dAutomask -epi functional.nii -save_skullstrip -suffix _al -tshift off -volreg off'
178
173
>>> res = allineate.run() # doctest: +SKIP
179
174
"""
180
- _cmd = 'echo "" && '
175
+ _cmd = 'align_epi_anat.py '
181
176
input_spec = AlignEpiAnatPyInputSpec
182
177
output_spec = AlignEpiAnatPyOutputSpec
183
178
184
179
def _list_outputs (self ):
185
180
outputs = self .output_spec ().get ()
186
181
anat_prefix = '' .join (self ._gen_fname (self .inputs .anat ).split ('+' )[:- 1 ])
187
182
epi_prefix = '' .join (self ._gen_fname (self .inputs .in_file ).split ('+' )[:- 1 ])
188
- ext = '.HEAD'
189
- matext = '.1D'
190
- if not isdefined (self .inputs .suffix ):
191
- suffix = '_al'
183
+ outputtype = self .inputs .outputtype
184
+ if outputtype == 'AFNI' :
185
+ ext = '.HEAD'
192
186
else :
193
- suffix = '_' + self .inputs .suffix
187
+ Info .output_type_to_ext (outputtype )
188
+ matext = '.1D'
189
+ suffix = self .inputs .suffix
194
190
if self .inputs .anat2epi :
195
- outputs ['anat_al_orig' ] = os . path . abspath ( self ._gen_fname (anat_prefix , suffix = suffix + '+orig' ) + ext )
196
- outputs ['anat_al_mat' ] = os . path . abspath ( self ._gen_fname (anat_prefix , suffix = suffix + '_mat.aff12' ) + matext )
191
+ outputs ['anat_al_orig' ] = self ._gen_fname (anat_prefix , suffix = suffix + '+orig' , ext = ext )
192
+ outputs ['anat_al_mat' ] = self ._gen_fname (anat_prefix , suffix = suffix + '_mat.aff12' , ext = matext )
197
193
if self .inputs .epi2anat :
198
- outputs ['epi_al_orig' ] = os . path . abspath ( self ._gen_fname (epi_prefix , suffix = suffix + '+orig' ) + ext )
199
- outputs ['epi_al_mat' ] = os . path . abspath ( self ._gen_fname (epi_prefix , suffix = suffix + '_mat.aff12' ) + matext )
194
+ outputs ['epi_al_orig' ] = self ._gen_fname (epi_prefix , suffix = suffix + '+orig' , ext = ext )
195
+ outputs ['epi_al_mat' ] = self ._gen_fname (epi_prefix , suffix = suffix + '_mat.aff12' , ext = matext )
200
196
if self .inputs .volreg == 'on' :
201
- outputs ['epi_vr_al_mat' ] = os . path . abspath ( self ._gen_fname (epi_prefix , suffix = '_vr' + suffix + '_mat.aff12' ) + matext )
197
+ outputs ['epi_vr_al_mat' ] = self ._gen_fname (epi_prefix , suffix = '_vr' + suffix + '_mat.aff12' , ext = matext )
202
198
if self .inputs .tshift == 'on' :
203
- outputs ['epi_vr_motion' ] = os . path . abspath ( self ._gen_fname (epi_prefix , suffix = 'tsh_vr_motion' ) + matext )
199
+ outputs ['epi_vr_motion' ] = self ._gen_fname (epi_prefix , suffix = 'tsh_vr_motion' , ext = matext )
204
200
elif self .inputs .tshift == 'off' :
205
- outputs ['epi_vr_motion' ] = os . path . abspath ( self ._gen_fname (epi_prefix , suffix = 'vr_motion' ) + matext )
201
+ outputs ['epi_vr_motion' ] = self ._gen_fname (epi_prefix , suffix = 'vr_motion' , ext = matext )
206
202
if self .inputs .volreg == 'on' and self .inputs .epi2anat :
207
- outputs ['epi_reg_al_mat' ]= os . path . abspath ( self ._gen_fname (epi_prefix , suffix = '_reg' + suffix + '_mat.aff12' ) + matext )
203
+ outputs ['epi_reg_al_mat' ] = self ._gen_fname (epi_prefix , suffix = '_reg' + suffix + '_mat.aff12' , ext = matext )
208
204
if self .inputs .save_skullstrip :
209
- outputs .skullstrip = os . path . abspath ( self ._gen_fname (anat_prefix , suffix = '_ns' + '+orig' ) + ext )
205
+ outputs .skullstrip = self ._gen_fname (anat_prefix , suffix = '_ns' + '+orig' , ext = ext )
210
206
return outputs
211
207
212
208
class AllineateInputSpec (AFNICommandInputSpec ):
0 commit comments