0

I am trying to run a bash script for rescaling fMRI data using AFNI's 3dcalc.

One of the arguments for this function is "expr" which will "Apply the expression - within quotes - to the input datasets (dnames), one voxel at time, to produce the output dataset". When trying to launch this job, I am met with a syntax error as follows:

-bash: -c: line 0: syntax error near unexpected token `('
-bash: -c: line 0: `apptainer run --cleanenv /Users/user44/fMRI/my_images/afni-binaries.sif 3dcalc -a /Users/user44/fMRI/PPMI/derivatives/afni_blur/sub-3102/sub-3102+tlrc.BRIK -b /Users/user44/fMRI/PPMI/derivatives/afni_scale/sub-3102/sub-3102_desc-scalestats+tlrc.BRIK -c /Users/user44/fMRI/PPMI/derivatives/fmriprep/sub-3102/func/sub-3102_task-rest_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz -expr c*min(200,a/b*100)*step(a)*step(b) -prefix /Users/user44/fMRI/PPMI/derivatives/afni_scale/sub-3102/sub-3102_task-rest_space-MNI152NLin2009cAsym_desc-preprocScaled_bold.nii '

My bash script is attached here:

#!/bin/bash

for fn in /Users/user44/fMRI/PPMI/derivatives/fmriprep/sub*/; do
    id=$(echo $fn | cut -d '/' -f 8)
    qsub -b y -q $QUEUE_NAME -pe orte 8 -l h_vmem=8G -N $id apptainer run --cleanenv ~/fMRI/my_images/afni-binaries.sif 3dcalc \
        -a ~/fMRI/PPMI/derivatives/afni_blur/${id}/${id}+tlrc.BRIK \
        -b ~/fMRI/PPMI/derivatives/afni_scale/${id}/${id}_desc-scalestats+tlrc.BRIK \
        -c ~/fMRI/PPMI/derivatives/fmriprep/${id}/func/${id}_task-rest_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz \
        -expr "c*min(200,a/b*100)*step(a)*step(b)" \
        -prefix ~/fMRI/PPMI/derivatives/afni_scale/${id}/${id}_task-rest_space-MNI152NLin2009cAsym_desc-preprocScaled_bold.nii
    break
done

I have tried replacing the quoted expression with various other syntactical representations, but my bash experience is a bit lacking and I haven't been able to figure out quite what the problem is. Attempted solutions included:

-expr "'c*min(200,a/b*100)*step(a)*step(b)'" \
-expr "\'c*min(200,a/b*100)*step(a)*step(b)\'" \
-expr "$('c*min(200,a/b*100)*step(a)*step(b)')" \

I'm sure I'm violating a very simple syntax rule but would appreciate any help identifying said violation!

1

1 Answer 1

1

qsub concatenates all its arguments into a shell command. The shell treats parenthese specially. You need to escape or quote the () characters in the expr.

        -expr "'c*min(200,a/b*100)*step(a)*step(b)'" \
Sign up to request clarification or add additional context in comments.

2 Comments

Why is this necessary? There are no special characters inside which would not be protected by the outside double quotes? Or is this a quirk, necessitated by qsub (which I don't know)?
qsub is simply concatenating all the arguments into a shell command. The shell treats () specially.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.