Mercurial > repos > lecorguille > xcms_retcor
annotate xcms.r @ 28:13885e67b123 draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 5f19510181ee5f15e2a2bee139c2cb2e6a5dd78e
| author | lecorguille | 
|---|---|
| date | Thu, 26 Oct 2017 11:16:24 -0400 | 
| parents | 30410a052ab3 | 
| children | c013ed353a2f | 
| rev | line source | 
|---|---|
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 1 #!/usr/bin/env Rscript | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 2 # xcms.r version="2.2.0" | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 3 #Authors ABIMS TEAM | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 4 #BPC Addition from Y.guitton | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 5 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 6 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 7 # ----- LOG FILE ----- | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 8 log_file=file("log.txt", open = "wt") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 9 sink(log_file) | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 10 sink(log_file, type = "output") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 11 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 12 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 13 # ----- PACKAGE ----- | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 14 cat("\tPACKAGE INFO\n") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 15 #pkgs=c("xcms","batch") | 
| 27 
30410a052ab3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit bff1445c9b00ccdbe05ee3dc6ed24221033384b9
 lecorguille parents: 
25diff
changeset | 16 pkgs=c("tools","parallel","BiocGenerics", "Biobase", "Rcpp", "mzR", "xcms","snow","batch") | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 17 for(pkg in pkgs) { | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 18 suppressPackageStartupMessages( stopifnot( library(pkg, quietly=TRUE, logical.return=TRUE, character.only=TRUE))) | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 19 cat(pkg,"\t",as.character(packageVersion(pkg)),"\n",sep="") | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 20 } | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 21 source_local <- function(fname){ argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } | 
| 15 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 22 cat("\n\n"); | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 23 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 24 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 25 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 26 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 27 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 28 # ----- ARGUMENTS ----- | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 29 cat("\tARGUMENTS INFO\n") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 30 listArguments = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 31 write.table(as.matrix(listArguments), col.names=F, quote=F, sep='\t') | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 32 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 33 cat("\n\n"); | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 34 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 35 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 36 # ----- ARGUMENTS PROCESSING ----- | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 37 cat("\tINFILE PROCESSING INFO\n") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 38 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 39 #image is an .RData file necessary to use xset variable given by previous tools | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 40 if (!is.null(listArguments[["image"]])){ | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 41 load(listArguments[["image"]]); listArguments[["image"]]=NULL | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 42 } | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 43 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 44 #Import the different functions | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 45 source_local("lib.r") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 46 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 47 cat("\n\n") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 48 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 49 #Import the different functions | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 50 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 51 # ----- PROCESSING INFILE ----- | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 52 cat("\tARGUMENTS PROCESSING INFO\n") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 53 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 54 # Save arguments to generate a report | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 55 if (!exists("listOFlistArguments")) listOFlistArguments=list() | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 56 listOFlistArguments[[paste(format(Sys.time(), "%y%m%d-%H:%M:%S_"),listArguments[["xfunction"]],sep="")]] = listArguments | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 57 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 58 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 59 #saving the commun parameters | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 60 thefunction = listArguments[["xfunction"]]; listArguments[["xfunction"]]=NULL #delete from the list of arguments | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 61 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 62 xsetRdataOutput = paste(thefunction,"RData",sep=".") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 63 if (!is.null(listArguments[["xsetRdataOutput"]])){ | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 64 xsetRdataOutput = listArguments[["xsetRdataOutput"]]; listArguments[["xsetRdataOutput"]]=NULL | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 65 } | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 66 | 
| 15 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 67 #saving the specific parameters | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 68 sampleMetadataOutput = "sampleMetadata.tsv" | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 69 if (!is.null(listArguments[["sampleMetadataOutput"]])){ | 
| 22 
411d2b9ea412
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 87dc789d7cd70a3733a1ad0b5a427f4d5905795d
 lecorguille parents: 
