comparison xcms_group.r @ 14:833d2c821d9c draft

planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 9f72e947d9c241d11221cad561f3525d27231857
author lecorguille
date Tue, 18 Sep 2018 16:11:06 -0400
parents
children c8f8d598f562
comparison
equal deleted inserted replaced
13:13558e8a4778 14:833d2c821d9c
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 source_local("lib-xcms3.x.x.r")
16
17 pkgs <- c("xcms","batch","RColorBrewer")
18 loadAndDisplayPackages(pkgs)
19 cat("\n\n");
20
21
22 # ----- ARGUMENTS -----
23 cat("\tARGUMENTS INFO\n")
24 args <- parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects
25 write.table(as.matrix(args), col.names=F, quote=F, sep='\t')
26
27 cat("\n\n")
28
29 # ----- PROCESSING INFILE -----
30 cat("\tARGUMENTS PROCESSING INFO\n")
31
32 #saving the specific parameters
33 method <- args$method
34
35 if (!is.null(args$convertRTMinute)) convertRTMinute <- args$convertRTMinute
36 if (!is.null(args$numDigitsMZ)) numDigitsMZ <- args$numDigitsMZ
37 if (!is.null(args$numDigitsRT)) numDigitsRT <- args$numDigitsRT
38 if (!is.null(args$intval)) intval <- args$intval
39 if (!is.null(args$naTOzero)) naTOzero <- args$naTOzero
40
41 cat("\n\n")
42
43
44 # ----- ARGUMENTS PROCESSING -----
45 cat("\tINFILE PROCESSING INFO\n")
46
47 #image is an .RData file necessary to use xset variable given by previous tools
48 load(args$image)
49 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.*")
50
51 # Handle infiles
52 if (!exists("singlefile")) singlefile <- NULL
53 if (!exists("zipfile")) zipfile <- NULL
54 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args)
55 zipfile <- rawFilePath$zipfile
56 singlefile <- rawFilePath$singlefile
57 directory <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile)
58
59 # Check some character issues
60 md5sumList <- list("origin" = getMd5sum(directory))
61 checkXmlStructure(directory)
62 checkFilesCompatibilityWithXcms(directory)
63
64
65 cat("\n\n")
66
67
68 # ----- MAIN PROCESSING INFO -----
69 cat("\tMAIN PROCESSING INFO\n")
70
71
72 cat("\t\tCOMPUTE\n")
73
74
75 cat("\t\t\tPerform the correspondence\n")
76 args$sampleGroups = xdata$sample_group
77
78 # clear the arguement list to remove unexpected key/value as singlefile_galaxyPath or method ...
79 args <- args[names(args) %in% slotNames(do.call(paste0(method,"Param"), list(sampleGroups=c(1,2))))]
80
81 groupChromPeaksParam <- do.call(paste0(method,"Param"), args)
82 print(groupChromPeaksParam)
83 xdata <- groupChromPeaks(xdata, param = groupChromPeaksParam)
84
85
86 cat("\t\tDRAW GRAPHICS\n")
87 getPlotChromPeakDensity(xdata)
88
89 if (exists("intval")) {
90 getPeaklistW4M(xdata, intval, convertRTMinute, numDigitsMZ, numDigitsRT, naTOzero, "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", "chromTIC", "chromBPI", "chromTIC_adjusted", "chromBPI_adjusted")
109 save(list=objects2save[objects2save %in% ls()], file="group.RData")
110
111 cat("\n\n")
112
113
114 cat("\tDONE\n")