Wrapping afni commandline tool and using its output


I am working with structural scans (t1, t2, flair). For my project i need to first axialize the t1 and then co-register t2 and flair to it. since the default nipype afni interfaces didn’t have my required function (fat_proc_axialize_anat) i tried to write my own wrapper function and used it to get the axialize.nii file. next i tried to input the output of my axialize node into allineate (3dAllineate) node as a reference, as well as t2.nii as the in_file. However I get the following error when the pipeline finishes the axialization. it seems like i am not using maybe the right format of reference file. Any idea why this goes wrong?

traits.trait_errors.TraitError: The ‘reference’ trait of an AllineateInputSpec instance must be a pathlike object or string representing an existing file, but a value of ‘/Users/…/Desktop/nipype/MRI/_subject_id_5/axialize/axialize.nii’ <class ‘str’> was specified.

and this is how i am defining & connecting my nodes:
subj_infosource = pe.Node(interface=niu.IdentityInterface(fields=[‘subject_id’]), name=“subject_info”)
subj_infosource.iterables = (‘subject_id’, subject_list)

Search for MRI inputs

outfields=[‘mri_folder’, ‘T1’, ‘T2’, ‘FL’]),

mrisource.inputs.base_directory = raw_mri_dir
mrisource.inputs.template = ‘
mrisource.inputs.sort_filelist = True
mrisource.inputs.template_args = { ‘mri_folder’ : [[‘subject_id’]],
‘T1’ : [[‘subject_id’]],
‘T2’ : [[‘subject_id’]],
‘FL’ : [[‘subject_id’]],
mrisource.inputs.field_template = { ‘mri_folder’ : ‘sub-%02d’,
‘T1’ : 'sub-%02d/ses-
‘T2’ : 'sub-%02d/ses-
‘FL’ : 'sub-%02d/ses-
#Axialize mprage
axialized = pe.Node(interface=FCD_preproc.AxializeAnat(), name=‘axialize’)
axialized.inputs.ref_file = ref_file
axialized.inputs.out_file = ‘axialize’

#Coregister t2 & flair to axialized t1
allineate = pe.Node(interface=afni.Allineate(), name=‘allineate’)
allineate.inputs.cost = ‘nmi’

#combine nodes into a pipeline
pipeline = pe.Workflow(name=‘MRI’, base_dir=base_pipeline_forlder)

#Get data
pipeline.connect(subj_infosource, ‘subject_id’, mrisource, ‘subject_id’)
pipeline.connect(mrisource, ‘T1’, axialized, ‘in_file’)

pipeline.connect(axialized,‘out_file’, allineate, ‘reference’)
pipeline.connect(mrisource,‘T2’, allineate, ‘in_file’)