Making single ROI files from atlas

Hello! I'm trying to make a separate file for each ROI in the Destrieux atlas. I began by using the following script for the first ROI, typing it directly into my Terminal:

3dcalc -a aparc.a2009s_aseg_REN_all.nii.gz'<1>' -expr 'step(a)' -prefix Destrieux_ROI1_test.nii.gz

This worked, and the Terminal output was:

++ 3dcalc: AFNI version=AFNI_24.2.07 (Sep 18 2024) [64-bit]
++ Authored by: A cast of thousands
++ Output dataset ./Destrieux_ROI1_test.nii.gz

I then wrote a script to loop through all the ROIs (in this case starting with 2 as a trial):

!/bin/bash

for i in $(seq 1 2)
  do
    3dcalc -a "aparc.a2009s_aseg_REN_all.nii.gz'<$i>'" -expr 'step(a)' -prefix "Destrieux_ROI_"$i".nii.gz"
  done

This failed with the following output:

++ 3dcalc: AFNI version=AFNI_24.2.07 (Sep 18 2024) [64-bit]
++ Authored by: A cast of thousands
** FATAL ERROR: can't open dataset aparc.a2009s_aseg_REN_all.nii.gz'<1>'
** Program compile date = Sep 18 2024
++ 3dcalc: AFNI version=AFNI_24.2.07 (Sep 18 2024) [64-bit]
++ Authored by: A cast of thousands
** FATAL ERROR: can't open dataset aparc.a2009s_aseg_REN_all.nii.gz'<2>'
** Program compile date = Sep 18 2024

I'm wondering why it says it can't open dataset aparc.a2009s_aseg_REN_all.nii.gz'<1>' when that is what was typed directly into the Terminal (same directory) in the single test that worked?

Those single quotes should be processed by the shell and not seen by the AFNI program. In the looping case, get rid of the single quotes and just use the double quotes. Also, for the -prefix, the double quote separation around $i should not be needed, i.e. try:

3dcalc -a "aparc.a2009s_aseg_REN_all.nii.gz<$i>" -expr 'step(a)' -prefix "Destrieux_ROI_$i.nii.gz"

-rick

That worked, thank you!

Howdy-

Also, I notice your file is aparc.a2009s_aseg_REN_all.nii.gz, but the actual file created by @SUMA_Make_Spec_FS is aparc.a2009s+aseg_REN_all.nii.gz. That is, note where the "+" is in the latter, but not the former.

I guess since your code worked in the end with Rick's suggestion, you must have copied/renamed the file or something?

--pt

Yes, I renamed the file when I was testing whether the + was another character that I needed to escape. Thanks for pointing this out, especially for anyone who searches this topic in the future!