FSL FLIRT registration tool does not work as nipype interface/node but works as command line script

285 views
Skip to first unread message

Augustine Koh

unread,
Mar 16, 2014, 10:16:57 AM3/16/14
to nipy...@googlegroups.com
Dear all Nipype users and developers,

I've recently set out to code workflow involving 4 nodes that would perform linear and non-linear registration. These 4 nodes would run sequentially one after another. After creating the nodes and connecting them, I set out to execute the whole workflow but ran into a few errors indicating that there were issues with the connections between some of the nodes that stemmed from the lack of a file that would have been an output from the very first node. To troubleshoot the issue and isolate a problem, I decided to breakup my workflow and execute the very first registration node on its own in ipython interpreter. It was then that I discovered a problem that prevented the first node from even running and generating the necessary outputs that would be fed to the remaining nodes. It seems like the interface for this very first node cannot work:

In [1]: from nipype.interfaces import fsl as fsl

In [2]: from nipype.pipeline import engine as pe

In [3]: register_brain = pe.Node(interface = fsl.FLIRT(), name = 'register_brain')

In [4]: register_brain.inputs.in_file = 'T2_N3rescalenorm_brain.nii.gz'

In [5]: register_brain.inputs.reference = 'T2_p140_brain_template.nii.gz'

In [6]: register_brain.inputs.searchr_x = [10, 10]

In [7]: register_brain.inputs.searchr_y = [10, 10]

In [8]: register_brain.inputs.searchr_z = [10, 10]

In [9]: register_brain.inputs.dof = 12

In [10]: register_brain.inputs.interp = 'sinc'

In [11]: register_brain.inputs.cost = 'corratio'

In [12]: register_brain.inputs.out_file = 'T2_N3rescalebrain_adhoc_FLIRT.nii.gz'

In [13]: register_brain.inputs.out_matrix_file = 'T2_N3rescalebrain_adhoc_matrix.mat'

In [14]: register_brain.run()

140316-21:41:08,456 workflow INFO:

Executing node register_brain in dir: /var/folders/qn/7q7tkzyj2v11l1cjzhjphfwm0000gn/T/tmp9aGuGN/register_brain

140316-21:41:08,462 workflow INFO:

Running: flirt -in T2_N3rescalenorm_brain.nii.gz -ref T2_p140_brain_template.nii.gz -out T2_N3rescalebrain_adhoc_FLIRT.nii.gz -omat T2_N3rescalebrain_adhoc_matrix.mat -cost corratio -dof 12 -interp sinc -searchrx 10 10 -searchry 10 10 -searchrz 10 10

140316-21:41:08,868 interface INFO:

stderr 2014-03-16T21:41:08.868350:Image Exception : #22 :: ERROR: Could not open image T2_p140_brain_template

140316-21:41:08,868 interface INFO:

stderr 2014-03-16T21:41:08.868822:libc++abi.dylib: terminating with uncaught exception of type RBD_COMMON::BaseException

---------------------------------------------------------------------------

RuntimeError                              Traceback (most recent call last)

<ipython-input-17-2eb19defd70d> in <module>()

----> 1 register_brain.run()


/users/kohaugustine/continuum_miniconda/miniconda/lib/python2.7/site-packages/nipype/pipeline/engine.pyc in run(self, updatehash)

   1388                     self.inputs.get_traitsfree())

   1389             try:

-> 1390                 self._run_interface()

   1391             except:

   1392                 os.remove(hashfile_unfinished)


/users/kohaugustine/continuum_miniconda/miniconda/lib/python2.7/site-packages/nipype/pipeline/engine.pyc in _run_interface(self, execute, updatehash)

   1498         old_cwd = os.getcwd()

   1499         os.chdir(self.output_dir())

-> 1500         self._result = self._run_command(execute)

   1501         os.chdir(old_cwd)

   1502 


/users/kohaugustine/continuum_miniconda/miniconda/lib/python2.7/site-packages/nipype/pipeline/engine.pyc in _run_command(self, execute, copyfiles)

   1624                 logger.info('Running: %s' % cmd)

   1625             try:

-> 1626                 result = self._interface.run()

   1627             except Exception, msg:

   1628                 self._result.runtime.stderr = msg


/users/kohaugustine/continuum_miniconda/miniconda/lib/python2.7/site-packages/nipype/interfaces/base.pyc in run(self, **inputs)

    944                         version=self.version)

    945         try:

