-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdbGaPdb_app.Rmd
157 lines (91 loc) · 3.59 KB
/
dbGaPdb_app.Rmd
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
---
title: "Selecting dbGaP studies using metadata queries"
resource_files:
- demo_dbgap_metadata.Rdata
runtime: shiny
output:
flexdashboard::flex_dashboard:
social: menu
---
Results
============================================
Column {.sidebar}
-----------------------------------------------------------------------
```{r}
#Load the proper libraries
Sys.setenv(RSTUDIO_PANDOC="/usr/lib/rstudio/bin/pandoc")
enableBookmarking()
library("tm")
library("tidyverse")
library("shiny")
library("DT")
library("RSQLite")
library("dbplyr")
library(wordcloud)
#Load local data
#load("demo_dbgap_metadata.Rdata")
#Collect user input to later subset the data
inputPanel(
selectizeInput("dat", label = h4("Data Type"), c("", "RNA-seq", "Whole Genome Sequencing", "Whole Exome Sequencing")),
selectizeInput("pheno", label = h4("Phenotype"), c("", "asthma", "insomnia", "hypertension")),
selectizeInput("n", label = h4("Minimum sample size"), c(0,10,50,100,500,1000,5000,10000), selected = 10000)
)
dbGaPdb <- src_sqlite('dbGaPdb.sqlite')
study_variable_info_SQL <<- tbl(dbGaPdb, "study_variable_info")
```
Column
-----------------------------------------------------------------------
Studies containing your queries:
```{r}
#Make a subset of the data based on the search terms
subset_dat <- reactive({
inph <- paste0("%",input$pheno,"%")
indt <- paste0("%",input$dat,"%")
inn <- input$n
# tables$study_variable_info[(as.numeric(tables$study_variable_info$male_count) + as.numeric(tables$study_variable_info$female_count) > as.numeric(input$n)),] %>% filter(grepl(input$pheno, description, ignore.case=T)&grepl(input$dat ,description, ignore.case=T))
study_variable_info_SQL %>% mutate(mf_count = as.numeric(male_count) + as.numeric(female_count)) %>% filter(mf_count > as.numeric(inn)) %>% filter(description %LIKE% inph) %>% filter(description %LIKE% indt) %>% data.frame()
#study_variable_info_SQL %>% mutate(mf_count = as.numeric(male_count) + as.numeric(female_count)) %>% filter(mf_count > 10000) %>% filter(grepl("asthma", description, ignore.case=T)&grepl("" ,description, ignore.case=T)) %>% head() %>% data.frame()
})
#Render a data table of the subsetted data
renderDataTable({
subset_dat()
})
```
Word Cloud
========================================
```{r}
#study_dataset_info_SQL <- tbl(dbGaPdb, "study_dataset_info")
df_sdis <- tbl(dbGaPdb, 'study_dataset_info') %>% select(study_accession, description) %>% data.frame()
out_ccat <- reactive({
inph <- paste0("%",input$pheno,"%")
indt <- paste0("%",input$dat,"%")
inn <- input$n
to_filt <- study_variable_info_SQL %>% mutate(mf_count = as.numeric(male_count) + as.numeric(female_count)) %>% filter(mf_count > as.numeric(inn)) %>% filter(description %LIKE% inph) %>% filter(description %LIKE% indt) %>% data.frame()
vec_to_filt <- to_filt$study_accession
filt <- df_sdis[df_sdis$study_accession %in% vec_to_filt,]
ccat <- ""
for (each in filt$description){
ccat <- paste0(ccat, each)
}
new_ccat <- gsub('quot','',ccat)
jeopCorpus <- Corpus(VectorSource(new_ccat))
jeopCorpus <- tm_map(jeopCorpus, PlainTextDocument)
jeopCorpus <- tm_map(jeopCorpus, removeWords, stopwords('english'))
})
renderPlot({
wordcloud(out_ccat(), min.freq = 5, max.words = 100, colors=brewer.pal(6,"Dark2"), scale=c(6,2), random.order = FALSE)
})
```
Download
========================================
Column
-----------------------------------------------------------------------
```{r}
#Download page
downloadHandler(filename = function(){
("dbGaPdb_query.csv")},
content = function(file) {
write.csv(subset_dat(), file)
}
)
```