Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
Added getInfos(mzfiles) function to complete output results
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielctn committed Apr 8, 2018
1 parent 22dc8e5 commit 06b079d
Showing 1 changed file with 44 additions and 3 deletions.
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

1 comment on commit 06b079d

@gabrielctn
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I should have made another commit for the part "allowing range for min and max peakwidth and ppm if given in arguments".

Please sign in to comment.