Stanford BIDS Tutorial Series troubleshooting

Hello, I’m new to bids & coding. I am working through part 1b of Stanfords BIDS Tutorial Series (BIDS Tutorial Series: Automate the Introductory Walkthrough | Stanford Center for Reproducible Neuroscience). I am currently spending a lot of time troubleshooting the code that is provided in the tutorial. For example, in order to complete Step 2, I had to change the code provided in the tutorial from:

####Anatomical Organization####
for subj in 2475376; do
echo “Processing subject $subj”

###Create structure
mkdir -p {niidir}/sub-{subj}/ses-1/anat

###Convert dcm to nii
#Only convert the Dicom folder anat
for direcs in anat; do
{dcm2niidir}/dcm2niix -o {niidir}/sub-{subj} -f {subj}%f%p {dcmdir}/{subj}/${direcs}

to

for subj in 2475376; do
echo “Processing subject $subj”;
done

for subj in 2475376; do
mkdir -p {niidir}/sub-{subj}/ses-1/anat**;**
done

for direcs in anat; do
[removed {dcm2niidir}]/**dcm2niix -o {niidir}/sub-{subj} -f {subj}%f%p {dcmdir}/{subj}/${direcs};**
done

Now I am on step 3, trying to rename the .nii and .json files, but I continue to receive the following error ouput:

ls: 2475376_anat_MPRAGE.json
2475376_anat_MPRAGE.nii: No such file or directory
mv: rename . to sub-2475376_ses-1_T1w.: Invalid argument
changed to sub-2475376_ses-1_T1w.

ls: 2475376_anat_MPRAGE.json
2475376_anat_MPRAGE.nii: No such file or directory
mv: rename . to sub-2475376_ses-1_T1w.: Invalid argument
changed to sub-2475376_ses-1_T1w.

I am confused because the code provided in the tutorial specifically mentions that the line Anat=$(ls MPRAGE) was included specifically to avoid the error “No such file or directory”.

Because I am beginner to bids and coding, I am struggling to troubleshoot the tutorial myself. My question is: is the code provided by the tutorial accurate? (i.e.: no syntax errors, commands appear in the correct), or is it merely a rough guideline?

For example, I am pretty confused why the third for-loop in step 2 included “${dcm2niidir}”? Is that a mistake, or am I misunderstanding something basic?

I would really appreciate any guidance in the topic.

Thank you so much in advance!

hi @gwunsae

thank you for your message. if I may clarify a few questions you posed: the code should be accurate (it was evaluated prior to publishing and has been used with no issues surfaced since it was published in Feb. 2018), the dollar sign is part of the syntax for bash (for a longer explanation of the dollar sign: bash - What does $(command) & do? - Ask Ubuntu).

Regarding the specific errors you are encountering - does your directory structure look similar to the screenshot at the end of step 2? This will help understand what may be going on

Thank you,
Franklin