Commit db88eca3 authored by daniel.eilertz's avatar daniel.eilertz
Browse files

Stuff

parent be864b8a
......@@ -11,14 +11,13 @@
#'
#' @export
process_batch <- function(nowfolder = "", parameters = list(), return_msd=FALSE) {
# process_batch('~/data/helperfiles/testdata/LC_machine_learning/ccm2/' )
# Initialize analysis ------------------------------
#setwd("/home/rstudio/data/helperfiles/testdata/LC_machine_learning/4sample_am")
# Initialize analysis
ptm <- proc.time()
pardefault <- par(no.readonly = TRUE)
options("scipen"=100, "digits"=4)
# Set working directory (in Testmode)
# Set working directory (use current directory if not specified)
if (nowfolder == '') {
nowfolder <- getwd()
}else{
......@@ -33,23 +32,18 @@ process_batch <- function(nowfolder = "", parameters = list(), return_msd=FALSE)
}
}
# Remove existing log file and create new one
#system(paste0("rm ", file.path(nowfolder, "R_messages.log")))
# Initialize prm (global settings)
prm <- initialize_prm()
# create new log file
prm$log_con <- file(file.path(nowfolder, "R_messages.log"),open="a")
# update prm from local settings in mzML folder
# 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)) {
......@@ -70,6 +64,7 @@ process_batch <- function(nowfolder = "", parameters = list(), return_msd=FALSE)
paranames <- names(parameters)
if (!is.null(paranames)) {
for (ip in 1:length(paranames)) {
#ip = 1
prm[[paranames[ip]]] <- parameters[[paranames[ip]]]
}
}
......@@ -77,11 +72,12 @@ process_batch <- function(nowfolder = "", parameters = list(), return_msd=FALSE)
# save nowfolder to prm
prm$batchdir <- nowfolder
if(!prm$runninglocal){ # if running on server
sink(prm$log_con, append=TRUE) # output errors and messages to log file
# output errors and messages to log file if running on server
if(!prm$runninglocal){
sink(prm$log_con, append=TRUE)
}
# shortcut for mltrain_prepare
# ??? shortcut for mltrain_prepare
troubleshootpath <- file.path(prm$batchdir, 'troubleshoot.RData')
if (prm$runninglocal && (prm$ml_type == 'mltrain_prepare') && file.exists(troubleshootpath)) {
load(file = troubleshootpath) # partially processed data from initial training
......@@ -92,7 +88,6 @@ process_batch <- function(nowfolder = "", parameters = list(), return_msd=FALSE)
prm[[paranames[ip]]] <- parameters[[paranames[ip]]]
}
}
prm$batchdir <- nowfolder
prm$log_con <- file(file.path(prm$batchdir, "R_messages.log"),open="a")
load(file = prm$model_path) # 1. model to detect best peak in MRM
......@@ -138,7 +133,7 @@ process_batch <- function(nowfolder = "", parameters = list(), return_msd=FALSE)
prm <- get_unirt(file.path(prm$batchdir, list.files(path = prm$batchdir, pattern='.mzML')[1]) , prm)
# Read mzML-files for unirt, chromdata and samplenames
smpl <- read_mzmlfiles( list.files(path = prm$batchdir, pattern='.mzML'), prm)
smpl <- read_mzmlfiles(list.files(path = prm$batchdir, pattern='.mzML'), prm)
prm$nsmpl <- length(smpl$chroms)
# get additional info from sample.info
......@@ -159,6 +154,7 @@ process_batch <- function(nowfolder = "", parameters = list(), return_msd=FALSE)
# Detect peaks (anchromet, groupmets) per sample | shiftgroup ------------------------------
msd <- peak_detection(metab, smpl, prm)
# Save troubleshoot data eventually
if (prm$verbose >= 2) {
save(metab, smpl, msd, prm, file = file.path(prm$batchdir, 'troubleshoot.RData') )
}
......
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