MicroArray.r

### Micro array methods
#

## General paths  *** CHANGE ACCORDING TO NEEDS ***
dataroot=file.path('E:','ProjectData'); # Main data directory (for use in process_arrays.r)
projroot=file.path('D:','Projects'); # Main project directory (for use in process_arrays.r)
rprogroot=file.path(projroot,'_Appl_','_R_'); # R script directory (for importing R scripts)

## General methods

# Log message immediately
log.message=function(...) {
	message(paste(...,sep=""));
	flush.console();
}

# String and file path building
pasteall=function(...,sep="") paste(...,sep=sep,collapse=sep);
pastename=function(...,sep="_") paste(...,sep=sep,collapse=sep);
file.tag.path=function(...,dir=NULL) pasteall(c(dir,pasteall(c(...),sep='_')),sep=.Platform$file.sep);

# Construct path and create it if it doesn't exist
ensure.path=function(...) {
  path=file.path(...);
  if (!file.exists(path)) {
    log.message("Creating path: ",path);
    dir.create(path,recursive=TRUE);
  }
  return(path);
}

## matrix.mean(mat,index,group): compute mean of mat by group, where index is 1=row or 2=column
matrix.mean=function(mat,index,group) apply(mat,index,function(x) tapply(x,group,function(t) mean(t,na.rm=TRUE)));
matrix.column.mean=function(mat,group) matrix.mean(mat,1,group);
matrix.row.mean=function(mat,group) matrix.mean(mat,2,group);

## Set dataset name and subset selection
SubsetSelection=function(name='main',subdir=NULL,tags=NULL) {
  dataname<<-name;
  exportdir<<-paste(exportroot,subdir,sep=.Platform$file.sep);
  taglist<<-tags;
}

## Include source files
source(file.path(rprogroot,"MicroArrayReader.r"));
source(file.path(rprogroot,"MicroArrayData.r"));
source(file.path(rprogroot,"MicroArrayAggregate.r"));
source(file.path(rprogroot,"MicroArrayNormalize.r"));
Last modified March 06, 2014.