-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
375 lines (307 loc) · 12.7 KB
/
app.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(ggplot2)
library(dplyr)
library(maps)
library(ggmap)
library(mongolite)
library(lubridate)
library(gridExtra)
library("XML")
library("methods")
library(xml2)
library(tidyverse)
library(rvest)
library(hash)
library(heatmaply)
source("HsaggregateQueries.R")
source("MusMusculusaggregateQueries.R")
source("HsEntrezGeneQueries.R")
source("MmEntrezGeneQueries.R")
source("MongoDBConnection.R")
source("HsaggregateQueries.R")
source("NA12878phasingdataqueries.R")
library(Hmisc)
library(shinythemes)
# Define UI for application that draws a histogram
ui <- fluidPage(
theme = shinytheme("cerulean"),
# Application title
titlePanel("Entrez Data Visualizer (Hs and Mm)"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
titlePanel("Input parameters"),
sidebarPanel(uiOutput("Choice of box plot")),
selectInput(
inputId = 'organism',
label = 'Choose a organism',
choices = c('human', 'mouse'),
),
uiOutput('chosenorganism'),
selectInput(
inputId = "ChoiceOfBoxPlot",
label = "Choose gene function, whose distribution is to be viewed across human chromosomes",
choices = c(
"Protein coding genes (human)",
"Lysosomal genes (human)",
"Musculoskeletal genes (human)",
"Protein coding genes (mouse)",
"Lysosomal genes (mouse)",
"Musculoskeletal genes (mouse)",
"NA12878 phasing data distribution (phase1)",
"NA12878 phasing data distribution (phase2)"
)
),
uiOutput("secondSelection"),
numericInput(
inputId = "numberofrecordstodisplay",
label = "Number of observations to view:",
value = 62839,
min = 100
),
#dataTableOutput("mousedataview"),
#dataTableOutput("humandataview"),
#fileInput("files", "Choose File", multiple = TRUE),
#checkboxInput("center", "Center", TRUE),
#selectInput("cv", "cross-validation",
# list (none =
# "none", Q2 = "q2")),
#checkboxInput("outliers", "Show outliers", TRUE)
# selectInput(
# "scaling",
# "Scale",
# list(
# none = "none",
# "unit variance" = "uv",
# pareto = "pareto"
# )
# ),
uiOutput("PCs"),
),
# Show a plot of the generated distribution
mainPanel(
h3(textOutput("caption", container = span)),
plotOutput("boxPlot"),
verbatimTextOutput("summary"),
dataTableOutput("humandataview"),
dataTableOutput("mousedataview")
)
)
)
# Define server logic required to draw a histogram
#' Title
#'
#' @param input
#' @param output
#' @param session
#'
#' @return
#' @export
#'
#' @examples
server <- function(input, output, session) {
values <- reactiveValues()
homosapiensmongodbconnection = dbconnectionhs()
musmusculusphasingdatadbconnection = dbconnectionphasing()
musmusculusentrezgenedbconnection = dbconnectionmm()
getStatus <- reactive({
if (input$organism == 'human') {
values$result <- 'human'
} else if (input$choice == 'mouse') {
values$result <- 'mouse'
}
})
# get count of number of records in human and mouse entrez datasets
humanentrezgenerecords = HsEntrezGeneQueries(entrezhsallrecords(homosapiensmongodbconnection))
mouseentrezgenerecords = MmEntrezGeneQueries(entrezMmallrecords(musmusculusentrezgenedbconnection))
output$numrecords <-
renderUI({
if(input$organism == 'human') {
numericInput(
inputId = "humannumberofrecordstodisplay",
label = "Number of observations to view:",
value = humanentrezgenerecords,
min = 100
)
}
else if (input$organism == 'mouse') {
numericInput(
inputId = "mousenumberofrecordstodisplay",
label = "Number of observations to view:",
value = mousentrezgenerecords,
min = 100
)}
})
observeEvent(input$controller, {
# We'll use the input$controller variable multiple times, so save it as x
# for convenience.
controller <- input$controller
updateNumericInput(session, "numberofrecordstodisplay", value = controller)
#updateNumericInput(session, "inNumber2",
# label = paste("Number label ", x),
# value = x, min = x-10, max = x+10, step = 5)
})
output$chosenorganism <- renderUI({
if (input$organism == 'human') {
values$organism <- 'human'
selectInput(
inputId = c("humanqueries"),
label = 'Choice of datasets for visualization',
choices = c(
"All distinct genes for species homo sapiens in Entrez",
"Gene Symbol and Synonyms for species homo sapiens in Entrez",
"Count of all genes for species homo sapiens in Entrez",
"Gene Symbols, Synonyms, Feature types for homo sapines in Entrez",
"List of all locus tags",
"Gene Symbols and db cross references",
"Gene Symbols and chromosomal map locations",
"Gene Types",
"Gene, Description and Feature type"
)
)
} else if (input$organism == 'mouse') {
values$organism <- 'mouse'
selectInput(
inputId = c("mousequeries"),
label = 'Choice of datasets for visualization',
choices = c(
"All distinct genes for species mus musculus in Entrez",
"Count of all genes for species mus musculus in Entrez",
"Gene Symbols, Synonyms, Feature types for mus musculus in Entrez",
"List of all locus tags",
"Gene Symbols and db cross references",
"Gene Symbols and chromosomal map locations",
"Gene Types",
"Gene, Description and Feature type"
)
)
}
})
boxpolottobedisplayed <- reactive({
switch (
input$ChoiceOfBoxPlot,
"Protein coding genes (human)" = findNumberOfProteinCodingGenesPerChromosome(homosapiensmongodbconnection),
"Lysosomal genes (human)" = findNumberOflysosomalGenesPerChromosome(homosapiensmongodbconnection),
"Musculoskeletal genes (human)" = findNumberOfskeletalmuscleGenesPerChromosome(homosapiensmongodbconnection),
"Protein coding genes (mouse)" = findNumberOfProteinCodingGenesPerChromosomeMouse(musmusculusentrezgenedbconnection),
"Lysosomal genes (mouse)" = findNumberOflysosomalGenesPerChromosomeMouse(musmusculusentrezgenedbconnection),
"Musculoskeletal genes (mouse)" = findNumberOfskeletalmuscleGenesPerChromosomeMouse(musmusculusentrezgenedbconnection),
"NA12878 phasing data distribution (phase1)" = getdistributionofphasedsequencelengthphase1(musmusculusphasingdatadbconnection),
"NA12878 phasing data distribution (phase2)" = getdistributionofphasedsequencelengthphase2(musmusculusphasingdatadbconnection)
)
})
data <- eventReactive(input$displayrecords, {
# get the data from
dataset <- datasetToBeDisplayed()
df <- data.frame()
df
})
output$summarytable <- renderDataTable({
data()
})
# Count of protein coding genes by chromosome
proteincodingboxplotdata <-
findNumberOfProteinCodingGenesPerChromosome(homosapiensmongodbconnection)
lysosomalgenesboxplotdata <-
findNumberOflysosomalGenesPerChromosome(homosapiensmongodbconnection)
skeletalmuscleboxplotdata <-
findNumberOfskeletalmuscleGenesPerChromosome(homosapiensmongodbconnection)
# NA12878phasingdatatsvformat=read.csv(
# "NA12878_sv_phasing.tsv",
# sep="\t",
# header=TRUE,
# quote="\"",
# comment.char="",
# fill=TRUE)
# musmusculusdbconnection$insert(NA12878phasingdatatsvformat)
updateNA12878phasingrecords(musmusculusphasingdatadbconnection)
humandatasetToBeDisplayed <- reactive({
switch(
input$humanqueries,
"Count of all genes for species homo sapiens in Entrez" = HsEntrezGeneQueries(entrezhsallrecords(homosapiensmongodbconnection)),
"All distinct genes for species homo sapiens in Entrez" = entrezhsdistinctgeneids(entrezhsallrecords(homosapiensmongodbconnection)),
"Gene Symbol and Synonyms for species homo sapiens in Entrez" = hsSymbolsSynonymsFeaturetype(entrezhsallrecords(homosapiensmongodbconnection)),
"Gene Symbols, Synonyms, Feature types for homo sapines in Entrez" = hsSymbolsSynonymsFeaturetype(entrezhsallrecords(homosapiensmongodbconnection)),
"List of all locus tags" = hsLocusTags(entrezhsallrecords(homosapiensmongodbconnection)),
"Gene Symbols and db cross references" = geneSymbolsAnddbCrossRefs(entrezhsallrecords(homosapiensmongodbconnection)),
"Gene Symbols and chromosomal map locations" = genesymbolandmaplocation(entrezhsallrecords(homosapiensmongodbconnection)),
"Gene Types" = extractTypeOfGene(entrezhsallrecords(homosapiensmongodbconnection)),
"Gene, Description and Feature type" = extractdescriptionfeaturetype(entrezhsallrecords(homosapiensmongodbconnection)),
)
})
mousedatasetToBeDisplayed <- reactive({
switch(
input$mousequeries,
#Choice for the mouse aggregate queries
"Count of all genes for species mus musculus in Entrez" = MmEntrezGeneQueries(entrezMmallrecords(musmusculusentrezgenedbconnection)),
"All distinct genes for species mus musculus in Entrez" = entrezMmdistinctgeneids(entrezMmallrecords(musmusculusentrezgenedbconnection)),
"Gene Symbols, Synonyms, Feature types for mus musculus in Entrez" = MmSymbolsSynonymsFeaturetype(entrezMmallrecords(musmusculusentrezgenedbconnection)),
"List of all locus tags" = MmLocusTags(entrezMmallrecords(musmusculusentrezgenedbconnection)),
"Gene Symbols and db cross references" = geneSymbolsAnddbCrossRefs(entrezMmallrecords(musmusculusentrezgenedbconnection)),
"Gene Symbols and chromosomal map locations" = genesymbolandmaplocation(entrezMmallrecords(musmusculusentrezgenedbconnection)),
"Gene Types" = extractTypeOfGene(entrezMmallrecords(musmusculusentrezgenedbconnection)),
"Gene, Description and Feature type" = extractdescriptionfeaturetype(entrezMmallrecords(musmusculusentrezgenedbconnection))
)
})
# observeEvent(
# {
# input$humanqueries
# input$mousequeries
# },
# {
# df1 <- input$humanqueries
# df2 <- input$mousequeries
# }
# )
# add a column to find location on chromosome and find average coordinates of that...
# for now, modification date is place holder for average field
# total genes per chromosome for mouse entrez gene data
#mmtotalgenesperchromosome <- musmusculusdbconnection$aggregate('[{"$group":{"_id":"$mmchromosome", "count": {"$sum":1}}}]')
#print("after printing total genes per chromosome")
# x <- hsproteincodingclass.df
# print(names(x))
# output$hist <- renderPlot({
# # d1<-(plotData())
# # print(ggplot(d1, aes(x=s1)) + geom_histogram(fill = "dark green", alpha = 0.6, binwidth = 1))
# # print(str(d1))
# print(hsproteincodingclass.df)
# hist.data.frame(hsproteincodingclass.df)
# hist.data.frame(
# hsproteincodingclass.df,
# n.unique = 3,
# nclass = "compute",
# na.big = TRUE,
# rugs = TRUE,
# freq = TRUE
# )
#hist(hsclass.df, xname = "Chromosome Number", freq = TRUE, axes=TRUE, plot=TRUE, labels=TRUE, main=paste("Histogram of gene counts by chromosome"), ylim = NULL, density = NULL, include.lowest = TRUE, right = TRUE,
# col = NULL, border = NULL, breaks=c(1:24))
#print(ggplot(data_numberofgenesperchromosome, aes(x=s1)) + geom_histogram(fill = "dark green", alpha = 0.6, binwidth = 1))
#})
# Show the first "n" observations ----
output$humandataview <- renderDataTable({
head(humandatasetToBeDisplayed(),
n = input$numberofrecordstodisplay)
})
# Show the first "n" observations ----
output$mousedataview <- renderDataTable({
head(mousedatasetToBeDisplayed(),
n = input$numberofrecordstodisplay)
})
output$boxPlot <- renderPlot({
boxplotdata <- boxpolottobedisplayed()
})
output$caption <- renderText({
input$caption
})
}
# Run the application
shinyApp(ui = ui, server = server)