Mercurial > repos > lecorguille > xcms_fillpeaks
comparison lib.r @ 37:9eefb022a189 draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 088699d00f7e45bebb7da07bebc005c68df058d8
| author | lecorguille |
|---|---|
| date | Wed, 05 Sep 2018 06:00:18 -0400 |
| parents | e3efe78b14c5 |
| children | a3e80894efd3 |
comparison
equal
deleted
inserted
replaced
| 36:e3efe78b14c5 | 37:9eefb022a189 |
|---|---|
| 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. | 31 # This function merge several chromBPI or chromTIC into one. |
| 32 mergeChrom <- function(chromTIC_merged, chromTIC, xdata_merged) { | 32 mergeChrom <- function(chrom_merged, chrom) { |
| 33 if (is.null(chromTIC_merged)) return(NULL) | 33 if (is.null(chrom_merged)) return(NULL) |
| 34 chromTIC_merged@.Data <- cbind(chromTIC_merged@.Data, chromTIC@.Data) | 34 chrom_merged@.Data <- cbind(chrom_merged@.Data, chrom@.Data) |
| 35 chromTIC_merged@phenoData <- xdata_merged@phenoData | 35 return(chrom_merged) |
| 36 return(chromTIC_merged) | |
| 37 } | 36 } |
| 38 | 37 |
| 39 #@author G. Le Corguille | 38 #@author G. Le Corguille |
| 40 # This function merge several xdata into one. | 39 # This function merge several xdata into one. |
| 41 mergeXData <- function(args) { | 40 mergeXData <- function(args) { |
| 42 chromTIC <- NULL; chromBPI <- NULL | 41 chromTIC <- NULL |
| 42 chromBPI <- NULL | |
| 43 chromTIC_adjusted <- NULL | |
| 44 chromBPI_adjusted <- NULL | |
| 43 for(image in args$images) { | 45 for(image in args$images) { |
| 46 | |
| 44 load(image) | 47 load(image) |
| 45 # Handle infiles | 48 # Handle infiles |
| 46 if (!exists("singlefile")) singlefile <- NULL | 49 if (!exists("singlefile")) singlefile <- NULL |
| 47 if (!exists("zipfile")) zipfile <- NULL | 50 if (!exists("zipfile")) zipfile <- NULL |
| 48 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args) | 51 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args) |
| 49 zipfile <- rawFilePath$zipfile | 52 zipfile <- rawFilePath$zipfile |
| 50 singlefile <- rawFilePath$singlefile | 53 singlefile <- rawFilePath$singlefile |
| 51 retrieveRawfileInTheWorkingDirectory(singlefile, zipfile) | 54 retrieveRawfileInTheWorkingDirectory(singlefile, zipfile) |
| 55 | |
| 52 if (exists("raw_data")) xdata <- raw_data | 56 if (exists("raw_data")) xdata <- raw_data |
| 53 if (!exists("xdata")) stop("\n\nERROR: The RData doesn't contain any object called 'xdata'. This RData should have been created by an old version of XMCS 2.*") | 57 if (!exists("xdata")) stop("\n\nERROR: The RData doesn't contain any object called 'xdata'. This RData should have been created by an old version of XMCS 2.*") |
| 58 | |
| 54 cat(sampleNamesList$sampleNamesOrigin,"\n") | 59 cat(sampleNamesList$sampleNamesOrigin,"\n") |
| 60 | |
| 55 if (!exists("xdata_merged")) { | 61 if (!exists("xdata_merged")) { |
| 56 xdata_merged <- xdata | 62 xdata_merged <- xdata |
| 57 singlefile_merged <- singlefile | 63 singlefile_merged <- singlefile |
| 58 md5sumList_merged <- md5sumList | 64 md5sumList_merged <- md5sumList |
| 59 sampleNamesList_merged <- sampleNamesList | 65 sampleNamesList_merged <- sampleNamesList |
| 60 chromTIC_merged <- chromTIC | 66 chromTIC_merged <- chromTIC |
| 61 chromBPI_merged <- chromBPI | 67 chromBPI_merged <- chromBPI |
| 68 chromTIC_adjusted_merged <- chromTIC_adjusted | |
| 69 chromBPI_adjusted_merged <- chromBPI_adjusted | |
| 62 } else { | 70 } else { |
| 63 if (is(xdata, "XCMSnExp")) xdata_merged <- c(xdata_merged,xdata) | 71 if (is(xdata, "XCMSnExp")) xdata_merged <- c(xdata_merged,xdata) |
| 64 else if (is(xdata, "OnDiskMSnExp")) xdata_merged <- .concatenate_OnDiskMSnExp(xdata_merged,xdata) | 72 else if (is(xdata, "OnDiskMSnExp")) xdata_merged <- .concatenate_OnDiskMSnExp(xdata_merged,xdata) |
| 65 else stop("\n\nERROR: The RData either a OnDiskMSnExp object called raw_data or a XCMSnExp object called xdata") | 73 else stop("\n\nERROR: The RData either a OnDiskMSnExp object called raw_data or a XCMSnExp object called xdata") |
| 74 | |
| 66 singlefile_merged <- c(singlefile_merged,singlefile) | 75 singlefile_merged <- c(singlefile_merged,singlefile) |
| 67 md5sumList_merged$origin <- rbind(md5sumList_merged$origin,md5sumList$origin) | 76 md5sumList_merged$origin <- rbind(md5sumList_merged$origin,md5sumList$origin) |
| 68 sampleNamesList_merged$sampleNamesOrigin <- c(sampleNamesList_merged$sampleNamesOrigin,sampleNamesList$sampleNamesOrigin) | 77 sampleNamesList_merged$sampleNamesOrigin <- c(sampleNamesList_merged$sampleNamesOrigin,sampleNamesList$sampleNamesOrigin) |
| 69 sampleNamesList_merged$sampleNamesMakeNames <- c(sampleNamesList_merged$sampleNamesMakeNames,sampleNamesList$sampleNamesMakeNames) | 78 sampleNamesList_merged$sampleNamesMakeNames <- c(sampleNamesList_merged$sampleNamesMakeNames,sampleNamesList$sampleNamesMakeNames) |
| 70 chromTIC_merged <- mergeChrom(chromTIC_merged, chromTIC, xdata_merged) | 79 chromTIC_merged <- mergeChrom(chromTIC_merged, chromTIC) |
| 71 chromBPI_merged <- mergeChrom(chromBPI_merged, chromBPI, xdata_merged) | 80 chromBPI_merged <- mergeChrom(chromBPI_merged, chromBPI) |
| 81 chromTIC_adjusted_merged <- mergeChrom(chromTIC_adjusted_merged, chromTIC_adjusted) | |
| 82 chromBPI_adjusted_merged <- mergeChrom(chromBPI_adjusted_merged, chromBPI_adjusted) | |
| 72 } | 83 } |
| 73 } | 84 } |
| 74 rm(image) | 85 rm(image) |
| 75 xdata <- xdata_merged; rm(xdata_merged) | 86 xdata <- xdata_merged; rm(xdata_merged) |
| 76 singlefile <- singlefile_merged; rm(singlefile_merged) | 87 singlefile <- singlefile_merged; rm(singlefile_merged) |
| 77 md5sumList <- md5sumList_merged; rm(md5sumList_merged) | 88 md5sumList <- md5sumList_merged; rm(md5sumList_merged) |
| 78 sampleNamesList <- sampleNamesList_merged; rm(sampleNamesList_merged) | 89 sampleNamesList <- sampleNamesList_merged; rm(sampleNamesList_merged) |
| 79 chromTIC <- chromTIC_merged; rm(chromTIC_merged) | |
| 80 chromBPI <- chromBPI_merged; rm(chromBPI_merged) | |
| 81 | 90 |
| 82 if (!is.null(args$sampleMetadata)) { | 91 if (!is.null(args$sampleMetadata)) { |
| 83 cat("\tXSET PHENODATA SETTING...\n") | 92 cat("\tXSET PHENODATA SETTING...\n") |
| 84 sampleMetadataFile <- args$sampleMetadata | 93 sampleMetadataFile <- args$sampleMetadata |
| 85 sampleMetadata <- getDataFrameFromFile(sampleMetadataFile, header=F) | 94 sampleMetadata <- getDataFrameFromFile(sampleMetadataFile, header=F) |
| 90 error_message <- paste("Those samples are missing in your sampleMetadata:", paste(sample_missing, collapse=" ")) | 99 error_message <- paste("Those samples are missing in your sampleMetadata:", paste(sample_missing, collapse=" ")) |
| 91 print(error_message) | 100 print(error_message) |
| 92 stop(error_message) | 101 stop(error_message) |
| 93 } | 102 } |
| 94 } | 103 } |
| 95 return(list("xdata"=xdata, "singlefile"=singlefile, "md5sumList"=md5sumList,"sampleNamesList"=sampleNamesList, "chromTIC"=chromTIC, "chromBPI"=chromBPI)) | 104 |
| 105 if (!is.null(chromTIC_merged)) { chromTIC <- chromTIC_merged; chromTIC@phenoData <- xdata@phenoData } | |
| 106 if (!is.null(chromBPI_merged)) { chromBPI <- chromBPI_merged; chromBPI@phenoData <- xdata@phenoData } | |
| 107 if (!is.null(chromTIC_adjusted_merged)) { chromTIC_adjusted <- chromTIC_adjusted_merged; chromTIC_adjusted@phenoData <- xdata@phenoData } | |
| 108 if (!is.null(chromBPI_adjusted_merged)) { chromBPI_adjusted <- chromBPI_adjusted_merged; chromBPI_adjusted@phenoData <- xdata@phenoData } | |
| 109 | |
| 110 return(list("xdata"=xdata, "singlefile"=singlefile, "md5sumList"=md5sumList,"sampleNamesList"=sampleNamesList, "chromTIC"=chromTIC, "chromBPI"=chromBPI, "chromTIC_adjusted"=chromTIC_adjusted, "chromBPI_adjusted"=chromBPI_adjusted)) | |
| 96 } | 111 } |
| 97 | 112 |
| 98 #@author G. Le Corguille | 113 #@author G. Le Corguille |
| 99 # This function convert if it is required the Retention Time in minutes | 114 # This function convert if it is required the Retention Time in minutes |
| 100 RTSecondToMinute <- function(variableMetadata, convertRTMinute) { | 115 RTSecondToMinute <- function(variableMetadata, convertRTMinute) { |
| 190 stop(error_message) | 205 stop(error_message) |
| 191 } | 206 } |
| 192 return(myDataFrame) | 207 return(myDataFrame) |
| 193 } | 208 } |
| 194 | 209 |
| 210 #@author G. Le Corguille | |
| 211 # Draw the BPI and TIC graphics | |
| 212 # colored by sample names or class names | |
| 195 getPlotChromatogram <- function(chrom, xdata, pdfname="Chromatogram.pdf", aggregationFun = "max") { | 213 getPlotChromatogram <- function(chrom, xdata, pdfname="Chromatogram.pdf", aggregationFun = "max") { |
| 196 | 214 |
| 197 if (aggregationFun == "sum") | 215 if (aggregationFun == "sum") |
| 198 type="Total Ion Chromatograms" | 216 type="Total Ion Chromatograms" |
| 199 else | 217 else |
| 406 | 424 |
| 407 singlefile <- NULL | 425 singlefile <- NULL |
| 408 for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) { | 426 for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) { |
| 409 singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] | 427 singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] |
| 410 singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] | 428 singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] |
| 411 # In case, an url is used to import data within Galaxy | 429 # In case, an url is used to import data within Galaxy |
| 412 singlefile_sampleName <- tail(unlist(strsplit(singlefile_sampleName,"/")), n=1) | 430 singlefile_sampleName <- tail(unlist(strsplit(singlefile_sampleName,"/")), n=1) |
| 413 singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath | 431 singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath |
| 414 } | 432 } |
| 415 } | 433 } |
| 416 return(list(zipfile=zipfile, singlefile=singlefile)) | 434 return(list(zipfile=zipfile, singlefile=singlefile)) |
