Commit 7936ac9d authored by svolant's avatar svolant
Browse files

Ajout de la normalisation par groupe

parents 8381410f 075362b4
......@@ -6,37 +6,37 @@ dataTableOutput <- DT::dataTableOutput
shinyServer(function(input, output,session) {
#####################################################
##
## LOAD FILES
##
#####################################################
#####################################################
##
## LOAD FILES
##
#####################################################
## Create base for contrast
rand = floor(runif(1,0,1e9))
namesfile = tempfile(pattern = "BaseContrast", tmpdir = tempdir(), fileext = "")
file.create(namesfile,showWarnings=FALSE)
## Popup messages
observe(if(input$AddRegScatter) info("By adding the regression line, you will lose interactivity."))
## Counts file
dataInputCounts <-reactive({
inFile <- input$fileCounts
if (is.null(inFile)) return(NULL)
data = read.csv(inFile$datapath,sep="\t",header=TRUE)
## Rownames
if(!TRUE%in%duplicated(data[,1])) rownames(data)=data[,1];data=data[,-1]
return(as.data.frame(data))
})
## Taxo File
dataInputTaxo <-reactive({
......@@ -55,7 +55,7 @@ shinyServer(function(input, output,session) {
data=as.matrix(data[,-1])
rownames(data)=DataNames
colnames(data) = colNames
}
}
}
if(input$TypeTaxo=="RDP")
......@@ -70,8 +70,8 @@ shinyServer(function(input, output,session) {
return(as.data.frame(data))
})
## BIOM File
dataInputBiom <-reactive({
......@@ -82,9 +82,9 @@ shinyServer(function(input, output,session) {
return(data)
})
## Input data
dataInput <-reactive({
......@@ -121,7 +121,7 @@ shinyServer(function(input, output,session) {
})
## Size factor file (optional)
......@@ -153,7 +153,7 @@ shinyServer(function(input, output,session) {
if(length(tmp)!=length(normFactors)){Error = "The number of samples is not the same than in the target file, size factors will be estimated"; Check = FALSE}
if(!identical(names(tmp),names(normFactors))){Error = "The names are not the same or in the same order than in the target file, size factors will be estimated"; Check = FALSE}
if(Check) normFactors = tmp
}
......@@ -196,8 +196,8 @@ shinyServer(function(input, output,session) {
return(list(counts=counts,CheckTarget=CheckTarget,normFactors=normFactors,CT_noNorm=CT_noNorm, CT_Norm=CT_Norm))
#return(list(counts=counts,target=target,labeled=labeled,normFactors=normFactors,CT_noNorm=CT_noNorm))
})
# Infobox Error counts
output$InfoErrorCounts <- renderInfoBox({
......@@ -216,7 +216,7 @@ shinyServer(function(input, output,session) {
return(res)
})
# Infobox Error counts
output$InfoErrorTaxo <- renderInfoBox({
......@@ -235,8 +235,8 @@ shinyServer(function(input, output,session) {
return(res)
})
# Infobox Error counts
output$valueErrorPercent <- renderInfoBox({
......@@ -256,14 +256,14 @@ shinyServer(function(input, output,session) {
return(res)
})
#####################################################
##
## DYNAMIC MENU
##
#####################################################
#####################################################
##
## DYNAMIC MENU
##
#####################################################
......@@ -275,7 +275,7 @@ shinyServer(function(input, output,session) {
## Check error in the counts and taxonomy table
CheckOK = (is.null(check$CheckCounts$Error) && is.null(check$CheckTaxo$Error) && is.null(check$CheckPercent))
if(!is.null(data$counts) && !is.null(data$taxo) && nrow(data$counts)>0 && nrow(data$taxo)>0 && CheckOK)
{
sidebarMenu(
......@@ -290,9 +290,9 @@ shinyServer(function(input, output,session) {
menuSubItem("Comparison plots",tabName="CompPlot"),
tabName = "Visu"),
menuItem("Perspective plots", icon = icon("pie-chart"), tabName = "Krona")
)
}
}
else{
sidebarMenu()
}
......@@ -300,7 +300,7 @@ shinyServer(function(input, output,session) {
})
#####################################################
##
## DATA TABLE
......@@ -320,9 +320,9 @@ shinyServer(function(input, output,session) {
resDiff = ResDiffAnal()
BaseContrast = read.table(namesfile,header=TRUE)
GetData_venn(input,SelContrast,BaseContrast,resDiff)$df.tot
}, options = list(lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
pageLength = 10,scrollX=TRUE
))
}, options = list(lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
pageLength = 10,scrollX=TRUE
))
## Taxonomy table
......@@ -331,7 +331,7 @@ shinyServer(function(input, output,session) {
options = list(lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
pageLength = 10,scrollX=TRUE
))
## Tab box for data visualisation
output$TabBoxData <- renderUI({
......@@ -349,7 +349,7 @@ shinyServer(function(input, output,session) {
}
})
output$SummaryView <- renderGvis({
data = dataInput()$data
taxo = data$taxo
......@@ -359,13 +359,13 @@ shinyServer(function(input, output,session) {
{
taxo = rbind(taxo,rep(NA,ncol(taxo)))
tmpPercent = round(apply(is.na(taxo),2,table)["FALSE",]/nrow(counts)*100,2)
#print(tmpPercent)
df <- data.frame(Label = colnames(taxo),Value = tmpPercent)
res = gvisGauge(df,options=list(min=0, max=100, greenFrom=80,
greenTo=100, yellowFrom=60, yellowTo=80,
redFrom=0, redTo=60, width=1200, height=300))
greenTo=100, yellowFrom=60, yellowTo=80,
redFrom=0, redTo=60, width=1200, height=300))
}
return(res)
})
......@@ -396,7 +396,7 @@ shinyServer(function(input, output,session) {
##
#####################################################
## Load target file
dataInputTarget <-reactive({
......@@ -420,19 +420,19 @@ shinyServer(function(input, output,session) {
#rownames(data) <- colnames(counts)
# Percent annotated
# print(ind)
# print(colnames(counts))
# print(rownames(data))
# print(ind)
# print(colnames(counts))
# print(rownames(data))
labeled = length(ind)/length(colnames(counts))*100.0
return(list(target = target, labeled=labeled))
})
## Interest Variables
output$SelectInterestVar <- renderUI({
target=dataInputTarget()$target
if(!is.null(target))
......@@ -440,15 +440,15 @@ shinyServer(function(input, output,session) {
namesTarget = colnames(target)[2:ncol(target)]
selectInput("InterestVar",h6(strong("Select the variables")),namesTarget,selected=namesTarget,multiple=TRUE)
}
})
## Interactions
output$SelectInteraction2 <- renderUI({
target = dataInputTarget()$target
if(!is.null(target))
{
Interac = GetInteraction2(target)
......@@ -487,18 +487,18 @@ shinyServer(function(input, output,session) {
if(length(InterVar)>0)
{
names = paste0("Ref",InterVar)
for(i in 1:length(names))
{
val = unique(target[,InterVar[i]])
RB[[i]] = selectInput(names[i],paste("Reference for",InterVar[i]),as.vector(val))
}
for(i in 1:length(names))
{
val = unique(target[,InterVar[i]])
RB[[i]] = selectInput(names[i],paste("Reference for",InterVar[i]),as.vector(val))
}
}
}
return(RB)
})
# Infobox design
output$RowTarget <- renderInfoBox({
#target = dataInputTarget()
......@@ -517,25 +517,25 @@ shinyServer(function(input, output,session) {
return(res)
}
)
## target table
output$DataTarget <- renderDataTable(
dataInputTarget()$target,
options = list(lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
pageLength = 10,scrollX=TRUE
))
dataInputTarget()$target,
options = list(lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
pageLength = 10,scrollX=TRUE
))
## Counts table for the selected taxonomy level
output$CountsMerge <- renderDataTable(
round(counts(ResDiffAnal()$dds,normalized=TRUE)),
options = list(lengthMenu = list(c(10, 50, -1), c('10', '50', 'All')),
pageLength = 10,scrollX=TRUE
))
## Box for merged counts
output$BoxCountsMerge <- renderUI({
......@@ -552,19 +552,19 @@ shinyServer(function(input, output,session) {
}
})
## Export in .csv
output$ExportCounts <- downloadHandler(
filename = function() { 'NormCounts.csv' },
content = function(file){write.csv(dataMergeCounts()$counts, file)}
)
## Export in .csv
output$ExportRelative <- downloadHandler(
filename = function() { 'RelativeAb.csv' },
content = function(file){write.csv(dataMergeCounts()$counts/colSums(dataMergeCounts()$counts), file)}
)
## Export size factors
output$ExportSizeFactor <- downloadHandler(
filename = function() { 'SHAMAN_sizefactors.csv' },
......@@ -576,7 +576,7 @@ shinyServer(function(input, output,session) {
output$BoxTarget <- renderUI({
target = dataInputTarget()$target
if(!is.null(target) && nrow(target)>0)
{
box(title="Target file overview",width = NULL, status = "primary", solidHeader = TRUE,collapsible = TRUE,collapsed = TRUE,
......@@ -585,30 +585,30 @@ shinyServer(function(input, output,session) {
}
})
#####################################################
##
## DEFINE CONTRAST
##
#####################################################
#####################################################
##
## DEFINE CONTRAST
##
#####################################################
output$contrastMat <- renderUI({
resDiff = ResDiffAnal()
dds = resDiff$dds
names = resultsNames(dds)
Contrast=list()
for(i in 1:length(names)){Contrast[[i]] = numericInput(names[i],names[i],0,step=1,min=-1,max=1)}
return(Contrast)
})
output$ContrastOverview <- renderPrint({
resDiff = ResDiffAnal()
......@@ -625,15 +625,15 @@ shinyServer(function(input, output,session) {
div(HTML(PrintContrasts(names,sapply(ContrastBase[,ind],as.numeric),cont)))
}
})
## Add contrast function
AddCont <-eventReactive(input$AddContrast,{
resDiff = ResDiffAnal()
dds = resDiff$dds
names = resultsNames(dds)
BaseContrast(input,names,namesfile)
filesize = file.info(namesfile)[,"size"]
if(is.na(filesize)){filesize=0}
......@@ -645,15 +645,15 @@ shinyServer(function(input, output,session) {
updateSelectInput(session, "ContrastList_table_VisuComp","For which contrasts",Contrast)
updateSelectInput(session, "ContrastList_table_FC","Contrasts (Min = 2)",Contrast)
})
## Add contrast
observeEvent(input$AddContrast,{
AddCont()
},priority=1)
## Add contrast function
AddContEasy <-eventReactive(input$AddContrastEasy,{
......@@ -681,8 +681,8 @@ shinyServer(function(input, output,session) {
AddContEasy()
},priority=1)
AddContFromFile <-eventReactive(input$fileContrast,{
res = ReadContrastFile()
......@@ -690,7 +690,7 @@ shinyServer(function(input, output,session) {
filesize = file.info(namesfile)[,"size"]
if(is.na(filesize)){filesize=0}
if(filesize!=0){ createdCont = read.table(namesfile,header=TRUE) }
if(!is.null(res))
{
if(!is.null(createdCont)) res = cbind(res,createdCont)
......@@ -702,13 +702,13 @@ shinyServer(function(input, output,session) {
write.table(res,namesfile,row.names=FALSE)
}
})
observeEvent(input$fileContrast,{
observeEvent(input$fileContrast,{
AddContFromFile()
AddContFromFile()
},priority=1)
## Remove contrast function
RemoveCont <-eventReactive(input$RemoveContrast,{
......@@ -740,53 +740,53 @@ shinyServer(function(input, output,session) {
RemoveCont()
},priority=1)
## Remove all contrasts
RemoveAllCont <-eventReactive(input$RunDESeq,{
file.create(namesfile,showWarnings=FALSE)
updateSelectInput(session, "ContrastList","Contrasts",NULL)
updateSelectInput(session, "ContrastList_table","Contrasts",NULL)
updateSelectInput(session, "ContrastList_table_Visu","For which contrasts",NULL)
updateSelectInput(session, "ContrastList_table_VisuComp","For which contrasts",NULL)
updateSelectInput(session, "ContrastList_table_FC","Contrasts (Min = 2)",NULL)
file.create(namesfile,showWarnings=FALSE)
updateSelectInput(session, "ContrastList","Contrasts",NULL)
updateSelectInput(session, "ContrastList_table","Contrasts",NULL)
updateSelectInput(session, "ContrastList_table_Visu","For which contrasts",NULL)
updateSelectInput(session, "ContrastList_table_VisuComp","For which contrasts",NULL)
updateSelectInput(session, "ContrastList_table_FC","Contrasts (Min = 2)",NULL)
})
## Remove all contrast
observeEvent(input$RunDESeq,{
RemoveAllCont()
})
# Infobox Contrast
output$InfoContrast <- renderInfoBox({
input$RunDESeq
input$AddContrast
input$AddContrastEasy
input$RemoveContrast
input$fileContrast
resDiff = ResDiffAnal()
res=NULL
if(!is.null(resDiff)){
res = infoBox("Contrasts", subtitle = h6("At least one contrast (non null) must be defined"), icon = icon("warning"),color = "light-blue",width=NULL,fill=TRUE)
test = FALSE
filesize = isolate(file.info(namesfile)[,"size"])
if(is.na(filesize)){filesize=0}
if(filesize!=0)
{
tmp = read.table(namesfile,header=TRUE)
if(any(as.vector(tmp)!=0)) test = TRUE
# Infobox Contrast
output$InfoContrast <- renderInfoBox({
input$RunDESeq
input$AddContrast
input$AddContrastEasy
input$RemoveContrast
input$fileContrast
resDiff = ResDiffAnal()
res=NULL
if(!is.null(resDiff)){
res = infoBox("Contrasts", subtitle = h6("At least one contrast (non null) must be defined"), icon = icon("warning"),color = "light-blue",width=NULL,fill=TRUE)
test = FALSE
filesize = isolate(file.info(namesfile)[,"size"])
if(is.na(filesize)){filesize=0}
if(filesize!=0)
{
tmp = read.table(namesfile,header=TRUE)
if(any(as.vector(tmp)!=0)) test = TRUE
}
if(test) res = infoBox("Contrasts", subtitle = h6("Contrasts OK"), icon = icon("thumbs-o-up"),color = "green",width=NULL,fill=TRUE)
}
if(test) res = infoBox("Contrasts", subtitle = h6("Contrasts OK"), icon = icon("thumbs-o-up"),color = "green",width=NULL,fill=TRUE)
}
return(res)
})
output$contrastBox <- renderUI({
......@@ -819,14 +819,14 @@ output$InfoContrast <- renderInfoBox({
## Get the selected variable from the selected modality
Sel_Var = InterVar[which(unlist(lapply(as.data.frame(target[,InterVar]),FUN = function(x){input$Select1_contrast%in%x})))]
ModInterestCond = levels(target[,Sel_Var])
ModInterestCond = ModInterestCond[-which(ModInterestCond==input$Select1_contrast)]
updateSelectInput(session,"Select2_contrast","To",ModInterestCond)
})
observeEvent(input$Select1_contrast,{
ModifMod_ContEasy()
......@@ -846,6 +846,8 @@ output$InfoContrast <- renderInfoBox({
ModInterestAll = unique(unlist(lapply(as.data.frame(target[,InterVar]),levels)))
ModInterestAll = unique(unlist(lapply(as.data.frame(target[,InterVar]),levels)))
updateSelectInput(session, "Select1_contrast",label="Compare",ModInterestAll)
})
......@@ -917,8 +919,8 @@ output$InfoContrast <- renderInfoBox({
}
})
output$contrastDefined <- renderUI({
resDiff = ResDiffAnal()
......@@ -929,8 +931,8 @@ output$InfoContrast <- renderInfoBox({
column(width=11,
selectInput("ContrastList","Contrasts","",multiple=TRUE,size=4,selectize=FALSE,width = '100%'),
fluidRow(
column(width=6,actionButton("RemoveContrast","Remove",icon = icon("remove"))),
column(width=6,downloadButton("exportContrast", "Export"))
column(width=6,actionButton("RemoveContrast","Remove",icon = icon("remove"))),
column(width=6,downloadButton("exportContrast", "Export"))
),
htmlOutput("ContrastOverview")
)
......@@ -939,8 +941,8 @@ output$InfoContrast <- renderInfoBox({
)
}
})
ReadContrastFile <-reactive({
inFile <- input$fileContrast
......@@ -952,38 +954,38 @@ output$InfoContrast <- renderInfoBox({
return(res)
})