1+ library(dplyr )
2+ library(" PEcAn.all" )
3+ library(" RCurl" )
4+
5+ # ' Post a settings file for running a Meta-Analysis
6+ # ' @param req Send pecan.xml in body as xml filetype
7+ # ' @return A list of post.distns.MA.R
8+ # ' @author Nihar Sanda
9+ # * @post /run
10+ submitWorkflow <- function (req , res ){
11+ if (req $ HTTP_CONTENT_TYPE == " application/xml" ) {
12+ # read req$bosy as xml
13+ settingsXml <- XML :: xmlParseString(stringr :: str_replace(req $ body , " <?.*?>\n " , " " ))
14+
15+ # # convert the xml to a list
16+ settings <- XML :: xmlToList(settingsXml )
17+ settings <- as.Settings(settings )
18+ settings <- expandMultiSettings(settings )
19+
20+ # Update/fix/check settings.
21+ # Will only run the first time it's called, unless force=TRUE
22+ settings <-
23+ PEcAn.settings :: prepare.settings(settings , force = FALSE )
24+
25+ # Changing update to TRUE
26+ settings $ meta.analysis $ update <- TRUE
27+
28+ # Write pecan.CHECKED.xml
29+ PEcAn.settings :: write.settings(settings , outputfile = " pecan.CHECKED.xml" )
30+
31+ # Do conversions
32+ settings <- PEcAn.workflow :: do_conversions(settings )
33+ settings <- PEcAn.workflow :: runModule.get.trait.data(settings )
34+
35+ # initiating variables needed for running meta analysis
36+ pfts <- settings $ pfts
37+ iterations <- settings $ meta.analysis $ iter
38+ random <- settings $ meta.analysis $ random.effects $ on
39+ use_ghs <- settings $ meta.analysis $ random.effects $ use_ghs
40+ threshold <- settings $ meta.analysis $ threshold
41+ dbfiles <- settings $ database $ dbfiles
42+ database <- settings $ database $ bety
43+
44+ # running meta analysis
45+ run.meta.analysis(pfts , iterations , random , threshold ,
46+ dbfiles , database , use_ghs )
47+
48+ # PEcAn.MA::runModule.run.meta.analysis(settings = ma_settings)
49+
50+ if (dir.exists(settings $ pfts $ pft $ outdir )){
51+ filepath <- paste0(settings $ pfts $ pft $ outdir , " /post.distns.Rdata" )
52+ e <- new.env(parent = emptyenv())
53+ load(filepath , envir = e )
54+ return (list (status = " Meta Analysis ran successfully" , data = as.list(e ))
55+ }
56+ }
57+ else {
58+ res $ status <- 415
59+ return (paste(" Unsupported request content type:" , req $ HTTP_CONTENT_TYPE ))
60+ }
61+ }
0 commit comments