Difference between revisions of "ReadAgilent.R"
From Organic Design wiki
(new article) |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | # {{R}} | |
− | + | readAgilent <- function(dataDir="/Volumes/HD2/Data/Nutrigenomics/MultipleScans/Agilent"){ | |
− | # | + | require(limma) |
− | |||
− | dataDir | ||
− | |||
− | |||
# 1) Read in data using limma | # 1) Read in data using limma | ||
− | + | 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 13: | ||
} | } | ||
− | ind <- getInd(RGsub$genes$Row, RGsub$genes$Col, nx=215 | + | ind <- getInd(RGsub$genes$Row, RGsub$genes$Col, nx=215) |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
# 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) | ||
+ | } |
Latest revision as of 00:44, 6 June 2007
Code snipits and programs written in R, S or S-PLUS readAgilent <- function(dataDir="/Volumes/HD2/Data/Nutrigenomics/MultipleScans/Agilent"){
require(limma)
- 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") }
- 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)
- 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)
- 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
- Checking the rows that needed padding
rowstopad <- as.numeric(rownames(RGsub$genes) [ !(rownames(RGsub$genes) %in% ind) ]) rowstopad
- 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)
}