Repository: nipy/nipype

Issue:
fsl_out=True does not work for freesurfer.TKregister2
### Summary
Hi! I am writing a diffusion processing workflow, and wants to use the `freesurfer.TKregister2` interface for transforming a freesurfer transformation matrix to a fsl one. I see that the `fsl_out` option can be set to True according to the documentation ( and from the `Tkregister2InputSpec` code). However, doing that gives an error.

The causes seem to be these lines in nipype/interfaces/freesurfer/utils.py:
1. line 1969-1970 in (`TKregister2._format_arg`)
```python
if name in ("fsl_out", "lta_out") and value is True:
    value = self._list_outputs()[name]
```
2. line 1981-1984 in (`TKregister2._list_outputs`)
```python
if fsl_out is True:
    outputs["fsl_file"] = fname_presuffix(
        reg_file, suffix=".mat", newpath=cwd, use_ext=False
    )
```
So, with 'fsl_out=True', `TKregister2._list_outputs` sets up the output field 'fsl_file' and returns a dictionary (I think?) updated with a key called `fsl_file`. However, the key `fsl_out` is checked in `TKregister2._format_arg` which is not set.

### Actual behavior
These errors were generated by nipype:
```console
Traceback:
	Traceback (most recent call last):
	  File "/home/jwu/.venvs/mpp-dwi-proc/lib/python3.11/site-packages/nipype/interfaces/base/core.py", line 935, in _parse_inputs
	    arg = self._format_arg(name, spec, value)
	          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/home/jwu/.venvs/mpp-dwi-proc/lib/python3.11/site-packages/nipype/interfaces/freesurfer/utils.py", line 1970, in _format_arg
	    value = self._list_outputs()[name]
	            ~~~~~~~~~~~~~~~~~~~~^^^^^^
	KeyError: 'fsl_out'

	The above exception was the direct cause of the following exception:

	Traceback (most recent call last):
	  File "/home/jwu/.venvs/mpp-dwi-proc/lib/python3.11/site-packages/nipype/interfaces/base/core.py", line 735, in _run_interface
	    runtime.cmdline = self.cmdline
	                      ^^^^^^^^^^^^
	  File "/home/jwu/.venvs/mpp-dwi-proc/lib/python3.11/site-packages/nipype/interfaces/base/core.py", line 660, in cmdline
	    allargs = [self._cmd_prefix + self.cmd] + self._parse_inputs()
	                                              ^^^^^^^^^^^^^^^^^^^^
	  File "/home/jwu/.venvs/mpp-dwi-proc/lib/python3.11/site-packages/nipype/interfaces/base/core.py", line 937, in _parse_inputs
	    raise ValueError(
	ValueError: Error formatting command line argument 'fsl_out' with value 'True'

	The above exception was the direct cause of the following exception:

	Traceback (most recent call last):
	  File "/home/jwu/.venvs/mpp-dwi-proc/lib/python3.11/site-packages/nipype/interfaces/base/core.py", line 397, in run
	    runtime = self._run_interface(runtime)
	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/home/jwu/.venvs/mpp-dwi-proc/lib/python3.11/site-packages/nipype/interfaces/base/core.py", line 737, in _run_interface
	    raise RuntimeError(
	RuntimeError: Error raised when interpolating the command line
```
### Expected behavior
This option should set a file value for the output field `fsl_file` without error

### How to replicate the behavior
This should replicate with any moving image and reg file:
```python
tkr2 = freesurfer.Tkregister2(moving_image=moving_image, reg_file=reg_file, fsl_out=True)
tkr2.run()
```

### Script/Workflow details

```python
command = 'singularity run -B work/work,features/features mfeatures.simg tkregister2'
tkr_diff2str = pe.Node(
            freesurfer.Tkregister2(command=command, noedit=True, fsl_out=True), name='tkr_diff2str')
diff_proc_wf.connect([ # part of the connections
            (nodif_bias, tkr_diff2str, [('out_file', 'moving_image')]),
            (bbr_epi2t1, tkr_diff2str, [('out_reg_file', 'reg_file')]),
            (split_t1_files, tkr_diff2str, [('t1', 'target_image')]),
            (tkr_diff2str, diff2str, [('fsl_file', 'in_file2')])])
```

### Platform details:

<!-- Please run the following code from your shell and place the output between the triple ticks, below.
python -c "import nipype; from pprint import pprint; pprint(nipype.get_info())"
-->

```
{'commit_hash': '<not found>',
 'commit_source': '(none found)',
 'networkx_version': '3.1',
 'nibabel_version': '5.1.0',
 'nipype_version': '1.8.6',
 'numpy_version': '1.24.3',
 'pkg_path': '/home/jwu/.venvs/mpp-dwi-proc/lib/python3.11/site-packages/nipype',
 'scipy_version': '1.10.1',
 'sys_executable': '/home/jwu/.venvs/mpp-dwi-proc/bin/python3',
 'sys_platform': 'linux',
 'sys_version': '3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]',
 'traits_version': '6.3.2'}
```

### Execution environment
- Container (Singularity 3): FreeSurfer 7.3.2
- My python environment outside container



Discussion:

Resolving patch:
diff --git a/nipype/interfaces/freesurfer/utils.py b/nipype/interfaces/freesurfer/utils.py
--- a/nipype/interfaces/freesurfer/utils.py
+++ b/nipype/interfaces/freesurfer/utils.py
@@ -1966,7 +1966,7 @@ def _format_arg(self, name, spec, value):
         if name == "lta_in" and self.inputs.invert_lta_in:
             spec = "--lta-inv %s"
         if name in ("fsl_out", "lta_out") and value is True:
-            value = self._list_outputs()[name]
+            value = self._list_outputs()[f'{name[:3]}_file']
         return super()._format_arg(name, spec, value)
 
     def _list_outputs(self):


Test patch: