History of AFNI updates  

|
January 15, 2021 11:45AM
The main command you want to calculate the average value of an INPUT_DSET within a MASK_DSET is:
3dmaskave -mask MASK_DSET INPUT_DSET

You are asking for larger scripting advice. I will take your example things literally (spacing, names, etc.)---even though you mentioned a CSV, your text file did *not* contain commas to separate values in a row, so neither did my example. I made this text file:
Subj Group InputFile
subj0046 patient subj.0046.nii
subj0047 patient subj.0047.nii
subj0048 patient subj.0048.nii
subj0049 control subj.0049.nii

I also made example/test 3D volumes with those names:
3dcalc -a jRandomDataset:5,5,5,1 -expr 'a' -prefix subj.0046.nii
etc. I also made a mask file to match:
3dcalc -a jRandomDataset:5,5,5,1 -expr '1' -prefix subj.MASK.nii
NB: *These* are not real datasets you would want to use (they are tiny 3D volumes with random numbers and a "full" mask), I just wanted some placeholders to be able to run a test script (below).

I then made+ran the following script:
#!/bin/tcsh

# just names of things
set file_old  = "file.txt"         # exists
set file_new  = "file_NEW.txt"     # new one to be created

set dset_mask = subj.MASK.nii

set nlines = `cat ${file_old} | wc -l`

# we assume that line 1 is a "header", so just copy it:
set line = `sed -n 1p "${file_old}"`
echo "${line} AVE" > "${file_new}"

foreach i ( `seq 2 1 ${nlines}` )

    set line = `sed -n ${i}p "${file_old}"`

    set dset = ${line[3]}

    set ave  = `3dmaskave -quiet -mask ${dset_mask} ${dset}`

    echo "${line} ${ave}" >> "${file_new}"
end

... by which this was created:
Subj Group InputFile AVE
subj0046 patient subj.0046.nii 0.126604
subj0047 patient subj.0047.nii -0.0212304
subj0048 patient subj.0048.nii 0.0762452
subj0049 control subj.0049.nii 0.0418862

Is that what you want? (This all depends on your mask being accurate, etc.)

--pt
Subject Author Posted

extract mean value of cluster

keke January 14, 2021 09:15AM

Re: extract mean value of cluster

ptaylor January 14, 2021 11:53AM

Re: extract mean value of cluster

keke January 15, 2021 06:02AM

Re: extract mean value of cluster

ptaylor January 15, 2021 11:45AM

Re: extract mean value of cluster

Daniel Glen January 15, 2021 02:06PM