Mercurial > repos > lecorguille > xcms_xcmsset
comparison xcms_xcmsSet.r @ 35:3990a65b45a4 draft default tip
planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics/ commit 95721ced8347c09e79340e6d67ecb41c5cc64163
author | workflow4metabolomics |
---|---|
date | Mon, 03 Feb 2025 14:48:09 +0000 |
parents | f5d51091cf84 |
children |
comparison
equal
deleted
inserted
replaced
34:6550698fe60f | 35:3990a65b45a4 |
---|---|
7 | 7 |
8 | 8 |
9 # ----- PACKAGE ----- | 9 # ----- PACKAGE ----- |
10 cat("\tSESSION INFO\n") | 10 cat("\tSESSION INFO\n") |
11 | 11 |
12 #Import the different functions | 12 # Import the different functions |
13 source_local <- function(fname) { | 13 source_local <- function(fname) { |
14 argv <- commandArgs(trailingOnly = FALSE) | 14 argv <- commandArgs(trailingOnly = FALSE) |
15 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) | 15 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) |
16 source(paste(base_dir, fname, sep = "/")) | 16 source(paste(base_dir, fname, sep = "/")) |
17 } | 17 } |
18 source_local("lib.r") | 18 source_local("lib.r") |
19 | 19 |
20 pkgs <- c("xcms", "batch") | 20 pkgs <- c("xcms", "batch") |
21 loadAndDisplayPackages(pkgs) | 21 loadAndDisplayPackages(pkgs) |
22 cat("\n\n") | 22 cat("\n\n") |
23 | 23 |
24 | 24 |
25 # ----- ARGUMENTS ----- | 25 # ----- ARGUMENTS ----- |
26 cat("\tARGUMENTS INFO\n") | 26 cat("\tARGUMENTS INFO\n") |
27 args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects | 27 args <- parseCommandArgs(evaluate = FALSE) # interpretation of arguments given in command line as an R list of objects |
28 write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t") | 28 write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t") |
29 | 29 |
30 cat("\n\n") | 30 cat("\n\n") |
31 | 31 |
32 | 32 |
33 # ----- PROCESSING INFILE ----- | 33 # ----- PROCESSING INFILE ----- |
34 cat("\tARGUMENTS PROCESSING INFO\n") | 34 cat("\tARGUMENTS PROCESSING INFO\n") |
35 | 35 |
36 #saving the commun parameters | 36 # saving the commun parameters |
37 BPPARAM <- MulticoreParam(1) | 37 BPPARAM <- MulticoreParam(1) |
38 if (!is.null(args$BPPARAM)) { | 38 if (!is.null(args$BPPARAM)) { |
39 BPPARAM <- MulticoreParam(args$BPPARAM) | 39 BPPARAM <- MulticoreParam(args$BPPARAM) |
40 } | 40 } |
41 register(BPPARAM) | 41 register(BPPARAM) |
42 | 42 |
43 #saving the specific parameters | 43 # saving the specific parameters |
44 if (!is.null(args$filterAcquisitionNum)) filterAcquisitionNumParam <- args$filterAcquisitionNum | 44 if (!is.null(args$filterAcquisitionNum)) filterAcquisitionNumParam <- args$filterAcquisitionNum |
45 if (!is.null(args$filterRt)) filterRtParam <- args$filterRt | 45 if (!is.null(args$filterRt)) filterRtParam <- args$filterRt |
46 if (!is.null(args$filterMz)) filterMzParam <- args$filterMz | 46 if (!is.null(args$filterMz)) filterMzParam <- args$filterMz |
47 if (!is.null(args$peaklist)) peaklistParam <- args$peaklist | 47 if (!is.null(args$peaklist)) peaklistParam <- args$peaklist |
48 | 48 |
49 method <- args$method | 49 method <- args$method |
50 | 50 |
51 if (!is.null(args$roiList)) { | 51 if (!is.null(args$roiList)) { |
52 cat("\t\troiList provided\n") | 52 cat("\t\troiList provided\n") |
53 args$roiList <- list(getDataFrameFromFile(args$roiList)) | 53 args$roiList <- list(getDataFrameFromFile(args$roiList)) |
54 print(args$roiList) | 54 print(args$roiList) |
55 } | 55 } |
56 | 56 |
57 cat("\n\n") | 57 cat("\n\n") |
58 | 58 |
59 # ----- INFILE PROCESSING ----- | 59 # ----- INFILE PROCESSING ----- |
60 cat("\tINFILE PROCESSING INFO\n") | 60 cat("\tINFILE PROCESSING INFO\n") |
61 | 61 |
62 #image is an .RData file necessary to use xset variable given by previous tools | 62 # image is an .RData file necessary to use xset variable given by previous tools |
63 load(args$image) | 63 load(args$image) |
64 if (!exists("raw_data")) stop("\n\nERROR: The RData doesn't contain any object called 'raw_data' which is provided by the tool: MSnbase readMSData") | 64 if (!exists("raw_data")) stop("\n\nERROR: The RData doesn't contain any object called 'raw_data' which is provided by the tool: MSnbase readMSData") |
65 | 65 |
66 # Handle infiles | 66 # Handle infiles |
67 rawFilePath <- retrieveRawfileInTheWorkingDir(singlefile, zipfile, args) | 67 rawFilePath <- retrieveRawfileInTheWorkingDir(singlefile, zipfile, args) |
77 | 77 |
78 | 78 |
79 cat("\t\tCOMPUTE\n") | 79 cat("\t\tCOMPUTE\n") |
80 | 80 |
81 cat("\t\t\tApply filter[s] (if asked)\n") | 81 cat("\t\t\tApply filter[s] (if asked)\n") |
82 if (exists("filterAcquisitionNumParam")) raw_data <- filterAcquisitionNum(raw_data, filterAcquisitionNumParam[1]:filterAcquisitionNumParam[2]) | 82 if (exists("filterAcquisitionNumParam")) raw_data <- filterAcquisitionNum(raw_data, filterAcquisitionNumParam[1]:filterAcquisitionNumParam[2]) |
83 if (exists("filterRtParam")) raw_data <- filterRt(raw_data, filterRtParam) | 83 if (exists("filterRtParam")) raw_data <- filterRt(raw_data, filterRtParam) |
84 if (exists("filterMzParam")) raw_data <- filterMz(raw_data, filterMzParam) | 84 if (exists("filterMzParam")) raw_data <- filterMz(raw_data, filterMzParam) |
85 #Apply this filter only if file contain MS and MSn | 85 # Apply this filter only if file contain MS and MSn |
86 if (length(unique(msLevel(raw_data))) != 1) { | 86 if (length(unique(msLevel(raw_data))) != 1) { |
87 raw_data <- filterMsLevel(raw_data, msLevel = 1) | 87 raw_data <- filterMsLevel(raw_data, msLevel = 1) |
88 } | 88 } |
89 | 89 |
90 cat("\t\t\tChromatographic peak detection\n") | 90 cat("\t\t\tChromatographic peak detection\n") |
91 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ... | 91 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ... |
92 args <- args[names(args) %in% slotNames(do.call(paste0(method, "Param"), list()))] | 92 args <- args[names(args) %in% slotNames(do.call(paste0(method, "Param"), list()))] |
101 # Create a sampleMetada file | 101 # Create a sampleMetada file |
102 sampleNamesList <- getSampleMetadata(xdata = xdata, sampleMetadataOutput = "sampleMetadata.tsv") | 102 sampleNamesList <- getSampleMetadata(xdata = xdata, sampleMetadataOutput = "sampleMetadata.tsv") |
103 | 103 |
104 # Create a chromPeaks table if required | 104 # Create a chromPeaks table if required |
105 if (exists("peaklistParam")) { | 105 if (exists("peaklistParam")) { |
106 if (peaklistParam) { | 106 if (peaklistParam) { |
107 cat("\nCreating the chromatographic peaks' table...\n") | 107 cat("\nCreating the chromatographic peaks' table...\n") |
108 write.table(chromPeaks(xdata), file = "chromPeak_table.tsv", sep = "\t", quote = FALSE, row.names = FALSE) | 108 write.table(chromPeaks(xdata), file = "chromPeak_table.tsv", sep = "\t", quote = FALSE, row.names = FALSE) |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 cat("\n\n") | 112 cat("\n\n") |
113 | 113 |
114 # ----- EXPORT ----- | 114 # ----- EXPORT ----- |
121 # Get the legacy xcmsSet object | 121 # Get the legacy xcmsSet object |
122 xset <- getxcmsSetObject(xdata) | 122 xset <- getxcmsSetObject(xdata) |
123 print(xset) | 123 print(xset) |
124 cat("\n\n") | 124 cat("\n\n") |
125 | 125 |
126 #saving R data in .Rdata file to save the variables used in the present tool | 126 # saving R data in .Rdata file to save the variables used in the present tool |
127 objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList") | 127 objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList") |
128 save(list = objects2save[objects2save %in% ls()], file = "xcmsSet.RData") | 128 save(list = objects2save[objects2save %in% ls()], file = "xcmsSet.RData") |
129 | 129 |
130 | 130 |
131 cat("\tDONE\n") | 131 cat("\tDONE\n") |