Skip to content

Instantly share code, notes, and snippets.

@czarrar
Last active August 29, 2015 14:16
Show Gist options
  • Save czarrar/49d9464b47323871998d to your computer and use it in GitHub Desktop.
Save czarrar/49d9464b47323871998d to your computer and use it in GitHub Desktop.
These are the steps to use the rparcellate scripts for spatially constrained parcellation of the brain.
# This script assumes that you have https://github.com/czarrar/rparcellate
# 1. Make sure to create a group mask (in some standard space)
# -- I would recommend using `fslmaths -Tstd -bin` or `fslmaths -Tmin -bin`
# -- Then make sure to mask your group mask by `rparcellate/rois/ho_maxprob25.nii.gz`. This is a special grey-matter mask.
# read in your group mask
suppressMessages(library(niftir))
mask_file <- "/path/to/group_mask.nii.gz"
grp_mask <- read.mask(mask_file)
# 2. Run the group-pca (Smith et al., 2014),
# which means you temporally concatenate your subject data and
# then reduce the dimensions (reduce the number of time-points) with PCA
# except with a memory efficient procedure that does the temporal concatenation and PCA in iterations (see Smith et al., 2014)
# Concatenate files and apply data reduction using the MIGP
# func_files => vector with list of your functional file paths (all in some standard space)
# grp_mask => vector with your group mask
source("/path/to/rparcellate/command/lib/temporal_concatenation.R")
func_migp <- migp_files(func_files, grp_mask, scale=TRUE)
# Save the file
hdr <- read.nifti.header(func_files[1])
write.nifti(t(func_migp), hdr, grp_mask, outfile="/path/to/group_migp_output.nii.gz", overwrite=T) # overwrite=T will overwrite output
# 3. Runs the parcellation scheme on the group-pca output data
source("/path/to/rparcellate/command/lib/region_growing.R")
# Masks for each hemisphere
prior_file <- "/path/to/rparcellate/rois/ho_maxprob25.nii.gz"
# Paths to the data
func_file <- "/path/to/group_migp_output.nii.gz"
mask_file <- "/path/to/group_mask.nii.gz"
# Parcellate
cat("Parcellate\n")
outdir <- "/path/to/output_directory"
if (file.exists(outdir)) system(sprintf("rm -r %s", outdir)) # removes output if exists
if (!file.exists(outdir)) dir.create(outdir) # creates output
parcels <- region_growing_wrapper(func_file, mask_file, prior_file, outdir=outdir, roi.scale=10000)
## look in your output directory for parcels_relabel.nii.gz.
## note: this script will calculate the spatially constrained parcellations separately
## within the left and right hemispheres separately for the cortex, subcortical, and cerebellum (all separately)
## these anatomical divisions are all based on the harvard-oxford anatomical atlas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment