Skip to content
This repository was archived by the owner on Dec 16, 2019. It is now read-only.
8 changes: 4 additions & 4 deletions galaxy/ipo/ipo4retgroup.r
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -42,8 +44,6 @@ source_local("lib.r")

cat("\n\n")

#Import the different functions

# ----- PROCESSING INFILE -----
cat("\tARGUMENTS PROCESSING INFO\n")

Expand All @@ -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
Expand Down
22 changes: 15 additions & 7 deletions galaxy/ipo/ipo4retgroup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -41,19 +47,19 @@

## 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
missing $retcor.methods.section_retcor_peakgroups_non_optimizable.missing
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

Expand All @@ -63,6 +69,8 @@
]]></command>

<inputs>

<param name="input" type="data" format="mzxml,mzml,mzdata,netcdf,no_unzip.zip,zip" label="File(s) from your history containing your chromatograms" help="Single file mode for the format: mzxml, mzml, mzdata and netcdf. Zip file mode for the format: no_unzip.zip, zip. See the help section below." />

<param name="image" type="data" format="rdata.xcms.raw,rdata.xcms.group,rdata.xcms.retcor,rdata" label="xset RData file" help="output file from another function xcms (xcmsSet, retcor etc.)" />

Expand Down Expand Up @@ -104,8 +112,8 @@

<section name="retcor" title="Retcor Options" expanded="True">
<conditional name="methods">
<param name="method" type="select" label="Method to use for retention time correction" help="[method] See the help section below" >
<option value="obiwarp">obiwarp</option>
<param name="retcormethod" type="select" label="Method to use for retention time correction" help="[method] See the help section below" >
<option value="obiwarp" selected="true">obiwarp</option>
<option value="peakgroups">peakgroups</option>
</param>
<when value="obiwarp">
Expand Down Expand Up @@ -179,7 +187,7 @@
</section>
<section name="retcor">
<conditional name="methods">
<param name="method" value="peakgroups"/>
<param name="retcormethod" value="peakgroups"/>
<section name="section_retcor_peakgroups_non_optimizable">
<param name="smooth" value="loess"/>
<param name="rextra" value="1"/>
Expand Down
13 changes: 7 additions & 6 deletions galaxy/ipo/ipo4xcmsSet.r
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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");



Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -160,4 +162,3 @@ cat("\n\n")


cat("\tDONE\n")

47 changes: 44 additions & 3 deletions galaxy/ipo/lib.r
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
Expand Down