annotate CAMERA_annotateDiffreport.r @ 26:3d63a762954a draft default tip

planemo upload commit a923a432239a1f2ffee2dae1281fe2d8f41bac38
author workflow4metabolomics
date Mon, 30 Sep 2024 12:22:28 +0000
parents 4b9ab71be05e
children
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
25
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
6 # Import the different functions
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
7 source_local <- function(fname) {
25
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
8 argv <- commandArgs(trailingOnly = FALSE)
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
9 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
10 source(paste(base_dir, fname, sep = "/"))
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
11 }
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
12 source_local("lib.r")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
13
23
abf1775ac14d "planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents: 19
diff changeset
14 pkgs <- c("CAMERA", "multtest", "batch")
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
15 loadAndDisplayPackages(pkgs)
25
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
16 cat("\n\n")
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
17 # ----- ARGUMENTS -----
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
18 cat("\tARGUMENTS INFO\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
19
25
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
20 args <- parseCommandArgs(evaluate = FALSE) # interpretation of arguments given in command line as an R list of objects
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
21 write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t")
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
22
25
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
23 cat("\n\n")
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
24 # ----- PROCESSING INFILE -----
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
25 cat("\tINFILE PROCESSING INFO\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
diff changeset
26
25
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
27 # image is an .RData file necessary to use xset variable given by previous tools
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
28 load(args$image)
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
29 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
26
3d63a762954a planemo upload commit a923a432239a1f2ffee2dae1281fe2d8f41bac38
workflow4metabolomics
parents: 25
diff changeset
38 if (!exists("listOFlistArguments")) listOFlistArguments <- list()
3d63a762954a planemo upload commit a923a432239a1f2ffee2dae1281fe2d8f41bac38
workflow4metabolomics
parents: 25
diff changeset
39 listOFlistArguments[[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")) {
25
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
53 xset <- getxcmsSetObject(xdata)
18
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
25
4b9ab71be05e planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents: 23
diff changeset
75 # saving R data in .Rdata file to save the variables used in the present tool
26
3d63a762954a planemo upload commit a923a432239a1f2ffee2dae1281fe2d8f41bac38
workflow4metabolomics
parents: 25
diff changeset
76 objects2save <- c("xa", "variableMetadata", "diffrep", "cAnnot", "listOFlistArguments", "zipfile", "singlefile")
23
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")