library(aroma.affymetrix)
#Note need to rename the CDF file from affymetrix ( replace a . with ,)
cdf <- AffymetrixCdfFile$byChipType("GenomeWideSNP_6",tags="Full")
#Checking to see if the UFL and UGP files can be loaded
gi <- getGenomeInformation(cdf)
print(gi)
si <- getSnpInformation(cdf)
print(si)

out.dir <- "Results/CUP"

#Setting up the CEL files

cs <- AffymetrixCelSet$byName("CUP", cdf=cdf)
print(cs)

#Allelic cross talk calibration
acc <- AllelicCrosstalkCalibration(cs) 
print(acc)
csC <- process(acc)

print(csC)

#Summarization 
plm <- AvgCnPlm(csC, mergeStrands=TRUE, combineAlleles=TRUE, shift=+300)
print(plm)
fit(plm)

#Estimate the chip effect
ces <- getChipEffectSet(plm)
print(ces)

#PCR fragment length normalization

fln <- FragmentLengthNormalization(ces)
print(fln)
cesN <- process(fln) 
print(cesN)


#cdf <- getCdf(cesN)
gi <- getGenomeInformation(cdf)
print(gi)


all.data <- NULL

for( chr in 1:24)
{
	units <- getUnitsOnChromosome(gi,chromosome=chr);
	pos <- getPositions(gi,units = units)
	unitNames <- getUnitNames(cdf,units = units)
	theta <- extractMatrix(cesN,units = units)
	#theta <- extractMatrix(ces,units = units)
	rownames(theta) <- unitNames
	all.data <- rbind(all.data,theta)
}



fname <-paste(out.dir,"/aroma_normalized_data.rdata",sep="")
save(all.data,file=fname)
