Extracting CLUT from .annot Files Using R
freesurferformats
There are at least two R packages written to work with FreeSurfer files. The freesurferformats package has utilities to pull the CLUT from a .annot file
Installing freesurferformats
In R:
install.packages('freesurferformats', dependencies=TRUE)
Reading .annot files
With the package installed, you can now read .annot file information:
library('freesurferformats') annotfile='lh.aparc.annot' annot=read.fs.annot(annotfile) colortable=colortable.from.annot(annot)
Scripting
You can run an R script from the terminal using the Rscript shell interpreter by beginning your script with the following:
#!/usr/local/bin/Rscript
Write the rest of your script using normal R syntax. Save it with a .R extension and make it executable and you can run it from the terminal. You can even pass parameters:
#!/usr/local/bin/Rscript args = commandArgs(trailingOnly=TRUE) print(args[1]) #this prints the first argument
clutteR.R
I learned all this this morning, and wrote an R script to extract the CLUT from a .annot file. The script, clutteR.R can be found in the /ubfs/Scripts/R folder. Run it as follows:
./clutteR.R annot-file [outfile]
For example:
./clutteR.R lh.aparc.a2009s.annot lh.a2009s-CLUT.txt
If an outfile is not specified, the outputfile will be the name of the input file with -CLUT.txt appended to it.