Skip to content

Generating the group mask

Zarrar Shehzad edited this page Oct 19, 2016 · 4 revisions

Before running any of the connectir group analyses, you will need to generate a group mask. You can use the --automask1 option with connectir_subdist.R that does this automatically for you. This is a new option so still experimental. Below I suggest another possible approach. Whatever approach you take, the goal is to create a mask where each voxel has a time-series with a non-zero standard-deviation across 100% of the subjects.

AFNI/FSL Approach

I assume that you have a file with the list of your 4D functional files in standard space or can get the list via glob expressions. For now, I imagine a file called func_paths.txt as your input. First, for each subject, we will generate a brain mask that includes voxel with non-zero standard deviation values. Then, we will combine those masks together and take only those voxels present in 100% of the subjects. The commands below should be run in the terminal.

# I/O Paths
funcpaths=( $(cat func_paths.txt) ) # inputs
maskdir=$(pwd)  # output directory for subject masks
maskfile="group_mask.nii.gz" # output file

# Create individual subject brain masks
n=${#funcpaths[@]}
for (( i = 0; i < $n; i++ )); do
    func=${funcpaths[$i]}
    mask="${maskdir}/mask${i}.nii.gz"
    #3dTstat -stdev -prefix ${mask} ${func}
    fslmaths ${func} -Tstd -bin ${mask}
done

# Take the mean of the masks
# (i.e., proportion of subjects with value in each voxel)
3dMean -prefix group_prop_subjs.nii.gz ${maskdir}/mask*.nii.gz
  
# Note: you may also want to concatenate all the subject masks together to view them
# Here's how you could do that (optional!)
fslmerge -t ${maskdir}/subject_masks.nii.gz ${maskdir}/mask*.nii.gz

# Get voxels with all subjects having a value
3dcalc -a group_prop_subjs.nii.gz -expr 'equals(a,1)' -prefix ${mask_file}

# And if you want to mask the group mask further
grey_matter="/path/to/grey_matter_mask.nii.gz"
3dcalc -a ${mask_file} -b ${grey_matter} -expr 'a*step(b)' -prefix /path/to/mask

Things to Think About

Note that I plan on creating an automatic group mask generation script into the different scripts. Stay tuned.