annotate CAMERA_annotateDiffreport.r @ 23:abf1775ac14d draft

"planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
author workflow4metabolomics
date Thu, 22 Apr 2021 10:27:38 +0000
parents 01459b73daf9
children 4b9ab71be05e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
1 #!/usr/bin/env Rscript
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
2
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
3 # ----- PACKAGE -----
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
4 cat("\tSESSION INFO\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
5
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
6 #Import the different functions
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
7 source_local <- function(fname) {
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
8 argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/"))
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
9 }
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
10 source_local("lib.r")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
11
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
12 pkgs <- c("CAMERA", "multtest", "batch")
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
13 loadAndDisplayPackages(pkgs)
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
14 cat("\n\n");
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
15
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
16 # ----- ARGUMENTS -----
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
17 cat("\tARGUMENTS INFO\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
18
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
19 args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
20 write.table(as.matrix(args), col.names = F, quote = F, sep = "\t")
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
21
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
22 cat("\n\n");
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
23
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
24
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
25 # ----- PROCESSING INFILE -----
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
26 cat("\tINFILE PROCESSING INFO\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
27
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
28 #image is an .RData file necessary to use xset variable given by previous tools
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
29 load(args$image); args$image <- NULL
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
30
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
31 cat("\n\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
32
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
33
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
34 # ----- ARGUMENTS PROCESSING -----
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
35 cat("\tARGUMENTS PROCESSING INFO\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
36
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
37 # Save arguments to generate a report
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
38 if (!exists("listOFargs")) listOFargs <- list()
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
39 listOFargs[[format(Sys.time(), "%y%m%d-%H:%M:%S_annotatediff")]] <- args
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
40
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
41 # We unzip automatically the chromatograms from the zip files.
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
42 if (!exists("zipfile")) zipfile <- NULL
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
43 if (!exists("singlefile")) singlefile <- NULL
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
44 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args)
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
45 zipfile <- rawFilePath$zipfile
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
46 singlefile <- rawFilePath$singlefile
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
47 args <- rawFilePath$args
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
48 directory <- retrieveRawfileInTheWorkingDir(singlefile, zipfile)
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
49
19
01459b73daf9 "planemo upload commit 4fcbbcbc6d6b0a59e801870d31fe886a920ef429"
workflow4metabolomics
parents: 18
diff changeset
50
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
51 # Because so far CAMERA isn't compatible with the new XCMSnExp object
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
52 if (exists("xdata")) {
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
53 xset <- getxcmsSetObject(xdata)
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
54 }
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
55
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
56 cat("\n\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
57
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
58
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
59 # ----- PROCESSING INFO -----
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
60 cat("\tMAIN PROCESSING INFO\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
61
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
62 results_list <- annotatediff(xset = xset, args = args, variableMetadataOutput = "variableMetadata.tsv")
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
63 xa <- results_list$xa
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
64 diffrep <- results_list$diffrep
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
65 variableMetadata <- results_list$variableMetadata
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
66
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
67 cat("\n\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
68
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
69 # ----- EXPORT -----
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
70
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
71 cat("\tXSET OBJECT INFO\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
72 print(xa)
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
73 cat("\n\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
74
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
75 #saving R data in .Rdata file to save the variables used in the present tool
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
76 objects2save <- c("xa", "variableMetadata", "diffrep", "cAnnot", "listOFargs", "zipfile", "singlefile")
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
77 save(list = objects2save[objects2save %in% ls()], file = "annotatediff.RData")
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
78
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
79 cat("\n\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
80
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
81 cat("\tDONE\n")