Difference between revisions of "ReadAgilent.R"

From Organic Design wiki
(new article)
 
Line 1: Line 1:
library(limma)
+
readAgilent <- function(dataDir="/Volumes/HD2/Data/Nutrigenomics/MultipleScans/Agilent"){
 
+
  require(limma)
# 0) Set up directories
 
auxillaryDir <- "/Volumes/HD2/Data/Nutrigenomics/MultipleScans/Auxillary"
 
dataDir     <- "/Volumes/HD2/Data/Nutrigenomics/MultipleScans/Agilent"
 
plotDir      <- "AgilentDiagnosticImages"
 
 
 
 
# 1) Read in data using limma
 
# 1) Read in data using limma
targets <- readTargets(dir(auxillaryDir, pattern="Agilent"), path=auxillaryDir)
+
  if(exists("targets", inherits=FALSE)) {
RGsub <- read.maimages(targets$Filename, path = dataDir, source="agilent", name=targets$Filetype)
+
    RGsub <- read.maimages(targets$Filename, path = dataDir, source="agilent", name=targets$Filetype)
 
+
  } else {
 +
    RGsub <- read.maimages(dir(dataDir, pattern=".txt"), path = dataDir, source="agilent")
 +
  }
 
# 2) Find Agilent indices from x ,y coords
 
# 2) Find Agilent indices from x ,y coords
 
getInd <- function(x,y, nx, byrow=T) {
 
getInd <- function(x,y, nx, byrow=T) {
Line 15: Line 12:
 
}
 
}
  
ind <- getInd(RGsub$genes$Row, RGsub$genes$Col, nx=215)
+
  ind <- getInd(RGsub$genes$Row, RGsub$genes$Col, nx=215)
length(ind)
 
max(ind)
 
 
 
oldind <- as.numeric(rownames(RGsub$genes))
 
length(oldind)
 
max(oldind)
 
  
 
# 3) Construct complete RGList
 
# 3) Construct complete RGList
RGfull <- new("RGList")
+
  RGfull <- new("RGList")
RGfull$R <-RGfull$G <-RGfull$Rb <-RGfull$Gb <- matrix(NA, nc=ncol(RGsub), nr=max(ind))
+
  RGfull$R <-RGfull$G <-RGfull$Rb <-RGfull$Gb <- matrix(NA, nc=ncol(RGsub), nr=max(ind))
RGfull$genes <- data.frame(matrix(NA, nc=7, nr=max(ind), dimnames = list(NULL, names(RGsub$genes))))
+
  RGfull$genes <- data.frame(matrix(NA, nc=7, nr=max(ind), dimnames = list(NULL, names(RGsub$genes))))
  
matrixNames <- dimnames(RGsub$R)
+
  matrixNames <- dimnames(RGsub$R)
  
 
# 4) Populate complete list
 
# 4) Populate complete list
RGfull$R[ind,]    <- RGsub$R
+
  RGfull$R[ind,]    <- RGsub$R
RGfull$Rb[ind,]    <- RGsub$Rb
+
  RGfull$Rb[ind,]    <- RGsub$Rb
RGfull$G[ind,]    <- RGsub$G
+
  RGfull$G[ind,]    <- RGsub$G
RGfull$Gb[ind,]    <- RGsub$Gb
+
  RGfull$Gb[ind,]    <- RGsub$Gb
RGfull$genes[ind,] <- RGsub$genes
+
  RGfull$genes[ind,] <- RGsub$genes
RGfull$targets <- RGsub$targets
+
  RGfull$targets <- RGsub$targets
 
+
 
dimnames(RGfull$R) <- dimnames(RGfull$Rb) <- dimnames(RGfull$G) <- dimnames(RGfull$Gb) <- matrixNames
+
  dimnames(RGfull$R) <- dimnames(RGfull$Rb) <- dimnames(RGfull$G) <- dimnames(RGfull$Gb) <- matrixNames
  
 
# Checking the rows that needed padding
 
# Checking the rows that needed padding
rowstopad <- as.numeric(rownames(RGsub$genes) [ !(rownames(RGsub$genes) %in% ind) ])
+
  rowstopad <- as.numeric(rownames(RGsub$genes) [ !(rownames(RGsub$genes) %in% ind) ])
rowstopad
+
  rowstopad
  
 
# Indexing looks ok
 
# Indexing looks ok
RGfull[rowstopad,]
+
  RGfull[rowstopad,]
  
RGfull$printer <- structure(list(ngrid.r=1, ngrid.c=1, nspot.r=105, nspot.c=215), class = "PrintLayout")
+
  RGfull$printer <- structure(list(ngrid.r=1, ngrid.c=1, nspot.r=105, nspot.c=215), class = "PrintLayout")
rm(RGsub)
+
  rm(RGsub)
 +
  return(RGfull)
 +
}

Revision as of 03:30, 23 February 2006

readAgilent <- function(dataDir="/Volumes/HD2/Data/Nutrigenomics/MultipleScans/Agilent"){

 require(limma)
  1. 1) Read in data using limma
 if(exists("targets", inherits=FALSE)) {
   RGsub <- read.maimages(targets$Filename, path = dataDir, source="agilent", name=targets$Filetype)
 } else {
   RGsub <- read.maimages(dir(dataDir, pattern=".txt"), path = dataDir, source="agilent")
 }
  1. 2) Find Agilent indices from x ,y coords

getInd <- function(x,y, nx, byrow=T) {

 return( (x-1)* nx + y)

}

 ind <- getInd(RGsub$genes$Row, RGsub$genes$Col, nx=215)
  1. 3) Construct complete RGList
 RGfull <- new("RGList")
 RGfull$R <-RGfull$G <-RGfull$Rb <-RGfull$Gb <- matrix(NA, nc=ncol(RGsub), nr=max(ind))
 RGfull$genes <- data.frame(matrix(NA, nc=7, nr=max(ind), dimnames = list(NULL, names(RGsub$genes))))
 matrixNames <- dimnames(RGsub$R)
  1. 4) Populate complete list
 RGfull$R[ind,]     <- RGsub$R
 RGfull$Rb[ind,]    <- RGsub$Rb
 RGfull$G[ind,]     <- RGsub$G
 RGfull$Gb[ind,]    <- RGsub$Gb
 RGfull$genes[ind,] <- RGsub$genes
 RGfull$targets <- RGsub$targets
 
 dimnames(RGfull$R) <- dimnames(RGfull$Rb) <- dimnames(RGfull$G) <- dimnames(RGfull$Gb) <- matrixNames
  1. Checking the rows that needed padding
 rowstopad <- as.numeric(rownames(RGsub$genes) [ !(rownames(RGsub$genes) %in% ind) ])
 rowstopad
  1. Indexing looks ok
 RGfull[rowstopad,]
 RGfull$printer <- structure(list(ngrid.r=1, ngrid.c=1, nspot.r=105, nspot.c=215), class = "PrintLayout")
 rm(RGsub)
 return(RGfull)

}