frankyeh / DSI-Studio

A Tractography Tool for Diffusion MRI
http://dsi-studio.labsolver.org
Other
118 stars 54 forks source link

Getting .src files from a BIDS-like dataset with multiple sessions using action=src command #74

Closed JohannesWiesner closed 1 year ago

JohannesWiesner commented 1 year ago

I have a BIDS-like dataset (aka. I cannot guarantee that the BIDS-validator will approve it as a BIDS dataset, but it roughly follows the BIDS structure) with several subjects and several session folders for these subjects. I want to get .src files using each of the *-preproc_dwi.nii.gz files (and the respective *-preproc_dwi.bval and *-preproc_dwi.bvec files. I also would like to make use of the recursive function of DSI-Studio, i.e. find all files for each subject and for each session process them and output them to the output folder. I wanted to use the following command to do that:

dsi_studio --action=src --source=/data --output=/output

It seems that it successfully recursively searches through all the folders but then stops:

+ DSI Studio version: Chen"陳" command line
| DSI Studio version: Chen"陳"
| action=src
| source=/data
| loop=/data
| + run src
| | look for BIDS structure at /data
| | output=/output
| | + batch creating src
| | | + opening sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
| | | |_0 ms
| | | + opening sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz
| | | |_0 ms
| | | + opening sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz
| | | |_2 ms
| | | + opening sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz
| | | |_0 ms
| | | + opening sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
| | | |_0 ms
| | | + opening sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
| | | |_0 ms
| | | + opening sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz
| | | |_0 ms
| | | + opening sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz
| | | |_0 ms
| | | + opening sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz
| | | |_0 ms
| | | + opening sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
| | | |_0 ms
| | | + opening sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
| | | |_0 ms
| | | + opening sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz
| | | |_0 ms
| | | + opening sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz
| | | |_0 ms
| | | + opening sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz
| | | |_0 ms
| | | + opening sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
| | | |_0 ms
| | |_6 ms
| |_6 ms
|_8 ms

This is my folder structure:

/data
 |-sub-INDI132M2
 | |-ses-01
 | | |-anat
 | | | |-sub-INDI132M2_ses-01_from-orig_to-T1w_mode-image_xfm.txt
 | | |-dwi
 | | | |-sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.bval
 | | | |-sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz
 | | | |-sub-INDI132M2_ses-01_acq-multishell_dir-pa_desc-SliceQC_dwi.json
 | | | |-sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.bvec
 | | | |-sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz
 | | | |-sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
 | | | |-sub-INDI132M2_ses-01_acq-multishell_dir-pa_dwiqc.json
 | | | |-sub-INDI132M2_ses-01_acq-multishell_dir-pa_desc-ImageQC_dwi.csv
 | | | |-sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz
 | | | |-sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.b
 | | | |-sub-INDI132M2_ses-01_acq-multishell_dir-pa_confounds.tsv
 |-sub-INDI292BG
 | |-ses-01
 | | |-anat
 | | | |-sub-INDI292BG_ses-01_from-orig_to-T1w_mode-image_xfm.txt
 | | |-dwi
 | | | |-sub-INDI292BG_ses-01_acq-multishell_dir-pa_desc-ImageQC_dwi.csv
 | | | |-sub-INDI292BG_ses-01_acq-multishell_dir-pa_desc-SliceQC_dwi.json
 | | | |-sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz
 | | | |-sub-INDI292BG_ses-01_acq-multishell_dir-pa_dwiqc.json
 | | | |-sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz
 | | | |-sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.b
 | | | |-sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz
 | | | |-sub-INDI292BG_ses-01_acq-multishell_dir-pa_confounds.tsv
 | | | |-sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
 | | | |-sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.bval
 | | | |-sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.bvec
 | |-ses-02
 | | |-anat
 | | | |-sub-INDI292BG_ses-02_from-orig_to-T1w_mode-image_xfm.txt
 | | |-dwi
 | | | |-sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.bvec
 | | | |-sub-INDI292BG_ses-02_acq-multishell_dir-pa_confounds.tsv
 | | | |-sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz
 | | | |-sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.bval
 | | | |-sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.b
 | | | |-sub-INDI292BG_ses-02_acq-multishell_dir-pa_dwiqc.json
 | | | |-sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz
 | | | |-sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz
 | | | |-sub-INDI292BG_ses-02_acq-multishell_dir-pa_desc-SliceQC_dwi.json
 | | | |-sub-INDI292BG_ses-02_acq-multishell_dir-pa_desc-ImageQC_dwi.csv
 | | | |-sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
mattcieslak commented 1 year ago

Hi @JohannesWiesner are these from qsiprep? If so you should take a look at the DSI Studio reconstruction workflows, which will create src files. It's of course also possible to use DSI Studio directly on these outputs but be careful on how the bvecs are interpreted. The version of DSI Studio in qsiprep is a bit behind the current DSI Studio and interprets bvecs differently. The bvec file is in LPS+ world coordinates, not LAS+ voxel coordinates (the FSL convention)

frankyeh commented 1 year ago

There is a file named log.txt generated. Could you post its content? Frank

On Wed, Nov 16, 2022 at 8:39 AM Matt Cieslak @.***> wrote:

Hi @JohannesWiesner https://github.com/JohannesWiesner are these from qsiprep? If so you should take a look at the DSI Studio reconstruction workflows, which will create src files. It's of course also possible to use DSI Studio directly on these outputs but be careful on how the bvecs are interpreted. The version of DSI Studio in qsiprep is a bit behind the current DSI Studio and interprets bvecs differently. The bvec file is in LPS+ world coordinates, not LAS+ voxel coordinates (the FSL convention)

— Reply to this email directly, view it on GitHub https://github.com/frankyeh/DSI-Studio/issues/74#issuecomment-1317039767, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACDI4KED3KAAQJYTM4EHI3WITPZNANCNFSM6AAAAAASB6PRRI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

JohannesWiesner commented 1 year ago

Hi @JohannesWiesner are these from qsiprep? If so you should take a look at the DSI Studio reconstruction workflows, which will create src files. It's of course also possible to use DSI Studio directly on these outputs but be careful on how the bvecs are interpreted. The version of DSI Studio in qsiprep is a bit behind the current DSI Studio and interprets bvecs differently. The bvec file is in LPS+ world coordinates, not LAS+ voxel coordinates (the FSL convention)

Nope, I am using the DSI-Studio docker image. The output is from a colleague that used qsiprep, where reconstruction and fiber-tracking are still missing.

frankyeh commented 1 year ago

The log.txt file generated may inform whether the SRC files are generated or if there is any other issue. If still doesn't work, you may upload a sample dataset and I can help checking. Frank

JohannesWiesner commented 1 year ago

Ah, didn't know that it generates a log.txt! Here is the content:

directory:/data
Process sub-INDI132M2
Process sub-INDI292BG
Process sub-INDI132M2/ses-01
    DWI dim=(195,232,197)
    Parsing phase encoding directions
    Cannot parse phase encoding direction for /data/sub-INDI132M2/ses-01/dwi/sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
    /data/sub-INDI132M2/ses-01/dwi/sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
    /data/sub-INDI132M2/ses-01/dwi/sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz
    /data/sub-INDI132M2/ses-01/dwi/sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz
    /data/sub-INDI132M2/ses-01/dwi/sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz
    No reversed phase encoding direction dataset found. Create one SRC file -> ERROR: not a 4D nifti file
Process sub-INDI292BG/ses-01
    DWI dim=(195,232,197)
    Parsing phase encoding directions
    Cannot parse phase encoding direction for /data/sub-INDI292BG/ses-01/dwi/sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
    /data/sub-INDI292BG/ses-01/dwi/sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
    /data/sub-INDI292BG/ses-01/dwi/sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz
    /data/sub-INDI292BG/ses-01/dwi/sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz
    /data/sub-INDI292BG/ses-01/dwi/sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz
    No reversed phase encoding direction dataset found. Create one SRC file -> ERROR: not a 4D nifti file
Process sub-INDI292BG/ses-02
    DWI dim=(195,232,197)
    Parsing phase encoding directions
    Cannot parse phase encoding direction for /data/sub-INDI292BG/ses-02/dwi/sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
    /data/sub-INDI292BG/ses-02/dwi/sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz
    /data/sub-INDI292BG/ses-02/dwi/sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz
    /data/sub-INDI292BG/ses-02/dwi/sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz
    /data/sub-INDI292BG/ses-02/dwi/sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz
    No reversed phase encoding direction dataset found. Create one SRC file -> ERROR: not a 4D nifti file

Apparently, it thinks that the brain mask is an image that it should preprocess. I was already thinking that this might cause problems because DSI-Studio has to automatically detect the "correct files". But I thought that this is somehow cleverly handled by finding a .bval and a .bvec file with the same filename (which means that only *_dwi.niig.z is eligible because it is the only file that has the same name as the .bval and .bvec files

See Parse all 4d NIFTI files in a folder (each of them has a bval and bvec file that shares a similar file name) and generate corresponding SRC files to a new folder

Parse all 4d NIFTI files in a folder (each of them has a bval and bvec file that shares a similar file name) and generate corresponding SRC files to a new folder

Apart from that it also thinks that the dataset contains multiple files with reversed phase-encoding which is not the case. Instead it's only one run per session.

frankyeh commented 1 year ago

Thanks for the information. I am revising the code and will commit an update soon. Frank

On Wed, Nov 16, 2022 at 10:24 AM JohannesWiesner @.***> wrote:

Ah, didn't know that it generates a log.txt! Here is the content:

directory:/data Process sub-INDI132M2 Process sub-INDI292BG Process sub-INDI132M2/ses-01 DWI dim=(195,232,197) Parsing phase encoding directions Cannot parse phase encoding direction for /data/sub-INDI132M2/ses-01/dwi/sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz /data/sub-INDI132M2/ses-01/dwi/sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz /data/sub-INDI132M2/ses-01/dwi/sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz /data/sub-INDI132M2/ses-01/dwi/sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz /data/sub-INDI132M2/ses-01/dwi/sub-INDI132M2_ses-01_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz No reversed phase encoding direction dataset found. Create one SRC file -> ERROR: not a 4D nifti file Process sub-INDI292BG/ses-01 DWI dim=(195,232,197) Parsing phase encoding directions Cannot parse phase encoding direction for /data/sub-INDI292BG/ses-01/dwi/sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz /data/sub-INDI292BG/ses-01/dwi/sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz /data/sub-INDI292BG/ses-01/dwi/sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz /data/sub-INDI292BG/ses-01/dwi/sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz /data/sub-INDI292BG/ses-01/dwi/sub-INDI292BG_ses-01_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz No reversed phase encoding direction dataset found. Create one SRC file -> ERROR: not a 4D nifti file Process sub-INDI292BG/ses-02 DWI dim=(195,232,197) Parsing phase encoding directions Cannot parse phase encoding direction for /data/sub-INDI292BG/ses-02/dwi/sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz /data/sub-INDI292BG/ses-02/dwi/sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-brain_mask.nii.gz /data/sub-INDI292BG/ses-02/dwi/sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-eddy_cnr.nii.gz /data/sub-INDI292BG/ses-02/dwi/sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_desc-preproc_dwi.nii.gz /data/sub-INDI292BG/ses-02/dwi/sub-INDI292BG_ses-02_acq-multishell_dir-pa_space-T1w_dwiref.nii.gz No reversed phase encoding direction dataset found. Create one SRC file -> ERROR: not a 4D nifti file

Apparently, it thinks that the brain mask is an image that it should preprocess. I was already thinking that this might cause problems because DSI-Studio has to automatically detect the "correct files". But I thought that this is somehow cleverly handled by finding a .bval and a .bvec file with the same filename (which means that only *_dwi.niig.z is eligible because it is the only file that has the same name as the .bval and .bvec files

See Parse all 4d NIFTI files in a folder (each of them has a bval and bvec file that shares a similar file name) and generate corresponding SRC files to a new folder https://dsi-studio.labsolver.org/doc/cli_t1.html

Parse all 4d NIFTI files in a folder (each of them has a bval and bvec file that shares a similar file name) and generate corresponding SRC files to a new folder

Apart from that it also thinks that the dataset contains multiple files with reversed phase-encoding which is not the case. Instead it's only one run per session.

— Reply to this email directly, view it on GitHub https://github.com/frankyeh/DSI-Studio/issues/74#issuecomment-1317194151, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACDI4PBZGQOT3NZTFQDSYTWIT4B7ANCNFSM6AAAAAASB6PRRI . You are receiving this because you commented.Message ID: @.***>

frankyeh commented 1 year ago

A new release is under build: https://github.com/frankyeh/DSI-Studio/actions/runs/3481332497 Once completed, please download DSI Studio again and see if it works. The updated version will not generate log.txt (will just output to the command line messages)

JohannesWiesner commented 1 year ago

Will do! :)