Generating a mean b=0 image

Could I please have a hand with step 2 of Diffusion Image Processing in the Structural Connectome for HCP tutorial?

srun -n1 -N1 --mem=8192 -t60 dwiextract DWI.mif - -bzero | mrmath - mean meanb0.mif -axis 3
srun: job 5931830 queued and waiting for resources
srun: job 5931830 has been allocated resources
dwiextract: [100%] extracting volumes…
mrmath: [ERROR] failed to open key/value file “/tmp/mrtrix-tmp-abOTiJ.mif”: No such file or directory
mrmath: [ERROR] error opening image “-”

Not sure what srun is, I’m assuming it’s your job scheduler for execution on a cluster or something? In any case, I reckon the issue is that you can’t use a UNIX pipeline like that: what you’re asking here is for the first command (srun) to feed its output to the next command (mrmath), when presumably you want srun to execute the dwiextract | mrmath pipeline as a single job. You’ll either have to write a script encapsulating all these commands (and more if you want) and feed that to srun, or split the pipeline, storing the temporary results to file, like this:

srun -n1 -N1 --mem=8192 -t60 dwiextract DWI.mif -bzero bzero.mif 
srun -n1 -N1 --mem=8192 -t60 mrmath bzero.mif mean meanb0.mif -axis 3

Personally I’d go for a script rather than splitting the command into multiple jobs. These are small tasks, there’s no reason not to run the whole lot as a single job.

srun runs jobs. Yeah, the pipeline doesn’t work like what I entered. I wrote the script based on your reply and it seemed to work…but is the problem here that it is not 4D?

srun -n1 -N1 --mem=8192 -t60 scripts/dwi2response msmt_5tt DWI.mif 5tt.mif RF_GM.txt RF_WM.txt RF_CSF.txt
srun: job 5931861 queued and waiting for resources
srun: job 5931861 has been allocated resources
dwi2response:
dwi2response: Note that this script makes use of commands / algorithms that have relevant articles for citation; INCLUDING FROM EXTERNAL SOFTWARE PACKAGES. Please consult the help page (-help option) for more information.
dwi2response:
dwi2response: Generated temporary directory: /tmp/dwi2response-tmp-LLUV6O/

mrconvert: [100%] copying from “5tt.mif” to “/tmp/dwi2response-tmp-LLUV6O/5tt.mif”…

mrconvert: [100%] copying from “DWI.mif” to “/tmp/dwi2response-tmp-LLUV6O/dwi.mif”…
dwi2response: Changing to temporary directory (/tmp/dwi2response-tmp-LLUV6O/)
mrinfo: [ERROR] unknown option "-size"
dwi2response: Changing back to original directory (/vlsci/UOM0015/chenay)
dwi2response: Deleting temporary directory /tmp/dwi2response-tmp-LLUV6O/
dwi2response: [ERROR] Input image must be a 4D image
srun: error: barcoo022: task 0: Exited with exit code 1

Actually the key error there is slightly earlier:
mrinfo: [ERROR] unknown option "-size"
This suggests that the mrinfo binary being found first in your path is either from an earlier version of MRtrix3 (when that option was -dim instead), or it is finding the MRtrix 0.2 binary. You’ll need to clear out old installations, or make sure that the version of MRtrix3 that you are using is the first in your path, so that the binaries executed by the script are from the same code version.

Right - so the latest version is 0.3.14 (http://www.mrtrix.org/developer-documentation/). I must use 0.3.13 (I don’t have access to root), so I modified the script to use dimensions instead of size. Thanks.

And now I get…
dwi2response: Changing to temporary directory (/tmp/dwi2response-tmp-NT31LV/)
dwi2mask: [100%] finding min/max of “mean b=5 image”…
dwi2mask: [done] optimising threshold…
dwi2mask: [100%] thresholding…
dwi2mask: [100%] finding min/max of “mean b=998 image”…
dwi2mask: [done] optimising threshold…
dwi2mask: [100%] thresholding…
dwi2mask: [100%] finding min/max of “mean b=1998 image”…
dwi2mask: [done] optimising threshold…
dwi2mask: [100%] thresholding…
dwi2mask: [100%] finding min/max of “mean b=2996 image”…
dwi2mask: [done] optimising threshold…
dwi2mask: [100%] thresholding…
dwi2mask: [done] computing dwi brain mask…
mrinfo: [ERROR] unknown option "-size"
mrinfo: [ERROR] several matches possible for option “-datatype”: "-datatype_long, "-datatype_short"
dwi2response: Changing back to original directory (/vlsci/UOM0015/chenay)
dwi2response: Deleting temporary directory /tmp/dwi2response-tmp-NT31LV/
dwi2response: [ERROR] Imported anatomical image 5tt.mif is not in the 5TT format
srun: error: barcoo027: task 0: Exited with exit code 1

The dwi2response script was never a part of version 0.3.13: in fact, at that tag, there is a binary called dwi2response, which is approximately equivalent to the tax algorithm in the script in version 0.3.14. You will likely run into a number of hurdles trying to get the 0.3.14 script to work with 0.3.13 code. It would probably be easier to either stick to 0.3.13 and use the old binary dwi2response, or simply install 0.3.14 within your home directory on the cluster and make sure that version appears first in your PATH variable (shouldn’t require root access).

I would strongly recommend this option. There’s nothing stopping you from installing MRtrix3 locally in your home folder - this is how all of us use our systems currently. It allows you to set up different versions side-by-side in different folders if you want to, check out the latest release without affecting your current installation, stay up to date without requiring admin rights, etc. And in your case, it would allow you to actually use the up to date version on your cluster…