Update meta_analysis_api.R
Browse files- meta_analysis_api.R +38 -12
meta_analysis_api.R
CHANGED
@@ -1,27 +1,53 @@
|
|
1 |
library(plumber)
|
2 |
-
|
|
|
|
|
3 |
packages <- c("aggregation", "aides", "altmeta", "amanida", "baggr", "bamdit", "BayesCombo", "bayesmeta", "BayesMultMeta", "bipd", "bnma", "boot.heterogeneity", "boutliers", "brms", "bspmma", "CAMAN", "catmap", "CausalMetaR", "CBnetworkMA", "CIAAWconsensus", "citationchaser", "clubSandwich", "coefa", "CohensdpLibrary", "compute.es", "corrmeta", "CoTiMA", "CPBayes", "crossnma", "crwbmetareg", "dfmeta", "diagmeta", "digitize", "dmetar", "dmetatools", "dosresmeta", "dplyr", "DTAplots", "ecoreg", "effectsize", "effsize", "epiR", "es.dif", "esc", "esci", "estimraw", "estmeansd", "EValue", "EvidenceSynthesis", "extraDistr", "forcats", "forestly", "forestmodel", "forestplot", "forestploter", "forplo", "fsn", "gap", "gemtc", "GENMETA", "getmstatistic", "getspres", "ggplot2", "ggridges", "glue", "GMCM", "harmonicmeanp", "heterometa", "igraph", "jarbes", "joint.Cox", "juicr", "KenSyn", "MAd", "mada", "MBNMAdose", "MBNMAtime", "mc.heterogeneity", "MendelianRandomization", "meta", "meta.shrinkage", "meta4diag", "MetaAnalyser", "metabias", "metaBLUE", "metaBMA", "metabolic", "metabup", "metacart", "metaconfoundr", "metadat", "metaDigitise", "metafor", "metaforest", "metafuse", "metagam", "metaGE", "metagear", "metainc", "MetaIntegration", "MetaIntegrator", "metaLik", "metaMA", "metamedian", "metamicrobiomeR", "metamisc", "metansue", "metap", "metapack", "metaplus", "metapower", "metapro", "metarep", "metaRNASeq", "metaSEM", "metasens", "MetaSKAT", "MetaStan", "MetaSubtract", "metaSurvival", "metatest", "metaumbrella", "MetaUtility", "metavcov", "metaviz", "metawho", "miniMeta", "mixmeta", "MOTE", "multibiasmeta", "multinma", "mvmeta", "MVPBT", "mvtmeta", "netmeta", "NMA", "nmadb", "NMADiagT", "nmaINLA", "NMAoutlier", "nmaplateplot", "nmarank", "nmathresh", "ofGEM", "openxlsx", "OssaNMA", "osfr", "pcnetmeta", "pema", "PerformanceAnalytics", "phacking", "pimeta", "PINMA", "POMADE", "poolr", "PRISMA2020", "PRISMAstatement", "psychmeta", "psymetadata", "PublicationBias", "publipha", "puniform", "ra4bayesmeta", "RandMeta", "rankinma", "ratesci", "RBesT", "RcmdrPlugin.EZR", "RcmdrPlugin.MA", "RcmdrPlugin.RMTCJags", "reappraised", "rema", "remaCor", "revtools", "rjags", "rma.exact", "rmeta", "rnmamod", "RoBMA", "robumeta", "RobustBayesianCopas", "robustmeta", "RobustRankAggreg", "robvis", "RTSA", "SCMA", "selectMeta", "semPlot", "SingleCaseES", "smd", "SPAtest", "ssifs", "stringr", "TFisher", "tidybayes", "tidyverse", "vcmeta", "viscomp", "weightr", "wildmeta", "xmeta")
|
4 |
|
5 |
for (pkg in packages) {
|
6 |
-
suppressWarnings(library(pkg, character.only = TRUE))
|
7 |
}
|
8 |
|
9 |
#* @apiTitle Comprehensive Meta-Analysis API
|
10 |
|
11 |
-
#* Perform meta-analysis
|
12 |
#* @param package The name of the package to use
|
13 |
-
#* @param
|
14 |
-
#* @param
|
15 |
#* @post /analyze
|
16 |
-
function(package,
|
17 |
-
#
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
result <- tryCatch({
|
22 |
-
|
|
|
23 |
}, error = function(e) {
|
24 |
-
list(error = paste("Error in", package, ":", e$message))
|
25 |
})
|
26 |
|
27 |
return(result)
|
@@ -30,4 +56,4 @@ function(package, method, data) {
|
|
30 |
#* @plumber
|
31 |
function(pr) {
|
32 |
pr$setDebug(TRUE)
|
33 |
-
}
|
|
|
1 |
library(plumber)
|
2 |
+
library(jsonlite)
|
3 |
+
|
4 |
+
# Load all the meta-analysis packages (as per your original code)
|
5 |
packages <- c("aggregation", "aides", "altmeta", "amanida", "baggr", "bamdit", "BayesCombo", "bayesmeta", "BayesMultMeta", "bipd", "bnma", "boot.heterogeneity", "boutliers", "brms", "bspmma", "CAMAN", "catmap", "CausalMetaR", "CBnetworkMA", "CIAAWconsensus", "citationchaser", "clubSandwich", "coefa", "CohensdpLibrary", "compute.es", "corrmeta", "CoTiMA", "CPBayes", "crossnma", "crwbmetareg", "dfmeta", "diagmeta", "digitize", "dmetar", "dmetatools", "dosresmeta", "dplyr", "DTAplots", "ecoreg", "effectsize", "effsize", "epiR", "es.dif", "esc", "esci", "estimraw", "estmeansd", "EValue", "EvidenceSynthesis", "extraDistr", "forcats", "forestly", "forestmodel", "forestplot", "forestploter", "forplo", "fsn", "gap", "gemtc", "GENMETA", "getmstatistic", "getspres", "ggplot2", "ggridges", "glue", "GMCM", "harmonicmeanp", "heterometa", "igraph", "jarbes", "joint.Cox", "juicr", "KenSyn", "MAd", "mada", "MBNMAdose", "MBNMAtime", "mc.heterogeneity", "MendelianRandomization", "meta", "meta.shrinkage", "meta4diag", "MetaAnalyser", "metabias", "metaBLUE", "metaBMA", "metabolic", "metabup", "metacart", "metaconfoundr", "metadat", "metaDigitise", "metafor", "metaforest", "metafuse", "metagam", "metaGE", "metagear", "metainc", "MetaIntegration", "MetaIntegrator", "metaLik", "metaMA", "metamedian", "metamicrobiomeR", "metamisc", "metansue", "metap", "metapack", "metaplus", "metapower", "metapro", "metarep", "metaRNASeq", "metaSEM", "metasens", "MetaSKAT", "MetaStan", "MetaSubtract", "metaSurvival", "metatest", "metaumbrella", "MetaUtility", "metavcov", "metaviz", "metawho", "miniMeta", "mixmeta", "MOTE", "multibiasmeta", "multinma", "mvmeta", "MVPBT", "mvtmeta", "netmeta", "NMA", "nmadb", "NMADiagT", "nmaINLA", "NMAoutlier", "nmaplateplot", "nmarank", "nmathresh", "ofGEM", "openxlsx", "OssaNMA", "osfr", "pcnetmeta", "pema", "PerformanceAnalytics", "phacking", "pimeta", "PINMA", "POMADE", "poolr", "PRISMA2020", "PRISMAstatement", "psychmeta", "psymetadata", "PublicationBias", "publipha", "puniform", "ra4bayesmeta", "RandMeta", "rankinma", "ratesci", "RBesT", "RcmdrPlugin.EZR", "RcmdrPlugin.MA", "RcmdrPlugin.RMTCJags", "reappraised", "rema", "remaCor", "revtools", "rjags", "rma.exact", "rmeta", "rnmamod", "RoBMA", "robumeta", "RobustBayesianCopas", "robustmeta", "RobustRankAggreg", "robvis", "RTSA", "SCMA", "selectMeta", "semPlot", "SingleCaseES", "smd", "SPAtest", "ssifs", "stringr", "TFisher", "tidybayes", "tidyverse", "vcmeta", "viscomp", "weightr", "wildmeta", "xmeta")
|
6 |
|
7 |
for (pkg in packages) {
|
8 |
+
suppressWarnings(suppressMessages(library(pkg, character.only = TRUE)))
|
9 |
}
|
10 |
|
11 |
#* @apiTitle Comprehensive Meta-Analysis API
|
12 |
|
13 |
+
#* Perform meta-analysis using the selected package and function
|
14 |
#* @param package The name of the package to use
|
15 |
+
#* @param function The name of the function within the package to execute
|
16 |
+
#* @param params A list containing all necessary parameters for the function
|
17 |
#* @post /analyze
|
18 |
+
function(package, function, params) {
|
19 |
+
# Check if the package is installed
|
20 |
+
if (!requireNamespace(package, quietly = TRUE)) {
|
21 |
+
res <- list(error = paste("Package", package, "is not installed."))
|
22 |
+
return(res)
|
23 |
+
}
|
24 |
+
|
25 |
+
# Load the package
|
26 |
+
suppressWarnings(suppressMessages(library(package, character.only = TRUE)))
|
27 |
+
|
28 |
+
# Check if the function exists in the package
|
29 |
+
if (!exists(function, where = asNamespace(package), mode = "function")) {
|
30 |
+
res <- list(error = paste("Function", function, "does not exist in package", package))
|
31 |
+
return(res)
|
32 |
+
}
|
33 |
|
34 |
+
# Convert params from JSON to R objects if necessary
|
35 |
+
params <- lapply(params, function(x) {
|
36 |
+
if (is.character(x)) {
|
37 |
+
# Attempt to parse JSON strings
|
38 |
+
parsed <- tryCatch(jsonlite::fromJSON(x), error = function(e) x)
|
39 |
+
return(parsed)
|
40 |
+
} else {
|
41 |
+
return(x)
|
42 |
+
}
|
43 |
+
})
|
44 |
+
|
45 |
+
# Perform the analysis by calling the specified function with the provided params
|
46 |
result <- tryCatch({
|
47 |
+
func <- get(function, envir = asNamespace(package))
|
48 |
+
do.call(func, params)
|
49 |
}, error = function(e) {
|
50 |
+
list(error = paste("Error in", package, "function", function, ":", e$message))
|
51 |
})
|
52 |
|
53 |
return(result)
|
|
|
56 |
#* @plumber
|
57 |
function(pr) {
|
58 |
pr$setDebug(TRUE)
|
59 |
+
}
|