R/all.R

Defines functions initDbConnection getDb closeDb .onLoad .onUnload

globals <- new.env(hash=TRUE, parent=emptyenv())

globals$DEBUG <- FALSE

## setup the path at package level so that DB can be accessed
## during package install/lazyload db creation.
##
## We reset the DB_PATH in .onLoad since we need to
## get the right one based on libpath
globals$DB_PATH <- system.file("extdata", "pd.feinberg.mm8.me.hx1.sqlite",
                               package="pd.feinberg.mm8.me.hx1")
if (nchar(globals$DB_PATH) == 0)
  stop("Unable to locate DB file")

initDbConnection <- function() {
    globals$dbCon <- dbConnect(dbDriver("SQLite"), dbname=globals$DB_PATH)
    globals$dbCon
}

getDb  <- function() {
    if (!is.null(globals$dbCon) && isIdCurrent(globals$dbCon))
      return(globals$dbCon)
    initDbConnection()
}

closeDb <- function() {
    ## FIXME: check for valid connection?
    sapply(dbListResults(globals$dbCon), dbClearResult)
    dbDisconnect(globals$dbCon)
    remove(list="dbCon", envir=globals)
}

.onLoad <- function(libname, pkgname) {
    require("methods", quietly=TRUE)
    require("RSQLite", quietly=TRUE)
    globals$DB_PATH <- system.file("extdata", "pd.feinberg.mm8.me.hx1.sqlite",
                                   package="pd.feinberg.mm8.me.hx1",
                                   lib.loc=libname)
    if (nchar(globals$DB_PATH) == 0)
      stop("Unable to locate DB file")
    ## Establish a connection to the SQLite DB
    initDbConnection()
}

.onUnload <- function(libpath) {
    closeDb()
}

pd.feinberg.mm8.me.hx1 <- new("NgsTilingPDInfo",
                    genomebuild="MM 8",
                    getdb=getDb,
                    geometry=as.integer(strsplit("4200;1050", ";")[[1]]),
                    annotation="pd.feinberg.mm8.me.hx1")

Try the pd.feinberg.mm8.me.hx1 package in your browser

Any scripts or data that you put into this service are public.

pd.feinberg.mm8.me.hx1 documentation built on May 2, 2019, 6:53 p.m.