AFNI scaling headache

Hi everyone,

I am trying to run a simple script within AFNI to smooth and then scale the images that was based off Andy’s brain book.

https://andysbrainbook.readthedocs.io/en/latest/OpenScience/OS/fMRIPrep_Demo_6_GroupAnalysis.html

I have run this very simple command so many times, but I keep getting errors. It seems to be unhappy with my 3dcalc command.

This appears to be the offending script…

3dcalc -a sub-${id}_run-${run}blur.nii   \
                                -b rm.mean_run-${run}.nii  \
                                -c ${m} -expr 'c * min(200, a/b*100)*step(a)*step(b)'     \
                                 -prefix sub_${id}run_${run}_scale.nii;

When I run this I get the following error…

** FATAL ERROR: Extra command line arguments puzzle me! argv[9]=CPT_01 …

When I run this…

> 3dcalc -a sub-${id}_run-${run}blur.nii   \
>                                 -b rm.mean_run-${run}.nii  \
>                                 -c ${m}
>                                  -expr 'c * min(200, a/b*100)*step(a)*step(b)'     \
>                                 -prefix sub_${id}run_${run}_scale.nii;

** FATAL ERROR: No expression given!

Then this…

3dcalc -a sub-${id}_run-${run}blur.nii   \
                               -b rm.mean_run-${run}.nii  \
                               -c ${m}      \
                                -expr 'c * min(200, a/b*100)*step(a)*step(b)'     \
                                -prefix sub_${id}run_${run}_scale.nii;

Back to ** FATAL ERROR: Extra command line arguments puzzle me! argv[9]=CPT_01

I have tried to copy what’s in the AFNI help file but keep getting error no matter what I change. Could someone please help?

for file in "${dicomfilename[@]}";do
        session=$(echo "$file" | cut -d \. -f 2| grep -o '..')
        id=$(echo "$file" | cut -d \. -f 1 | grep -o '......$')
        id=${id^^}
        if [ $afni_smooth == "yes" ]; then
                #dir=$fmriprep_output"sub-"$id"/ses-"$session"/func"
                dir=/work/06953/jes6785/ls6/ALMEIDA_LASER/derivatives/afni-v6.0first_level/LSB_103/ses-01/func/
                cd $dir
                outputdir=sub-${id}_${ses}-smooth_scale
                mkdir $outputdir
                cd $outputdir
                mkdir CPT_${session}
                # blur each volume of each run
                for run in 01 02; do
                        f=${dir}sub-LSB103_ses-01_task-rest_dir-AP_run-${run}_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz
                        m=${dir}sub-LSB103_ses-01_task-rest_dir-AP_run-${run}_space-MNI152NLin2009cAsym_desc-brain_mask.nii
                        3dmerge -1blur_fwhm 6.0 -doall -prefix sub-${id}_run-${run}blur.nii ${f};
                        3dTstat -prefix rm.mean_run-${run}.nii sub-${id}_run-${run}blur.nii;
                        3dcalc -a sub-${id}_run-${run}blur.nii   \
                                -b rm.mean_run-${run}.nii  \
                                -c ${m} -expr 'c * min(200, a/b*100)*step(a)*step(b)'     \
                                 -prefix sub_${id}run_${run}_scale.nii;
                done
        fi
done

Hi,

Can you confirm that there are no spaces in ${m}, ${run}, or ${id}? Have you tried surrounding the arguments in quotes or apostrophes?

Best,
Steven

If you run that bash script with a -x option, then you will see what is happening according to the shell interpreter; from the bash help:

-x Print commands and their arguments as they are executed.

That will help clarify what those values are. So, try running it as:

bash -x SCRIPT_NAME.bash

… and see what happens.

You can capture the output streams and save them in a log file in a couple ways, depending on whether the shell you execute the script from is bash/zsh or tcsh/csh. (And you can see what your shell currently is by running echo $0, and seeing the name of a shell pop out—ignore any minus sign character, that would just provide extra information that you are still in the login shell.)

If your terminal uses bash/zsh, then:

bash -x SCRIPT_NAME.bash 2>&1 | tee log.cmd.txt

If your terminal uses tcsh/csh, then:

bash -x SCRIPT_NAME.bash |& tee log.cmd.txt

–pt

Oh my goodness, thank you so much! for some reason, moving the spaces in the formula seemed to resolve the problem! Thanks for the advice with bash -x. Here is the final correct version…
3

dcalc -a sub-${id}_run-${run}blur.nii   \
                               -b rm.mean_run-${run}.nii  \
                               -c ${m}      \
                                -expr 'c*min(200,a/b*100)*step(a)*step(b)'     \
                                -prefix sub_${id}run_${run}_scale.nii;

It’s good that your program is working now. I am not sure what exactly what wrong, but I would like to note that having spaces in the expression string is allowed—I just range the following, which has the same expression as your initial command, and it worked OK:

3dcalc                                            \
    -a DSET1                                      \
    -b DSET2                                      \
    -c DSET3                                      \
    -expr 'c * min(200, a/b*100)*step(a)*step(b)' \
    -prefix DSET_OUT

-pt

… and I also notice that the second command you showed above, which had the error message “** FATAL ERROR: No expression given!”, was missing a continuation of line character at the end of its third line (the one starting -c ...), so the shell never saw the full command—hence that error.