I am trying to run some basic probtrackx2 commands through nipype, and am having issues with the datagrabber. This is code I copied from an old Jupyter notebook, which worked in the past (but likely with an older version of nipype and/or not using Python 3…) So I am wondering if the syntax may have changed from python 2.7 --> 3.6
I think the key error from the stack trace is.
TraitError: Each key of the ‘field_template’ trait of a DataGrabberInputSpec instance must be dict_keys([‘thsamples’, ‘phsamples’, ‘fsamples’, ‘nodif_brain_mask’, ‘xfm’, ‘invxfm’]), but a value of ‘nodif_brain_mask’ <class ‘str’> was specified.
“”"
Setup for Probtrackx2 Computational Pipeline
“”"
infosource = pe.Node(interface=util.IdentityInterface(fields=[‘subject_id’]), name=“infosource”)
infosource.iterables = (‘subject_id’, FULL_SUBJECT_LIST[0:2])
Above just converts the list of subjects into an iterable list I can connect to the next part of the pipeline
info = dict(
thsamples = [[‘subject_id’,‘th1samples’]],
phsamples = [[‘subject_id’,‘ph1samples’]],
fsamples = [[‘subject_id’,‘f1samples’]] ,
nodif_brain_mask = [[‘subject_id’,‘nodif_brain_mask’]],
xfm = [[‘subject_id’,‘Unselected-Template_FNIRT-warpfield_T2.nii.gz’]],
invxfm = [[‘subject_id’, ‘T2_FNIRT-warpfield_Unselected-Template.nii.gz’ ]]
)
Generate the files/names for the DTI/bedpostX data
dti_datasource = pe.Node(interface=nio.DataGrabber(infields=[‘subject_id’], outfields=info.keys() ), name=‘dti_datasource’)
dti_datasource.inputs.base_directory = subjRootDir
dti_datasource.inputs.template = “*”
dti_datasource.inputs.sort_filelist=True
dti_datasource.inputs.field_template = dict(
nodif_brain_mask = ‘%s/data.bedpostX/%s.nii.gz’,
thsamples=’%s/data.bedpostX/merged_%s.nii.gz’,
phsamples=’%s/data.bedpostX/merged_%s.nii.gz’,
fsamples=’%s/data.bedpostX/merged_%s.nii.gz’,
xfm = “%s/xfms/%s”,
invxfm = “%s/xfms/%s”
)
dti_datasource.inputs.template_args = info
---- full stack trace–
TraitError Traceback (most recent call last)
in ()
26 fsamples=’%s/data.bedpostX/merged_%s.nii.gz’,
27 xfm = “%s/xfms/%s”,
—> 28 invxfm = “%s/xfms/%s”
29 )
30 dti_datasource.inputs.template_args = info
/opt/conda/lib/python3.6/site-packages/traits/trait_types.py in validate(self, object, name, value)
2623 if object is None:
2624 return value
-> 2625 return TraitDictObject( self, object, name, value )
2626
2627 self.error( object, name, value )
/opt/conda/lib/python3.6/site-packages/traits/trait_handlers.py in init(self, trait, object, name, value)
3061
3062 if len( value ) > 0:
-> 3063 dict.update( self, self._validate_dic( value ) )
3064
3065 def _send_trait_items_event(self, name, event, items_event=None):
/opt/conda/lib/python3.6/site-packages/traits/trait_handlers.py in _validate_dic(self, dic)
3255 except TraitError as excp:
3256 excp.set_prefix( ‘Each key of the’ )
-> 3257 raise excp
3258
3259 try:
/opt/conda/lib/python3.6/site-packages/traits/trait_handlers.py in _validate_dic(self, dic)
3252 for key, value in dic.items():
3253 try:
-> 3254 key = key_validate( object, name, key )
3255 except TraitError as excp:
3256 excp.set_prefix( ‘Each key of the’ )
/opt/conda/lib/python3.6/site-packages/traits/trait_types.py in validate(self, object, name, value)
2010 return value
2011
-> 2012 self.error( object, name, value )
2013
2014 def full_info ( self, object, name, value ):
/opt/conda/lib/python3.6/site-packages/traits/trait_handlers.py in error(self, object, name, value)
170 “”"
171 raise TraitError( object, name, self.full_info( object, name, value ),
–> 172 value )
173
174 def full_info ( self, object, name, value ):
TraitError: Each key of the ‘field_template’ trait of a DataGrabberInputSpec instance must be dict_keys([‘thsamples’, ‘phsamples’, ‘fsamples’, ‘nodif_brain_mask’, ‘xfm’, ‘invxfm’]), but a value of ‘nodif_brain_mask’ <class ‘str’> was specified.