diff --git a/galaxy/ipo/ipo4retgroup.r b/galaxy/ipo/ipo4retgroup.r index a6d94d1..1179f73 100755 --- a/galaxy/ipo/ipo4retgroup.r +++ b/galaxy/ipo/ipo4retgroup.r @@ -1,6 +1,8 @@ #!/usr/bin/env Rscript #Authors Gildas Le Corguille and Yann Guitton +# Setup R error handling to go to stderr for better error messages in Galaxy +options(show.error.messages=F, error=function(){cat(geterrmessage(),file=stderr());q("no",1,F)}) # ----- LOG FILE ----- log_file=file("log.txt", open = "wt") @@ -42,8 +44,6 @@ source_local("lib.r") cat("\n\n") -#Import the different functions - # ----- PROCESSING INFILE ----- cat("\tARGUMENTS PROCESSING INFO\n") @@ -68,8 +68,8 @@ if (!is.null(listArguments[["zipfile"]])){ if (!is.null(listArguments[["singlefile_galaxyPath"]])){ - singlefile_galaxyPath = unlist(strsplit(listArguments[["singlefile_galaxyPath"]],",")); listArguments[["singlefile_galaxyPath"]]=NULL - singlefile_sampleName = unlist(strsplit(listArguments[["singlefile_sampleName"]],",")); listArguments[["singlefile_sampleName"]]=NULL + singlefile_galaxyPath = listArguments[["singlefile_galaxyPath"]]; listArguments[["singlefile_galaxyPath"]]=NULL + singlefile_sampleName = listArguments[["singlefile_sampleName"]]; listArguments[["singlefile_sampleName"]]=NULL } # single file case diff --git a/galaxy/ipo/ipo4retgroup.xml b/galaxy/ipo/ipo4retgroup.xml index 8ad8653..ac5528d 100644 --- a/galaxy/ipo/ipo4retgroup.xml +++ b/galaxy/ipo/ipo4retgroup.xml @@ -21,6 +21,12 @@ LANG=C Rscript $__tool_directory__/ipo4retgroup.r image '$image' + + #if $input.is_of_type("mzxml") or $input.is_of_type("mzml") or $input.is_of_type("mzdata") or $input.is_of_type("netcdf"): + singlefile_galaxyPath '$input' singlefile_sampleName '$input.name' + #else + zipfile '$input' + #end if parametersOutput '$parametersOutput' @@ -41,11 +47,11 @@ ## retcor methods - #if $retcor.methods.method == "obiwarp": + #if $retcor.methods.retcormethod == "obiwarp": retcorMethod obiwarp - profStep $methods.section_retcor_obiwarp_non_optimizable.profStep + profStep $retcor.methods.section_retcor_obiwarp_non_optimizable.profStep - #elif $retcor.methods.method == "peakgroups": + #elif $retcor.methods.retcormethod == "peakgroups": retcorMethod loess smooth $retcor.methods.section_retcor_peakgroups_non_optimizable.smooth extra $retcor.methods.section_retcor_peakgroups_non_optimizable.extra @@ -53,7 +59,7 @@ span $retcor.methods.section_retcor_peakgroups_non_optimizable.span family $retcor.methods.section_retcor_peakgroups_non_optimizable.family plottype $retcor.methods.section_retcor_peakgroups_non_optimizable.plottype - #elif $retcor.methods.method == "none": + #elif $retcor.methods.retcormethod == "none": retcorMethod none #end if @@ -63,6 +69,8 @@ ]]> + + @@ -104,8 +112,8 @@
- - + + @@ -179,7 +187,7 @@
- +
diff --git a/galaxy/ipo/ipo4xcmsSet.r b/galaxy/ipo/ipo4xcmsSet.r index 4851b75..639dbd1 100755 --- a/galaxy/ipo/ipo4xcmsSet.r +++ b/galaxy/ipo/ipo4xcmsSet.r @@ -1,6 +1,8 @@ #!/usr/bin/env Rscript #Authors Gildas Le Corguille and Yann Guitton +# Setup R error handling to go to stderr for better error messages in Galaxy +options(show.error.messages=F, error=function(){cat(geterrmessage(),file=stderr());q("no",1,F)}) # ----- LOG FILE ----- log_file=file("log.txt", open = "wt") @@ -18,7 +20,7 @@ for(pkg in pkgs) { cat(pkg,"\t",as.character(packageVersion(pkg)),"\n",sep="") } source_local <- function(fname){ argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } -cat("\n\n"); +cat("\n\n"); @@ -82,15 +84,15 @@ if(exists("singlefile_galaxyPath") && (singlefile_galaxyPath!="")) { error_message=paste("Cannot access the sample:",singlefile_sampleName,"located:",singlefile_galaxyPath,". Please, contact your administrator ... if you have one!") print(error_message); stop(error_message) } - + cwd=getwd() dir.create("raw") setwd("raw") file.symlink(singlefile_galaxyPath,singlefile_sampleName) setwd(cwd) - + directory = "raw" - + } # We unzip automatically the chromatograms from the zip files. @@ -109,7 +111,7 @@ if(exists("zipfile") && (zipfile!="")) { setwd("ipoworkingdir") #unzip - suppressWarnings(unzip(zipfile, unzip="unzip")) + suppressWarnings(unzip(zipfile, unzip=getOption("unzip"))) #get the directory name filesInZip=unzip(zipfile, list=T); @@ -160,4 +162,3 @@ cat("\n\n") cat("\tDONE\n") - 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) }