Hello,
I am reorganising a longitudinal study to BIDS convention. Then I plan to process the study using sct_run_batch.py
script. My question is β is the sct_run_batch.py
compatible with BIDS recommendation for longitudinal studies:
sub-01/
ses-01/
anat/
sub-01_ses-01_T1w.nii.gz
sub-01_ses-01_T1w.json
dwi/
ses-02/
anat/
sub-01_ses-02_T1w.nii.gz
sub-01_ses-02_T1w.json
dwi/
Or is there another recommendation how to deal with longitudinal studies?
Thanks!
Hi @valosekj!
SCT should be able to handle nested folders starting with ses-
. For more details see the implementation.
Please test it out and let us know if it does the job as expected
Thank you for your feedback!
Julien
1 Like
Thank you Julien! I let you know when I test it.
Okay, I tested it using the latest SCT version. Generally it works, but I had to do two small tweaks on $SUBJECT
variable. I try to describe that for future users.
I have organised data according to BIDS for longitudinal studies like this:
βββ sub-01
β βββ ses-01
β βββ anat
β β βββ sub-01_ses-01_T1w.json
β β βββ sub-01_ses-01_T1w.nii.gz
And letβs say I have simple test_script.sh
script for spinal cord segmentation which I run using sct_run_batch
as follow:
sct_run_batch -path-data ./data_bids -path-output ./data_bids_results -sub sub-01 -script test_script.sh
$1
variable passed from sct_run_batch
to test_script.sh
would be standardly sub-01
, but since data has additional subfolder ses-
, $1
would be sub-01/ses-01
which is absolutely expected and okay.
In my test_script.sh
I had to modify $SUBJECT
variable at two places, though:
-
For rsync
command it is necessary to remove ses-
from the source path, otherwise data would be copied to data_processed/ses-01/
folder instead of data_processed/sub-01/ses-01/
-
Since $SUBJECT
variable contains sub-01/ses-01
, it is necessary to replace /
by _
(to get filename like sub-01_ses-01_T1w.nii.gz
instead of sub-2246B/ses-01_T1w.nii.gz
) for any other command (such as sct_deepseg_sc
) which works with filenames
My test_script.sh
then looks like:
#!/bin/bash
set -x
# Retrieve input param from sct_run_batch script
SUBJECT=$1
# Go to folder where data will be copied and processed
cd ${PATH_DATA_PROCESSED}
# Copy source images, NB - ${SUBJECT%/*} removes ses-01 from source path
rsync -avzh ${PATH_DATA}/${SUBJECT%/*} .
# Go to anat folder where all structural data are located
cd ${SUBJECT}/anat/
# Run SC segmentation on T1w image, NB - ${SUBJECT/\//_} replaces '/' by '_'
file_t1="${SUBJECT/\//_}_T1w"
sct_deepseg_sc -i ${file_t1}.nii.gz -c t1
I hope it is understandable
Hi @valosekj,
Thank you for the feedback! Indeed, I forgot to mention that the batch script needs to be updated. This should be left at the discretion of the user though, because BIDS allows to name files either with (βsub-XX_ses-YY_ZZβ) or without the βses-β field nested in the file name (βsub-XX_ZZβ).
Your modification is exactly what was needed in your case. You might also want to consider changing the SUBJECT
variable in the first place. See for example this recent pipeline that also uses multiple sessions.
1 Like