Mercurial > repos > lecorguille > xcms_retcor
comparison lib.r @ 29:c013ed353a2f draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 73791d74546087b2a872d9279df960f5bc207298
author | lecorguille |
---|---|
date | Tue, 13 Feb 2018 04:44:03 -0500 |
parents | 30410a052ab3 |
children | 4d6f4cd7c3ef |
comparison
equal
deleted
inserted
replaced
28:13885e67b123 | 29:c013ed353a2f |
---|---|
49 | 49 |
50 write.table(variableMetadata, file=variableMetadataOutput,sep="\t",quote=F,row.names=F) | 50 write.table(variableMetadata, file=variableMetadataOutput,sep="\t",quote=F,row.names=F) |
51 write.table(dataMatrix, file=dataMatrixOutput,sep="\t",quote=F,row.names=F) | 51 write.table(dataMatrix, file=dataMatrixOutput,sep="\t",quote=F,row.names=F) |
52 } | 52 } |
53 | 53 |
54 #@author G. Le Corguille | |
55 exportTicBpcTabular <- function(dataset, filenameBase, ticORbpc, rt='raw') { | |
56 | |
57 rawORcorrected = '' | |
58 title = '' | |
59 if (rt=='corrected') { | |
60 rawORcorrected = '_corrected' | |
61 title = ' corrected by retcor' | |
62 } | |
63 | |
64 if (ticORbpc == "TIC") { | |
65 section_name = paste0('TIC',rawORcorrected) | |
66 title = paste0('Total Ion Current (TIC) chromatogram',title) | |
67 description = 'Sum of intensity (Y) of all ions detected at each retention time(X)' | |
68 } else if (ticORbpc == "BPC") { | |
69 section_name = paste0('BPC',rawORcorrected) | |
70 title = paste0('Base Peak Chromatogram (BPC)',title) | |
71 description = 'Sum of intensity (Y) of the most intense peaks at each retention time(X)' | |
72 } | |
73 | |
74 filename=paste0(basename(file_path_sans_ext(filenameBase)),"-",ticORbpc,rawORcorrected,"_mqc.out") | |
75 | |
76 # Headers for MultiQC | |
77 cat("# file_format: 'tsv'\n", sep="", file = filename) | |
78 cat("# section_name: '",section_name,"'\n", sep="", file = filename, append = T) | |
79 cat("# title: '",title,"'\n", sep="", file = filename, append = T) | |
80 cat("# description: '",description,"'\n", sep="", file = filename, append = T) | |
81 cat("# plot_type: 'linegraph'\n", sep="", file = filename, append = T) | |
82 cat("# pconfig:\n", sep="", file = filename, append = T) | |
83 cat("# id: '",ticORbpc,rawORcorrected,"_lineplot'\n", sep="", file = filename, append = T) | |
84 cat("# ylab: 'Base Peak Intensity'\n", sep="", file = filename, append = T) | |
85 cat("# xlab: 'Retention Time'\n", sep="", file = filename, append = T) | |
86 cat("Intensity\tRT\n", file = filename, append = T) | |
87 write.table(dataset, filename ,row.names = F, col.names = F, sep = "\t", append = T, quote = F) | |
88 } | |
89 | |
90 #@author Y. Guitton | 54 #@author Y. Guitton |
91 getBPC <- function(file,rtcor=NULL, ...) { | 55 getBPC <- function(file,rtcor=NULL, ...) { |
92 object <- xcmsRaw(file) | 56 object <- xcmsRaw(file) |
93 sel <- profRange(object, ...) | 57 sel <- profRange(object, ...) |
94 cbind(if (is.null(rtcor)) object@scantime[sel$scanidx] else rtcor ,xcms:::colMax(object@env$profile[sel$massidx,sel$scanidx,drop=FALSE])) | 58 cbind(if (is.null(rtcor)) object@scantime[sel$scanidx] else rtcor ,xcms:::colMax(object@env$profile[sel$massidx,sel$scanidx,drop=FALSE])) |
128 rtcor <- xcmsSet@rt$corrected[[j]] | 92 rtcor <- xcmsSet@rt$corrected[[j]] |
129 else | 93 else |
130 rtcor <- NULL | 94 rtcor <- NULL |
131 | 95 |
132 TIC[[j]] <- getBPC(files[j],rtcor=rtcor) | 96 TIC[[j]] <- getBPC(files[j],rtcor=rtcor) |
133 | |
134 exportTicBpcTabular(TIC[[j]], files[j], "BPC", rt=rt) | |
135 | |
136 # TIC[[j]][,1]<-rtcor | 97 # TIC[[j]][,1]<-rtcor |
137 } | 98 } |
138 | 99 |
139 | 100 |
140 | 101 |
258 for (i in 1:N) { | 219 for (i in 1:N) { |
259 if (!is.null(xcmsSet) && rt == "corrected") | 220 if (!is.null(xcmsSet) && rt == "corrected") |
260 rtcor <- xcmsSet@rt$corrected[[i]] else | 221 rtcor <- xcmsSet@rt$corrected[[i]] else |
261 rtcor <- NULL | 222 rtcor <- NULL |
262 TIC[[i]] <- getTIC(files[i],rtcor=rtcor) | 223 TIC[[i]] <- getTIC(files[i],rtcor=rtcor) |
263 | |
264 exportTicBpcTabular(TIC[[i]], files[i], "TIC", rt=rt) | |
265 } | 224 } |
266 | 225 |
267 pdf(pdfname,w=16,h=10) | 226 pdf(pdfname,w=16,h=10) |
268 cols <- rainbow(N) | 227 cols <- rainbow(N) |
269 lty = 1:N | 228 lty = 1:N |
515 return(as.matrix(md5sum(files))) | 474 return(as.matrix(md5sum(files))) |
516 } | 475 } |
517 | 476 |
518 | 477 |
519 # This function get the raw file path from the arguments | 478 # This function get the raw file path from the arguments |
520 getRawfilePathFromArguments <- function(singlefile, zipfile, listArguments) { | 479 getRawfilePathFromArguments <- function(singlefile, zipfile, listArguments) { |
521 if (!is.null(listArguments[["zipfile"]])) zipfile = listArguments[["zipfile"]] | 480 if (!is.null(listArguments[["zipfile"]])) zipfile = listArguments[["zipfile"]] |
522 if (!is.null(listArguments[["zipfilePositive"]])) zipfile = listArguments[["zipfilePositive"]] | 481 if (!is.null(listArguments[["zipfilePositive"]])) zipfile = listArguments[["zipfilePositive"]] |
523 if (!is.null(listArguments[["zipfileNegative"]])) zipfile = listArguments[["zipfileNegative"]] | 482 if (!is.null(listArguments[["zipfileNegative"]])) zipfile = listArguments[["zipfileNegative"]] |
524 | 483 |
525 if (!is.null(listArguments[["singlefile_galaxyPath"]])) { | 484 if (!is.null(listArguments[["singlefile_galaxyPath"]])) { |