Nothing
#set of functions, directly/indirectly involved, in oneChannelGUI normalizeMenu
#oneChannelGUI NormalizeNow is a modification of the original function of affylmGUI and is used to handle ExpressionSets
#oneChannelGUI showDataset describes the content of the loaded data set present in the filemenu.R
#oneChannelGUI myExpresso is a graphical interphace to the affy expresso function. It works but is very slow
#oneChannelGUI largedatasetNorm this function alows the normalization by variosu methods if unnormalized tab delimited files are loaded
#oneChannelGUI rankingConversion converts intensity signal in normalized ranks
#oneChannelGUI log2Conversion makes a log2 transformation of the counts
#oneChannelGUI refiningPeaks combine nearby NGS peaks if any.
#oneChannelGUI edgeRNorm normalize libraries as describedb by Robinson and Oshlack Genome Biology 2010, 11:R25.
#oneChannelGUI EDASeq GC normalization
# EDAwithinLane GC/length based wtihin lane normalization
# EDAbetweenLane normalization similar to microarrays
################################################################################
################################################################################
#modified from the affylmGUI version to load ExpressionSet in NormalizeAffyData
NormalizeNow <- function(){
# require(preprocessCore) || stop("\npreprocessCore lib is missing!\n")
Try(ArraysLoaded <- get("ArraysLoaded", envir=affylmGUIenvironment))
Try(
if (ArraysLoaded==FALSE){
Try(tkmessageBox(title="Normalization",message="Error: No arrays have been loaded.",icon="error",default="ok"))
return()
}
)
# Require("affy")
Try(RawAffyData <- get("RawAffyData",envir=affylmGUIenvironment))
#
Try(NormalizationMethod <- GetNormalizationMethod())
Try(if (NormalizationMethod=="") return())
#
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="watch"))
Try(tkfocus(.affylmGUIglobals$ttMain))
Try(Targets <- get("Targets",envir=affylmGUIenvironment))
Try(rownames(Targets) <- Targets$FileName)
Try(var.tmp.pd<-data.frame(names(Targets)))
Try(names(var.tmp.pd)<-"labelDescription" )
Try(rownames(var.tmp.pd)<-names(Targets))
Try(tmp1.pd<-new("AnnotatedDataFrame", data=Targets, varMetadata=var.tmp.pd))
Try(
if (NormalizationMethod=="RMA"){
Try(NormalizedAffyDataExpressionSet <- rma(RawAffyData))
#rma returns an ExpressionSet as shown below:
# new("ExpressionSet",
# phenoData = phenoData(object),
# annotation = .annotation(object),
# experimentData = experimentData(object),
# exprs = exprs)
# NormalizedAffyData is an ExpressionSet as from R2.5.0
Try(phenoData(NormalizedAffyDataExpressionSet) <- tmp1.pd)
Try(assign("NormalizedAffyData", NormalizedAffyDataExpressionSet, affylmGUIenvironment))
Try(assign("NormMethod","RMA",affylmGUIenvironment))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
Try(tkfocus(.affylmGUIglobals$ttMain))
}else if (NormalizationMethod=="GCRMA"){
# Require("gcrma")
Try(NormalizedAffyDataExpressionSet <- gcrma(RawAffyData, fast=FALSE))
# gcrma returns an ExpressionSet, using the rma function as shown:
# return(rma(object,subset=subset,background=FALSE,normalize=normalize,verbose=verbose))
# NormalizedAffyData is an ExpressionSet as from R2.5.0
#Just store the exprs values and set se.exprs values to NULL
Try(phenoData(NormalizedAffyDataExpressionSet) <- tmp1.pd)
Try(assign("NormalizedAffyData", NormalizedAffyDataExpressionSet,affylmGUIenvironment))
Try(assign("NormMethod","GCRMA",affylmGUIenvironment))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
Try(tkfocus(.affylmGUIglobals$ttMain))
}
#else{
# Require("affyPLM")
#creating an expressionSet
# Try(rownames(Targets) <- Targets$FileName)
# Try(var.tmp.pd<-data.frame(names(Targets)))
# Try(names(var.tmp.pd)<-"labelDescription" )
# Try(rownames(var.tmp.pd)<-names(Targets))
# Try(tmp1.pd<-new("AnnotatedDataFrame", data=Targets, varMetadata=var.tmp.pd))
# Try(NormalizedAffyDataPset <- fitPLM(RawAffyData))
#affyPLM returns an object of class PLMset.
# Try(NormalizedAffyData.exprs <- coefs(NormalizedAffyDataPset))
# Try(NormalizedAffyData <- new("ExpressionSet", exprs=as.matrix(NormalizedAffyData.exprs), phenoData=tmp1.pd, annotation=""))
# Try(assign("NormMethod","PLM",affylmGUIenvironment))
# }
)
Try(assign("NormalizedAffyData.Available",TRUE,affylmGUIenvironment))
#Try(assign("NormalizedAffyData.exprs","",affylmGUIenvironment))
#Try(assign("NormalizedAffyData.se.exprs","",affylmGUIenvironment))
Try(tkdelete(.affylmGUIglobals$mainTree,"NormalizedAffyData.Status"))
Try(
if(NormalizationMethod=="RMA"){
Try(tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available (RMA)",font=.affylmGUIglobals$affylmGUIfontTree))
}else if(NormalizationMethod=="GCRMA"){
Try(tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available (GCRMA)",font=.affylmGUIglobals$affylmGUIfontTree))
}
#else{
# Try(tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available (PLM)",font=.affylmGUIglobals$affylmGUIfontTree))
#}
)
}#end of NormalizeNow <- function(){
GetNormalizationMethod <- function(){
Try(ttGetNormalizationMethod <- tktoplevel(.affylmGUIglobals$ttMain))
Try(tkwm.deiconify(ttGetNormalizationMethod))
Try(tkgrab.set(ttGetNormalizationMethod))
Try(tkfocus(ttGetNormalizationMethod))
Try(tkwm.title(ttGetNormalizationMethod,"Normalization Method"))
#
Try(tkgrid(tklabel(ttGetNormalizationMethod,text=" ")))
Try(NormalizationMethodTcl <- tclVar("RMA"))
Try(rbRMA <- tkradiobutton(ttGetNormalizationMethod,text="RMA (Robust Multiarray Averaging)",variable=NormalizationMethodTcl,value="RMA",font=.affylmGUIglobals$affylmGUIfont2))
Try(rbGCRMA<-tkradiobutton(ttGetNormalizationMethod,text="GCRMA (Background Adjustment Using Sequence Information)",variable=NormalizationMethodTcl,value="GCRMA",font=.affylmGUIglobals$affylmGUIfont2))
#Try(rbPLM <- tkradiobutton(ttGetNormalizationMethod,text="Robust Probe-level Linear Model",variable=NormalizationMethodTcl,value="RPLM",font=.affylmGUIglobals$affylmGUIfont2))
Try(tkgrid(tklabel(ttGetNormalizationMethod,text=" "),rbRMA))
Try(tkgrid(tklabel(ttGetNormalizationMethod,text=" "),rbGCRMA))
#Try(tkgrid(tklabel(ttGetNormalizationMethod,text=" "),rbPLM))
Try(tkgrid.configure(rbRMA,rbGCRMA,columnspan=2,sticky="w"))
Try(tkgrid(tklabel(ttGetNormalizationMethod,text=" "),tklabel(ttGetNormalizationMethod,text=" ")))
#
Try(ReturnVal <- "")
Try(
onCancel <- function() {
Try(ReturnVal <<- "");
Try(tkgrab.release(ttGetNormalizationMethod));
Try(tkdestroy(ttGetNormalizationMethod));
Try(tkfocus(.affylmGUIglobals$ttMain))
}
)
Try(
onOK <- function() {
Try(ReturnVal <<- tclvalue(NormalizationMethodTcl));
Try(tkgrab.release(ttGetNormalizationMethod));
Try(tkdestroy(ttGetNormalizationMethod));
Try(tkfocus(.affylmGUIglobals$ttMain))
}
)
#
Try(OK.but <- tkbutton(ttGetNormalizationMethod,text="OK",command=onOK,font=.affylmGUIglobals$affylmGUIfont2))
Try(Cancel.but <- tkbutton(ttGetNormalizationMethod,text="Cancel",command=onCancel,font=.affylmGUIglobals$affylmGUIfont2))
#
Try(tkgrid(tklabel(ttGetNormalizationMethod,text=" "),OK.but,Cancel.but,tklabel(ttGetNormalizationMethod,text=" ")))
Try(tkgrid.configure(OK.but,sticky="e"))
Try(tkgrid.configure(Cancel.but,sticky="w"))
Try(tkgrid(tklabel(ttGetNormalizationMethod,text=" ")))
#
Try(tkbind(ttGetNormalizationMethod,"<Destroy>",function() {ReturnVal <- "";Try(tkgrab.release(ttGetNormalizationMethod));Try(tkfocus(.affylmGUIglobals$ttMain));}))
Try(tkbind(OK.but, "<Return>",onOK))
Try(tkbind(Cancel.but, "<Return>",onCancel))
#
Try(tkwait.window(ttGetNormalizationMethod))
#
return (ReturnVal)
}#end of GetNormalizationMethod <- function()
ExportNormalizedExpressionValues <- function(){
Try(limmaDataSetNameText <- get("limmaDataSetNameText",envir=affylmGUIenvironment))
Try(ArraysLoaded <- get("ArraysLoaded",envir=affylmGUIenvironment))
Try(
if (ArraysLoaded==FALSE){
Try(tkmessageBox(title="Export Normalized Expression Values",message="Error: No arrays have been loaded.",icon="error",default="ok"))
return()
}
)
Try(NormalizedAffyData.Available <- get("NormalizedAffyData.Available",envir=affylmGUIenvironment))
Try(
if (NormalizedAffyData.Available==FALSE){
NormalizeNow()
}
)
Try(NormalizedAffyData.Available <- get("NormalizedAffyData.Available",envir=affylmGUIenvironment))
Try(
if (NormalizedAffyData.Available==FALSE){
tkmessageBox(title="Export Normalized Expression Values",message="An error or cancellation occured while trying to normalize the data.")
return()
}
)#end of Try
Try(NormalizedAffyData <- get("NormalizedAffyData",envir=affylmGUIenvironment))
Try(NormalizedAffyData.exprs <- exprs(NormalizedAffyData))
Try(
FileName <- tclvalue(
tkgetSaveFile(
initialfile=paste(
limmaDataSetNameText,
"_exprs.xls",
sep=""),
filetypes="{{Tab-Delimited Text Files} {.txt .xls}} {{All files} *}"
)#end of tkgetSaveFile
)#end of FileName <- tclvalue
)#end of Try
Try(if (!nchar(FileName)) return())
Try(len <- nchar(FileName))
if (len <= 4){
Try(FileName <- paste(FileName,".xls",sep=""))
}else if ((substring(FileName,len-3,len)!=".txt") &&(substring(FileName,len-3,len)!=".xls")){
Try(FileName <- paste(FileName,".xls",sep=""))
}
Try(write.table(NormalizedAffyData.exprs,file=FileName,sep="\t",quote=FALSE,col.names=NA))
}#end of ExportNormalizedExpressionValues <- function()
################################################################################
"myExpresso" <- function(){
# require(tkWidgets) || stop("library tkWidgets could not be found !")
#error if no data are loaded
Try(whichArrayPlatform <- get("whichArrayPlatform",envir=affylmGUIenvironment))
if(whichArrayPlatform ==""){
Try(tkmessageBox(title="Normalization",message="No arrays have been loaded. Please try New or Open from the File menu.",type="ok",icon="error"))
Try(tkfocus(.affylmGUIglobals$ttMain))
Try(return())
}
#########################
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="watch"))
Try( x <- get("RawAffyData",envir=affylmGUIenvironment))
Try(xx<- expresso(x, widget=T))
assign("NormalizedAffyData" , xx, affylmGUIenvironment)
assign("NormalizedAffyData.Available" , TRUE, affylmGUIenvironment)
Try(tkdelete(.affylmGUIglobals$mainTree,"NormalizedAffyData.Status"))
Try(tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available",font=.affylmGUIglobals$affylmGUIfontTree))
Try(tkmessageBox(title="Expresso widget",message=paste("Normalized data are now available for further analysis")))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
}
################################################################################
"largedatasetNorm" <- function(){
# require(affy) || stop("library affy could not be found !")
# require(preprocessCore) || stop("library preprocessCore could not be found !")
#error if no data are loaded
Try(whichArrayPlatform <- get("whichArrayPlatform",envir=affylmGUIenvironment))
if(whichArrayPlatform ==""){
Try(tkmessageBox(title="Normalization",message="No arrays have been loaded. Please try New or Open from the File menu.",type="ok",icon="error"))
Try(tkfocus(.affylmGUIglobals$ttMain))
Try(return())
}
#########################
if(affylmGUIenvironment$NormalizedAffyData.Available){
Try(NormalizedAffyData <- get("NormalizedAffyData", env=affylmGUIenvironment))
} else Try(tkmessageBox(title="Large data set normalization",message="Normalized data are not available.", type="ok", icon="error"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="watch"))
##makning the menu for selecting large data set normalization
Try(ttTabNormMethod <- tktoplevel(.affylmGUIglobals$ttMain))
Try(tkwm.deiconify(ttTabNormMethod))
Try(tkgrab.set(ttTabNormMethod))
Try(tkfocus(ttTabNormMethod))
Try(tkwm.title(ttTabNormMethod,"Normlization method for tab delimited files"))
Try(tkgrid(tklabel(ttTabNormMethod,text=" ")))
Try(ttTabNormMethodTcl <- tclVar("loess"))
Try(rb1 <- tkradiobutton(ttTabNormMethod,text="Cyclic LOESS",variable=ttTabNormMethodTcl,value="loess",font=.affylmGUIglobals$affylmGUIfont2))
Try(rb2<-tkradiobutton(ttTabNormMethod,text="QUANTILE",variable=ttTabNormMethodTcl,value="quantile",font=.affylmGUIglobals$affylmGUIfont2))
Try(rb3<-tkradiobutton(ttTabNormMethod,text="QSPLINE",variable=ttTabNormMethodTcl,value="qspline",font=.affylmGUIglobals$affylmGUIfont2))
Try(tkgrid(tklabel(ttTabNormMethod,text=" "),rb1))
Try(tkgrid(tklabel(ttTabNormMethod,text=" "),rb2))
Try(tkgrid(tklabel(ttTabNormMethod,text=" "),rb3))
Try(tkgrid.configure(rb1,rb2,rb3,columnspan=2,sticky="w"))
Try(tkgrid(tklabel(ttTabNormMethod,text=" "),tklabel(ttTabNormMethod,text=" ")))
Try(ReturnVal <- "")
Try(onCancel <- function() {Try(ReturnVal <<- "");Try(tkgrab.release(ttTabNormMethod));Try(tkdestroy(ttTabNormMethod));Try(tkfocus(.affylmGUIglobals$ttMain))})
Try(onOK <- function() {Try(ReturnVal <<- tclvalue(ttTabNormMethodTcl));Try(tkgrab.release(ttTabNormMethod));Try(tkdestroy(ttTabNormMethod));Try(tkfocus(.affylmGUIglobals$ttMain))})
Try(OK.but <- tkbutton(ttTabNormMethod,text="OK",command=onOK,font=.affylmGUIglobals$affylmGUIfont2))
Try(Cancel.but <- tkbutton(ttTabNormMethod,text="Cancel",command=onCancel,font=.affylmGUIglobals$affylmGUIfont2))
Try(tkgrid(tklabel(ttTabNormMethod,text=" "),OK.but,Cancel.but,tklabel(ttTabNormMethod,text=" ")))
Try(tkgrid.configure(OK.but,sticky="e"))
Try(tkgrid.configure(Cancel.but,sticky="w"))
Try(tkgrid(tklabel(ttTabNormMethod,text=" ")))
Try(tkbind(ttTabNormMethod,"<Destroy>",function() {ReturnVal <- "";Try(tkgrab.release(ttTabNormMethod));Try(tkfocus(.affylmGUIglobals$ttMain));}))
Try(tkbind(OK.but, "<Return>",onOK))
Try(tkbind(Cancel.but, "<Return>",onCancel))
Try(tkwait.window(ttTabNormMethod))
if(ReturnVal==""){
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
return()
} else if(ReturnVal=="loess"){
Try(tmp <- normalize.loess(exprs(NormalizedAffyData)))
Try(dimnames(tmp)[[2]] <- sampleNames(NormalizedAffyData))
Try(dimnames(tmp)[[1]] <- featureNames(NormalizedAffyData))
Try(exprs(NormalizedAffyData) <- tmp)
Try(assign("NormalizedAffyData", NormalizedAffyData, env=affylmGUIenvironment))
tkdelete(.affylmGUIglobals$mainTree,"NormalizedAffyData.Status")
tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available Loess",font=.affylmGUIglobals$affylmGUIfontTree)
Try(tkmessageBox(title="Large data set normalization",message="Loess normalized data are now available in NormalizedAffyData.", type="ok"))
} else if(ReturnVal=="quantile"){
Try(tmp <- normalize.quantiles(exprs(NormalizedAffyData)))
Try(dimnames(tmp)[[2]] <- sampleNames(NormalizedAffyData))
Try(dimnames(tmp)[[1]] <- featureNames(NormalizedAffyData))
Try(exprs(NormalizedAffyData) <- tmp)
Try(assign("NormalizedAffyData", NormalizedAffyData, env=affylmGUIenvironment))
tkdelete(.affylmGUIglobals$mainTree,"NormalizedAffyData.Status")
tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available Quantile",font=.affylmGUIglobals$affylmGUIfontTree)
Try(tkmessageBox(title="Large data set normalization",message="Quantile normalized data are now available in NormalizedAffyData.", type="ok"))
} else if(ReturnVal=="qspline"){
Try(tmp <- normalize.qspline(exprs(NormalizedAffyData)))
Try(dimnames(tmp)[[2]] <- sampleNames(NormalizedAffyData))
Try(dimnames(tmp)[[1]] <- featureNames(NormalizedAffyData))
Try(exprs(NormalizedAffyData) <- tmp)
Try(assign("NormalizedAffyData", NormalizedAffyData, env=affylmGUIenvironment))
tkdelete(.affylmGUIglobals$mainTree,"NormalizedAffyData.Status")
tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available qspline",font=.affylmGUIglobals$affylmGUIfontTree)
Try(tkmessageBox(title="Large data set normalization",message="Qspline normalized data are now available in NormalizedAffyData.", type="ok"))
} else {return()}
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
}
################################################################################
"log2Conversion" <- function(){
if(affylmGUIenvironment$NormalizedAffyData.Available){
Try(NormalizedAffyData <- get("NormalizedAffyData", env=affylmGUIenvironment))
} else Try(tkmessageBox(title="NGS data set normalization",message="Normalized data are not available.", type="ok", icon="error"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="watch"))
Try(tmp.rank <- esApply(NormalizedAffyData, 2, log2))
if(affylmGUIenvironment$NGS.Available){
Try(exprs(NormalizedAffyData) <- tmp.rank)
} else Try(exprs(NormalizedAffyData) <- tmp.rank)
Try(assign("NormalizedAffyData", NormalizedAffyData, env=affylmGUIenvironment))
Try(assign("NGSconversion.available", TRUE, env=affylmGUIenvironment))
tkdelete(.affylmGUIglobals$mainTree,"NormalizedAffyData.Status")
tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available log2 transformed counts",font=.affylmGUIglobals$affylmGUIfontTree)
Try(tkmessageBox(title="Large data set normalization",message="Data are now available as log2 transformed counts in NormalizedAffyData.", type="ok"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
}
#################################################################################
"refiningPeaks" <- function(){
if(affylmGUIenvironment$NormalizedAffyData.Available & affylmGUIenvironment$NGS.Available){
Try(NormalizedAffyData <- get("NormalizedAffyData", env=affylmGUIenvironment))
} else Try(tkmessageBox(title="NGS data set normalization",message="Normalized data are not available.", type="ok", icon="error"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="watch"))
Try(chrs.names <- get("chrsLength", env=affylmGUIenvironment))
Try(chrs.names <- as.character(names(chrs.names)))
Try(peaks.names <- featureNames(NormalizedAffyData))
Try(peaks.tmp <- strsplit(peaks.names, "\\."))
Try(peaks.chr <- sapply(peaks.tmp, function(x) x[1]) )
Try(peaks.chr <- sub("chr", "", peaks.chr))
Try(peaks.location <- sapply(peaks.tmp, function(x) x[3]))
Try(peaks.location <- strsplit(peaks.location, "-"))
Try(peaks.start <- sapply(peaks.location, function(x) x[1]))
Try(peaks.end <- sapply(peaks.location, function(x) x[2]))
#calculating the distance between each peak and the following
Try(peaks.dist <- abs(diff(as.numeric(peaks.end), 1)))
Try(peaks.dist.sort <- sort(unique(peaks.dist)))
#calculating the frequence of the distances
Try(peaks.dist.freq <- sapply(peaks.dist.sort, function(x, distances){length(which(peaks.dist == x))},distances = peaks.dist))
Try(names(peaks.dist.freq) <- peaks.dist.sort)
Try(plot(peaks.dist.sort , peaks.dist.freq, ylab="Frequence", xlab="Distance between \nconsecutive peaks", xlim=c(0,1000), type="l", main="Defining the threshold to combine peaks"))
#selecting the merging threshold
Try(ttmergingThr<-tktoplevel(.affylmGUIglobals$ttMain))
Try(tkwm.deiconify(ttmergingThr))
Try(tkgrab.set(ttmergingThr))
Try(tkfocus(ttmergingThr))
Try(tkwm.title(ttmergingThr,"Defining the max distance threshold for peaks merging"))
Try(tkgrid(tklabel(ttmergingThr,text=" ")))
Try(mergingThrnum <- "0")
Try(Local.mergingThr <- tclVar(init=mergingThrnum))
Try(entry.mergingThr <-tkentry(ttmergingThr,width="4",font=.affylmGUIglobals$affylmGUIfont2,textvariable=Local.mergingThr,bg="white"))
Try(tkgrid(tklabel(ttmergingThr,text="Please enter a threshold value.",font=.affylmGUIglobals$affylmGUIfont2)))
Try(tkgrid(entry.mergingThr))
onOK <- function()
{
Try(mergingThrnum <- as.numeric(tclvalue(Local.mergingThr)))
Try(assign("mergingThr", as.numeric(tclvalue(Local.mergingThr)),affylmGUIenvironment))
Try(assign("mergingThr.available", TRUE,affylmGUIenvironment))
Try(tkgrab.release(ttmergingThr));Try(tkdestroy(ttmergingThr));Try(tkfocus(.affylmGUIglobals$ttMain))
}
Try(OK.but <-tkbutton(ttmergingThr,text=" OK ",command=onOK,font=.affylmGUIglobals$affylmGUIfont2))
Try(tkgrid(tklabel(ttmergingThr,text=" ")))
Try(tkgrid(OK.but))
Try(tkgrid.configure(OK.but))
Try(tkgrid(tklabel(ttmergingThr,text=" ")))
Try(tkfocus(entry.mergingThr))
Try(tkbind(entry.mergingThr, "<Return>",onOK))
Try(tkbind(ttmergingThr, "<Destroy>", function(){Try(tkgrab.release(ttmergingThr));Try(tkfocus(.affylmGUIglobals$ttMain));return(0)}))
Try(tkwait.window(ttmergingThr))
Try(tkfocus(.affylmGUIglobals$ttMain))
Try(mergingThrnum <- get("mergingThr", env=affylmGUIenvironment))
Try(abline(v=as.numeric(mergingThrnum), lty=2, col="red"))
Try(mbVal <- tkmessageBox(title="Merging peaks threshold",
message="The selected inter-peak distance for peaks merging is shown by a dashed line in the main R window\n Is it OK? Answering NO peaks will be merged.\nAnswering NO, the data set will not be modified.",
icon="question",type="yesno",default="yes"))
Try(if(tclvalue(mbVal)=="yes"){
Try(peaks.2be.merged <- which(peaks.dist <= mergingThrnum))
while(length(peaks.2be.merged) > 1){
#recursive merge
Try(peaks.names <- featureNames(NormalizedAffyData))
Try(peaks.tmp <- strsplit(peaks.names, "\\."))
Try(peaks.chr <- sapply(peaks.tmp, function(x) x[1]) )
Try(peaks.chr <- sub("chr", "", peaks.chr))
Try(peaks.location <- sapply(peaks.tmp, function(x) x[3]))
Try(peaks.location <- strsplit(peaks.location, "-"))
Try(peaks.start <- sapply(peaks.location, function(x) x[1]))
Try(peaks.end <- sapply(peaks.location, function(x) x[2]))
#calculating the distance between each peak and the following
Try(peaks.dist <- abs(diff(as.numeric(peaks.end), 1)))
Try(peaks.dist.sort <- sort(unique(peaks.dist)))
#calculating the frequence of the distances
Try(peaks.dist.freq <- sapply(peaks.dist.sort, function(x, distances){length(which(peaks.dist == x))},distances = peaks.dist))
Try(names(peaks.dist.freq) <- peaks.dist.sort)
Try(peaks.2be.merged <- which(peaks.dist <= mergingThrnum))
Try(if(length(peaks.2be.merged) == 0) { cat("\n Peaks to be still merged: 0\n"); return()} )
cat("\n Peaks to be still merged: ", length(peaks.2be.merged))
Try(mymat <- exprs(NormalizedAffyData))
#defining the modified matrix that will sobstitue dthe subset of peaks to be merged
Try(new.mat <- matrix(rep(0, length(peaks.2be.merged) * dim(mymat)[2]), ncol= dim(mymat)[2]))
Try(dimnames(new.mat) <- list(seq(1, length(peaks.2be.merged)), dimnames(mymat)[[2]]))
for(i in 1: length(peaks.2be.merged)){
Try(tmp.merged <- mymat[peaks.2be.merged[i],] + mymat[peaks.2be.merged[i]+1,])
Try(peak1 <- peaks.names[peaks.2be.merged[i]])
Try(peak2 <- peaks.names[peaks.2be.merged[i]+1])
Try(peak.tmp <- strsplit(peaks.names[c(peaks.2be.merged[i],peaks.2be.merged[i]+1)], "\\."))
Try(peak.location <- sapply(peak.tmp, function(x) x[3]))
Try(peak.location <- strsplit(peak.location, "-"))
Try(peak.start <- sapply(peak.location, function(x) x[1]))
Try(peak.end <- sapply(peak.location, function(x) x[2]))
Try(new.name <- paste(paste(peak.tmp[[1]][1:2], collapse = "."), ".", peak.start[1], "-", peak.end[2], sep=""))
Try(new.mat[i,] <- tmp.merged)
Try(dimnames(new.mat)[[1]][i] <- new.name)
}
Try(tobe.removed <- c(peaks.2be.merged, peaks.2be.merged + 1))
Try(mymat <- mymat[setdiff(seq(1, dim(mymat)[1]), tobe.removed),])
Try(mymat <- rbind(mymat, new.mat))
Try(exprs(NormalizedAffyData) <- mymat)
}
cat("\n")
Try(plot(peaks.dist.sort , peaks.dist.freq, ylab="Frequence", xlab="Distance between \nconsecutive peaks", xlim=c(0,1000), type="l", main="Defining the threshold to combine peaks"))
Try(abline(v=as.numeric(mergingThrnum), lty=2, col="red"))
Try(assign("NormalizedAffyData", NormalizedAffyData,affylmGUIenvironment))
tkdelete(.affylmGUIglobals$mainTree,"NormalizedAffyData.Status")
tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="NGS refined peaks",font=.affylmGUIglobals$affylmGUIfontTree)
Try(tkmessageBox(title="NGS",message="refined peaks are present in NormalizedAffyData.", type="ok"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
} else{
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
Try(return())
})
}
################################################################################
#exchanging intenisty signal with nomralized rank
"rankingConversion" <- function(){
if(affylmGUIenvironment$NormalizedAffyData.Available){
Try(NormalizedAffyData <- get("NormalizedAffyData", env=affylmGUIenvironment))
} else Try(tkmessageBox(title="Large data set normalization",message="Normalized data are not available.", type="ok", icon="error"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="watch"))
Try(tmp.rank <- esApply(NormalizedAffyData, 2, rank))
Try(tmp.rank <- apply(tmp.rank, 2, .myrk, df=tmp.rank))
Try(exprs(NormalizedAffyData) <- tmp.rank)
Try(assign("NormalizedAffyData", NormalizedAffyData, env=affylmGUIenvironment))
tkdelete(.affylmGUIglobals$mainTree,"NormalizedAffyData.Status")
tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available normalized ranking",font=.affylmGUIglobals$affylmGUIfontTree)
Try(tkmessageBox(title="Large data set normalization",message="Data are now available as normalized ranks in NormalizedAffyData.", type="ok"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
}
#internal function
.myrk <- function(x, df) {x/dim(df)[1]}
################################################################################
"edgeRNorm" <- function(){
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="watch"))
# require(edgeR) || stop("\nMisssing edgeR package\n")
Try(NGSscaling.Available <- get("NGSscaling.Available", env=affylmGUIenvironment))
if(NGSscaling.Available){
Try(tkmessageBox(title="NGS data set normalization",message="Normalized data are already available.", type="ok", icon="error"))
Try(return())
}
if(affylmGUIenvironment$NormalizedAffyData.Available & affylmGUIenvironment$NGS.Available){
Try(NormalizedAffyData <- get("NormalizedAffyData", env=affylmGUIenvironment))
Try(mappedReads <- get("mappedReads", env=affylmGUIenvironment))
Try(targets <- get("Targets", env=affylmGUIenvironment))
} else Try(tkmessageBox(title="NGS data set normalization",message="Normalized data are not available.", type="ok", icon="error"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="watch"))
cat("\ncreating the DGEList")
Try(mbLIb <- tkmessageBox(title="Which library size",
message="Do you wish to used as library size the number of mapped reads for each sample?\nIf you answer NO the size will be given by the total number of sequenced reads", icon="question",type="yesno",default="yes"
)#end of tkmessageBox
)#end of Try(mb(mbLIb..
if(tclvalue(mbLIb)=="yes"){
Try(mylist <- DGEList(counts= exprs(NormalizedAffyData), group=as.factor(targets$Target)))
} else{
Try(mylist <- DGEList(counts= exprs(NormalizedAffyData), group=as.factor(targets$Target), lib.size=mappedReads))
}
cat("\nCommon dispersion is ")
Try(mylist <- estimateCommonDisp(mylist))
cat(mylist$common.dispersion, "\n")
Try(par(mfrow=c(1,2)))
Try(plotMDS.dge(mylist, main=paste("Multidimensional scaling plot\nCommon disp. before normalization",signif(mylist$common.dispersion,2),sep=" ")))
#calculating nomralization factor
Try(norm.factor <- calcNormFactors(exprs(NormalizedAffyData)))
Try(norm.factor <- norm.factor/exp(mean(log(norm.factor))))
Try(scaledReads <- colSums(exprs(NormalizedAffyData)) * norm.factor)
Try(assign("NGSscaling.Available", TRUE, env=affylmGUIenvironment))
Try(assign("NGSscaling", scaledReads, env=affylmGUIenvironment))
Try(mylist <- DGEList(counts= exprs(NormalizedAffyData), group=as.factor(targets$Target), lib.size=scaledReads))
Try(mylist <- estimateCommonDisp(mylist))
Try(plotMDS.dge(mylist, main=paste("Multidimensional scaling plot\nCommon disp. after normalization",signif(mylist$common.dispersion,2),sep=" ")))
cat(mylist$common.dispersion, "\n")
tkdelete(.affylmGUIglobals$mainTree,"NormalizedAffyData.Status")
tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available normalized scaled",font=.affylmGUIglobals$affylmGUIfontTree)
Try(tkmessageBox(title="NGS data set normalization",message="Data are now scaled as described by Robinson and Oshlack Genome Biology 2010, 11:R25.", type="ok"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
}
################################################################################
"EDAwithinLane" <- function(){
# Try(require(EDASeq) || stop("Missing EDASeq library"))
Try(whichArrayPlatform <- get("whichArrayPlatform",envir=affylmGUIenvironment))
if(whichArrayPlatform ==""){
Try(tkmessageBox(title="QC",message="No arrays have been loaded. Please try New or Open from the File menu.",type="ok",icon="error"))
Try(tkfocus(.affylmGUIglobals$ttMain))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
Try(return())
}
if(affylmGUIenvironment$NormalizedAffyData.Available & affylmGUIenvironment$NGS.Available){
Try(NormalizedAffyData <- get("NormalizedAffyData", env=affylmGUIenvironment))
Try(Targets <- get("Targets", env=affylmGUIenvironment))
} else {
Try(tkmessageBox(title="NGS data set",message="Normalized data are not available.", type="ok", icon="error"))
Try(return())
}
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="watch"))
Try(bowtieDirAvailable <- get("whichArrayPlatform",envir=affylmGUIenvironment))
Try(bowtieDirLocation.Available <- get("bowtieDirLocation.Available",envir=affylmGUIenvironment))
if(bowtieDirLocation.Available){
Try(bowtieDirLocation <- get("bowtieDirLocation",envir=affylmGUIenvironment))
} else{
Try(tkmessageBox(title="Bowtie data",message="It seems that Bowtie dir is missing!\nPlease install Bowtie using the function in General Tools menu",icon="error"))
Try(return())
}
#adding gc content to eset
Try(whichGenome <- annotation(NormalizedAffyData))
if(whichGenome == ""){
Try(tkmessageBox(title="Genome selection",message="No genome is indicated in the annotation slot of ExpressionSet",type="ok", icon="error"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
Try(return())
} else if (whichGenome == "hs19"){
Try(annlibname <- system.file("bowtie/hg19_gene-level.scaffold.Rda",package="oneChannelGUI"))
Try(load(annlibname))
} else if (whichGenome == "mm9"){
Try(annlibname <- system.file("bowtie/mm9_gene-level.scaffold.Rda",package="oneChannelGUI"))
Try(load(annlibname))
} else if (whichGenome == "rn4"){
Try(annlibname <- system.file("bowtie/rn4_gene-level.scaffold.Rda",package="oneChannelGUI"))
Try(load(annlibname))
} else{
Try(tkmessageBox(title="Genome selection",message="In the annotation slot of ExpressionSet is present a genome not annotated in oneChannelGUI!\nContact the maintainer for Genome implementation",type="ok", icon="error"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
Try(return())
}
#detecting the chr under analysis
Try(chr <- strsplit(Targets$FileName[1], "_")) #getting the chr
Try(chr <- as.vector(unlist(chr)))
Try(chr <- chr[length(chr)])
Try(chr <- sub(".bam", "", chr)) #needed to extract the right subset of gene-level annotation from makeGeneScaffold generated GRanges list
Try(chr <- sub("chr0", "chr", chr))
#selecting the chromosome genomic reanges on which assigning BAM data
Try(chr.gr <- chr.gr[which(names(chr.gr) == chr)])
Try(genes.lenght <- width(ranges(chr.gr[[1]])))
Try(names(genes.lenght) <- elementMetadata(chr.gr[[1]])$names)
Try(gc.freq <- gc.freq[which(names(gc.freq) == chr)])
Try(gc.freq <- unlist(gc.freq))
Try(tmp.names <- names(gc.freq))
Try(tmp.names <- sapply(tmp.names,function(x,chr){tmp<-sub(chr,'',x);return(tmp)},chr=paste(chr,'.', sep="")))
Try(tmp.names <- as.character(tmp.names))
Try(names(gc.freq) <- tmp.names)
if(identical(names(genes.lenght), names(gc.freq))){
Try(feature <- data.frame(gc=gc.freq,length=genes.lenght))
}else{
Try(gc.freq <- gc.freq[order(names(gc.freq))])
Try(genes.lenght <- genes.lenght[order(names(genes.lenght))])
Try(feature <- data.frame(gc=gc.freq,length=genes.lenght))
}
Try(var.tmp.pd<-data.frame(names(feature)))
Try(names(var.tmp.pd)<-"labelDescription" )
Try(rownames(var.tmp.pd)<-names(feature))
Try(tmp1.pd<-new("AnnotatedDataFrame", data=feature, varMetadata=var.tmp.pd))
#making eset featureNames identical to names gc.freq and genes.length
.myFeature <- function(eset){
tmp.names <- featureNames(NormalizedAffyData)
tmp.names <- sapply(tmp.names, function(x){sub('\\-_','#',x)})
tmp.names <- as.character(tmp.names)
tmp.names <- sapply(tmp.names, function(x){sub('\\+_','#',x)})
tmp.names <- as.character(tmp.names)
tmp.names <- sapply(tmp.names, function(x){tmp <- strsplit(x, '#');return(tmp[[1]][2])})
tmp.names <- as.character(tmp.names)
return(tmp.names)
}
Try(counts <- NormalizedAffyData)
Try(rownames(exprs(counts)) <- .myFeature(NormalizedAffyData))
#I need this to reassign the correct names to the peaks
Try(recovery.fN <- featureNames(counts))
Try(names(recovery.fN) <- featureNames(NormalizedAffyData))
Try(tmp1.pd <- tmp1.pd[which(featureNames(tmp1.pd)%in%featureNames(counts)),])
Try(counts <- counts[which(featureNames(counts)%in%featureNames(tmp1.pd)),])
Try(counts <- counts[order(featureNames(counts)),])
Try(tmp1.pd <- tmp1.pd[order(featureNames(tmp1.pd)),])
Try(eseq <- newSeqExpressionSet(exprs(counts), phenoData=pData(counts), featureData=tmp1.pd))
Try(names(pData(eseq))[1] <- "conditions")
#defining normalization
Try(ttIfDialog<-tktoplevel(.affylmGUIglobals$ttMain))
Try(tkwm.deiconify(ttIfDialog))
Try(tkgrab.set(ttIfDialog))
Try(tkfocus(ttIfDialog))
Try(tkwm.title(ttIfDialog,"Within-lane Normalization Options"))
Try(tkgrid(tklabel(ttIfDialog,text=" ")))
Try(frame1 <- tkframe(ttIfDialog,relief="groove",borderwidth=2))
Try(HowManyQuestion1 <- tklabel(frame1,text="Normalization parameter",font=.affylmGUIglobals$affylmGUIfont2))
Try(tkgrid(HowManyQuestion1))
Try(tkgrid.configure(HowManyQuestion1,columnspan=2,sticky="w"))
Try(thresholdTcl <- tclVar("gc"))
Try(I1.but <- tkradiobutton(frame1,text="GC", variable=thresholdTcl,value="gc",font=.affylmGUIglobals$affylmGUIfont2))
Try(I2.but <- tkradiobutton(frame1,text="Length", variable=thresholdTcl,value="length",font=.affylmGUIglobals$affylmGUIfont2))
Try(tkgrid(I1.but,sticky="w"))
Try(tkgrid(I2.but,sticky="w"))
Try(tkgrid.configure(HowManyQuestion1,I1.but, I2.but,sticky="w"))
Try(frame2 <- tkframe(ttIfDialog,relief="groove",borderwidth=2))
Try(fractionLabel <- tklabel(frame2,text="Normalization method",font=.affylmGUIglobals$affylmGUIfont2))
Try(tkgrid(fractionLabel,sticky="w"))
Try(tkgrid.configure(fractionLabel,sticky="w"))
Try(fractionTcl <- tclVar("full"))
Try(F1.but <- tkradiobutton(frame2,text="Full-quantile",variable=fractionTcl,value="full",font=.affylmGUIglobals$affylmGUIfont2))
Try(F2.but <- tkradiobutton(frame2,text="Upper-quantile",variable=fractionTcl,value="upper",font=.affylmGUIglobals$affylmGUIfont2))
Try(F3.but <- tkradiobutton(frame2,text="Median",variable=fractionTcl,value="median",font=.affylmGUIglobals$affylmGUIfont2))
Try(F4.but <- tkradiobutton(frame2,text="Loess",variable=fractionTcl,value="loess",font=.affylmGUIglobals$affylmGUIfont2))
Try(tkgrid(F1.but,sticky="w"))
Try(tkgrid(F2.but,sticky="w"))
Try(tkgrid(F3.but,sticky="w"))
Try(tkgrid(F4.but,sticky="w"))
Try(tkgrid.configure(fractionLabel,F1.but,F2.but,F3.but,F4.but,sticky="w"))
Try(onOK <- function()
{
ReturnVal1 <- tclvalue(thresholdTcl)
ReturnVal2 <- tclvalue(fractionTcl)
Try(ReturnVal <<- paste(ReturnVal1, ReturnVal2, sep=";"))
Try(tkgrab.release(ttIfDialog))
Try(tkdestroy(ttIfDialog))
Try(tkfocus(.affylmGUIglobals$ttMain))
})
Try(frame3 <- tkframe(ttIfDialog,borderwidth=2))
Try(onCancel <- function() {Try(ReturnVal <<- ""); Try(tkgrab.release(ttIfDialog));Try(tkdestroy(ttIfDialog));Try(tkfocus(.affylmGUIglobals$ttMain))})
Try(OK.but <-tkbutton(frame3,text=" OK ",command=onOK,font=.affylmGUIglobals$affylmGUIfont2))
Try(Cancel.but <-tkbutton(frame3,text=" Cancel ",command=onCancel,font=.affylmGUIglobals$affylmGUIfont2))
Try(tkgrid(tklabel(frame3,text=" "),OK.but,Cancel.but,tklabel(frame3,text=" ")))
Try(tkgrid(tklabel(ttIfDialog,text=" "),frame1,frame2,tklabel(ttIfDialog,text=" ")))
Try(tkgrid(tklabel(ttIfDialog,text=" ")))
Try(tkgrid(tklabel(ttIfDialog,text=" "),frame3,tklabel(ttIfDialog,text=" ")))
Try(tkgrid(tklabel(ttIfDialog,text=" ")))
Try(tkgrid.configure(frame1,frame3,sticky="w"))
Try(tkfocus(ttIfDialog))
Try(tkbind(ttIfDialog, "<Destroy>", function() {Try(tkgrab.release(ttIfDialog));Try(tkfocus(.affylmGUIglobals$ttMain));}))
Try(tkwait.window(ttIfDialog))
Try(norm.parameters <-strsplit(ReturnVal, ";"))
Try(norm.parameters<- as.character(unlist(norm.parameters)))
Try(eseqWithin <- withinLaneNormalization(eseq,norm.parameters[1],which=norm.parameters[2]))
#plotting normalization effect
Try(par(mfrow=c(2,3)))
Try(boxplot(eseq, ylab="log10 counts", main="Before normalization."))
Try(biasPlot(eseq, "gc", log=T))
Try(biasPlot(eseq, "length", log=T))
Try(boxplot(eseqWithin, ylab="log10 counts", main=paste("After normalization.", "\nNormalization Param=",norm.parameters[1], "\nNormalization Method=",norm.parameters[2])))
Try(biasPlot(eseqWithin, "gc", log=T))
Try(biasPlot(eseqWithin, "length", log=T))
#saving normalization
Try(tmp.exprs <- exprs(eseqWithin))
Try(recovery.fN <- recovery.fN[which(recovery.fN%in%featureNames(eseqWithin))])
if(identical(row.names(tmp.exprs), recovery.fN)){
Try(row.names(tmp.exprs) <- names(recovery.fN))
}else{
Try(recovery.fN[order(recovery.fN)])
Try(tmp.exprs[order(row.names(tmp.exprs)),])
Try(row.names(tmp.exprs) <- names(recovery.fN))
}
Try(exprs(NormalizedAffyData) <- tmp.exprs)
Try(assign("NormalizedAffyData", NormalizedAffyData, env=affylmGUIenvironment))
Try(tkdelete(.affylmGUIglobals$mainTree,"NormalizedAffyData.Status"))
Try(tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available within-lane normalized",font=.affylmGUIglobals$affylmGUIfontTree))
Try(tkmessageBox(title="NGS data set normalization",message=paste("Data are now within-lane normalized as described by Risso et al. 2011.", "Normalization param:",norm.parameters[1],norm.parameters[2],sep="\n"), type="ok"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
}
##########################################################################################################################
"EDAbetweenLane" <- function(){
# Try(require(EDASeq) || stop("Missing EDASeq library"))
Try(whichArrayPlatform <- get("whichArrayPlatform",envir=affylmGUIenvironment))
if(whichArrayPlatform ==""){
Try(tkmessageBox(title="QC",message="No arrays have been loaded. Please try New or Open from the File menu.",type="ok",icon="error"))
Try(tkfocus(.affylmGUIglobals$ttMain))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
Try(return())
}
if(affylmGUIenvironment$NormalizedAffyData.Available & affylmGUIenvironment$NGS.Available){
Try(NormalizedAffyData <- get("NormalizedAffyData", env=affylmGUIenvironment))
Try(Targets <- get("Targets", env=affylmGUIenvironment))
} else {
Try(tkmessageBox(title="NGS data set",message="Normalized data are not available.", type="ok", icon="error"))
Try(return())
}
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="watch"))
Try(bowtieDirAvailable <- get("whichArrayPlatform",envir=affylmGUIenvironment))
Try(bowtieDirLocation.Available <- get("bowtieDirLocation.Available",envir=affylmGUIenvironment))
if(bowtieDirLocation.Available){
Try(bowtieDirLocation <- get("bowtieDirLocation",envir=affylmGUIenvironment))
} else{
Try(tkmessageBox(title="Bowtie data",message="It seems that Bowtie dir is missing!\nPlease install Bowtie using the function in General Tools menu",icon="error"))
Try(return())
}
#adding gc content to eset
Try(whichGenome <- annotation(NormalizedAffyData))
if(whichGenome == ""){
Try(tkmessageBox(title="Genome selection",message="No genome is indicated in the annotation slot of ExpressionSet",type="ok", icon="error"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
Try(return())
} else if (whichGenome == "hs19"){
Try(annlibname <- system.file("bowtie/hg19_gene-level.scaffold.Rda",package="oneChannelGUI"))
Try(load(annlibname))
} else if (whichGenome == "mm9"){
Try(annlibname <- system.file("bowtie/mm9_gene-level.scaffold.Rda",package="oneChannelGUI"))
Try(load(annlibname))
} else if (whichGenome == "rn4"){
Try(annlibname <- system.file("bowtie/rn4_gene-level.scaffold.Rda",package="oneChannelGUI"))
Try(load(annlibname))
} else{
Try(tkmessageBox(title="Genome selection",message="In the annotation slot of ExpressionSet is present a genome not annotated in oneChannelGUI!\nContact the maintainer for Genome implementation",type="ok", icon="error"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
Try(return())
}
#detecting the chr under analysis
Try(chr <- strsplit(Targets$FileName[1], "_")) #getting the chr
Try(chr <- as.vector(unlist(chr)))
Try(chr <- chr[length(chr)])
Try(chr <- sub(".bam", "", chr)) #needed to extract the right subset of gene-level annotation from makeGeneScaffold generated GRanges list
Try(chr <- sub("chr0", "chr", chr))
#selecting the chromosome genomic reanges on which assigning BAM data
Try(chr.gr <- chr.gr[which(names(chr.gr) == chr)])
Try(genes.lenght <- width(ranges(chr.gr[[1]])))
Try(names(genes.lenght) <- elementMetadata(chr.gr[[1]])$names)
Try(gc.freq <- gc.freq[which(names(gc.freq) == chr)])
Try(gc.freq <- unlist(gc.freq))
Try(tmp.names <- names(gc.freq))
Try(tmp.names <- sapply(tmp.names,function(x,chr){tmp<-sub(chr,'',x);return(tmp)},chr=paste(chr,'.', sep="")))
Try(tmp.names <- as.character(tmp.names))
Try(names(gc.freq) <- tmp.names)
if(identical(names(genes.lenght), names(gc.freq))){
Try(feature <- data.frame(gc=gc.freq,length=genes.lenght))
}else{
Try(gc.freq <- gc.freq[order(names(gc.freq))])
Try(genes.lenght <- genes.lenght[order(names(genes.lenght))])
Try(feature <- data.frame(gc=gc.freq,length=genes.lenght))
}
Try(var.tmp.pd<-data.frame(names(feature)))
Try(names(var.tmp.pd)<-"labelDescription" )
Try(rownames(var.tmp.pd)<-names(feature))
Try(tmp1.pd<-new("AnnotatedDataFrame", data=feature, varMetadata=var.tmp.pd))
#making eset featureNames identical to names gc.freq and genes.length
.myFeature <- function(eset){
tmp.names <- featureNames(NormalizedAffyData)
tmp.names <- sapply(tmp.names, function(x){sub('\\-_','#',x)})
tmp.names <- as.character(tmp.names)
tmp.names <- sapply(tmp.names, function(x){sub('\\+_','#',x)})
tmp.names <- as.character(tmp.names)
tmp.names <- sapply(tmp.names, function(x){tmp <- strsplit(x, '#');return(tmp[[1]][2])})
tmp.names <- as.character(tmp.names)
return(tmp.names)
}
Try(counts <- NormalizedAffyData)
Try(rownames(exprs(counts)) <- .myFeature(NormalizedAffyData))
#I need this to reassign the correct names to the peaks
Try(recovery.fN <- featureNames(counts))
Try(names(recovery.fN) <- featureNames(NormalizedAffyData))
Try(tmp1.pd <- tmp1.pd[which(featureNames(tmp1.pd)%in%featureNames(counts)),])
Try(counts <- counts[which(featureNames(counts)%in%featureNames(tmp1.pd)),])
Try(counts <- counts[order(featureNames(counts)),])
Try(tmp1.pd <- tmp1.pd[order(featureNames(tmp1.pd)),])
Try(eseq <- newSeqExpressionSet(exprs(counts), phenoData=pData(counts), featureData=tmp1.pd))
Try(names(pData(eseq))[1] <- "conditions")
#defining normalization
Try(ttGetNormMethod <- tktoplevel(.affylmGUIglobals$ttMain))
Try(tkwm.deiconify(ttGetNormMethod))
Try(tkgrab.set(ttGetNormMethod))
Try(tkfocus(ttGetNormMethod))
Try(tkwm.title(ttGetNormMethod,"Between-lanes normalization"))
Try(tkgrid(tklabel(ttGetNormMethod,text=" ")))
Try(ttGetNormMethodTcl <- tclVar("full"))
Try(rbIQR.5 <- tkradiobutton(ttGetNormMethod,text="Full-quantile",variable=ttGetNormMethodTcl,value="full",font=.affylmGUIglobals$affylmGUIfont2))
Try(rbIQR.25<-tkradiobutton(ttGetNormMethod,text="Median",variable=ttGetNormMethodTcl,value="medina",font=.affylmGUIglobals$affylmGUIfont2))
Try(rbIQR.1<-tkradiobutton(ttGetNormMethod,text="Upper",variable=ttGetNormMethodTcl,value="upper",font=.affylmGUIglobals$affylmGUIfont2))
Try(rbIQR.2<-tkradiobutton(ttGetNormMethod,text="Loess",variable=ttGetNormMethodTcl,value="loess",font=.affylmGUIglobals$affylmGUIfont2))
Try(tkgrid(tklabel(ttGetNormMethod,text=" "),rbIQR.5))
Try(tkgrid(tklabel(ttGetNormMethod,text=" "),rbIQR.25))
Try(tkgrid(tklabel(ttGetNormMethod,text=" "),rbIQR.1))
Try(tkgrid(tklabel(ttGetNormMethod,text=" "),rbIQR.2))
Try(tkgrid.configure(rbIQR.5,rbIQR.25,rbIQR.1,rbIQR.2,columnspan=2,sticky="w"))
Try(tkgrid(tklabel(ttGetNormMethod,text=" "),tklabel(ttGetNormMethod,text=" ")))
Try(ReturnVal <- "")
Try(onCancel <- function() {Try(ReturnVal <<- "");Try(tkgrab.release(ttGetNormMethod));Try(tkdestroy(ttGetNormMethod));Try(tkfocus(.affylmGUIglobals$ttMain))})
Try(onOK <- function() {Try(ReturnVal <<- tclvalue(ttGetNormMethodTcl));Try(tkgrab.release(ttGetNormMethod));Try(tkdestroy(ttGetNormMethod));Try(tkfocus(.affylmGUIglobals$ttMain))})
Try(onHelp <- function() tkmessageBox(title="Between-lanes normalization methods",
message="The loess normalization transforms the data by regressing the counts on GC and \nsubtracting the loess fit from the counts to remove the dependence.
\nThe median, upper and full normalizations are based on the \nstratification of the genes based on GC then, \nmedian: scales the data to have the same median in each bin, \nupper: the same but with the upper quartile, \nfull: forces the distribution of each stratum to be the same using a non linear full quantile normalization.",
icon="info"))
Try(Help.but <- tkbutton(ttGetNormMethod,text=" Help ",command=function()Try(onHelp()),font=.affylmGUIglobals$affylmGUIfont2))
Try(OK.but <- tkbutton(ttGetNormMethod,text="OK",command=onOK,font=.affylmGUIglobals$affylmGUIfont2))
Try(Cancel.but <- tkbutton(ttGetNormMethod,text="Cancel",command=onCancel,font=.affylmGUIglobals$affylmGUIfont2))
Try(tkgrid(tklabel(ttGetNormMethod,text=" "),OK.but,Cancel.but, Help.but,tklabel(ttGetNormMethod,text=" ")))
Try(tkgrid.configure(OK.but,sticky="e"))
Try(tkgrid.configure(Cancel.but,sticky="w"))
Try(tkgrid.configure(Help.but,sticky="e"))
Try(tkgrid(tklabel(ttGetNormMethod,text=" ")))
Try(tkbind(ttGetNormMethod,"<Destroy>",function() {ReturnVal <- "";Try(tkgrab.release(ttGetNormMethod));Try(tkfocus(.affylmGUIglobals$ttMain));}))
Try(tkbind(OK.but, "<Return>",onOK))
Try(tkbind(Cancel.but, "<Return>",onCancel))
Try(tkbind(Help.but, "<Return>",onCancel))
Try(tkwait.window(ttGetNormMethod))
Try(eseqWithin <- betweenLaneNormalization(eseq,which=ReturnVal))
#plotting normalization effect
Try(par(mfrow=c(1,2)))
Try(boxplot(eseq, ylab="log10 counts", main="Before normalization."))
Try(boxplot(eseqWithin, ylab="log10 counts", main=paste("After normalization.", "\nNormalization Param=",ReturnVal)))
#saving normalized data
Try(tmp.exprs <- exprs(eseqWithin))
Try(recovery.fN <- recovery.fN[which(recovery.fN%in%featureNames(eseqWithin))])
if(identical(row.names(tmp.exprs), recovery.fN)){
Try(row.names(tmp.exprs) <- names(recovery.fN))
}else{
Try(recovery.fN[order(recovery.fN)])
Try(tmp.exprs[order(row.names(tmp.exprs)),])
Try(row.names(tmp.exprs) <- names(recovery.fN))
}
Try(exprs(NormalizedAffyData) <- tmp.exprs)
Try(assign("NormalizedAffyData", NormalizedAffyData, env=affylmGUIenvironment))
Try(tkdelete(.affylmGUIglobals$mainTree,"NormalizedAffyData.Status"))
Try(tkinsert(.affylmGUIglobals$mainTree,"end","NormalizedAffyData","NormalizedAffyData.Status" ,text="Available between-lanes normalized",font=.affylmGUIglobals$affylmGUIfontTree))
Try(tkmessageBox(title="NGS data set normalization",message=paste("Data are now between-lane normalized as described by Risso et al. 2011.", "Normalization param:",ReturnVal,sep="\n"), type="ok"))
Try(tkconfigure(.affylmGUIglobals$ttMain,cursor="arrow"))
}
##########################################################################################################################
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.