19diff
changeset | 70 sampleMetadataOutput = listArguments[["sampleMetadataOutput"]]; listArguments[["sampleMetadataOutput"]]=NULL | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 71 } | 
| 15 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 72 variableMetadataOutput = "variableMetadata.tsv" | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 73 if (!is.null(listArguments[["variableMetadataOutput"]])){ | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 74 variableMetadataOutput = listArguments[["variableMetadataOutput"]]; listArguments[["variableMetadataOutput"]]=NULL | 
| 15 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 75 } | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 76 dataMatrixOutput = "dataMatrix.tsv" | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 77 if (!is.null(listArguments[["dataMatrixOutput"]])){ | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 78 dataMatrixOutput = listArguments[["dataMatrixOutput"]]; listArguments[["dataMatrixOutput"]]=NULL | 
| 15 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 79 } | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 80 if (!is.null(listArguments[["convertRTMinute"]])){ | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 81 convertRTMinute = listArguments[["convertRTMinute"]]; listArguments[["convertRTMinute"]]=NULL | 
| 15 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 82 } | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 83 if (!is.null(listArguments[["numDigitsMZ"]])){ | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 84 numDigitsMZ = listArguments[["numDigitsMZ"]]; listArguments[["numDigitsMZ"]]=NULL | 
| 15 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 85 } | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 86 if (!is.null(listArguments[["numDigitsRT"]])){ | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 87 numDigitsRT = listArguments[["numDigitsRT"]]; listArguments[["numDigitsRT"]]=NULL | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 88 } | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 89 if (!is.null(listArguments[["intval"]])){ | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 90 intval = listArguments[["intval"]]; listArguments[["intval"]]=NULL | 
| 15 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 91 } | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 92 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 93 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 94 if (thefunction %in% c("xcmsSet","retcor","fillPeaks")) { | 
| 25 
b8be2b25957d
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 5583baab62c0f17cabbfe93ba4f2522e8df9b36b
 lecorguille parents: 
23diff
changeset | 95 if (!exists("singlefile")) singlefile=NULL | 
| 
b8be2b25957d
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 5583baab62c0f17cabbfe93ba4f2522e8df9b36b
 lecorguille parents: 
23diff
changeset | 96 if (!exists("zipfile")) zipfile=NULL | 
| 
b8be2b25957d
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 5583baab62c0f17cabbfe93ba4f2522e8df9b36b
 lecorguille parents: 
23diff
changeset | 97 rawFilePath = getRawfilePathFromArguments(singlefile, zipfile, listArguments) | 
| 22 
411d2b9ea412
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 87dc789d7cd70a3733a1ad0b5a427f4d5905795d
 lecorguille parents: 
19diff
changeset | 98 zipfile = rawFilePath$zipfile | 
| 
411d2b9ea412
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 87dc789d7cd70a3733a1ad0b5a427f4d5905795d
 lecorguille parents: 
19diff
changeset | 99 singlefile = rawFilePath$singlefile | 
| 
411d2b9ea412
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 87dc789d7cd70a3733a1ad0b5a427f4d5905795d
 lecorguille parents: 
19diff
changeset | 100 listArguments = rawFilePath$listArguments | 
| 
411d2b9ea412
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 87dc789d7cd70a3733a1ad0b5a427f4d5905795d
 lecorguille parents: 
19diff
changeset | 101 directory = retrieveRawfileInTheWorkingDirectory(singlefile, zipfile) | 
| 
411d2b9ea412
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 87dc789d7cd70a3733a1ad0b5a427f4d5905795d
 lecorguille parents: 
19diff
changeset | 102 md5sumList=list("origin"=getMd5sum(directory)) | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 103 } | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 104 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 105 #addition of the directory to the list of arguments in the first position | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 106 if (thefunction == "xcmsSet") { | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 107 checkXmlStructure(directory) | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 108 checkFilesCompatibilityWithXcms(directory) | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 109 listArguments=append(directory, listArguments) | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 110 } | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 111 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 112 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 113 #addition of xset object to the list of arguments in the first position | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 114 if (exists("xset")){ | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 115 listArguments=append(list(xset), listArguments) | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 116 } | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 117 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 118 cat("\n\n") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 119 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 120 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 121 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 122 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 123 # ----- MAIN PROCESSING INFO ----- | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 124 cat("\tMAIN PROCESSING INFO\n") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 125 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 126 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 127 #Verification of a group step before doing the fillpeaks job. | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 128 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 129 if (thefunction == "fillPeaks") { | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 130 res=try(is.null(groupnames(xset))) | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 131 if (class(res) == "try-error"){ | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 132 error<-geterrmessage() | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 133 write(error, stderr()) | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 134 stop("You must always do a group step after a retcor. Otherwise it won't work for the fillpeaks step") | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 135 } | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 136 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 137 } | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 138 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 139 #change the default display settings | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 140 #dev.new(file="Rplots.pdf", width=16, height=12) | 
| 27 
30410a052ab3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit bff1445c9b00ccdbe05ee3dc6ed24221033384b9
 lecorguille parents: 
25diff
changeset | 141 pdf(file="Rplots.pdf", width=16, height=12) | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 142 if (thefunction == "group") { | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 143 par(mfrow=c(2,2)) | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 144 } | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 145 #else if (thefunction == "retcor") { | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 146 #try to change the legend display | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 147 # par(xpd=NA) | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 148 # par(xpd=T, mar=par()$mar+c(0,0,0,4)) | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 149 #} | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 150 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 151 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 152 #execution of the function "thefunction" with the parameters given in "listArguments" | 
| 15 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 153 | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 154 cat("\t\tCOMPUTE\n") | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 155 xset = do.call(thefunction, listArguments) | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 156 | 
| 23 
38fa090ae98f
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e1f22c9b6d39de7aabc6bb625f65aa5ba6a91312
 lecorguille parents: 
