Mercurial > repos > lecorguille > xcms_retcor
comparison xcms_retcor.r @ 25:aa252eec9229 draft
"planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
| author | workflow4metabolomics |
|---|---|
| date | Wed, 07 Apr 2021 12:08:25 +0000 |
| parents | faf4a6b67304 |
| children |
comparison
equal
deleted
inserted
replaced
| 24:c8011370e90f | 25:aa252eec9229 |
|---|---|
| 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","RColorBrewer") | 18 pkgs <- c("xcms", "batch", "RColorBrewer") |
| 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 # ----- PROCESSING INFILE ----- | 30 # ----- PROCESSING INFILE ----- |
| 29 cat("\tARGUMENTS PROCESSING INFO\n") | 31 cat("\tARGUMENTS PROCESSING INFO\n") |
| 36 | 38 |
| 37 # ----- ARGUMENTS PROCESSING ----- | 39 # ----- ARGUMENTS PROCESSING ----- |
| 38 cat("\tINFILE PROCESSING INFO\n") | 40 cat("\tINFILE PROCESSING INFO\n") |
| 39 | 41 |
| 40 #image is an .RData file necessary to use xset variable given by previous tools | 42 #image is an .RData file necessary to use xset variable given by previous tools |
| 41 load(args$image); args$image=NULL | 43 load(args$image); args$image <- NULL |
| 42 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.*") | 44 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.*") |
| 43 | 45 |
| 44 # Handle infiles | 46 # Handle infiles |
| 45 if (!exists("singlefile")) singlefile <- NULL | 47 if (!exists("singlefile")) singlefile <- NULL |
| 46 if (!exists("zipfile")) zipfile <- NULL | 48 if (!exists("zipfile")) zipfile <- NULL |
| 47 rawFilePath <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile, args) | 49 rawFilePath <- retrieveRawfileInTheWorkingDir(singlefile, zipfile, args) |
| 48 zipfile <- rawFilePath$zipfile | 50 zipfile <- rawFilePath$zipfile |
| 49 singlefile <- rawFilePath$singlefile | 51 singlefile <- rawFilePath$singlefile |
| 50 | 52 |
| 51 cat("\n\n") | 53 cat("\n\n") |
| 52 | 54 |
| 57 | 59 |
| 58 cat("\t\tCOMPUTE\n") | 60 cat("\t\tCOMPUTE\n") |
| 59 | 61 |
| 60 cat("\t\t\tAlignment/Retention Time correction\n") | 62 cat("\t\t\tAlignment/Retention Time correction\n") |
| 61 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ... | 63 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ... |
| 62 args <- args[names(args) %in% slotNames(do.call(paste0(method,"Param"), list()))] | 64 args <- args[names(args) %in% slotNames(do.call(paste0(method, "Param"), list()))] |
| 63 | 65 |
| 64 adjustRtimeParam <- do.call(paste0(method,"Param"), args) | 66 adjustRtimeParam <- do.call(paste0(method, "Param"), args) |
| 65 print(adjustRtimeParam) | 67 print(adjustRtimeParam) |
| 66 | 68 |
| 67 if (hasAdjustedRtime(xdata)) { | 69 if (hasAdjustedRtime(xdata)) { |
| 68 cat("WARNING: a retention time ajustment had already been applied to your data.\nThe function applyAdjustedRtime was processed to cumulate the ajustment") | 70 cat("WARNING: a retention time ajustment had already been applied to your data.\nThe function applyAdjustedRtime was processed to cumulate the ajustment") |
| 69 cat("Replace raw retention times with adjusted retention times.\n") | 71 cat("Replace raw retention times with adjusted retention times.\n") |
| 70 xdata <- applyAdjustedRtime(xdata) | 72 xdata <- applyAdjustedRtime(xdata) |
| 71 } | 73 } |
| 72 xdata <- adjustRtime(xdata, param=adjustRtimeParam) | 74 xdata <- adjustRtime(xdata, param = adjustRtimeParam) |
| 73 | |
| 74 #cat("\t\t\tCompute and Store TIC and BPI\n") | |
| 75 #chromTIC_adjusted = chromatogram(xdata, aggregationFun = "sum") | |
| 76 #chromBPI_adjusted = chromatogram(xdata, aggregationFun = "max") | |
| 77 | 75 |
| 78 cat("\n\n") | 76 cat("\n\n") |
| 79 | 77 |
| 80 | 78 |
| 81 # -- TIC -- | 79 # -- TIC -- |
| 95 xset <- getxcmsSetObject(xdata) | 93 xset <- getxcmsSetObject(xdata) |
| 96 print(xset) | 94 print(xset) |
| 97 cat("\n\n") | 95 cat("\n\n") |
| 98 | 96 |
| 99 #saving R data in .Rdata file to save the variables used in the present tool | 97 #saving R data in .Rdata file to save the variables used in the present tool |
| 100 objects2save = c("xdata","zipfile","singlefile","md5sumList","sampleNamesList") #, "chromTIC", "chromBPI", "chromTIC_adjusted", "chromBPI_adjusted") | 98 objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList") |
| 101 save(list=objects2save[objects2save %in% ls()], file="retcor.RData") | 99 save(list = objects2save[objects2save %in% ls()], file = "retcor.RData") |
| 102 | 100 |
| 103 cat("\n\n") | 101 cat("\n\n") |
| 104 | 102 |
| 105 | 103 |
| 106 cat("\tDONE\n") | 104 cat("\tDONE\n") |
