Commit 297362bf authored by Amine  GHOZLANE's avatar Amine GHOZLANE

solved merging

parents ed1db183 391bf3cc
......@@ -46,7 +46,7 @@ Plot_Visu_Heatmap_FC <- function(input, BaseContrast, resDiff, ContrastListDebou
##############################
## P VALUE DENSITY PLOT
##############################
Plot_pValue_Density <- function(input, BaseContrast, resDiff, ContrastListDebounce, alphaVal){
Plot_pValue_Density <- function(input, BaseContrast, resDiff, ContrastListDebounce, alphaVal, InputpValueDensityfocus){
res = NULL
#SelContrast = input$ContrastList_table_FC
SelContrast = ContrastListDebounce()
......@@ -64,8 +64,10 @@ Plot_pValue_Density <- function(input, BaseContrast, resDiff, ContrastListDeboun
data <- rbind(data, data_cont)
}
data$contrast <- factor(data$contrast, levels = SelContrast)
# uncomment to zoom (X axis between 0 and input$alphaVal) (use "+ xlim(0,as.numeric(alphaVal))" instead, to redraw geom_density with only data under threshold)
p <- ggplot(data, aes(x = padj, color = contrast, fill = contrast)) + geom_density(alpha = input$fillOpacity, size = input$lineWidth) + theme_minimal() #+ coord_cartesian(xlim = c(0,as.numeric(alphaVal)))
p <- ggplot(data, aes(x = padj, color = contrast, fill = contrast)) + theme_minimal()
InputpValueDensityfocus() # for reactivity
if(isolate(input$adaptBWtoFocus)){p <- p + geom_density(alpha = input$fillOpacity, size = input$lineWidth, adjust = as.numeric(alphaVal), n = 2 ^ (input$numberPoints))}else{p <- p + geom_density(alpha = input$fillOpacity, size = input$lineWidth, adjust = 1, n = 2 ^ (input$numberPoints))}
if(isolate(input$focusUnderThreshold)){p <- p + coord_cartesian(xlim = c(0,as.numeric(alphaVal)))}
p <- p + theme(axis.title = element_text(size = input$FontSizepValueDensity),
axis.text = element_text(size = input$FontSizepValueDensity),
legend.title = element_text(size = input$FontSizepValueDensity),
......@@ -130,8 +132,6 @@ Plot_Comp_Logit <- function(input, BaseContrast, resDiff, SelectTaxoPlotCompDebo
ylab = paste("logit p value", input$Contrast2),
hover_opacity = 1,
tooltip_text = row.names(padj),
# xlim = xlimits,
# ylim = ylimits,
lines = if (input$showSignifThresholdsLogitPlot) {
if(input$showDiagonal){
data.frame(
......@@ -180,8 +180,6 @@ Plot_Comp_Logit <- function(input, BaseContrast, resDiff, SelectTaxoPlotCompDebo
# dom_id_reset_zoom = "scatterD3-reset-zoomLogit",
# dom_id_svg_export = "scatterD3-svg-exportLogit",
# menu = FALSE,
# height = input$heightVolcanoPlot,
# width=if(input$modifwidthVolcano){input$widthVolcanoPlot},
# disable_wheel = TRUE
)
}
......@@ -219,13 +217,20 @@ Plot_Comp_Logit <- function(input, BaseContrast, resDiff, SelectTaxoPlotCompDebo
##############################
Plot_Visu_Venn <- function(input,BaseContrast,resDiff, ContrastListVennDebounce, export=FALSE){
res = NULL
contrasts_without_diff = NULL
#SelContrast = input$ContrastList_table_FCVenn
SelContrast = ContrastListVennDebounce()
if(length(SelContrast)>=2 & length(SelContrast)<=4){
data = GetData_venn(input,SelContrast,BaseContrast,resDiff)$res
gotData = GetData_venn(input,SelContrast,BaseContrast,resDiff)
data2 = gotData$df.tot
if(length(SelContrast) - length(colnames(data2[sapply(data2,function(x) all(is.na(x)))])) < 2){contrasts_without_diff = colnames(data2[sapply(data2,function(x) all(is.na(x)))])
}
else{
data = gotData$res
res = venn_tooltip(d3vennR(data=data))
}
return(res)
}}
return(list(res = res, contrasts_without_diff=contrasts_without_diff))
}
##############################
......@@ -234,10 +239,16 @@ Plot_Visu_Venn <- function(input,BaseContrast,resDiff, ContrastListVennDebounce,
Plot_UpSet <- function(input,BaseContrast, resDiff, ContrastListDebounce, export=FALSE){
plot = NULL
df = NULL
contrasts_without_diff = NULL
#SelContrast = input$ContrastList_table_FC
SelContrast = ContrastListDebounce()
if(length(SelContrast)>=2){
data = GetData_venn(input,SelContrast,BaseContrast,resDiff)$df.tot
gotData = GetData_venn(input,SelContrast,BaseContrast,resDiff)
data = gotData$df.tot
if(length(SelContrast) - length(colnames(data[sapply(data,function(x) all(is.na(x)))])) < 2){contrasts_without_diff = colnames(data[sapply(data,function(x) all(is.na(x)))])
}
else{
listInput <- list()
n <- ncol(data)
for(i in 1:n){
......@@ -274,19 +285,27 @@ Plot_UpSet <- function(input,BaseContrast, resDiff, ContrastListDebounce, export
maxRow = max(apply(df,2,FUN=function(x) length(which(!is.na(x)))))
df = df[1:max(maxRow,1),]
df = df[,which(apply(!is.na(df),2,any))]
}
return(list(plot=plot,table=df))
}}
return(list(plot=plot,table=df, contrasts_without_diff=contrasts_without_diff))
}
##############################
## MULTIPLE VENN COMPAIR
## Contrasts comparison
##############################
Plot_MultipleVenn <- function(input,BaseContrast, resDiff, ContrastListDebounce){
plot = NULL
contrasts_without_diff = NULL
SelContrast = ContrastListDebounce()
if(length(SelContrast)>=2){
data = GetData_venn(input,SelContrast,BaseContrast,resDiff)$res_multiple_venn
gotData = GetData_venn(input,SelContrast,BaseContrast,resDiff)
data2 = gotData$df.tot
if(length(SelContrast) - length(colnames(data2[sapply(data2,function(x) all(is.na(x)))])) < 2){contrasts_without_diff = colnames(data2[sapply(data2,function(x) all(is.na(x)))])
}
else{
data = gotData$res_multiple_venn
plot <- ggplot(data,aes(x=x,y=y)) + geom_point() + theme_bw() +
geom_label_repel(aes(label=name), size = input$labelSizemultipleVenn) + xlim(c(0,1)) + ylim(c(0,1)) +
......@@ -294,8 +313,8 @@ Plot_MultipleVenn <- function(input,BaseContrast, resDiff, ContrastListDebounce)
ylab(bquote(Contrast1 *intersect(Contrast2) ~ "/ Contrast2"))
plot <- plot + theme(axis.title = element_text(size = input$FontSizeMultipleVenn),
axis.text = element_text(size = input$FontSizeMultipleVenn - 2))
}
return(plot)
}}
return(list(plot = plot, contrasts_without_diff=contrasts_without_diff))
}
......@@ -342,20 +361,17 @@ Get_log2FC_padj <-function(input,BaseContrast,resDiff, info = NULL)
independentFiltering=input$IndFiltering,alpha=alpha)
}
log2FC = as.matrix(round(result[[SelContrast[1]]][, "log2FoldChange"], 3))
#padj = as.matrix(round(result[[SelContrast[1]]][, "padj"], 3))
padj = as.matrix((result[[SelContrast[1]]][, "padj"]))
if(nbCont>1)
{
for(i in 2:nbCont)
{
log2FC = cbind(log2FC,round(result[[SelContrast[i]]][, "log2FoldChange"], 3))
#padj = cbind(padj,round(result[[SelContrast[i]]][, "padj"], 7))
padj = cbind(padj,(result[[SelContrast[i]]][, "padj"]))
}
}#
colnames(log2FC) = names(result)
colnames(padj) = names(result)
#}
}
colnames(log2FC) = names(result)
colnames(padj) = names(result)
rownames(log2FC) = rownames(result[[SelContrast[1]]])
rownames(padj) = rownames(result[[SelContrast[1]]])
......@@ -429,7 +445,7 @@ venn_tooltip <- function(venn){
}
## Transform the data for the venn diagram
## Transform the data for the venn diagram and the "contrasts comparison"
GetData_venn <-function(input,SelContrast,BaseContrast,resDiff)
{
res = list()
......@@ -506,7 +522,7 @@ GetData_venn <-function(input,SelContrast,BaseContrast,resDiff)
}
}
}
# For 'Multiple Venn Compair'
# For 'Contrasts comparison'
if(i!=j) {
if (is.null(res_multiple_venn))
{res_multiple_venn <- data.frame(name = c(rownames_multiple_venn, paste(names.df[i],names.df[j], sep = " vs ")),
......
......@@ -154,13 +154,6 @@ Volcano_Plot <- function(input, data, export = FALSE) {
} else{
""
})
# labels <-
# sapply(names, function(name)
# if (is.element(name, points_to_label)) {
# name
# } else{
# ""
# })
if(!export){
plot <-
scatterD3(
......
......@@ -2,9 +2,9 @@
#@ visualisation plots of SHAMAN
###########################
## Barplot
###########################
## ##
## Barplot ####
## ##
Plot_Visu_Barplot <- function(input,resDiff)
{
......@@ -76,9 +76,9 @@ Plot_Visu_Barplot <- function(input,resDiff)
##################################
## ##
## Same plot in ggplot2 for export
##################################
## ##
tax.colors=rep(c("#1f77b4","#aec7e8","#ff7f0e","#ffbb78", "#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b",
"#c49c94","#e377c2","#f7b6d2","#7f7f7f", "#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"),ceiling(nbKept/20))
......@@ -99,9 +99,9 @@ Plot_Visu_Barplot <- function(input,resDiff)
##############################
## HEATMAP
##############################
## ##
## HEATMAP ####
## ##
Plot_Visu_Heatmap <- function(input,resDiff,export=FALSE){
VarInt = input$VisuVarInt
......@@ -144,9 +144,9 @@ Plot_Visu_Heatmap <- function(input,resDiff,export=FALSE){
##############################
## BOXPLOTS
##############################
## ##
## BOXPLOTS ####
## ##
Plot_Visu_Boxplot <- function(input,resDiff,alpha=0.7){
gg = NULL
......@@ -219,9 +219,9 @@ Plot_Visu_Boxplot <- function(input,resDiff,alpha=0.7){
return(gg)
}
##############################
## KRONA
##############################
## ##
## KRONA ####
## ##
Plot_Visu_Krona <- function(input,resDiff,CT_OTU,taxo_table){
res = NULL
......@@ -256,9 +256,9 @@ Plot_Visu_Krona <- function(input,resDiff,CT_OTU,taxo_table){
return(res)
}
##############################
## Phylo PLOT
##############################
## ##
## Phylo PLOT ####
## ##
Plot_Visu_Phylotree = function(input, resDiff, CT_OTU, taxo_table, treeseq){
res = NULL
VarInt = input$VisuVarInt
......@@ -296,9 +296,9 @@ Plot_Visu_Phylotree = function(input, resDiff, CT_OTU, taxo_table, treeseq){
}
##############################
## SCATTER PLOT
##############################
## ##
## SCATTER PLOT ####
## ##
Plot_Visu_Scatterplot<- function(input,resDiff,export=FALSE,lmEst = FALSE,CorEst=FALSE){
plot = NULL
......@@ -410,9 +410,9 @@ Plot_Visu_Scatterplot<- function(input,resDiff,export=FALSE,lmEst = FALSE,CorEst
##############################
## Diversity
##############################
## ##
## Diversity ####
## ##
Plot_Visu_Diversity <- function(input,resDiff,ForScatter=FALSE){
gg = NULL
dataTmp = NULL
......@@ -528,9 +528,9 @@ Plot_Visu_Diversity <- function(input,resDiff,ForScatter=FALSE){
}
##############################
## RAREFACTION
##############################
## ##
## RAREFACTION ####
## ##
Plot_Visu_Rarefaction <- function(input,resDiff,xlim,ylim,ylab="Species"){
PlotRare = NULL
......@@ -558,11 +558,11 @@ Plot_Visu_Rarefaction <- function(input,resDiff,xlim,ylim,ylab="Species"){
##############################################################
## ##
##
## Useful functions
## Useful functions ####
##
##############################################################
## ##
## Get the non-zero taxo by sample
TaxoNumber <- function (x, groups, mar = 1)
......@@ -795,9 +795,9 @@ CreateTableTree <- function(input,resDiff,CT_Norm_OTU,taxo_table,VarInt,ind_taxo
###########################
## ##
## Tree
###########################
## ##
## The count matrix must be given at the leaf level.
......@@ -833,9 +833,9 @@ Plot_Visu_Tree <- function(input,resDiff,CT_Norm_OTU,taxo_table)
return(res)
}
#############################
## ##
## NETWORK
#############################
## ##
Plot_network <- function(input,resDiff,availableTaxo, ind_taxo, qualiVariable, export = FALSE){
plot = NULL
......@@ -864,19 +864,19 @@ Plot_network <- function(input,resDiff,availableTaxo, ind_taxo, qualiVariable, e
adjacency <- matrix(mapply(function(a,b) {mapply(function(x,y){x*y}, x=a, y=b)}, a=pval_bool, b=cor_sgn), nrow = n)
rownames(adjacency) <- colnames(countsMatrix)
colnames(adjacency) <- colnames(countsMatrix)
# ### Remove rows and columns with only NA
# ### Remove rows and columns with only NA # this way, elements with the same count in all sample (often 0 in this case) will not appear
# adjacency <- adjacency[apply(adjacency, 1, function(y) !all(is.na(y))),]
# adjacency <- t(adjacency)
# adjacency <- adjacency[apply(adjacency, 1, function(y) !all(is.na(y))),]
# adjacency <- t(adjacency)
### Replace NA by zeros (ie "no correlation")
### Replace NA by zeros (ie "no correlation") # this way, those elements will appear as single nodes
adjacency[is.na(adjacency)] <- 0
adjacency <- adjacency[,ind_taxo]
adjacency <- adjacency[ind_taxo,]
igraphGraph <- graph_from_adjacency_matrix(adjacency, diag = FALSE, mode = "upper" , weighted = TRUE) # "upper" for adjusted p-value, lower for p-value not adjusted
igraphGraph <- graph_from_adjacency_matrix(adjacency, diag = FALSE, mode = "upper" , weighted = TRUE) # mode = "upper" for adjusted p-value, mode = "lower" for p-value not adjusted
list_to_label <- isolate(input$ToLabelNetwork)
dataVN <- toVisNetworkData(igraphGraph)
......@@ -898,7 +898,7 @@ Plot_network <- function(input,resDiff,availableTaxo, ind_taxo, qualiVariable, e
plot <- visNetwork(nodes = dataVN$nodes, edges = dataVN$edges)
plot <- visIgraphLayout(plot, layout = "layout_nicely", physics = FALSE, smooth = FALSE)
plot <- visNodes(plot, size = 20) #, scaling = list(label = list(min = 30, max = 30, maxVisible = 30)))
plot <- visNodes(plot, size = 20)
plot <- visEdges(plot, width = 1)
plot <- visOptions(plot, width = if(isolate(input$modifwidthVisu)){isolate(input$widthVisu)}, height = isolate(input$heightVisu), autoResize = FALSE)
#plot <- visLegend(plot, addEdges = data.frame(color = c("red", "blue"), label = c("Positive correlation","Negative correlation")))
......
......@@ -2,11 +2,11 @@ shinyServer(function(input, output,session) {
hide(id = "loading-content", anim = TRUE, animType = "fade",time=1.5)
hide(id = "loading-content-bar", anim = TRUE, animType = "fade",time=1.5)
#####################################################
### ###
##
## LOAD FILES
#### LOAD FILES ####
##
#####################################################
### ###
......@@ -519,11 +519,11 @@ shinyServer(function(input, output,session) {
## output of plot_filter is ggplot class
plot_filter(counts,input$SliderThSamp,input$SliderThAb,type="Scatter")
})
#####################################################
### ###
##
## DYNAMIC MENU
## DYNAMIC MENU ####
##
#####################################################
### ###
......@@ -557,11 +557,11 @@ shinyServer(function(input, output,session) {
#####################################################
### ###
##
## DATA TABLE
## DATA TABLE ####
##
#####################################################
### ###
## Counts Table
output$DataCounts <- DT::renderDataTable(
......@@ -716,11 +716,10 @@ shinyServer(function(input, output,session) {
return(res)
})
#####################################################
### ###
##
## TARGET FILE
##
#####################################################
## TARGET FILE ####
### ###
observe({
counts = dataInput()$data$counts
data = dataInput()$data$target
......@@ -811,11 +810,11 @@ shinyServer(function(input, output,session) {
#############################################################
### ###
##
## MASQUE
## MASQUE ####
##
#############################################################
### ###
......@@ -1187,7 +1186,7 @@ shinyServer(function(input, output,session) {
htmltools::HTML('<img src="icons/underhill.png" alt="dna" style="width:80px;height:80px;">')
)
#####################################
### ###
......@@ -1982,6 +1981,24 @@ shinyServer(function(input, output,session) {
return(res)
})
## Run button
output$RunButton <- renderUI({
res = NULL
ChTM = "Error"
target = values$TargetWorking
labeled = values$labeled
CT = dataInput()$data$counts
taxo = input$TaxoSelect
VarInt = input$InterestVar
## Return NULL if there is no error
if(!is.null(target) && length(VarInt)>=1) ChTM = CheckTargetModel(input,target,labeled,CT)$Error
if(!is.null(target) && taxo!="..." && is.null(ChTM) && length(VarInt)>=1) res = actionButton("RunDESeq",strong("Run analysis"),icon = icon("caret-right"))
return(res)
})
## Var for normalization
output$SelectVarNorm <- renderUI({
......@@ -2147,11 +2164,11 @@ shinyServer(function(input, output,session) {
#####################################################
### ###
##
## DEFINE CONTRAST
## DEFINE CONTRAST ####
##
#####################################################
### ###
output$contrastMat <- renderUI({
......@@ -2595,11 +2612,11 @@ shinyServer(function(input, output,session) {
}, priority=1)
#####################################################
### ###
##
## DESEQ2 run
## DESEQ2 run ####
##
#####################################################
### ###
......@@ -2641,11 +2658,11 @@ shinyServer(function(input, output,session) {
})
#####################################################
### ###
##
## Taxonomy
## Taxonomy ####
##
#####################################################
### ###
# Infobox Contrast
......@@ -2795,11 +2812,11 @@ shinyServer(function(input, output,session) {
#####################################################
### ###
##
## Diagnostic plots
## DIAGNOSTIC PLOTS ####
##
#####################################################
### ###
......@@ -3021,11 +3038,11 @@ shinyServer(function(input, output,session) {
#####################################################
### ###
##
## EXPORT DIAG GRAPH
## EXPORT DIAG GRAPH ####
##
#####################################################
### ###
#### Export Diag
output$exportdiag <- downloadHandler(
......@@ -3043,11 +3060,11 @@ shinyServer(function(input, output,session) {
}
)
#####################################################
### ###
##
## EXPORT VISU GRAPH
## EXPORT VISU GRAPH ####
##
#####################################################
### ###
#### Export Visu
......@@ -3091,16 +3108,16 @@ shinyServer(function(input, output,session) {
if(is.na(filesize)){filesize=0}
if(input$PlotVisuSelectComp=="Venn"){
if(filesize!=0) print(Plot_Visu_Venn(input,BaseContrast,ResDiffAnal(),ContrastListVennDebounce, export=TRUE))
if(filesize!=0) print(Plot_Visu_Venn(input,BaseContrast,ResDiffAnal(),ContrastListVennDebounce, export=TRUE)$res)
}
if(input$PlotVisuSelectComp=="Heatmap_comp"){
if(filesize!=0) Plot_Visu_Heatmap_FC(input,BaseContrast,ResDiffAnal(),ContrastListDebounce, SelectTaxoPlotCompDebounce, export=TRUE)
}
if(input$PlotVisuSelectComp=="pValueDensity"){
if(filesize!=0) print(Plot_pValue_Density(input, BaseContrast, ResDiffAnal(), ContrastListDebounce, input$AlphaVal))
if(filesize!=0) print(Plot_pValue_Density(input, BaseContrast, ResDiffAnal(), ContrastListDebounce, input$AlphaVal, InputpValueDensityfocus))
}
if(input$PlotVisuSelectComp=="multipleVenn"){
if(filesize!=0) print(Plot_MultipleVenn(input, BaseContrast, ResDiffAnal(), ContrastListDebounce))
if(filesize!=0) print(Plot_MultipleVenn(input, BaseContrast, ResDiffAnal(), ContrastListDebounce)$plot)
}
if(input$PlotVisuSelectComp=="UpSet"){
if(filesize!=0) print(Plot_UpSet(input, BaseContrast, ResDiffAnal(), ContrastListDebounce)$plot)
......@@ -3133,11 +3150,11 @@ shinyServer(function(input, output,session) {
)
#####################################################
### ###
##
## DIFF TABLES
## DIFF TABLES ####
##
#####################################################
### ###
# output$ContrastListTable <- renderUI({
......@@ -3281,29 +3298,12 @@ shinyServer(function(input, output,session) {
}
})
# output$TabBoxTablesPlot <- renderUI({
# tabBox(
# id = "tabBoxPlotTables",
# width = NULL,
# selected = "Bar chart",
# tabPanel(
# "Bar chart",
# amChartsOutput("BarChartTables", height = input$heightBarChartTables)
# ),
# tabPanel(
# "Volcano plot",
# scatterD3Output("VolcanoPlot", height = input$heightVolcanoPlot, width = input$widthVolcanoPlot)
# )
# )
# })
output$BarChartContainer <- renderUI({
fluidPage(amChartsOutput("BarChartTables", height = input$heightBarChartTables))
})
output$VolcanoPlotContainer <- renderUI({
fluidPage(scatterD3Output("VolcanoPlot", height = input$heightVolcanoPlot + 10, width=ifelse(input$modifwidthVolcano,input$widthVolcanoPlot,"100%")))#width = input$widthVolcanoPlot + 10))
fluidPage(scatterD3Output("VolcanoPlot", height = input$heightVolcanoPlot + 10, width=ifelse(input$modifwidthVolcano,input$widthVolcanoPlot,"100%")))
})
output$BarChartTables <- renderAmCharts({
......@@ -3328,10 +3328,9 @@ shinyServer(function(input, output,session) {
withProgress(message = "Loading...", Volcano_Plot(input, data))
})
#####################
###