Hi all,
I've written a function that reads *.fsaverage.mgh files into the free statistical software environment "R" (http://www.r-project.org/) and thought it might be useful for other users. Apologies if this has already been done, searching for "R" is kind of non-specific. Any feedback is welcome.
Best wishes, Heath
Example usage (if you save the function as a text file called load_mgh.R). The output is a list with the thickness values stored in output.name$x
source("load_mgh.R") lh.thickness <- load.mgh("lh.thickness.fwhm10.fsaverage.mgh") lh.thickness$x[1:10]
[1] 3.0016668 2.9998362 2.4326897 2.2146511 3.3020024 2.2749729 2.6460392 [8] 2.9406335 0.7304581 3.0975394
--------------------------------------------------------------------------- # load mgh file into R
load.mgh <- function(input.file) { to.read <- file(input.file,"rb")
v <- readBin(to.read,integer(), endian = "big") ndim1 <- readBin(to.read,integer(), endian = "big") ndim2 <- readBin(to.read,integer(), endian = "big") ndim3 <- readBin(to.read,integer(), endian = "big") nframes <- readBin(to.read,integer(), endian = "big") type <- readBin(to.read,integer(), endian = "big") dof <- readBin(to.read,integer(), endian = "big") close(to.read)
to.read <- file(input.file,"rb") dump <- readBin(to.read,double(),size = 4,n = 71, endian = "big") x <- readBin(to.read,double(),size = 4, n = ndim1, endian = "big") close(to.read) list(x = x,v = v,ndim1 = ndim1,ndim2 = ndim2,ndim3 = ndim3,nframes = nframes,type = type,dof = dof)
} ------------------------------------------------------------------------------
thanks Heath,
we'll include it in our distribution if that's alright with you. I'm sure people will find it useful
cheers Bruce On Thu, 5 May 2011, Heath Pardoe wrote:
Hi all,
I've written a function that reads *.fsaverage.mgh files into the free statistical software environment "R" (http://www.r-project.org/) and thought it might be useful for other users. Apologies if this has already been done, searching for "R" is kind of non-specific. Any feedback is welcome.
Best wishes, Heath
Example usage (if you save the function as a text file called load_mgh.R). The output is a list with the thickness values stored in output.name$x
source("load_mgh.R") lh.thickness <- load.mgh("lh.thickness.fwhm10.fsaverage.mgh") lh.thickness$x[1:10]
[1] 3.0016668 2.9998362 2.4326897 2.2146511 3.3020024 2.2749729 2.6460392 [8] 2.9406335 0.7304581 3.0975394
# load mgh file into R
load.mgh <- function(input.file) { to.read <- file(input.file,"rb")
v <- readBin(to.read,integer(), endian = "big") ndim1 <- readBin(to.read,integer(), endian = "big") ndim2 <- readBin(to.read,integer(), endian = "big") ndim3 <- readBin(to.read,integer(), endian = "big") nframes <- readBin(to.read,integer(), endian = "big") type <- readBin(to.read,integer(), endian = "big") dof <- readBin(to.read,integer(), endian = "big") close(to.read)
to.read <- file(input.file,"rb") dump <- readBin(to.read,double(),size = 4,n = 71, endian = "big") x <- readBin(to.read,double(),size = 4, n = ndim1, endian = "big") close(to.read) list(x = x,v = v,ndim1 = ndim1,ndim2 = ndim2,ndim3 = ndim3,nframes = nframes,type = type,dof = dof)
}
freesurfer@nmr.mgh.harvard.edu