Correct way to combine MCFLIRT and ApplyXFM4D in nipype?


I am working with some complex volumes that need registering. My go-to method for this is running mcflirt on the magnitude volumes, splitting the complex volumes into real and imaginary parts, using applyxfm4D on these separately, then re-combining (this avoids problems with sampling phase across the 0/2pi boundary).

What is the correct way to pass the output matrices of mcflirt to ApplyXfm4D within nipype? ApplyXfm4D takes the trans_dir argument, because the underlying fsl tool also takes a directory as an argument that then contains all the transformation matrices. However the nipype wrapper of mcflirt does not expose this directory as an output, instead it provides a list of all the individual transformation matrix files.

For now I’ve hacked the MCFLIRT wrapper to also provide the output directory, but I feel like I’m missing something and ended up re-inventing the wheel.

nipype doesn’t have an interface for applyxfm4D. it would be good to add.

the interface should take a list of mat files (as produced by mcflirt) as input, such that hashing is proper (a directory is hard to hash in general on a system), and the interface can rerun if any of the transformation files change.

then internally it can format the argument (by overriding format arg) to simply point to the directory containing the files. if you send a PR to github, we can help refine it.

alternatively you can write a function node for now to do the same operation.


I double checked and you are correct, the ApplyXfm4D wrapper I am using is not part of nipype. However, I don’t remember writing it so I’m now very confused! It may have come from another member of our department and I forgot.

I’ve attached the wrapper as is. Converting the the list of mat files to the directory is beyond my knowledge of traits - and doesn’t seem a terribly good solution to me (I don’t see how one file can change without all of them being overwritten, due to the way mcflirt works, and I don’t know of any other tool that consumes the list of matrix files produced by mcflirt?).

applyxfm4d.txt (2.7 KB)

1 Like

Don’t you want to add the file in a PR? It would be great contribution.