From 06b079deef2cc4491297f7e8e2d942c611596797 Mon Sep 17 00:00:00 2001 From: gabrielctn Date: Sun, 8 Apr 2018 18:16:18 +0200 Subject: [PATCH] Added getInfos(mzfiles) function to complete output results --- galaxy/ipo/lib.r | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/galaxy/ipo/lib.r b/galaxy/ipo/lib.r index 42c499a..5986fa4 100644 --- a/galaxy/ipo/lib.r +++ b/galaxy/ipo/lib.r @@ -1,3 +1,22 @@ +getInfos = function(mzdatafiles){ + + # Get informations about instruments used and run + file.format = c("mzData", "mzdata") + if(tools::file_ext(mzdatafiles) %in% file.format){ + ms = openMSfile(mzdatafiles, backend="Ramp") + } else { + ms = openMSfile(mzdatafiles) + } + + runInfo = t(sapply(runInfo(ms), function(x) x[1], USE.NAMES=TRUE)) + instrumentInfo = t(sapply(instrumentInfo(ms), function(x) x, USE.NAMES=TRUE)) + + infos = list("runinfo" = runInfo, "instrumentInfo" = instrumentInfo) + return (infos) +} + + + ## ## This function launch IPO functions to get the best parameters for xcmsSet ## A sample among the whole dataset is used to save time @@ -32,13 +51,35 @@ ipo4xcmsSet = function(directory, parametersOutput, listArguments, samplebyclass # filter listArguments to only get releavant parameters and complete with those that are not declared peakpickingParametersUser = c(listArguments[names(listArguments) %in% names(peakpickingParameters)], peakpickingParameters[!(names(peakpickingParameters) %in% names(listArguments))]) peakpickingParametersUser$verbose.columns = TRUE + + # allow range for min and max peakwidth and ppm if given in arguments + if (!is.null(listArguments[["minPeakWidth"]])){ + peakpickingParametersUser$min_peakwidth = as.vector(as.numeric(unlist(strsplit(listArguments[["minPeakWidth"]],split = ",")))) + listArguments[["minPeakWidth"]] = NULL + } + + if (!is.null(listArguments[["maxPeakWidth"]])){ + peakpickingParametersUser$max_peakwidth = as.vector(as.numeric(unlist(strsplit(listArguments[["maxPeakWidth"]],split = ",")))) + listArguments[["maxPeakWidth"]] = NULL + } + + if (!is.null(listArguments[["ppm"]])){ + if(grepl(",", listArguments[["ppm"]])) + peakpickingParametersUser$ppm = as.vector(as.numeric(unlist(strsplit(listArguments[["ppm"]],split = ",")))) + else + peakpickingParametersUser$ppm = listArguments[["ppm"]] + listArguments[["ppm"]] = NULL + } #peakpickingParametersUser$profparam <- list(step=0.005) #not yet used by IPO have to think of it for futur improvement resultPeakpicking = optimizeXcmsSet(mzmlfile, peakpickingParametersUser, nSlaves=peakpickingParametersUser$nSlaves, subdir="../IPO_results") #some images generated by IPO - # export - resultPeakpicking_best_settings_parameters = resultPeakpicking$best_settings$parameters[!(names(resultPeakpicking$best_settings$parameters) %in% c("nSlaves","verbose.columns"))] - write.table(t(as.data.frame(resultPeakpicking_best_settings_parameters)), file=parametersOutput, sep="\t", row.names=T, col.names=F, quote=F) #can be read by user + # export results + resultPeakpicking_best_settings_parameters = resultPeakpicking$best_settings$parameters[!(names(resultPeakpicking$best_settings$parameters) %in% c("nSlaves","verbose.columns"))] + + infos = getInfos(mzmlfile) + # Write results in table with machine and run infos + write.table(cbind(mzmlfile, infos$instrumentInfo, infos$runInfo, t(as.matrix(resultPeakpicking_best_settings_parameters))), file=parametersOutput, sep="\t", row.names=F, col.names=T, quote=F) return (resultPeakpicking$best_settings$xset) }