Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
# load the RMINC library
library(RMINC)

# load the mapping of your input files and in this case genotype
# the aim of this example is to test the variance of the Jacobian determinants between wild types and mutants
gf <- read.csv("filenames_and_genotype.csv")

# Figure out how your function works on your data. For example test
# it on a single voxel:
voxel <- mincGetVoxel(gf$jacobians, 0,0,0)

# Run the function you want to use
# the "car" library provides "leveneTest"
library(car)
leveneTest(voxel, gf$Strain, center=mean)

# the output looks like this:
Levene's Test for Homogeneity of Variance (center = mean)
      Df F value Pr(>F)
group  2  1.5514 0.2188
      74               

# in this example we will extract the F value, and the 
# p value which can be done as so:
leveneTest(voxel, gf$Strain, center=mean)[1,2]
leveneTest(voxel, gf$Strain, center=mean)[1,3]
# also it's smart to encapsulate the return value by
# as.numeric to make sure it's returned as a number

# write a function that will be passed on to pMincApply. This
# function will directly refer to variables in the gf object
# this function will return the F-value and p value from the Levene's Test
# which comes from row 1, column 2 (as a numeric value) and column 3
leveneTestForRMINC <- function(x) {
  fout <- as.numeric(leveneTest(x, gf$Strain, center=mean)[1,2])
  pout <- as.numeric(leveneTest(x, gf$Strain, center=mean)[1,3])
 return(c(fout, pout))
}

###########################################################################################
#################                      SNOWFALL                       #####################
###########################################################################################

# loadUse snowfall
library(snowfall)

# initialize and indicate how many processors (workers) you want to use
sfInit(parallel=TRUE, cpus=8)

# indicate which libraries are necessary in the calculations that will be run with snowfall
sfLibrary(car)

# define variables and outside functions that are needed
sfExport('gf', 'leveneTestForRMINC')

# run command, the the "global" argument to specify all variables and functions you need
# Use the "packages" argument to specify all libraries
# The mask will restrict the calculations to that area
outLeveneTest <- pMincApply(gf$jacobians, quote(leveneTestForRMINC(x)),  mask="mask.mnc", workers=8, global=c("gf","leveneTest"), packages="car")

# write your stats out to file
mincWriteVolume(outLeveneTest, "f_values.mnc", 1)
mincWriteVolume(outLeveneTest, "p_values.mnc", 2)

###########################################################################################
#################                       SGE                           #####################
###########################################################################################

# instead of running the pMincApply in parallel on your machine, you can also use sge:
#
where snowfall used sfLibrary to attach the necessary libraries, now use the "packages" argument
# and use the "global" argument to list objects and functions similar to sfExport

outLeveneTest <- pMincApply(gf$jacobians, quote(leveneTestForRMINC(x)), mask="mask.mnc", workers=8, method="sge", global=c("gf","leveneTest"), packages="car", method="sge")

 

Installation

Installing RMINC from a release:

...