set: Variable name must contain alphanumeric characters. (SSwarper)

When trying to supply subject name and session to SSWarper as variables, I get the error: set: Variable name must contain alphanumeric characters.

I've tried this with all kinds of variations, e.g., underscores instead of hyphens between ${sub} and ${session}; no characters between the two variables in the -input filename and -subid; ${sub} only; translating my bash script to tcsh in case that's the issue... everything results in:
set: Variable name must contain alphanumeric characters.

#!/bin/bash

# Retrieve subject from the command-line arguments
subject=$1
# Define the sessions to loop over
sessions=("first" "second")

# Base directory where BIDS data is stored
baseDir=/path/to/my/data/bids_data

# Loop over each session
for session in "${sessions[@]}"; do
    # Define paths for the anatomical file and output directory
    anatPath="$baseDir/sub-${subject}/ses-${session}/anat/"
    outDir="/path/to/my/data/preproc/sub-${subject}/ses-${session}"

    # Create the output directory if it doesn't exist
    mkdir -p "$outDir"

    # Check if the anatomical path exists before proceeding
    if [ ! -d "$anatPath" ]; then
        echo "Error: Directory $anatPath does not exist. Skipping..."
        continue
    fi

    # Navigate to the anatomical path
    cd "$anatPath" || exit

    # Check if the T1w image exists before running @SSwarper
    anatFile="sub-${subject}_ses-${session}_T1w.nii.gz"
    if [ ! -f "$anatFile" ]; then
        echo "Error: T1w image $anatFile not found in $anatPath. Skipping..."
        continue
    fi

    # Run @SSwarper for this session using tcsh
    tcsh -c "@SSwarper -input $anatFile -subid sub-${subject}_ses-${session} -odir ${outDir}"
# also tried just:
# @SSwarper -input $anatFile -subid sub-${subject}_ses-${session} -odir ${outDir}

done

A minimal script in tcsh that yields the same error:

#!/bin/tcsh
cd /path/to/my/data/bids_data/sub-1234/ses-first/anat
set subject = 1234
set sessions = first

foreach session ($sessions)
    echo "Running @SSwarper for session $session"
    @SSwarper -input sub-${subject}_ses-${session}_T1w.nii.gz -subid sub-${subject}_ses-${session} 
end

Or via command line:

@SSwarper -input sub1234firstT1w.nii.gz -subid 1234
++ Starting: @SSwarper v2.33
++ Default OMP_NUM_THREADS is 96

++ Based on input, the output directory will be:
     .

set: Variable name must contain alphanumeric characters.

This is driving me crazy; I can't figure out what the issue is.

afni version is 21.0.02

...and of course I figure it out shortly after posting: it needed -base first.

@SSwarper -base MNI152_2009_template_SSW.nii.gz -input $anatFile -subid sub-${subject}_ses-${session} -odir ${outDir}"

OK, the program should have provided a better error message about missing the base, sorry about that confusion.

But note that even though @SSwarper is a tcsh script, you don't need to run it from an explicit tcsh environment. So, in line 37 of your initial script, you can just have:

@SSwarper -input $anatFile -subid sub-${subject}_ses-${session} -odir ${outDir} -base BASE_NAME

Also, there is now sswarper, that is an update to the original @SSwarper---it does the same job with almost all the same options, just a little improved in some cases.

--pt

1 Like

Oh, well, actually, I see you must have a pretty old version of AFNI---more recent @SSwarper versions do explicitly check for whether -base .. has been used and will give you a more detailed error message about that if you haven't. Based on the version number of that program, your AFNI is probably 4 years old or so.

It would probably be a good idea to update your local AFNI. There have been many improvements to @SSwarper in that time, as well as the recent sswarper2 and to a lot of other AFNI functionality.

--pt

1 Like

Thank you so much @ptaylor. Yes, I realized that my HPC cluster has a 24.x version in a different package directory so switched over to that. Will try out sswarper2 also!

Cool, here the OHBM poster about sswarper2, in case that is useful:

--pt

1 Like