AFNI Message Board

Dear AFNI users-

We are very pleased to announce that the new AFNI Message Board framework is up! Please join us at:

https://discuss.afni.nimh.nih.gov

Existing user accounts have been migrated, so returning users can login by requesting a password reset. New users can create accounts, as well, through a standard account creation process. Please note that these setup emails might initially go to spam folders (esp. for NIH users!), so please check those locations in the beginning.

The current Message Board discussion threads have been migrated to the new framework. The current Message Board will remain visible, but read-only, for a little while.

Sincerely, AFNI HQ

History of AFNI updates  

|
February 18, 2023 02:36AM
Hi,

I usually use 3dcalc to combine several ROIs into one ROI, such as via the following code:

3dcalc \
-a 1.nii \
-b 2.nii \
-c 3.nii \
-expr 'step(a+b+c)' \
-prefix Network.nii

But how can I combine 60, 100, or even 400 ROIs into one ROI using AFNI? Even if that was possible with 3dcalc, and as I understand it is not, writing 400 lines of code is prone to errors. What would be the best way to handle this job in AFNI?

Update one:
I found a nice solution by Peter Molfese, here: [blog.cogneurostats.com]
I tried this out, meaning the following steps:

1. 3dcalc: Create a zero dataset using 3dcalc.
2. 3dTcat: Concatenate the zero dataset with the specific ROIs one wants to combine.
3. 3dTstat: Assign number to the single ROIs
4. 3dcalc: Transform the dataset into a byte type.

Even though this works, thanks to the tutorial by Peter Molfese, I am happy to hear general comments or advice. For example, is there an even faster or better way to do this? Or would this be the way to go? Thanks.

Update two:
Another specific question came up. I am not sure if this question is really related to AFNI, or more to shell scripting. But I believe it is related to AFNI, let me explain. I am using z shell (zsh) on a Mac.

Think of 100 .nii ROI files stored in one folder, such as 1.nii, 2.nii, 3.nii, and so on. Now I would like to combine them using 3dTcat, as suggested by Peter Molfese.
Here is the relevant part of the code that works just fine.

# Concatenate zero dataset with rois
3dTcat \
-prefix Temp \
Zero_dataset+tlrc \
$directory_rois/{1..100}.nii

The code above combines ROIs 1 to 100 into a new output, called "Temp".

Now, imagine that I want to combine ROIs 1 to 100 together with ROIs 150 to 300. It is possible to build arrays in zsh, such as via:
array=({1..100}.nii {150..300}.nii)

I tried include the variable "array" into the AFNI code above as follows:

# Concatenate zero dataset with rois
3dTcat \
-prefix Temp \
Zero_dataset+tlrc \
$directory_rois/$array

That does not work and produces the following error message:
** FATAL ERROR: Can't open dataset 2.nii

I already tried many alternatives to include the variable’s array into 3dTcat, which I won't include here in order to prevent making this post too messy and complicated, but AFNI always fails with different errors. It always works fine when using only one brace expansion, such as {1..100}. The problem with AFNI appears once I start using two, such as {1..100} {150..300}. The code

echo  {1..100} {101..300}

prints all numbers from 1 to 300 in zsh, meaning it works fine from the perspective of the z shell.

Is there a way to define a specific array as variable (as shown above), and to then include this array into 3dTcat? Phrased differently: can I somehow combine many ROIs together that do not correspond to a continous list?



Edited 3 time(s). Last edit at 02/18/2023 08:09AM by Philipp.
Subject Author Posted

How to combine many ROIs (+60) into one ROI?

Philipp February 18, 2023 02:36AM

Re: How to combine many ROIs (+60) into one ROI?

rick reynolds February 18, 2023 09:43AM

Re: How to combine many ROIs (+60) into one ROI?

Philipp February 18, 2023 10:06AM

Re: How to combine many ROIs (+60) into one ROI?

Daniel Glen February 21, 2023 11:53AM