Mercurial > repos > lecorguille > xcms_group
comparison xcms_group.r @ 29:020d065edd9e draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit e384d6dd5f410799ec211f73bca0b5d5d7bc651e
author | lecorguille |
---|---|
date | Thu, 01 Mar 2018 04:16:06 -0500 |
parents | |
children | 68282292acc4 |
comparison
equal
deleted
inserted
replaced
28:a18fc7554c6d | 29:020d065edd9e |
---|---|
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","RColorBrewer") | |
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 <- args$method; args$method <- NULL | |
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 # Handle infiles | |
58 if (!exists("singlefile")) singlefile <- NULL | |
59 if (!exists("zipfile")) zipfile <- NULL | |
60 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args) | |
61 zipfile <- rawFilePath$zipfile | |
62 singlefile <- rawFilePath$singlefile | |
63 args <- rawFilePath$args | |
64 directory <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile) | |
65 | |
66 # Check some character issues | |
67 md5sumList <- list("origin" = getMd5sum(directory)) | |
68 checkXmlStructure(directory) | |
69 checkFilesCompatibilityWithXcms(directory) | |
70 | |
71 | |
72 cat("\n\n") | |
73 | |
74 | |
75 # ----- MAIN PROCESSING INFO ----- | |
76 cat("\tMAIN PROCESSING INFO\n") | |
77 | |
78 | |
79 cat("\t\tCOMPUTE\n") | |
80 | |
81 | |
82 cat("\t\t\tPerform the correspondence\n") | |
83 args$sampleGroups = xdata$sample_group | |
84 groupChromPeaksParam <- do.call(paste0(method,"Param"), args) | |
85 print(groupChromPeaksParam) | |
86 xdata <- groupChromPeaks(xdata, param = groupChromPeaksParam) | |
87 | |
88 | |
89 cat("\t\tDRAW GRAPHICS\n") | |
90 getPlotChromPeakDensity(xdata) | |
91 | |
92 if (exists("intval")) { | |
93 getPeaklistW4M(xdata, intval, convertRTMinute, numDigitsMZ, numDigitsRT, "variableMetadata.tsv", "dataMatrix.tsv") | |
94 } | |
95 | |
96 cat("\n\n") | |
97 | |
98 # ----- EXPORT ----- | |
99 | |
100 cat("\tXCMSnExp OBJECT INFO\n") | |
101 print(xdata) | |
102 cat("\n\n") | |
103 | |
104 cat("\txcmsSet OBJECT INFO\n") | |
105 # Get the legacy xcmsSet object | |
106 xset <- getxcmsSetObject(xdata) | |
107 print(xset) | |
108 cat("\n\n") | |
109 | |
110 #saving R data in .Rdata file to save the variables used in the present tool | |
111 objects2save <- c("xdata", "zipfile", "singlefile", "md5sumList", "sampleNamesList") | |
112 save(list=objects2save[objects2save %in% ls()], file="group.RData") | |
113 | |
114 cat("\n\n") | |
115 | |
116 | |
117 cat("\tDONE\n") |