Skip to content

Commit

Permalink
added dedicated mysql connection in get_study() to fix
Browse files Browse the repository at this point in the history
the mysql connection loss problem
  • Loading branch information
boxiangliu committed Apr 30, 2018
1 parent 1c572eb commit 656282d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 12 additions & 1 deletion global.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,16 @@ locuscompare_pool = dbPool(
dbname = "locuscompare",
host = aws_host,
username = aws_username,
password = aws_password
password = aws_password,
minSize = 4,
maxSize = Inf,
idleTimeout = 3600000
)

args = list(
drv = RMySQL::MySQL(),
dbname = "locuscompare",
host = aws_host,
username = aws_username,
password = aws_password
)
10 changes: 6 additions & 4 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ get_trait=function(study, conn = locuscompare_pool){
}

get_study = function(valid_study,study,trait,datapath,coordinate){
conn <- do.call(DBI::dbConnect, args)
on.exit(DBI::dbDisconnect(conn))
if (str_detect(study,'^eQTL')){
res = dbGetQuery(
conn = locuscompare_pool,
conn = conn,
statement = sprintf(
"select gene_id
from gencode_v19_gtex_v6p
Expand All @@ -123,7 +125,7 @@ get_study = function(valid_study,study,trait,datapath,coordinate){

if (valid_study){
res=dbGetQuery(
conn = locuscompare_pool,
conn = conn,
statement = sprintf(
"select t1.rsid, t1.pval
from %s as t1
Expand All @@ -145,7 +147,7 @@ get_study = function(valid_study,study,trait,datapath,coordinate){
shiny::validate(need(all(c('rsid','pval')%in%colnames(res)),'Input file must have columns rsid, pval!'))

rsid_list=dbGetQuery(
conn = locuscompare_pool,
conn = conn,
statement = sprintf(
"select rsid
from tkg_p3v5a
Expand All @@ -157,7 +159,7 @@ get_study = function(valid_study,study,trait,datapath,coordinate){
coordinate$end
)
)
res=res[rsid%in%rsid_list$rsid,]
res = res %>% dplyr::filter(rsid %in% rsid_list$rsid)
}
setDT(res)
return(res)
Expand Down

0 comments on commit 656282d

Please sign in to comment.