Commit 786e42da authored by daniel.eilertz's avatar daniel.eilertz
Browse files

Metabolomics: Outsourced updates to prm in function

parent a61c77e9
......@@ -38,39 +38,8 @@ process_batch <- function(nowfolder = "", parameters = list(), return_msd=FALSE)
# create new log file
prm$log_con <- file(file.path(nowfolder, "R_messages.log"),open="a")
# update prm from local settings in nowfolder
update_prm_path <- file.path(nowfolder,"update_prm.tsv")
if (file.exists(update_prm_path)){
updatedata <- read.table(update_prm_path, sep = '\t', stringsAsFactors = FALSE)
colnames(updatedata) <- updatedata[1, ]
updatedata <- updatedata[-1, ]
if (('Variable in prm' %in% colnames(updatedata)) && ('Value' %in% colnames(updatedata)) ) {
print(paste0('Updating parameters from ', update_prm_path))
for (iv in 1:nrow(updatedata)) {
nowvalue <- updatedata[iv,'Value']
if (nowvalue %in% c("TRUE", "FALSE")) {
nowvalue <- as.logical(nowvalue)
} else if ( !is.na(as.numeric(nowvalue)) ) {
nowvalue <- as.numeric(nowvalue)
}
prm[[updatedata[iv,'Variable in prm']]] <- nowvalue
}
} else {
print(paste0('Error in ',update_prm_path ,' , cannot find required columns "Variabel in prm" and "Value".'))
}
}
# update prm from argument parameters
paranames <- names(parameters)
if (!is.null(paranames)) {
for (ip in 1:length(paranames)) {
#ip = 1
prm[[paranames[ip]]] <- parameters[[paranames[ip]]]
}
}
# save nowfolder to prm
prm$batchdir <- nowfolder
# Update prm from tsv config file and arguments
prm <- update_prm(nowfolder,parameters,prm)
# output errors and messages to log file if running on server
if(!prm$runninglocal){
......
update_prm <- function(nowfolder,parameters,prm){
# update prm from local settings in nowfolder
update_prm_path <- file.path(nowfolder,"update_prm.tsv")
if (file.exists(update_prm_path)){
updatedata <- read.table(update_prm_path, sep = '\t', stringsAsFactors = FALSE)
colnames(updatedata) <- updatedata[1, ]
updatedata <- updatedata[-1, ]
if (('Variable in prm' %in% colnames(updatedata)) && ('Value' %in% colnames(updatedata)) ) {
print(paste0('Updating parameters from ', update_prm_path))
for (iv in 1:nrow(updatedata)) {
nowvalue <- updatedata[iv,'Value']
if (nowvalue %in% c("TRUE", "FALSE")) {
nowvalue <- as.logical(nowvalue)
} else if ( !is.na(as.numeric(nowvalue)) ) {
nowvalue <- as.numeric(nowvalue)
}
prm[[updatedata[iv,'Variable in prm']]] <- nowvalue
}
} else {
print(paste0('Error in ',update_prm_path ,' , cannot find required columns "Variabel in prm" and "Value".'))
}
}
# update prm from argument parameters
paranames <- names(parameters)
if (!is.null(paranames)) {
for (ip in 1:length(paranames)) {
#ip = 1
prm[[paranames[ip]]] <- parameters[[paranames[ip]]]
}
}
# save nowfolder to prm
prm$batchdir <- nowfolder
prm
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment