Mercurial > repos > lecorguille > xcms_fillpeaks
comparison lib.r @ 35:e67cbb96d9e9 draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 5e066c50d2e4ac6d5796b53331cbd3198ab8c4f9-dirty
| author | lecorguille | 
|---|---|
| date | Thu, 05 Apr 2018 18:10:27 -0400 | 
| parents | d8bac1291473 | 
| children | e3efe78b14c5 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 34:d8bac1291473 | 35:e67cbb96d9e9 | 
|---|---|
| 26 cat("Other loaded packages:\n") | 26 cat("Other loaded packages:\n") | 
| 27 for (pkg in names(sessioninfo$loadedOnly)) { cat(paste(pkg,packageVersion(pkg)),"\t") }; cat("\n") | 27 for (pkg in names(sessioninfo$loadedOnly)) { cat(paste(pkg,packageVersion(pkg)),"\t") }; cat("\n") | 
| 28 } | 28 } | 
| 29 | 29 | 
| 30 #@author G. Le Corguille | 30 #@author G. Le Corguille | 
| 31 # This function merge several chromBPI or chromTIC into one. | |
| 32 mergeChrom <- function(chromTIC_merged, chromTIC, xdata_merged) { | |
| 33 if (is.null(chromTIC_merged)) return(NULL) | |
| 34 chromTIC_merged@.Data <- cbind(chromTIC_merged@.Data, chromTIC@.Data) | |
| 35 chromTIC_merged@phenoData <- xdata_merged@phenoData | |
| 36 return(chromTIC_merged) | |
| 37 } | |
| 38 | |
| 39 #@author G. Le Corguille | |
| 31 # This function merge several xdata into one. | 40 # This function merge several xdata into one. | 
| 32 mergeXData <- function(args) { | 41 mergeXData <- function(args) { | 
| 42 chromTIC <- NULL; chromBPI <- NULL | |
| 33 for(image in args$images) { | 43 for(image in args$images) { | 
| 34 load(image) | 44 load(image) | 
| 35 # Handle infiles | 45 # Handle infiles | 
| 36 if (!exists("singlefile")) singlefile <- NULL | 46 if (!exists("singlefile")) singlefile <- NULL | 
| 37 if (!exists("zipfile")) zipfile <- NULL | 47 if (!exists("zipfile")) zipfile <- NULL | 
| 45 if (!exists("xdata_merged")) { | 55 if (!exists("xdata_merged")) { | 
| 46 xdata_merged <- xdata | 56 xdata_merged <- xdata | 
| 47 singlefile_merged <- singlefile | 57 singlefile_merged <- singlefile | 
| 48 md5sumList_merged <- md5sumList | 58 md5sumList_merged <- md5sumList | 
| 49 sampleNamesList_merged <- sampleNamesList | 59 sampleNamesList_merged <- sampleNamesList | 
| 60 chromTIC_merged <- chromTIC | |
| 61 chromBPI_merged <- chromBPI | |
| 50 } else { | 62 } else { | 
| 51 if (is(xdata, "XCMSnExp")) xdata_merged <- c(xdata_merged,xdata) | 63 if (is(xdata, "XCMSnExp")) xdata_merged <- c(xdata_merged,xdata) | 
| 52 else if (is(xdata, "OnDiskMSnExp")) xdata_merged <- .concatenate_OnDiskMSnExp(xdata_merged,xdata) | 64 else if (is(xdata, "OnDiskMSnExp")) xdata_merged <- .concatenate_OnDiskMSnExp(xdata_merged,xdata) | 
| 53 else stop("\n\nERROR: The RData either a OnDiskMSnExp object called raw_data or a XCMSnExp object called xdata") | 65 else stop("\n\nERROR: The RData either a OnDiskMSnExp object called raw_data or a XCMSnExp object called xdata") | 
| 54 singlefile_merged <- c(singlefile_merged,singlefile) | 66 singlefile_merged <- c(singlefile_merged,singlefile) | 
| 55 md5sumList_merged$origin <- rbind(md5sumList_merged$origin,md5sumList$origin) | 67 md5sumList_merged$origin <- rbind(md5sumList_merged$origin,md5sumList$origin) | 
| 56 sampleNamesList_merged$sampleNamesOrigin <- c(sampleNamesList_merged$sampleNamesOrigin,sampleNamesList$sampleNamesOrigin) | 68 sampleNamesList_merged$sampleNamesOrigin <- c(sampleNamesList_merged$sampleNamesOrigin,sampleNamesList$sampleNamesOrigin) | 
| 57 sampleNamesList_merged$sampleNamesMakeNames <- c(sampleNamesList_merged$sampleNamesMakeNames,sampleNamesList$sampleNamesMakeNames) | 69 sampleNamesList_merged$sampleNamesMakeNames <- c(sampleNamesList_merged$sampleNamesMakeNames,sampleNamesList$sampleNamesMakeNames) | 
| 70 chromTIC_merged <- mergeChrom(chromTIC_merged, chromTIC, xdata_merged) | |
| 71 chromBPI_merged <- mergeChrom(chromBPI_merged, chromBPI, xdata_merged) | |
| 58 } | 72 } | 
| 59 } | 73 } | 
| 60 rm(image) | 74 rm(image) | 
| 61 xdata <- xdata_merged; rm(xdata_merged) | 75 xdata <- xdata_merged; rm(xdata_merged) | 
| 62 singlefile <- singlefile_merged; rm(singlefile_merged) | 76 singlefile <- singlefile_merged; rm(singlefile_merged) | 
| 63 md5sumList <- md5sumList_merged; rm(md5sumList_merged) | 77 md5sumList <- md5sumList_merged; rm(md5sumList_merged) | 
| 64 sampleNamesList <- sampleNamesList_merged; rm(sampleNamesList_merged) | 78 sampleNamesList <- sampleNamesList_merged; rm(sampleNamesList_merged) | 
| 79 chromTIC <- chromTIC_merged; rm(chromTIC_merged) | |
| 80 chromBPI <- chromBPI_merged; rm(chromBPI_merged) | |
| 65 | 81 | 
| 66 if (!is.null(args$sampleMetadata)) { | 82 if (!is.null(args$sampleMetadata)) { | 
| 67 cat("\tXSET PHENODATA SETTING...\n") | 83 cat("\tXSET PHENODATA SETTING...\n") | 
| 68 sampleMetadataFile <- args$sampleMetadata | 84 sampleMetadataFile <- args$sampleMetadata | 
| 69 sampleMetadata <- getDataFrameFromFile(sampleMetadataFile, header=F) | 85 sampleMetadata <- getDataFrameFromFile(sampleMetadataFile, header=F) | 
| 74 error_message <- paste("Those samples are missing in your sampleMetadata:", paste(sample_missing, collapse=" ")) | 90 error_message <- paste("Those samples are missing in your sampleMetadata:", paste(sample_missing, collapse=" ")) | 
| 75 print(error_message) | 91 print(error_message) | 
| 76 stop(error_message) | 92 stop(error_message) | 
| 77 } | 93 } | 
| 78 } | 94 } | 
| 79 return(list("xdata"=xdata, "singlefile"=singlefile, "md5sumList"=md5sumList,"sampleNamesList"=sampleNamesList)) | 95 return(list("xdata"=xdata, "singlefile"=singlefile, "md5sumList"=md5sumList,"sampleNamesList"=sampleNamesList, "chromTIC"=chromTIC, "chromBPI"=chromBPI)) | 
| 80 } | 96 } | 
| 81 | 97 | 
| 82 #@author G. Le Corguille | 98 #@author G. Le Corguille | 
| 83 # This function convert if it is required the Retention Time in minutes | 99 # This function convert if it is required the Retention Time in minutes | 
| 84 RTSecondToMinute <- function(variableMetadata, convertRTMinute) { | 100 RTSecondToMinute <- function(variableMetadata, convertRTMinute) { | 
| 174 stop(error_message) | 190 stop(error_message) | 
| 175 } | 191 } | 
| 176 return(myDataFrame) | 192 return(myDataFrame) | 
| 177 } | 193 } | 
| 178 | 194 | 
| 179 getPlotChromatogram <- function(xdata, pdfname="Chromatogram.pdf", aggregationFun = "max") { | 195 getPlotChromatogram <- function(chrom, xdata, pdfname="Chromatogram.pdf", aggregationFun = "max") { | 
| 180 | 196 | 
| 181 chrom <- chromatogram(xdata, aggregationFun = aggregationFun) | |
| 182 if (aggregationFun == "sum") | 197 if (aggregationFun == "sum") | 
| 183 type="Total Ion Chromatograms" | 198 type="Total Ion Chromatograms" | 
| 184 else | 199 else | 
| 185 type="Base Peak Intensity Chromatograms" | 200 type="Base Peak Intensity Chromatograms" | 
| 186 | 201 | 
| 203 # Color by sample | 218 # Color by sample | 
| 204 plot(chrom, col = rainbow(length(xdata@phenoData@data$sample_name)), main=main) | 219 plot(chrom, col = rainbow(length(xdata@phenoData@data$sample_name)), main=main) | 
| 205 legend("topright", legend=xdata@phenoData@data$sample_name, col=rainbow(length(xdata@phenoData@data$sample_name)), cex=0.8, lty=1) | 220 legend("topright", legend=xdata@phenoData@data$sample_name, col=rainbow(length(xdata@phenoData@data$sample_name)), cex=0.8, lty=1) | 
| 206 | 221 | 
| 207 dev.off() | 222 dev.off() | 
| 208 } | |
| 209 | |
| 210 #@author G. Le Corguille | |
| 211 getPlotTICs <- function(xdata, pdfname="TICs.pdf") { | |
| 212 getPlotChromatogram(xdata, pdfname, aggregationFun = "sum") | |
| 213 } | |
| 214 | |
| 215 #@author G. Le Corguille | |
| 216 getPlotBPIs <- function(xdata, pdfname="BPIs.pdf") { | |
| 217 getPlotChromatogram(xdata, pdfname, aggregationFun = "max") | |
| 218 } | 223 } | 
| 219 | 224 | 
| 220 | 225 | 
| 221 # Get the polarities from all the samples of a condition | 226 # Get the polarities from all the samples of a condition | 
| 222 #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM | 227 #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM | 
