0

I am running an mriglm on bunch of small time series for my subjects, but I am getting an error when I run the for loop. I think its the for loop and not the command, because I have run this command without the for loop before. I also want to be able to run this on more than one subject if possible, but whenever I try to run for file in $SUBJECT_DATA_DIR; do if [[ "${file}" == "racsleep04_b" ]] with more than one subject it doesn't run.

so the two questions I have are:

  1. am I nesting the two for loops correctly?
  2. how would I apply this to more than one subject?

any help would be very much appreciated!


export SUBJECT_DATA_DIR=/path/to/subject/data/dir/*

export time=('15' '30') #each time series name 

for i in ${time[*]}; do
for file in $SUBJECT_DATA_DIR; do if [[ "${file}" == *"racsleep04_b"* ]]

   export MRTM=$SUBJECT_DATA_DIR/"$(basename $file)"/kinetic_modelling_intervals_all

   export OUTPUT=caudate

   export TIME=$SUBJECT_DATA_DIR/time

   #running mrtm1 analysis:
  
   mri_glmfit --y $MRTM/$OUTPUT/gtm${i}.nii --mrtm1  $MRTM/$OUTPUT/km.ref.tac${i}.dat $MRTM/$OUTPUT/frame.time${i}.dat --o $MRTM/mrtm1_${i} --no-est-fwhm --nii.gz


fi
done
done

when I run the script below I get this error:

/share/pkg.7/freesurfer/6.0/install/bin/mri_glmfit: line 3: 26183 Segmentation fault mri_glmfit.bin "$@"

I also wanted to do this for multiple subjects, e.g. sub01, sub02, sub03 on other similar scripts that work, only the first subject runs, but not the other two:


for i in ${time[*]}; do
for file in $SUBJECT_DATA_DIR; do if [[ "${file}" == "sub01" "sub02" "sub03" ]]

   export MRTM=$SUBJECT_DATA_DIR/"$(basename $file)"/kinetic_modelling_intervals_all

   export OUTPUT=caudate

   export TIME=$SUBJECT_DATA_DIR/time

   #running mrtm1 analysis:
  
   mri_glmfit --y $MRTM/$OUTPUT/gtm${i}.nii --mrtm1  $MRTM/$OUTPUT/km.ref.tac${i}.dat $MRTM/$OUTPUT/frame.time${i}.dat --o $MRTM/mrtm1_${i} --no-est-fwhm --nii.gz


fi
done
done
Dima Tisnek
  • 9,367
  • 4
  • 48
  • 106
Maria
  • 1
  • 2
  • Hi, a clearer question will help you get better answers. Is this bash or a different shell? Please show us the code that doesn’t work and relevant debugging info (like where it crashes). It may also help to print the values of variables as you go. – Arya McCarthy Feb 23 '21 at 14:31
  • 1
    Sorry! I edited the question a bit more, hopefully its a bit more clear now! – Maria Feb 23 '21 at 15:48
  • Because we don’t know your mriglmfit script, we can’t tell what the issue is. I’d print out the inputs you’re providing to it, to double-check that you’re giving it what you think you are. – Arya McCarthy Feb 23 '21 at 15:52
  • But for the multiple subjects question—there is a way to check whether an item is present in a list, in bash. That’s how you should check $file. See here: https://stackoverflow.com/questions/3685970/check-if-a-bash-array-contains-a-value – Arya McCarthy Feb 23 '21 at 15:52
  • 2 problems here: 1️⃣ `mri_glmfit` dies with Segmentation fault, it really should not, open a bug report to `freesurfer` project, somewhere at https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferWiki and 2️⃣ it seems as if, possibly, `mri_glmfit` calls `mri_glmfit.bin` with weird command line arguments. – Dima Tisnek Mar 03 '21 at 11:32

0 Answers0