-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage_enhancersDL.R
executable file
·100 lines (83 loc) · 3.82 KB
/
page_enhancersDL.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
library(shiny)
library(plotly)
library(dplyr)
library(GenomicRanges)
### ui ----
plot_EnhancerDL.ui <- function(id){
ns <- NS(id)
fluidPage(
fluidRow(
selectInput(inputId=NS(id, "cellType"),
label = "Cell type:",
choices = NULL,
selectize = TRUE),
selectInput(inputId=NS(id, "enhID"),
label = "Enhancer:",
choices = NULL,
selectize = TRUE)),
fluidRow(
column(10,
# imageOutput(NS(id, "dlPlot"), height="100px", inline=T))# "10%") # Does not resize... -.-
uiOutput(NS(id, "regionTitle")),
uiOutput(NS(id, "deepExplainerPlot")),
uiOutput(NS(id, "fullSizeLink")),
uiOutput(NS(id, "ucscLink")),
)) # %>% withSpinner(color="#0dc5c1")
)
}
### server ----
plot_EnhancerDL.server <- function(input, output, session, imgRootPath, dataPath) {
enhFiles <- readRDS(paste0(dataPath, file="DL_enhFiles.Rds"))
cellTypes <- unique(enhFiles$cellType)
# Initialization:
celltypeSelected <- cellTypes[1]
updateSelectInput(session, "cellType", choices=cellTypes, selected=celltypeSelected)
ctEnhancers <- enhFiles %>% filter(cellType==celltypeSelected) %>% dplyr::select(enhancer)
ctEnhancers <- as.character(ctEnhancers[,1])
updateSelectInput(session, "enhID", choices=ctEnhancers, selected=ctEnhancers[2])
# Start traking events (plots to show):
observe({
celltypeSelected <- input$cellType
# print(celltypeSelected)
if(!is.na(celltypeSelected)){
ctEnhancers <- enhFiles %>% filter(cellType==celltypeSelected) %>% dplyr::select(enhancer)
ctEnhancers <- as.character(ctEnhancers[,1])
updateSelectInput(session, "enhID", choices=ctEnhancers, selected=ctEnhancers[1])
}
})
observe({
enhSelected <- input$enhID
celltypeSelected <- input$cellType
# print(enhSelected)
if((!is.na(enhSelected)) && (enhSelected!="")){
# output$dlPlot <- renderImage(list(src = imgPath,contentType = "image/png", alt="Enhancer view"), delete=FALSE)
enhFileName <- enhFiles %>% filter((cellType==celltypeSelected) & (enhancer==enhSelected)) %>% dplyr::select(fileName) %>% as.character()
thumbFile <- file.path('deepExplainer/thumbnails', paste0(enhFileName, '_th.png'))
output$deepExplainerPlot <- renderUI(NULL)
if(file.exists(file.path(imgRootPath, thumbFile))){
output$deepExplainerPlot <- renderUI({tagList(img(src=thumbFile, alt='enhancer preview', width="100%"))})
}
else{
output$deepExplainerPlot <- renderUI({tagList(' - Thumbnail not available yet. Download the full file. -')})
}
output$fullSizeLink <- renderUI({
tagList(a("[View full size image]",
href=file.path(file.path('deepExplainer/img/', celltypeSelected, paste0(enhFileName, '.png'))),
target="_blank"))
})
output$regionTitle <- renderUI({tagList(enhFileName)}) # , "(", celltypeSelected, " enhancer: ", enhSelected, " region scored: ", "", ")"
toShow <- as.character(GenomicRanges::resize(GRanges(enhSelected), width=5000, fix="center"))
toShow <- sub(":", "%3A", toShow); toShow <- sub("-", "%2D", toShow)
enhSelected <- sub("-", "%3A", enhSelected); enhSelected <- sub("-", "%2D", enhSelected)
# toShow <- enhSelected
ucscURL <- paste0("http://genome.ucsc.edu/cgi-bin/hgTracks?db=dm6&hubUrl=http://ucsctracks.aertslab.org/papers/FlyBrain/hub.txt&position=", toShow,
"&highlight=dm6.", enhSelected, "%AAAAAACC")
output$ucscLink <- renderUI(
tagList(a("[View region in UCSC Genome Browser]",
href=ucscURL,
target="_blank")))
}
})
}
# Build page ----
page_enhancerArchitecture <- plot_EnhancerDL.ui("plot_DL")