Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove memory cache #33

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: MGnifyR
Type: Package
Version: 0.99.14
Version: 0.99.15
Authors@R:
c(person(given = "Tuomas", family = "Borman", role = c("aut", "cre"),
email = "[email protected]",
Expand Down
8 changes: 0 additions & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ export("authTok<-")
export("cacheDir<-")
export("clearCache<-")
export("databaseUrl<-")
export("memCache<-")
export("showWarnings<-")
export("useCache<-")
export("useMemCache<-")
export("verbose<-")
export(MgnifyClient)
export(authTok)
Expand All @@ -18,7 +16,6 @@ export(doQuery)
export(getFile)
export(getMetadata)
export(getResult)
export(memCache)
export(mgnify_analyses_from_samples)
export(mgnify_analyses_from_studies)
export(mgnify_client)
Expand All @@ -33,17 +30,14 @@ export(searchAnalysis)
export(searchFile)
export(showWarnings)
export(useCache)
export(useMemCache)
export(verbose)
exportClasses(MgnifyClient)
exportMethods("authTok<-")
exportMethods("cacheDir<-")
exportMethods("clearCache<-")
exportMethods("databaseUrl<-")
exportMethods("memCache<-")
exportMethods("showWarnings<-")
exportMethods("useCache<-")
exportMethods("useMemCache<-")
exportMethods("verbose<-")
exportMethods(authTok)
exportMethods(cacheDir)
Expand All @@ -53,12 +47,10 @@ exportMethods(doQuery)
exportMethods(getFile)
exportMethods(getMetadata)
exportMethods(getResult)
exportMethods(memCache)
exportMethods(searchAnalysis)
exportMethods(searchFile)
exportMethods(showWarnings)
exportMethods(useCache)
exportMethods(useMemCache)
exportMethods(verbose)
import(MultiAssayExperiment)
import(TreeSummarizedExperiment)
Expand Down
21 changes: 2 additions & 19 deletions R/MgnifyClient.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,11 @@
#' @param showWarnings A single boolean value specifying whether to print
#' warnings during invocation of some MGnifyR functions.
#' (By default: \code{showWarnings = FALSE})
#'
#'
#' @param verbose A single boolean value specifying whether to print extra
#' output during invocation of some MGnifyR functions.
#' (By default: \code{verbose = FALSE})
#'
#' @param useMemCache A single boolean value specifying whether to indicate
#' whether functional results obtained when \code{bulk_dl} is \code{TRUE}
#' in \code{mgnify_get_analyses_results} should be stored in an in-memory
#' cache, rather than the cached input being re-read for each accession. this
#' is currently NOT working properly and should therefore be set \code{FALSE}.
#' It has the potential to speed up searches considerably though, especially
#' for studies with a large number of samples, so will be implemented properly
#' in the future. (By default: \code{useMemCache = FALSE})
#'
#' @param clearCache A single boolean value specifying whether to clear the
#' cache. (By default: \code{clearCache = FALSE})
#'
Expand Down Expand Up @@ -76,8 +67,7 @@ NULL
#' @export
MgnifyClient <- function(
username = NULL, password = NULL, useCache = FALSE, cacheDir = NULL,
showWarnings = FALSE, verbose = TRUE, useMemCache = FALSE,
clearCache = FALSE, ...){
showWarnings = FALSE, verbose = TRUE, clearCache = FALSE, ...){
############################### INPUT CHECK ################################
if( !(is.null(username) || .is_non_empty_string(username)) ){
stop(
Expand Down Expand Up @@ -111,11 +101,6 @@ MgnifyClient <- function(
"extra output during invocation of MGnifyR functions.",
call. = FALSE)
}
if( !.is_a_bool(useMemCache) ){
stop(
"'useMemCache' must be a boolean value specifying whether use ",
"on-disk memory.", call. = FALSE)
}
if( !.is_a_bool(clearCache) ){
stop(
"'clearCache' must be a boolean value specifying whether to ",
Expand Down Expand Up @@ -161,8 +146,6 @@ MgnifyClient <- function(
useCache = useCache,
cacheDir = cachepath,
showWarnings = showWarnings,
memCache = list(),
useMemCache = useMemCache,
clearCache = clearCache,
verbose = verbose
)
Expand Down
29 changes: 1 addition & 28 deletions R/allAccessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'
#' @examples
#' mg <- MgnifyClient()
#'
#'
#' databaseUrl(mg)
#' showWarnings(mg) <- FALSE
#'
Expand Down Expand Up @@ -52,19 +52,6 @@ setMethod(
"showWarnings", signature = c(x = "MgnifyClient"),
function(x){ x@showWarnings })

#' @rdname MgnifyClient-accessors
#' @include allClasses.R allGenerics.R MgnifyClient.R utils.R
#' @export
setMethod(
"useMemCache", signature = c(x = "MgnifyClient"),
function(x){ x@useMemCache })

#' @rdname MgnifyClient-accessors
#' @include allClasses.R allGenerics.R MgnifyClient.R utils.R
#' @export
setMethod(
"memCache", signature = c(x = "MgnifyClient"), function(x){ x@memCache })

#' @rdname MgnifyClient-accessors
#' @include allClasses.R allGenerics.R MgnifyClient.R utils.R
#' @export
Expand Down Expand Up @@ -114,20 +101,6 @@ setMethod(
"showWarnings<-", signature = c(x = "MgnifyClient"),
function(x, value){ BiocGenerics:::replaceSlots(x, showWarnings = value) })

#' @rdname MgnifyClient-accessors
#' @include allClasses.R allGenerics.R MgnifyClient.R utils.R
#' @export
setMethod(
"useMemCache<-", signature = c(x = "MgnifyClient"),
function(x, value){ BiocGenerics:::replaceSlots(x, useMemCache = value) })

#' @rdname MgnifyClient-accessors
#' @include allClasses.R allGenerics.R MgnifyClient.R utils.R
#' @export
setMethod(
"memCache<-", signature = c(x = "MgnifyClient"),
function(x, value){ BiocGenerics:::replaceSlots(x, memCache = value) })

#' @rdname MgnifyClient-accessors
#' @include allClasses.R allGenerics.R MgnifyClient.R utils.R
#' @export
Expand Down
15 changes: 3 additions & 12 deletions R/allClasses.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,21 @@
#' database.
#'
#' @slot authTok A single character value specifying authentication token.
#'
#'
#' @slot useCache A single boolean value specifying whether to use cache.
#'
#' @slot cacheDir A single character value specifying cache directory.
#'
#' @slot showWarnings A single boolean value specifying whether to show
#' warnings.
#'
#' @slot useMemCache A single boolean value specifying whether to use on-disk
#' memory.
#'
#' @slot memCache A single character value specifying on-disk memory directory.
#'
#' @slot clearCache A single boolean value specifying whether to clear cache.
#'
#'
#' @slot verbose A single boolean value specifying whether to show messages.
#'
#' @section Constructor:
#' See \code{\link{MgnifyClient}} for constructor.
#'
#'
#' @section Accessor:
#' See \code{\link{MgnifyClient-accessors}} for accessor functions.
#'
Expand All @@ -45,16 +40,12 @@ setClass(
useCache = "logical",
cacheDir = "character",
showWarnings = "logical",
useMemCache = "logical",
memCache = "list",
clearCache = "logical",
verbose = "logical"),
prototype = list(
databaseUrl = "https://www.ebi.ac.uk/metagenomics/api/v1",
authTok = NULL,
useCache = FALSE,
cacheDir = NULL,
useMemCache = FALSE,
memCache = list(),
clearCache = FALSE,
verbose = TRUE))
23 changes: 0 additions & 23 deletions R/allGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ setGeneric(
"showWarnings", signature = c("x"), function(x)
standardGeneric("showWarnings"))

#' @rdname MgnifyClient-accessors
#' @export
setGeneric(
"useMemCache", signature = c("x"), function(x)
standardGeneric("useMemCache"))

#' @rdname MgnifyClient-accessors
#' @export
setGeneric(
"memCache", signature = c("x"), function(x) standardGeneric("memCache"))

#' @rdname MgnifyClient-accessors
#' @export
setGeneric(
Expand Down Expand Up @@ -78,18 +67,6 @@ setGeneric(
"showWarnings<-", signature = c("x"), function(x, value)
standardGeneric("showWarnings<-"))

#' @rdname MgnifyClient-accessors
#' @export
setGeneric(
"useMemCache<-", signature = c("x"), function(x, value)
standardGeneric("useMemCache<-"))

#' @rdname MgnifyClient-accessors
#' @export
setGeneric(
"memCache<-", signature = c("x"), function(x, value)
standardGeneric("memCache<-"))

#' @rdname MgnifyClient-accessors
#' @export
setGeneric(
Expand Down
2 changes: 1 addition & 1 deletion R/deprecate.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mgnify_client <- function(
url = url,
username = username, password = password,
useCache = usecache, cacheDir = cache_dir, warnings = warnings,
useMemCache = use_memcache)
use.mem.cache = use_memcache)
}

#' @rdname deprecate
Expand Down
23 changes: 17 additions & 6 deletions R/getResult.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
#' # Get OTU tables as TreeSE
#' accession_list <- c("MGYA00377505")
#' tse <- getResult(mg, accession_list, get.func=FALSE, get.taxa=TRUE)
#'
#'
#' \donttest{
#' # Get functional data along with OTU tables as MAE
#' mae <- getResult(mg, accession_list, get.func=TRUE, get.taxa=TRUE)
Expand All @@ -96,7 +96,7 @@
#' mg, accession_list, get.func=TRUE, get.taxa=TRUE, output = "list",
#' as.df = TRUE, use.cache = TRUE)
#' }
#'
#'
#' @name getResult
NULL

Expand Down Expand Up @@ -751,7 +751,7 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
.get_bulk_files <- function(
cur_type, client, r, metadata_df, downloadDIR,
use.cache, clear.cache = clearCache(client),
use.mem.cache = useMemCache(client), ...){
use.mem.cache = FALSE, mem.cache.name = "mgnify_memory_cache", ...){
# Input check
if( !.is_a_bool(clear.cache) ){
stop(
Expand All @@ -761,6 +761,18 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
stop(
"'use.mem.cache' must be a single boolean value.", call. = FALSE)
}
# Check mem.cache.name
if( !( length(mem.cache.name) == 1 && is.character(mem.cache.name) ) ){
stop("'mem.cache.name' must be a single character value.", call. = FALSE)
}
if( exists(mem.cache.name) && use.mem.cache ){
mgnify_memory_cache <- get(mem.cache.name)
if( !is.list(mgnify_memory_cache) ){
stop("'mem.cache.name' must specify a list object.", call. = FALSE)
}
} else if(use.mem.cache){
mgnify_memory_cache <- list()
}
#
# Get the url
data_url <- r$links$self
Expand Down Expand Up @@ -812,6 +824,8 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
if( use.mem.cache ){
mgnify_memory_cache[[cur_type]] <- list(
data=tmp_df, fname=fname)
# Assign to global variable so it is visible for user
assign(mem.cache.name, mgnify_memory_cache, envir = .GlobalEnv)
}

# Because there seem to be "mismatches" between the
Expand Down Expand Up @@ -866,9 +880,6 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
return(tmp_df)
}

# Result table caching
mgnify_memory_cache <- list()

# Which parser do you use for which type of output?
# a list of parsers for each output type. If new output types come, add them to
# here (and below) so that they are fetched from the database.
Expand Down
24 changes: 0 additions & 24 deletions man/MgnifyClient-accessors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading