Mercurial > repos > lecorguille > xcms_fillpeaks
comparison xcms_fillpeaks.r @ 31:8fd5b5afa24d draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e384d6dd5f410799ec211f73bca0b5d5d7bc651e
| author | lecorguille |
|---|---|
| date | Thu, 01 Mar 2018 04:17:29 -0500 |
| parents | |
| children | d8bac1291473 |
comparison
equal
deleted
inserted
replaced
| 30:6b5ed508f81f | 31:8fd5b5afa24d |
|---|---|
| 1 #!/usr/bin/env Rscript | |
| 2 | |
| 3 # ----- LOG FILE ----- | |
| 4 log_file=file("log.txt", open = "wt") | |
| 5 sink(log_file) | |
| 6 sink(log_file, type = "output") | |
| 7 | |
| 8 | |
| 9 # ----- PACKAGE ----- | |
| 10 cat("\tSESSION INFO\n") | |
| 11 | |
| 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="/")) } | |
| 14 source_local("lib.r") | |
| 15 | |
| 16 pkgs <- c("xcms","batch") | |
| 17 loadAndDisplayPackages(pkgs) | |
| 18 cat("\n\n"); | |
| 19 | |
| 20 | |
| 21 # ----- ARGUMENTS ----- | |
| 22 cat("\tARGUMENTS INFO\n") | |
| 23 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') | |
| 25 | |
| 26 cat("\n\n") | |
| 27 | |
| 28 # ----- PROCESSING INFILE ----- | |
| 29 cat("\tARGUMENTS PROCESSING INFO\n") | |
| 30 | |
| 31 #saving the specific parameters | |
| 32 method <- "FillChromPeaks" | |
| 33 | |
| 34 if (!is.null(args$convertRTMinute)){ | |
| 35 convertRTMinute <- args$convertRTMinute; args$convertRTMinute <- NULL | |
| 36 } | |
| 37 if (!is.null(args$numDigitsMZ)){ | |
| 38 numDigitsMZ <- args$numDigitsMZ; args$numDigitsMZ <- NULL | |
| 39 } | |
| 40 if (!is.null(args$numDigitsRT)){ | |
| 41 numDigitsRT <- args$numDigitsRT; args$numDigitsRT <- NULL | |
| 42 } | |
| 43 if (!is.null(args$intval)){ | |
| 44 intval <- args$intval; args$intval <- NULL | |
| 45 } | |
| 46 | |
| 47 cat("\n\n") | |
| 48 | |
| 49 | |
| 50 # ----- ARGUMENTS PROCESSING ----- | |
| 51 cat("\tINFILE PROCESSING INFO\n") | |
| 52 | |
| 53 #image is an .RData file necessary to use xset variable given by previous tools | |
| 54 load(args$image); args$image=NULL | |
| 55 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.*") | |
| 56 | |
| 57 #Verification of a group step before doing the fillpeaks job. | |
| 58 if (!hasFeatures(xdata)) stop("You must always do a group step after a retcor. Otherwise it won't work for the fillpeaks step") | |
| 59 | |
| 60 # Handle infiles | |
| 61 if (!exists("singlefile")) singlefile <- NULL | |
| 62 if (!exists("zipfile")) zipfile <- NULL | |
| 63 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args) | |
| 64 zipfile <- rawFilePath$zipfile | |
| 65 singlefile <- rawFilePath$singlefile | |
| 66 args <- rawFilePath$args | |
| 67 directory <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile) | |
| 68 | |
| 69 # Check some character issues | |
| 70 md5sumList <- list("origin" = getMd5sum(directory)) | |
| 71 checkXmlStructure(directory) | |
| 72 checkFilesCompatibilityWithXcms(directory) | |
| 73 | |
| 74 | |
| 75 cat("\n\n") | |
| 76 | |
| 77 | |
| 78 # ----- MAIN PROCESSING INFO ----- | |
| 79 cat("\tMAIN PROCESSING INFO\n") | |
| 80 | |
| 81 | |
| 82 cat("\t\tCOMPUTE\n") | |
| 83 | |
| 84 cat("\t\t\tFilling missing peaks using default settings\n") | |
| 85 fillChromPeaksParam <- do.call(paste0(method,"Param"), args) | |
| 86 print(fillChromPeaksParam) | |
| 87 xdata <- fillChromPeaks(xdata, param=fillChromPeaksParam) | |
| 88 | |
| 89 if (exists("intval")) { | |
| 90 getPeaklistW4M(xdata, intval, convertRTMinute, numDigitsMZ, numDigitsRT, "variableMetadata.tsv", "dataMatrix.tsv") | |
| 91 } | |
| 92 | |
| 93 cat("\n\n") | |
| 94 | |
| 95 # ----- EXPORT ----- | |
| 96 | |
| 97 cat("\tXCMSnExp OBJECT INFO\n") | |
| 98 print(xdata) | |
| 99 cat("\n\n") | |
| 100 | |
| 101 cat("\txcmsSet OBJECT INFO\n") | |
| 102 # Get the legacy xcmsSet object | |
| 103 xset <- getxcmsSetObject(xdata) | |
| 104 print(xset) | |
| 105 cat("\n\n") | |
| 106 | |
| 107 #saving R data in .Rdata file to save the variables used in the present tool | |
| 108 objects2save = c("xdata","zipfile","singlefile","md5sumList","sampleNamesList") | |
| 109 save(list=objects2save[objects2save %in% ls()], file="fillpeaks.RData") | |
| 110 | |
| 111 cat("\n\n") | |
| 112 | |
| 113 | |
| 114 cat("\tDONE\n") |
