-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpression_section.R
More file actions
135 lines (114 loc) · 5.44 KB
/
expression_section.R
File metadata and controls
135 lines (114 loc) · 5.44 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
expression<-list()
expression$id <- "expression"
expression$title <- "Expression Data"
expression$loadData<- function(){
#read the average expression data for the brain and substantia nigra and single cell data
expressionData <<- fread("www/expression/ExpressionData.csv")
colnames(expressionData) <<- c("GENE","GTEX_BRAIN_all","GTEX_nigra","SN Astrocyte","SN-Dop. Neuron","SN Endothelial","SN-GABA Neuron","SN Microglia","SN ODC","SN OPC")
}
expression$generateUI<- function(){
div(
fluidRow(
column(div(uiOutput('expressionSelectUI'),class="geneselect"),width =2)
),
fluidRow(
column(tabsetPanel(type="pills",
tabPanel("Table",
fluidRow(
column(dataTableOutput("expressionTable"), width = 12)
)
),
tabPanel("Single Cell Expression Bar Plot",
fluidRow(
column(align = "center", plotlyOutput("SingleCellPlot"), width = 12)
)
),
tabPanel("GTEx Expression Violin Plot",
fluidRow(
column(align = "center", h4("GTEx Expression Plot"), width = 12)
),
fluidRow(
column( align = "center", imageOutput("GTEXPlot", width = "40%", height = "auto"), width = 12)
)
),
selected = "Table"
)
,width = 12)
)
)
}
expression$serverLogic <- function(input,output,session,reactives)
{
#populate the dropdown using the reactive value
output$expressionSelectUI <- renderUI({
dropDownGenes <- (evidence[(evidence$RSID == reactives$selRiskVariant()$RSID & (evidence$GWAS == reactives$selRiskVariant()$GWAS)),]$GENE)
#add "All Genes" to the list for the other drop downs
dropDownGenes <- append(dropDownGenes, "All Genes", 0)
#default selected to the first in the list
selected_gene <- dropDownGenes[1]
#if there was a searched gene, select that
if(reactives$searchedGene()!="")
{
selected_gene <-dropDownGenes[match(toupper(reactives$searchedGene()), toupper(as.vector(dropDownGenes)))]
}
selectInput("expressionSelect",label = "Choose a gene", choices = dropDownGenes, selected = selected_gene)
})
#render expression table using genes matching the selected locus in the evidence table
output$expressionTable <- renderDT({
tableData <- NULL
#by default assume 'All Genes' option is selected
if(is.null(input$expressionSelect))
{
tableData <- expressionData[expressionData$GENE %in% (evidence[evidence$LOC_NUM== (reactives$selRiskVariant()$LOC_NUM) & evidence$GWAS == reactives$selRiskVariant()$GWAS,]$GENE),]
scrollYVal <- 300
}
else
{
if(input$expressionSelect=="All Genes")
{
tableData <- expressionData[expressionData$GENE %in% (evidence[evidence$LOC_NUM== (reactives$selRiskVariant()$LOC_NUM) & evidence$GWAS == reactives$selRiskVariant()$GWAS,]$GENE),]
scrollYVal <- 300
}
else
{
tableData <- expressionData[expressionData$GENE == input$expressionSelect,]
scrollYVal <- 50
}
}
colnames(tableData)[colnames(tableData)=='GENE']<-'Gene'
datatable(tableData, rownames = F, options = list(processing = F, searching = F, paginate = F, dom = 't', scrollY = paste0(scrollYVal,"px"), scrollX = T, columnDefs = list(list(
targets = c(1:9),
render = JS(
"function(data, type, row, meta) {",
"return (data==null) ? 'NA' : data.toFixed(2);",
"}"
)))))
})
#load the gtex plot
output$GTEXPlot <- renderImage({
no_plot_str <-""
if(input$expressionSelect!='All Genes')
{
no_plot_str <-paste0("No GTEx violin plot for ", input$expressionSelect)
}
else
{
no_plot_str <- "Please select a gene"
}
filename <- paste0("www/expression/gtex_plots/",input$expressionSelect,"_gtex8_expression.png")
list(src = filename, contentType = 'image/png', width = '100%', alt = no_plot_str)
# filename <- paste0("www/expression/gtex_plots/",input$GTEXSelect,"_gtex8_expression.png")
# list(src = filename, contentType = 'image/png', width = '100%', alt = "No Violin Plot for Gene")
}, deleteFile = FALSE)
#create plotly bar plot for single cell expression data
output$SingleCellPlot <- renderPlotly({
plotData <- NULL
if(input$expressionSelect!="All Genes")
{
plotData <- expressionData[expressionData$GENE == input$expressionSelect,] %>% select("SN Astrocyte","SN-Dop. Neuron","SN Endothelial", "SN-GABA Neuron", "SN Microglia", "SN ODC" ,"SN OPC")
colnames(plotData)<- c("Astrocyte","DaN","Endothelial", "GABA","Microglia","ODC","OPC")
plotData <- setDT(as.data.frame(t(plotData)), keep.rownames = "cell_types")[]
p <- plot_ly(data = plotData,x = plotData$V1, y = plotData$cell_types, type = "bar",orientation = "h") %>% layout(xaxis = list(title = "Gene Expression (TPM)") ) %>% plotly::config(modeBarButtonsToRemove = c("zoomIn2d", "zoomOut2d", "zoom2d","pan2d","select2d","lasso2d","toggleSpikelines","autoScale2d"),displaylogo=FALSE)
}
})
}