Mercurial > repos > lecorguille > xcms_xcmsset
comparison xcms_xcmsSet.r @ 32:b02d1992a43a draft
"planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
author | workflow4metabolomics |
---|---|
date | Wed, 07 Apr 2021 16:47:14 +0000 |
parents | eb15a3841da4 |
children | f5d51091cf84 |
comparison
equal
deleted
inserted
replaced
31:eb15a3841da4 | 32:b02d1992a43a |
---|---|
1 #!/usr/bin/env Rscript | 1 #!/usr/bin/env Rscript |
2 | 2 |
3 # ----- LOG FILE ----- | 3 # ----- LOG FILE ----- |
4 log_file <- file("log.txt", open="wt") | 4 log_file <- file("log.txt", open = "wt") |
5 sink(log_file) | 5 sink(log_file) |
6 sink(log_file, type = "output") | 6 sink(log_file, type = "output") |
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){ argv <- commandArgs(trailingOnly=FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } | 13 source_local <- function(fname) { |
14 argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/")) | |
15 } | |
14 source_local("lib.r") | 16 source_local("lib.r") |
15 | 17 |
16 pkgs <- c("xcms","batch") | 18 pkgs <- c("xcms", "batch") |
17 loadAndDisplayPackages(pkgs) | 19 loadAndDisplayPackages(pkgs) |
18 cat("\n\n"); | 20 cat("\n\n"); |
19 | 21 |
20 | 22 |
21 # ----- ARGUMENTS ----- | 23 # ----- ARGUMENTS ----- |
22 cat("\tARGUMENTS INFO\n") | 24 cat("\tARGUMENTS INFO\n") |
23 args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects | 25 args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects |
24 write.table(as.matrix(args), col.names=F, quote=F, sep='\t') | 26 write.table(as.matrix(args), col.names = F, quote = F, sep = "\t") |
25 | 27 |
26 cat("\n\n") | 28 cat("\n\n") |
27 | 29 |
28 | 30 |
29 # ----- PROCESSING INFILE ----- | 31 # ----- PROCESSING INFILE ----- |
30 cat("\tARGUMENTS PROCESSING INFO\n") | 32 cat("\tARGUMENTS PROCESSING INFO\n") |
31 | 33 |
32 #saving the commun parameters | 34 #saving the commun parameters |
33 BPPARAM <- MulticoreParam(1) | 35 BPPARAM <- MulticoreParam(1) |
34 if (!is.null(args$BPPARAM)){ | 36 if (!is.null(args$BPPARAM)) { |
35 BPPARAM <- MulticoreParam(args$BPPARAM) | 37 BPPARAM <- MulticoreParam(args$BPPARAM) |
36 } | 38 } |
37 register(BPPARAM) | 39 register(BPPARAM) |
38 | 40 |
39 #saving the specific parameters | 41 #saving the specific parameters |
42 if (!is.null(args$filterMz)) filterMzParam <- args$filterMz | 44 if (!is.null(args$filterMz)) filterMzParam <- args$filterMz |
43 if (!is.null(args$peaklist)) peaklistParam <- args$peaklist | 45 if (!is.null(args$peaklist)) peaklistParam <- args$peaklist |
44 | 46 |
45 method <- args$method | 47 method <- args$method |
46 | 48 |
47 if (!is.null(args$roiList)){ | 49 if (!is.null(args$roiList)) { |
48 cat("\t\troiList provided\n") | 50 cat("\t\troiList provided\n") |
49 args$roiList <- list(getDataFrameFromFile(args$roiList)) | 51 args$roiList <- list(getDataFrameFromFile(args$roiList)) |
50 print(args$roiList) | 52 print(args$roiList) |
51 } | 53 } |
52 | 54 |
58 #image is an .RData file necessary to use xset variable given by previous tools | 60 #image is an .RData file necessary to use xset variable given by previous tools |
59 load(args$image) | 61 load(args$image) |
60 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") | 62 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") |
61 | 63 |
62 # Handle infiles | 64 # Handle infiles |
63 rawFilePath <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile, args) | 65 rawFilePath <- retrieveRawfileInTheWorkingDir(singlefile, zipfile, args) |
64 zipfile <- rawFilePath$zipfile | 66 zipfile <- rawFilePath$zipfile |
65 singlefile <- rawFilePath$singlefile | 67 singlefile <- rawFilePath$singlefile |
66 | 68 |
67 | 69 |
68 cat("\n\n") | 70 cat("\n\n") |
77 cat("\t\t\tApply filter[s] (if asked)\n") | 79 cat("\t\t\tApply filter[s] (if asked)\n") |
78 if (exists("filterAcquisitionNumParam")) raw_data <- filterAcquisitionNum(raw_data, filterAcquisitionNumParam[1]:filterAcquisitionNumParam[2]) | 80 if (exists("filterAcquisitionNumParam")) raw_data <- filterAcquisitionNum(raw_data, filterAcquisitionNumParam[1]:filterAcquisitionNumParam[2]) |
79 if (exists("filterRtParam")) raw_data <- filterRt(raw_data, filterRtParam) | 81 if (exists("filterRtParam")) raw_data <- filterRt(raw_data, filterRtParam) |
80 if (exists("filterMzParam")) raw_data <- filterMz(raw_data, filterMzParam) | 82 if (exists("filterMzParam")) raw_data <- filterMz(raw_data, filterMzParam) |
81 #Apply this filter only if file contain MS and MSn | 83 #Apply this filter only if file contain MS and MSn |
82 if(length(unique(msLevel(raw_data)))!= 1){ | 84 if (length(unique(msLevel(raw_data))) != 1) { |
83 raw_data <- filterMsLevel(raw_data,msLevel=1) | 85 raw_data <- filterMsLevel(raw_data, msLevel = 1) |
84 } | 86 } |
85 | 87 |
86 cat("\t\t\tChromatographic peak detection\n") | 88 cat("\t\t\tChromatographic peak detection\n") |
87 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ... | 89 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ... |
88 args <- args[names(args) %in% slotNames(do.call(paste0(method,"Param"), list()))] | 90 args <- args[names(args) %in% slotNames(do.call(paste0(method, "Param"), list()))] |
89 | 91 |
90 findChromPeaksParam <- do.call(paste0(method,"Param"), args) | 92 findChromPeaksParam <- do.call(paste0(method, "Param"), args) |
91 print(findChromPeaksParam) | 93 print(findChromPeaksParam) |
92 xdata <- findChromPeaks(raw_data, param=findChromPeaksParam) | 94 xdata <- findChromPeaks(raw_data, param = findChromPeaksParam) |
93 | 95 |
94 # Check if there are no peaks | 96 # Check if there are no peaks |
95 if (nrow(chromPeaks(xdata)) == 0) stop("No peaks were detected. You should review your settings") | 97 if (nrow(chromPeaks(xdata)) == 0) stop("No peaks were detected. You should review your settings") |
96 | 98 |
97 # Create a sampleMetada file | 99 # Create a sampleMetada file |
98 sampleNamesList <- getSampleMetadata(xdata=xdata, sampleMetadataOutput="sampleMetadata.tsv") | 100 sampleNamesList <- getSampleMetadata(xdata = xdata, sampleMetadataOutput = "sampleMetadata.tsv") |
99 | |
100 #cat("\t\t\tCompute and Store TIC and BPI\n") | |
101 #chromTIC = chromatogram(xdata, aggregationFun = "sum") | |
102 #chromBPI = chromatogram(xdata, aggregationFun = "max") | |
103 | 101 |
104 # Create a chromPeaks table if required | 102 # Create a chromPeaks table if required |
105 if (exists("peaklistParam")) { | 103 if (exists("peaklistParam")) { |
106 if(peaklistParam){ | 104 if (peaklistParam) { |
107 cat("\nCreating the chromatographic peaks' table...\n") | 105 cat("\nCreating the chromatographic peaks' table...\n") |
108 write.table(chromPeaks(xdata), file="chromPeak_table.tsv",sep="\t",quote=F,row.names=F) | 106 write.table(chromPeaks(xdata), file = "chromPeak_table.tsv", sep = "\t", quote = F, row.names = F) |
109 } | 107 } |
110 } | 108 } |
111 | 109 |
112 cat("\n\n") | 110 cat("\n\n") |
113 | 111 |
114 # ----- EXPORT ----- | 112 # ----- EXPORT ----- |
122 xset <- getxcmsSetObject(xdata) | 120 xset <- getxcmsSetObject(xdata) |
123 print(xset) | 121 print(xset) |
124 cat("\n\n") | 122 cat("\n\n") |
125 | 123 |
126 #saving R data in .Rdata file to save the variables used in the present tool | 124 #saving R data in .Rdata file to save the variables used in the present tool |
127 objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList") #, "chromTIC", "chromBPI") | 125 objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList") |
128 save(list=objects2save[objects2save %in% ls()], file="xcmsSet.RData") | 126 save(list = objects2save[objects2save %in% ls()], file = "xcmsSet.RData") |
129 | 127 |
130 | 128 |
131 cat("\tDONE\n") | 129 cat("\tDONE\n") |