# This is the working back ground correction script
# Author: Sucheta
# Date: 9th Dec 2006
library(affy)
library(gcrma)
# Affinity info need not be calculated all the time, since it is
#mostly preserved with the workspace
#affinfo <- compute.affinities("soybean")
celfile<-read.table("list.txt") # read the elements of list.txt as a list
celfile<-as.matrix(celfile) # convert celfile from a list to a matrix
n<-dim(celfile)[1] # Getting the number of cel files
m <- 18;
dir<-"/home/XXX/cel/"
outdir<-"/home/XXX/bgCorrect/"
print(n);
k <- (m - 2*m)+1;
i<- k;
while( { i = i + m } < n){ # Replace for loop with while loop
print(i);
file <- NULL;
obj <- NULL;
tmp1 <- NULL;
for(j in 0:(m-1)){
tmpFile <- paste(dir, celfile[i+j], sep="");
file <- c(file, list(tmpFile)) # appending a list to the existing list
}
obj<-ReadAffy(filenames=file)
tmp1<-bg.adjust.gcrma(obj,optical.correct=T,affinity.info=affinfo)
outfile<-paste(outdir, celfile[i,1], "_bg.txt", sep="")
write.table(pm(tmp1), file=outfile, row.names=FALSE, col.names=TRUE, sep="\t")
}