forked from Ulas-lab/Shiny-Seq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVolcano_plot.R
85 lines (78 loc) · 2.44 KB
/
Volcano_plot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
source("functions.R")
Volcano_plot_UI<-function(id)
{
ns<-NS(id)
tagList(
uiOutput(ns("vol_comb")),
uiOutput(ns("vol_y")),
uiOutput(ns("vol_x")),
plotlyOutput(ns("volcano_plot"), width = "700px", height = "600px")
)
}
Volcano_plot<-function(input,output,session,combination,DE_genes,p_values,hypothesis_choice)
{
print("inside volcano plot line 14")
#combinations for volcano plot (A vs B, C vs D)
output$vol_comb <- renderUI({
if(!is.null(combination()))
{
#num <- length(combination())
num<- length(combination())
comb<-lapply(1:num, function(i) {
input$combination[i]
})
checklist<-list()
for (i in seq_along(comb)) {
checklist[[comb[[i]]]] = i
}
selectInput(session$ns("vol_choice"),label = h5("Choose comparison") ,
choices = checklist,selected = 1)
}
})
#Slider to adjust Y axis of volcano plot
output$vol_y<-renderUI({
if(!is.null(input$vol_choice))
{
num<- length(combination())
#Get the deseq2 dataset
res<-DE_genes()[[as.numeric(input$vol_choice)]][5] [[1]]
num<-(-log10(na.omit(res$padj)))
idx<-which(is.finite(num))
max<-max(round(num[idx],1))
#max<-(-log10(min(na.omit(res$padj))))
#max<-round(max,1)
sliderInput(session$ns("scale_voly"),"y-limit",0,max+5,value = max+2,step = 0.5)
}
})
#slider to adjust x axis of volcano plot
output$vol_x<-renderUI({
if(!is.null(input$vol_choice))
{
num<- length(combination())
#Get the deseq2 dataset
res<-DE_genes()[[as.numeric(input$vol_choice)]][5] [[1]]
max<-max(na.omit(abs(res$log2FoldChange)))
max<-round(max,1)
print(max)
sliderInput(session$ns("scale_volx"),"x-limit",0,max+5,value = max+2,step = 0.5)
}
})
#volcano plot
output$volcano_plot<- renderPlotly({
print("inside volcano plot line 64")
req(input$vol_choice)
req(input$scale_volx)
req(input$scale_voly)
if(!is.null(input$vol_choice) & !is.null(input$scale_volx) & !is.null(input$scale_voly))
{
print("inside volcano plot line 69")
volcano_plot(input$vol_choice,combination(),DE_genes(),input$scale_volx,input$scale_voly,p_values(),hypothesis_choice())[[2]]
}
else plotly_empty()
})
return(list(
input_scale_volx=reactive({input$scale_volx}),
input_scale_voly=reactive({input$scale_voly}),
hypothesis_choice=reactive({hypothesis_choice()})
))
}