22diff
changeset | 157 # check if there are no peaks | 
| 
38fa090ae98f
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e1f22c9b6d39de7aabc6bb625f65aa5ba6a91312
 lecorguille parents: 
22diff
changeset | 158 if (nrow(peaks(xset)) == 0) { | 
| 
38fa090ae98f
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e1f22c9b6d39de7aabc6bb625f65aa5ba6a91312
 lecorguille parents: 
22diff
changeset | 159 stop("No peaks were detected. You should review your settings") | 
| 
38fa090ae98f
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e1f22c9b6d39de7aabc6bb625f65aa5ba6a91312
 lecorguille parents: 
22diff
changeset | 160 } | 
| 
38fa090ae98f
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e1f22c9b6d39de7aabc6bb625f65aa5ba6a91312
 lecorguille parents: 
22diff
changeset | 161 | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 162 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 163 cat("\n\n") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 164 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 165 dev.off() #dev.new(file="Rplots.pdf", width=16, height=12) | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 166 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 167 if (thefunction == "xcmsSet") { | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 168 | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 169 #transform the files absolute pathways into relative pathways | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 170 xset@filepaths<-sub(paste(getwd(),"/",sep="") ,"", xset@filepaths) | 
| 22 
411d2b9ea412
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 87dc789d7cd70a3733a1ad0b5a427f4d5905795d
 lecorguille parents: 
19diff
changeset | 171 if(exists("zipfile") && !is.null(zipfile) && (zipfile!="")) { | 
| 15 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 172 | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 173 #Modify the samples names (erase the path) | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 174 for(i in 1:length(sampnames(xset))){ | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 175 | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 176 sample_name=unlist(strsplit(sampnames(xset)[i], "/")) | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 177 sample_name=sample_name[length(sample_name)] | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 178 sample_name= unlist(strsplit(sample_name,"[.]"))[1] | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 179 sampnames(xset)[i]=sample_name | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 180 | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 181 } | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 182 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 183 } | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 184 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 185 } | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 186 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 187 # -- TIC -- | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 188 if (thefunction == "xcmsSet") { | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 189 cat("\t\tGET TIC GRAPH\n") | 
| 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 190 sampleNamesList = getSampleMetadata(xcmsSet=xset, sampleMetadataOutput=sampleMetadataOutput) | 
| 27 
30410a052ab3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit bff1445c9b00ccdbe05ee3dc6ed24221033384b9
 lecorguille parents: 
25diff
changeset | 191 getTICs(xcmsSet=xset, rt="raw") | 
| 
30410a052ab3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit bff1445c9b00ccdbe05ee3dc6ed24221033384b9
 lecorguille parents: 
25diff
changeset | 192 getBPCs(xcmsSet=xset, rt="raw") | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 193 } else if (thefunction == "retcor") { | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 194 cat("\t\tGET TIC GRAPH\n") | 
| 27 
30410a052ab3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit bff1445c9b00ccdbe05ee3dc6ed24221033384b9
 lecorguille parents: 
25diff
changeset | 195 getTICs(xcmsSet=xset, rt="corrected") | 
| 
30410a052ab3
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit bff1445c9b00ccdbe05ee3dc6ed24221033384b9
 lecorguille parents: 
25diff
changeset | 196 getBPCs(xcmsSet=xset, rt="corrected") | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 197 } | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 198 | 
| 19 
2faecb1270fe
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 481448087f0e09c131b24f7d552db69f3552d371-dirty
 lecorguille parents: 
18diff
changeset | 199 if ((thefunction == "group" || thefunction == "fillPeaks") && exists("intval")) { | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 200 getPeaklistW4M(xset,intval,convertRTMinute,numDigitsMZ,numDigitsRT,variableMetadataOutput,dataMatrixOutput) | 
| 15 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 201 } | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 202 | 
| 
c04568596f40
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 08e7f269a5c59687a7768be8db5fcb4e4d736093
 lecorguille parents: 
6diff
changeset | 203 | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 204 cat("\n\n") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 205 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 206 # ----- EXPORT ----- | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 207 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 208 cat("\tXSET OBJECT INFO\n") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 209 print(xset) | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 210 #delete the parameters to avoid the passage to the next tool in .RData image | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 211 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 212 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 213 #saving R data in .Rdata file to save the variables used in the present tool | 
| 16 
20a75ba4345b
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 22c4e92909198328fc7439ff47e4546a273eb907
 lecorguille parents: 
15diff
changeset | 214 objects2save = c("xset","zipfile","singlefile","listOFlistArguments","md5sumList","sampleNamesList") | 
| 6 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 215 save(list=objects2save[objects2save %in% ls()], file=xsetRdataOutput) | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 216 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 217 cat("\n\n") | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 218 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 219 | 
| 
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
 lecorguille parents: diff
changeset | 220 cat("\tDONE\n") | 