--> 946             runtime = self._run_interface(runtime)

    947             outputs = self.aggregate_outputs(runtime)

    948             runtime.endTime = dt.isoformat(dt.utcnow())


/users/kohaugustine/continuum_miniconda/miniconda/lib/python2.7/site-packages/nipype/interfaces/base.pyc in _run_interface(self, runtime, correct_return_codes)

   1387         if runtime.returncode is None or \

   1388                         runtime.returncode not in correct_return_codes:

-> 1389             self.raise_exception(runtime)

   1390 

   1391         return runtime


/users/kohaugustine/continuum_miniconda/miniconda/lib/python2.7/site-packages/nipype/interfaces/base.pyc in raise_exception(self, runtime)

   1317         message += "Standard error:\n" + runtime.stderr + "\n"

   1318         message += "Return code: " + str(runtime.returncode)

-> 1319         raise RuntimeError(message)

   1320 

   1321     @classmethod


RuntimeError: Command:

flirt -in T2_N3rescalenorm_brain.nii.gz -ref T2_p140_brain_template.nii.gz -out T2_N3rescalebrain_adhoc_FLIRT.nii.gz -omat T2_N3rescalebrain_adhoc_matrix.mat -cost corratio -dof 12 -interp sinc -searchrx 10 10 -searchry 10 10 -searchrz 10 10

Standard output:


Standard error:

Image Exception : #22 :: ERROR: Could not open image T2_p140_brain_template

libc++abi.dylib: terminating with uncaught exception of type RBD_COMMON::BaseException

Return code: -6

Interface FLIRT failed to run. 


As can be seen from the above terminal lines that I have copied to here, the FLIRT interface failed to run and it could not open the image. However, I really couldn't understand why. I ensured that my shell's working directory was in the same folder as where all the input and reference files were residing (and this includes the file T2_p140_brain_template which the error message says cannot be opened), and launched ipython from there. To further trouble shoot the problem, I copied out the fsl command:

flirt -in T2_N3rescalenorm_brain.nii.gz -ref T2_p140_brain_template.nii.gz -out T2_N3rescalebrain_adhoc_FLIRT.nii.gz -omat T2_N3rescalebrain_adhoc_matrix.mat -cost corratio -dof 12 -interp sinc -searchrx 10 10 -searchry 10 10 -searchrz 10 10

exactly as it was shown in the error message, and gave it to my shell's prompt in another terminal window (whose working directory I again ensured was the same as where all the required files were residing) and it actually worked! When I executed the flirt command as a command line tool it worked, which indicates that the problem might not be with the command-line tool itself.

What could be the cause of the problem with the interface?

As an aside that might hopefully provide helpful information, my FSL version is 5.0.6 whilst my Nipype version is 0.9.2. Could it be that this is an incompatibility issue?

Could the problem be due to some path issue?

Thank you very much all in advance for your help on this puzzling error!

Best regards,
Augustine

Augustine Koh

unread,
Mar 17, 2014, 2:41:06 AM3/17/14
to nipy...@googlegroups.com
Today I also tried running the exact same registration using fsl.FLIRT as just an interface only:

In [1]: from nipype.interfaces import fsl as fsl


In [2]: register_brain = fsl.FLIRT()


In [3]: register_brain.inputs.in_file = 'T2_N3rescalenorm_brain.nii.gz'


In [4]: register_brain.inputs.reference = 'T2_p140_brain_template.nii.gz'


In [5]: register_brain.inputs.searchr_x = [10, 10]


In [6]: register_brain.inputs.searchr_y = [10, 10]


In [7]: register_brain.inputs.searchr_z = [10, 10]


In [8]: register_brain.inputs.dof = 12


In [9]: register_brain.inputs.interp = 'sinc'


In [10]: register_brain.inputs.cost = 'corratio'


In [11]: register_brain.inputs.out_file = 'T2_N3rescalebrain_adhoc_FLIRT.nii.gz'


In [12]: register_brain.inputs.out_matrix_file = 'T2_N3rescalebrain_adhoc_matrix.mat'


In [13]: register_brain.run()

Out[13]: <nipype.interfaces.base.InterfaceResult at 0x107e27d10>


and it worked! It seems like my problem arises only when I try to execute the registration as a node...
Reply all
Reply to author
Forward
0 new messages