Mercurial > repos > lecorguille > xcms_fillpeaks
comparison lib.r @ 29:f6d3e6be4ea3 draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit bff1445c9b00ccdbe05ee3dc6ed24221033384b9
| author | lecorguille |
|---|---|
| date | Tue, 24 Oct 2017 11:48:31 -0400 |
| parents | 4db7afa8284d |
| children | 6b5ed508f81f |
comparison
equal
deleted
inserted
replaced
| 28:9b0bf28bcbaf | 29:f6d3e6be4ea3 |
|---|---|
| 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 | |
| 54 #@author Y. Guitton | 90 #@author Y. Guitton |
| 55 getBPC <- function(file,rtcor=NULL, ...) { | 91 getBPC <- function(file,rtcor=NULL, ...) { |
| 56 object <- xcmsRaw(file) | 92 object <- xcmsRaw(file) |
| 57 sel <- profRange(object, ...) | 93 sel <- profRange(object, ...) |
| 58 cbind(if (is.null(rtcor)) object@scantime[sel$scanidx] else rtcor ,xcms:::colMax(object@env$profile[sel$massidx,sel$scanidx,drop=FALSE])) | 94 cbind(if (is.null(rtcor)) object@scantime[sel$scanidx] else rtcor ,xcms:::colMax(object@env$profile[sel$massidx,sel$scanidx,drop=FALSE])) |
| 92 rtcor <- xcmsSet@rt$corrected[[j]] | 128 rtcor <- xcmsSet@rt$corrected[[j]] |
| 93 else | 129 else |
| 94 rtcor <- NULL | 130 rtcor <- NULL |
| 95 | 131 |
| 96 TIC[[j]] <- getBPC(files[j],rtcor=rtcor) | 132 TIC[[j]] <- getBPC(files[j],rtcor=rtcor) |
| 133 | |
| 134 exportTicBpcTabular(TIC[[j]], files[j], "BPC", rt=rt) | |
| 135 | |
| 97 # TIC[[j]][,1]<-rtcor | 136 # TIC[[j]][,1]<-rtcor |
| 98 } | 137 } |
| 99 | 138 |
| 100 | 139 |
| 101 | 140 |
| 219 for (i in 1:N) { | 258 for (i in 1:N) { |
| 220 if (!is.null(xcmsSet) && rt == "corrected") | 259 if (!is.null(xcmsSet) && rt == "corrected") |
| 221 rtcor <- xcmsSet@rt$corrected[[i]] else | 260 rtcor <- xcmsSet@rt$corrected[[i]] else |
| 222 rtcor <- NULL | 261 rtcor <- NULL |
| 223 TIC[[i]] <- getTIC(files[i],rtcor=rtcor) | 262 TIC[[i]] <- getTIC(files[i],rtcor=rtcor) |
| 263 | |
| 264 exportTicBpcTabular(TIC[[i]], files[i], "TIC", rt=rt) | |
| 224 } | 265 } |
| 225 | 266 |
| 226 pdf(pdfname,w=16,h=10) | 267 pdf(pdfname,w=16,h=10) |
| 227 cols <- rainbow(N) | 268 cols <- rainbow(N) |
| 228 lty = 1:N | 269 lty = 1:N |
| 474 return(as.matrix(md5sum(files))) | 515 return(as.matrix(md5sum(files))) |
| 475 } | 516 } |
| 476 | 517 |
| 477 | 518 |
| 478 # This function get the raw file path from the arguments | 519 # This function get the raw file path from the arguments |
| 479 getRawfilePathFromArguments <- function(singlefile, zipfile, listArguments) { | 520 getRawfilePathFromArguments <- function(singlefile, zipfile, listArguments) { |
| 480 if (!is.null(listArguments[["zipfile"]])) zipfile = listArguments[["zipfile"]] | 521 if (!is.null(listArguments[["zipfile"]])) zipfile = listArguments[["zipfile"]] |
| 481 if (!is.null(listArguments[["zipfilePositive"]])) zipfile = listArguments[["zipfilePositive"]] | 522 if (!is.null(listArguments[["zipfilePositive"]])) zipfile = listArguments[["zipfilePositive"]] |
| 482 if (!is.null(listArguments[["zipfileNegative"]])) zipfile = listArguments[["zipfileNegative"]] | 523 if (!is.null(listArguments[["zipfileNegative"]])) zipfile = listArguments[["zipfileNegative"]] |
| 483 | 524 |
| 484 if (!is.null(listArguments[["singlefile_galaxyPath"]])) { | 525 if (!is.null(listArguments[["singlefile_galaxyPath"]])) { |
