Error with dwi2response

Hello All!

I’m a beginner at mrtrix and I have been trying out the following command:

dwi2response msmt_5tt 102513_DWI.mif 102513_5TT_freesurfer.mif 102513_RF_WM_freesurfer.txt 102513_RF_GM_freesurfer.txt 102513_RF_CSF_freesurfer.txt -voxels 102513_RF_voxels_freesurfer.mif

However I seem to keep getting the following error:

dwi2response:

dwi2response: *Note that this script makes use of commands / algorithms that have relevant articles for citation. Please consult the help page (-help option) for more information.*

dwi2response:

dwi2response: *Generated temporary directory: /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/*

*Command:* mrconvert /home/rkumar/hcp_sc/connectomes_freesurfer/102513_DWI.mif /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/dwi.mif -stride 0,0,0,1

*Command:* mrconvert /home/rkumar/hcp_sc/connectomes_freesurfer/102513_5TT_freesurfer.mif /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/5tt.mif

dwi2response: *Changing to temporary directory (/home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/)*

*Command:* dwi2mask dwi.mif mask.mif

*Command:* 5ttcheck 5tt.mif

*Command:* dwi2tensor dwi.mif - -mask mask.mif | tensor2metric - -fa fa.mif -vector vector.mif

*Function:* shutil.copy(vector.mif, dirs.mif)

*Command:* mrtransform 5tt.mif 5tt_regrid.mif -template fa.mif -interp linear

*Command:* mrconvert 5tt_regrid.mif - -coord 3 2 -axes 0,1,2 | mrcalc - 0.95 -gt mask.mif -mult wm_mask.mif

*Command:* mrconvert 5tt_regrid.mif - -coord 3 0 -axes 0,1,2 | mrcalc - 0.95 -gt fa.mif 0.2 -lt -mult mask.mif -mult gm_mask.mif

*Command:* mrconvert 5tt_regrid.mif - -coord 3 3 -axes 0,1,2 | mrcalc - 0.95 -gt fa.mif 0.2 -lt -mult mask.mif -mult csf_mask.mif

dwi2response: *Calling dwi2response recursively to select WM single-fibre voxels using 'tournier' algorithm*

*Command:* dwi2response tournier dwi.mif wm_ss_response.txt -mask wm_mask.mif -voxels wm_sf_mask.mif -tempdir /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/

dwi2response:

dwi2response: **[ERROR] Command failed: dwi2response tournier dwi.mif wm_ss_response.txt -mask wm_mask.mif -voxels wm_sf_mask.mif -tempdir /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/** *(msmt_5tt.py:83)*

dwi2response: *Output of failed command:*

dwi2response:

dwi2response: *Note that this script makes use of commands / algorithms that have relevant articles for citation. Please consult the help page (-help option) for more information.*

dwi2response:

dwi2response: *Generated temporary directory: /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/dwi2response-tmp-REM08P/*

*Command:* mrconvert /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/dwi.mif - -stride 0,0,0,1 | dwiextract - /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/dwi2response-tmp-REM08P/dwi.mif -singleshell -no_bzero

*Command:* mrconvert /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/wm_mask.mif /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/dwi2response-tmp-REM08P/mask.mif -datatype bit

dwi2response: *Changing to temporary directory (/home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/dwi2response-tmp-REM08P/)*

dwi2response: **[ERROR] Input mask does not contain any voxels**

dwi2response: *Changing back to original directory (/home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z)*

dwi2response: *Contents of temporary directory kept, location: /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/dwi2response-tmp-REM08P/*

dwi2response: *Changing back to original directory (/home/rkumar/hcp_sc)*

dwi2response: Script failed while executing the command: dwi2response tournier dwi.mif wm_ss_response.txt -mask wm_mask.mif -voxels wm_sf_mask.mif -tempdir /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/

dwi2response: For debugging, inspect contents of temporary directory: /home/rkumar/hcp_sc/dwi2response-tmp-T2VI9Z/

I even tried to change the response algorithm I was using to dhollander but I keep get getting this error with that too:

dwi2response:

dwi2response: *Note that this script makes use of commands / algorithms that have relevant articles for citation. Please consult the help page (-help option) for more information.*

dwi2response:

dwi2response: *Generated temporary directory: /home/rkumar/hcp_sc/dwi2response-tmp-3O5Z07/*

*Command:* mrconvert /home/rkumar/hcp_sc/connectomes_freesurfer/102513_DWI.mif /home/rkumar/hcp_sc/dwi2response-tmp-3O5Z07/dwi.mif -stride 0,0,0,1

dwi2response: *Changing to temporary directory (/home/rkumar/hcp_sc/dwi2response-tmp-3O5Z07/)*

*Command:* dwi2mask dwi.mif mask.mif

dwi2response: *4 unique b-value(s) detected: 5,998,1998,2996 with 18,90,90,90 volumes.*

*Command:* maskfilter mask.mif erode eroded_mask.mif -npass 3

*Command:* dwiextract dwi.mif -shell 5 - | mrmath - mean mean_b5.mif -axis 3

*Command:* mrcalc mean_b5.mif -finite mean_b5.mif 0 -if 0 -le err_b5.mif -datatype bit

*Command:* dwiextract dwi.mif -shell 998 - | mrmath - mean mean_b998.mif -axis 3

*Command:* mrcalc mean_b998.mif -finite mean_b998.mif 0 -if 0 -le err_b998.mif -datatype bit

*Command:* mrcalc mean_b5.mif mean_b998.mif -divide -log sdm_b998.mif

*Command:* dwiextract dwi.mif -shell 1998 - | mrmath - mean mean_b1998.mif -axis 3

*Command:* mrcalc mean_b1998.mif -finite mean_b1998.mif 0 -if 0 -le err_b1998.mif -datatype bit

*Command:* mrcalc mean_b5.mif mean_b1998.mif -divide -log sdm_b1998.mif

*Command:* dwiextract dwi.mif -shell 2996 - | mrmath - mean mean_b2996.mif -axis 3

*Command:* mrcalc mean_b2996.mif -finite mean_b2996.mif 0 -if 0 -le err_b2996.mif -datatype bit

*Command:* mrcalc mean_b5.mif mean_b2996.mif -divide -log sdm_b2996.mif

*Command:* mrcalc sdm_b998.mif 90 -mult sdm_b1998.mif 90 -mult -add sdm_b2996.mif 90 -mult -add 270 -divide full_sdm.mif

*Command:* mrcalc full_sdm.mif -finite full_sdm.mif 0 -if 0 -le err_sdm.mif -datatype bit

*Command:* mrcalc err_b5.mif err_b998.mif -add err_b1998.mif -add err_b2996.mif -add err_sdm.mif -add 0 eroded_mask.mif -if safe_mask.mif -datatype bit

*Command:* mrcalc safe_mask.mif full_sdm.mif 0 -if 10 -min safe_sdm.mif

*Command:* dwi2tensor dwi.mif - -mask safe_mask.mif | tensor2metric - -fa safe_fa.mif -vector safe_vecs.mif -modulate none -mask safe_mask.mif

*Command:* mrcalc safe_mask.mif safe_fa.mif 0 -if 100.0 -gt crude_wm.mif -datatype bit

*Command:* mrcalc crude_wm.mif 0 safe_mask.mif -if _crudenonwm.mif -datatype bit

mrstats: **[ERROR] Cannot output statistic of interest; no values read (empty mask?)**

*Command:* mrcalc _crudenonwm.mif safe_sdm.mif -subtract 0 -if - | mrthreshold - - -mask _crudenonwm.mif | mrcalc _crudenonwm.mif - 0 -if crude_csf.mif -datatype bit

dwi2response:

dwi2response: **[ERROR] Command failed: mrcalc _crudenonwm.mif safe_sdm.mif -subtract 0 -if - | mrthreshold - - -mask _crudenonwm.mif | mrcalc _crudenonwm.mif - 0 -if crude_csf.mif -datatype bit** *(dhollander.py:105)*

dwi2response: *Output of failed command:*

mrcalc: [ERROR] not enough operands in stack for operation "if"

mrthreshold: [ERROR] no filename supplied to standard input (broken pipe?)

mrthreshold: [ERROR] error opening image "-"

mrcalc: [ERROR] error converting string "-"

dwi2response: *Changing back to original directory (/home/rkumar/hcp_sc)*

dwi2response: Script failed while executing the command: mrcalc _crudenonwm.mif safe_sdm.mif -subtract 0 -if - | mrthreshold - - -mask _crudenonwm.mif | mrcalc _crudenonwm.mif - 0 -if crude_csf.mif -datatype bit

dwi2response: For debugging, inspect contents of temporary directory: /home/rkumar/hcp_sc/dwi2response-tmp-3O5Z07/

The command I used for the dhollander algorithm was:

dwi2response dhollander 102513_DWI.mif 102513_RF_WM_freesurfer.txt 102513_RF_GM_freesurfer.txt 102513_RF_CSF_freesurfer.txt

It would be great if someone could tell me where I’m going wrong :slight_smile:

Also I just wanted to add that the version of mrtrix I am using is 3.0 release candidate 2. I’m not sure if that has anything to do with my issue but I just wanted to put that out there.

Thanks for all your help in advance!

Hi @ritvik123,

Some strange stuff going on there. When dwi2response dhollander stops, can you go into the temporary folder and run an…

mrview safe_fa.mif

…for me, and then show us a screenshot of what that looks like?

Apart from that, what baffles me, is this line in your output:

*Command:* mrcalc safe_mask.mif safe_fa.mif 0 -if 100.0 -gt crude_wm.mif -datatype bit

This because the code in the script at RC2 for this line is this one: https://github.com/MRtrix3/mrtrix3/blob/3.0_RC2/lib/mrtrix3/dwi2response/dhollander.py#L100

…which graps app.args.fa directly from your input, or uses a default value of 0.2 if you didn’t specify the -fa option, as seen on this line: https://github.com/MRtrix3/mrtrix3/blob/3.0_RC2/lib/mrtrix3/dwi2response/dhollander.py#L12

Now that’s weird, because in your output, it reads 100.0 for this value, but you haven’t specified the -fa option manually. We can check what the script thinks you’ve provided if you show us the contents of the command.txt file, again in the temporary folder of the script.

Finally, can you maybe try and explicitly provide this -fa option, just to check, by running:

dwi2response dhollander 102513_DWI.mif sfwm.txt gm.txt csf.txt -fa 0.2

Thank you for your response @ThijsDhollander

I changed my dwi2reponse dhollander command to this one instead as you mentioned:

dwi2response dhollander 102513_DWI.mif 102513_RF_WM.txt 102513_RF_GM.txt 102513_RF_CSF.txt -fa 0.2

This was the error message I obtained this time:

dwi2response:

dwi2response: *Note that this script makes use of commands / algorithms that have relevant articles for citation. Please consult the help page (-help option) for more information.*

dwi2response:

dwi2response: *Generated temporary directory: /home/rkumar/hcp_sc/dwi2response-tmp-SGT1BW/*

*Command:* mrconvert /home/rkumar/hcp_sc/connectomes_freesurfer/102513_DWI.mif /home/rkumar/hcp_sc/dwi2response-tmp-SGT1BW/dwi.mif -stride 0,0,0,1

dwi2response: *Changing to temporary directory (/home/rkumar/hcp_sc/dwi2response-tmp-SGT1BW/)*

*Command:* dwi2mask dwi.mif mask.mif

dwi2response: *4 unique b-value(s) detected: 5,998,1998,2996 with 18,90,90,90 volumes.*

*Command:* maskfilter mask.mif erode eroded_mask.mif -npass 3

*Command:* dwiextract dwi.mif -shell 5 - | mrmath - mean mean_b5.mif -axis 3

*Command:* mrcalc mean_b5.mif -finite mean_b5.mif 0 -if 0 -le err_b5.mif -datatype bit

*Command:* dwiextract dwi.mif -shell 998 - | mrmath - mean mean_b998.mif -axis 3

*Command:* mrcalc mean_b998.mif -finite mean_b998.mif 0 -if 0 -le err_b998.mif -datatype bit

*Command:* mrcalc mean_b5.mif mean_b998.mif -divide -log sdm_b998.mif

*Command:* dwiextract dwi.mif -shell 1998 - | mrmath - mean mean_b1998.mif -axis 3

*Command:* mrcalc mean_b1998.mif -finite mean_b1998.mif 0 -if 0 -le err_b1998.mif -datatype bit

*Command:* mrcalc mean_b5.mif mean_b1998.mif -divide -log sdm_b1998.mif

*Command:* dwiextract dwi.mif -shell 2996 - | mrmath - mean mean_b2996.mif -axis 3

*Command:* mrcalc mean_b2996.mif -finite mean_b2996.mif 0 -if 0 -le err_b2996.mif -datatype bit

*Command:* mrcalc mean_b5.mif mean_b2996.mif -divide -log sdm_b2996.mif

*Command:* mrcalc sdm_b998.mif 90 -mult sdm_b1998.mif 90 -mult -add sdm_b2996.mif 90 -mult -add 270 -divide full_sdm.mif

*Command:* mrcalc full_sdm.mif -finite full_sdm.mif 0 -if 0 -le err_sdm.mif -datatype bit

*Command:* mrcalc err_b5.mif err_b998.mif -add err_b1998.mif -add err_b2996.mif -add err_sdm.mif -add 0 eroded_mask.mif -if safe_mask.mif -datatype bit

*Command:* mrcalc safe_mask.mif full_sdm.mif 0 -if 10 -min safe_sdm.mif

*Command:* dwi2tensor dwi.mif - -mask safe_mask.mif | tensor2metric - -fa safe_fa.mif -vector safe_vecs.mif -modulate none -mask safe_mask.mif

*Command:* mrcalc safe_mask.mif safe_fa.mif 0 -if 0.2 -gt crude_wm.mif -datatype bit

*Command:* mrcalc crude_wm.mif 0 safe_mask.mif -if _crudenonwm.mif -datatype bit

mrstats: **[ERROR] Cannot output statistic of interest; no values read (empty mask?)**

*Command:* mrcalc _crudenonwm.mif safe_sdm.mif -subtract 0 -if - | mrthreshold - - -mask _crudenonwm.mif | mrcalc _crudenonwm.mif - 0 -if crude_csf.mif -datatype bit

dwi2response:

dwi2response: **[ERROR] Command failed: mrcalc _crudenonwm.mif safe_sdm.mif -subtract 0 -if - | mrthreshold - - -mask _crudenonwm.mif | mrcalc _crudenonwm.mif - 0 -if crude_csf.mif -datatype bit** *(dhollander.py:105)*

dwi2response: *Output of failed command:*

mrcalc: [ERROR] not enough operands in stack for operation "if"

mrthreshold: [ERROR] no filename supplied to standard input (broken pipe?)

mrthreshold: [ERROR] error opening image "-"

mrcalc: [ERROR] error converting string "-"

dwi2response: *Changing back to original directory (/home/rkumar/hcp_sc)*

dwi2response: Script failed while executing the command: mrcalc _crudenonwm.mif safe_sdm.mif -subtract 0 -if - | mrthreshold - - -mask _crudenonwm.mif | mrcalc _crudenonwm.mif - 0 -if crude_csf.mif -datatype bit

dwi2response: For debugging, inspect contents of temporary directory: /home/rkumar/hcp_sc/dwi2response-tmp-SGT1BW/


After I ran the above command I took the following screenshot of safe_fa.mif:

I’m guessing that this shouldn’t be completely black and that the error arises due to this. The safe_mask file is also completely black. I’m slightly confused as to what is causing this.

Thanks for your help,
Rakshita

Just as a side note: I can’t seem to find the folder with the -fa 100 command so Ive redone the entire thing with -fa 0.2 instead. Sorry about that!

Hi again Rakshita,

Ok, so the -fa option is now passing as it should. I’m still baffled why the default didn’t end up in there in your previous output, let alone why it would suddenly become 100 rather than 0.2…

Let’s backtrack; luckily the dwi2response dhollander algorithm provides lots of steps and images in between, all the way to the source (hopefully). :wink:

So starting from the beginning, again checking files in that folder, what does mask.mif look like? That’s the first mask, computed straight from the data via a simple dwi2mask dwi.mif mask.mif… If that’s wrong (empty or otherwise weird), something’s off about the data itself somehow.

If that still checks out, lets to an intermediate check at another stage; can you in that case show me what full_sdm.mif looks like? To view this one well, load it in mrview, and manually set the intensity scaling (in the View options tool) to a range from 0 to 5.

Just a general question about the data: it looks like this is HCP data, right? Is it the (already) minimally preprocessed data you downloaded, or did you perform any preprocessing yourself?

Cheers,
Thijs

Hi @ThijsDhollander,

It turns out that the dwi.mif file that I inputted into the function was blank itself and that’s why the dhollander algorithm failed. I’ve fixed the dwi.mif file now and it seems to be working now.

Thank you so much for your help :smiley: ,

Rakshita

1 Like

Good to hear! Sometimes it’s the simplest explanation indeed. :wink: :+1:

I’ve found the dwi2response dhollander algorithm to be more accurate, even on the high quality HCP data. I hope it serves you well!