-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from habitus-eu/issue90_integrate_hbGPS
Issue90 integrate hb gps
- Loading branch information
Showing
30 changed files
with
993 additions
and
496 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#' Function to check that the config files have the expected format | ||
#' | ||
#' @param file data path to config file | ||
#' @param tool either PALMSpy, GGIR, or palmsplusr for now. | ||
#' | ||
#' @return message with the result of the check (either ok or the description of a problem) | ||
#' @export | ||
checkConfigFile = function(file=c(), tool=c()) { | ||
# intialize check object, ok by default, it would be overwritten if | ||
# any problem is identified in the config file. | ||
check = "ok" | ||
|
||
# General check on file existence and extension | ||
if (!file.exists(file)) { | ||
# stop("No config file found at ", path) | ||
check = "No config file found at " | ||
} else { | ||
path_unlist = unlist(strsplit(x = file, split = ".", fixed = TRUE)) | ||
path_ext = tolower(path_unlist[length(path_unlist)]) | ||
if (tool %in% c("GGIR", "hbGPS", "palmsplusr") & path_ext != "csv") { | ||
check = "The GGIR config file uploaded is not a csv file" | ||
} else if (tool == "PALMSpy" & path_ext != "json") { | ||
check = "The GGIR config file uploaded is not a json file" | ||
} | ||
} | ||
|
||
# Specific file content check | ||
if (check == "ok") { | ||
if (tool == "PALMSpy") { | ||
# TO BE DEVELOPED | ||
} else if (tool == "GGIR" || tool == "hbGPS") { | ||
# read config file if it exists and it is a csv file | ||
params = read.csv(file = file) | ||
# sanity check 2: colnames of config file ---- | ||
if (ncol(params) == 3 && tool != "palmsplusr") { | ||
check_colnames = all.equal(colnames(params), c("argument", "value", "context")) | ||
} else if (ncol(params) == 5 && tool == "palmsplusr") { | ||
check_colnames = all.equal(colnames(params), c("context", "name", "formula", "domain_field", "after_conversion")) | ||
} else { | ||
check_colnames = FALSE | ||
} | ||
if (check_colnames == FALSE) { | ||
# this automatically also checks that csv is separated by commas, as | ||
# it would generate just one column (e.g., "argument;value;context") otherwise | ||
check = paste0("The csv file uploaded is not a ", tool, " config file") | ||
} | ||
} | ||
} | ||
return(check) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#' hbGPS_shiny | ||
#' | ||
#' @param ggiroutdir GGIR time series output directory | ||
#' @param gpsdir Path to GPS directory | ||
#' @param outputdir Path to output directory | ||
#' @param dataset_name Name of dataset | ||
#' @param configfile Path to configuration file | ||
#' @return no object is returned, only a new file is created in the output directory | ||
#' @import hbGPS | ||
#' @export | ||
|
||
hbGPS_shiny = function(ggiroutdir = NULL, gpsdir = NULL, outputdir = NULL, | ||
dataset_name = "", configfile = c()) { | ||
# create R script with the code to run the data analysis via a command line call | ||
# in this way turning off or restarting the app will not kill the data analysis | ||
fileConn <- file(paste0(outputdir, "/hbgps_cmdline.R")) | ||
writeLines(c("#!/usr/bin/env Rscript", | ||
"args = commandArgs(trailingOnly = TRUE)", | ||
"if (length(args) < 4) {", | ||
"stop(\"At least four arguments are expected\", call. = FALSE)", | ||
"}", | ||
"hbGPS::hbGPS(gps_file = args[1], ", | ||
"GGIRpath = args[2],", | ||
"outputDir = args[3],", | ||
"configFile = args[4])" | ||
), | ||
fileConn) | ||
close(fileConn) | ||
if (.Platform$OS.type == "windows") { | ||
logFile = paste0(outputdir, "/hbGPS.log") | ||
fileConn = file(logFile) | ||
writeLines(c("Hello, this Shiny app is primarily designed for Unix.", | ||
"In Windows OS live progress of the analysis can be followed in the RStudio console.", | ||
"In Unix-like systems the progress would be shown here inside this window in the Shiny app."), fileConn) | ||
close(fileConn) | ||
|
||
basecommand = paste0(outputdir, "/hbgps_cmdline.R ", | ||
gpsdir, " ", | ||
ggiroutdir, " ", | ||
outputdir, " ", | ||
configfile) | ||
system2(command = "Rscript", args = basecommand, | ||
stdout = "", | ||
stderr = "", wait = TRUE) | ||
write.table(x = paste0(""), | ||
file = paste0(outputdir, "/hbGPS.log")) | ||
|
||
fileConn = file(logFile) | ||
writeLines(c(""), fileConn) | ||
close(fileConn) | ||
|
||
} else { | ||
basecommand = paste0("cd ", outputdir, " ; nohup Rscript hbgps_cmdline.R ", | ||
gpsdir, " ", | ||
ggiroutdir, " ", | ||
outputdir, " ", | ||
configfile, " > ", outputdir, "/hbGPS.log 2>&1 &") | ||
system2(command = "cd", args = gsub(pattern = "cd ", replacement = "", x = basecommand), | ||
stdout = "", stderr = "", wait = TRUE) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.