forked from jminnier/STARTapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-dotplot.R
115 lines (100 loc) · 4.42 KB
/
server-dotplot.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
## ==================================================================================== ##
# START Shiny App for analysis and visualization of transcriptome data.
# Copyright (C) 2016 Jessica Minnier
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# You may contact the author of this code, Jessica Minnier, at <[email protected]>
## ==================================================================================== ##
## ==================================================================================== ##
## Gene Data/ DOT PLOT variables
## ==================================================================================== ##
# loads list of genes on the server side
#observeEvent(input$upload_data,ignoreNULL = TRUE, {
observe({
print("server-dotplot-update")
data_analyzed = analyzeCountDataReactive()
tmpgeneids = data_analyzed$geneids
data_analyzedgenes = as.character(unlist(tmpgeneids))
tmpgroups = data_analyzed$group_names
#data_analyzedgenes = c("a","b","c")
#
tmpynames = data_analyzed$data_long%>%select(-unique_id,-sampleid,-group)%>%colnames()
updateSelectizeInput(session,'sel_gene',
choices= data_analyzedgenes,
server=TRUE)
updateCheckboxGroupInput(session,'sel_group',
choices=tmpgroups, selected=tmpgroups)
updateRadioButtons(session,'sel_gene_header',
choices=colnames(tmpgeneids))
updateRadioButtons(session,"ytype",
choices=sort(tmpynames,decreasing = TRUE))
#
#
# output$geneurl <- renderText({
# genename = input$sel_gene_rna # this needs to be fixed to have a gene_name to look up
# # need to have annotation to get gene name always
# out = ""
# if(length(genename)>0) {out <- paste0(out,"<p>Click for Info:</p>")}
# for(gene in genename) {
# tmprow = (unique(as.numeric(unlist(apply(tmpgeneids,2,function(k) match(gene,k,nomatch =0))))))
# tmpout = tmpgeneids[tmprow,]
#
# #if(gene%in%tmpgeneids$gene.id) gene = as.character(mousedata$gene.name[match(gene,mousedata$gene.id)])
#
# out <- paste(out,"<p>",gene,":",
# paste0("<a href=\"http://www.genecards.org/cgi-bin/carddisp.pl?gene=",
# gene,"\" target=\"_blank\">Genecards;</a>"),
# paste0("<a href=\"http://www.ncbi.nlm.nih.gov/gene/?term=(",
# gene,"%5BGene+Name%5D)+AND+(Mus+musculus%5BOrganism%5D+)\" target=\"_blank\">NCBI:gene</a></p>")
# )
# }
# out
# })
#
#
})
#Show dotplot
output$dotplot <- renderPlotly({
print("drawing dotplot")
validate(need(length(input$sel_gene)>0,"Please select a gene."))
validate(need(length(input$sel_group)>0,"Please select group(s)."))
data_analyzed = analyzeCountDataReactive()
data_long = data_analyzed$data_long
geneids = data_analyzed$geneids
dotplot_fun(data_long = data_long,geneids = geneids,
genelabel=input$sel_gene_header,
sel_group=input$sel_group,sel_gene=input$sel_gene,
#log2y=input$log2cpm_checked,
ytype=input$ytype)
}) #renderPlot
#Based on dotplot filters create data
DataDotplotReactive <- reactive({
print("DataDotplotReactive")
data_analyzed = analyzeCountDataReactive()
subdat = dotplot_dat(data_long = data_analyzed$data_long,geneids = data_analyzed$geneids,
sel_group=input$sel_group,sel_gene=input$sel_gene,
ytype=input$ytype)
return(subdat)
})
output$dat_dotplot <- DT::renderDataTable({
tmpdat = DataDotplotReactive()
tmpdat[,sapply(tmpdat,is.numeric)] <- signif(tmpdat[,sapply(tmpdat,is.numeric)],3)
DT::datatable(tmpdat)
}
)
output$downloadSubsetData <- downloadHandler(
filename = c('dotplot_data.csv'),
content = function(file) {write.csv(DataDotplotReactive(), file, row.names=FALSE)}
)