A question regarding Fibre density and cross-section - Single-tissue CSD tutorial

Hello all,

In this tutorial under the step 9, there is this line of code:

foreach * : dwiextract IN/dwi_denoised_unringed_preproc_unbiased_normalised_upsampled.mif - \| dwi2fod msmt_csd - ../group_average_response.txt IN/wmfod.mif -mask IN/dwi_mask_upsampled.mif

Could someone please check if this is actually a correct command and there is no typo in it?
When copy and paste the command it gives me an error.

Also, if this is a correct command line, could you please elaborate how it works?

Thank you!

1 Like

Not as far as I can tell. It would help a great deal if you copy/pasted exactly what you typed and the full output produced, so we can try to figure out what might have gone wrong…

The foreach command is a convenience script provided with MRtrix3 to help with batch processing – see this page for details.

In this case, it uses a Unix pipeline to feed the output of the first command into the next. This is equivalent to running:

foreach * : dwiextract IN/dwi_denoised_unringed_preproc_unbiased_normalised_upsampled.mif IN/tmp.mif
foreach * : dwi2fod msmt_csd IN/tmp.mif ../group_average_response.txt IN/wmfod.mif -mask IN/dwi_mask_upsampled.mif

with the benefit that there is no need to store the temporary tmp.mif file.

The only odd things about this command are

  • the need to use an escape character before the pipe symbol (|) to prevent the shell from interpreting it.

  • the use of the special - character in place of the filename for what would have been the output of the first command and what would have been in the input of the second. More on that in the documentation.


Does this piping strategy only work for mrtrix command?
I tried to use if for a mixture of fsl and mrtrix commands and it seems that fsl command does not like the “-” as the output.
Any advise?

Yes, that’s specific to MRtrix. It’s not good to work with other packages. You’ll need to split that off into separate commands, storing the output from the first explicitly, then passing as input for the next.

1 Like