|
| 1 | +getInfos = function(mzdatafiles){ |
| 2 | + |
| 3 | + # Get informations about instruments used and run |
| 4 | + file.format = c("mzData", "mzdata") |
| 5 | + if(tools::file_ext(mzdatafiles) %in% file.format){ |
| 6 | + ms = openMSfile(mzdatafiles, backend="Ramp") |
| 7 | + } else { |
| 8 | + ms = openMSfile(mzdatafiles) |
| 9 | + } |
| 10 | + |
| 11 | + runInfo = t(sapply(runInfo(ms), function(x) x[1], USE.NAMES=TRUE)) |
| 12 | + instrumentInfo = t(sapply(instrumentInfo(ms), function(x) x, USE.NAMES=TRUE)) |
| 13 | + |
| 14 | + infos = list("runinfo" = runInfo, "instrumentInfo" = instrumentInfo) |
| 15 | + return (infos) |
| 16 | +} |
| 17 | + |
| 18 | + |
| 19 | + |
1 | 20 | ## |
2 | 21 | ## This function launch IPO functions to get the best parameters for xcmsSet |
3 | 22 | ## A sample among the whole dataset is used to save time |
@@ -32,13 +51,35 @@ ipo4xcmsSet = function(directory, parametersOutput, listArguments, samplebyclass |
32 | 51 | # filter listArguments to only get releavant parameters and complete with those that are not declared |
33 | 52 | peakpickingParametersUser = c(listArguments[names(listArguments) %in% names(peakpickingParameters)], peakpickingParameters[!(names(peakpickingParameters) %in% names(listArguments))]) |
34 | 53 | peakpickingParametersUser$verbose.columns = TRUE |
| 54 | + |
| 55 | + # allow range for min and max peakwidth and ppm if given in arguments |
| 56 | + if (!is.null(listArguments[["minPeakWidth"]])){ |
| 57 | + peakpickingParametersUser$min_peakwidth = as.vector(as.numeric(unlist(strsplit(listArguments[["minPeakWidth"]],split = ",")))) |
| 58 | + listArguments[["minPeakWidth"]] = NULL |
| 59 | + } |
| 60 | + |
| 61 | + if (!is.null(listArguments[["maxPeakWidth"]])){ |
| 62 | + peakpickingParametersUser$max_peakwidth = as.vector(as.numeric(unlist(strsplit(listArguments[["maxPeakWidth"]],split = ",")))) |
| 63 | + listArguments[["maxPeakWidth"]] = NULL |
| 64 | + } |
| 65 | + |
| 66 | + if (!is.null(listArguments[["ppm"]])){ |
| 67 | + if(grepl(",", listArguments[["ppm"]])) |
| 68 | + peakpickingParametersUser$ppm = as.vector(as.numeric(unlist(strsplit(listArguments[["ppm"]],split = ",")))) |
| 69 | + else |
| 70 | + peakpickingParametersUser$ppm = listArguments[["ppm"]] |
| 71 | + listArguments[["ppm"]] = NULL |
| 72 | + } |
35 | 73 |
|
36 | 74 | #peakpickingParametersUser$profparam <- list(step=0.005) #not yet used by IPO have to think of it for futur improvement |
37 | 75 | resultPeakpicking = optimizeXcmsSet(mzmlfile, peakpickingParametersUser, nSlaves=peakpickingParametersUser$nSlaves, subdir="../IPO_results") #some images generated by IPO |
38 | 76 |
|
39 | | - # export |
40 | | - resultPeakpicking_best_settings_parameters = resultPeakpicking$best_settings$parameters[!(names(resultPeakpicking$best_settings$parameters) %in% c("nSlaves","verbose.columns"))] |
41 | | - 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 |
| 77 | + # export results |
| 78 | + resultPeakpicking_best_settings_parameters = resultPeakpicking$best_settings$parameters[!(names(resultPeakpicking$best_settings$parameters) %in% c("nSlaves","verbose.columns"))] |
| 79 | + |
| 80 | + infos = getInfos(mzmlfile) |
| 81 | + # Write results in table with machine and run infos |
| 82 | + 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) |
42 | 83 |
|
43 | 84 | return (resultPeakpicking$best_settings$xset) |
44 | 85 | } |
|
0 commit comments