Mercurial > repos > lecorguille > camera_annotate
annotate lib.r @ 27:75a1b3f7bacc draft default tip
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
author | workflow4metabolomics |
---|---|
date | Sun, 24 Nov 2024 21:27:48 +0000 |
parents | 4b9ab71be05e |
children |
rev | line source |
---|---|
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
1 # lib.r |
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
2 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
3 # @author G. Le Corguille |
18
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
4 # solve an issue with batch if arguments are logical TRUE/FALSE |
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
5 parseCommandArgs <- function(...) { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
6 args <- batch::parseCommandArgs(...) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
7 for (key in names(args)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
8 if (args[key] %in% c("TRUE", "FALSE")) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
9 args[key] <- as.logical(args[key]) |
18
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
10 } |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
11 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
12 return(args) |
18
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
13 } |
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
14 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
15 # @author G. Le Corguille |
18
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
16 # This function will |
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
17 # - load the packages |
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
18 # - display the sessionInfo |
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
19 loadAndDisplayPackages <- function(pkgs) { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
20 for (pkg in pkgs) suppressPackageStartupMessages(stopifnot(library(pkg, quietly = TRUE, logical.return = TRUE, character.only = TRUE))) |
18
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
21 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
22 sessioninfo <- sessionInfo() |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
23 cat(sessioninfo$R.version$version.string, "\n") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
24 cat("Main packages:\n") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
25 for (pkg in names(sessioninfo$otherPkgs)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
26 cat(paste(pkg, packageVersion(pkg)), "\t") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
27 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
28 cat("\n") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
29 cat("Other loaded packages:\n") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
30 for (pkg in names(sessioninfo$loadedOnly)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
31 cat(paste(pkg, packageVersion(pkg)), "\t") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
32 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
33 cat("\n") |
18
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
34 } |
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
35 |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
36 # This function retrieve a xset like object |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
37 # @author Gildas Le Corguille lecorguille@sb-roscoff.fr |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
38 getxcmsSetObject <- function(xobject) { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
39 # XCMS 1.x |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
40 if (class(xobject) == "xcmsSet") { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
41 return(xobject) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
42 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
43 # XCMS 3.x |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
44 if (class(xobject) == "XCMSnExp") { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
45 # Get the legacy xcmsSet object |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
46 suppressWarnings(xset <- as(xobject, "xcmsSet")) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
47 if (is.null(xset@phenoData$sample_group)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
48 sampclass(xset) <- "." |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
49 } else { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
50 sampclass(xset) <- xset@phenoData$sample_group |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
51 } |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
52 if (!is.null(xset@phenoData$sample_name)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
53 rownames(xset@phenoData) <- xset@phenoData$sample_name |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
54 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
55 return(xset) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
56 } |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
57 } |
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
58 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
59 # @author G. Le Corguille |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
60 # The function create a pdf from the different png generated by diffreport |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
61 diffreport_png2pdf <- function(filebase) { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
62 dir.create("pdf") |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
63 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
64 pdfEicOutput <- paste0("pdf/", filebase, "-eic_pdf.pdf") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
65 pdfBoxOutput <- paste0("pdf/", filebase, "-box_pdf.pdf") |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
66 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
67 system(paste0("gm convert ", filebase, "_eic/*.png ", pdfEicOutput)) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
68 system(paste0("gm convert ", filebase, "_box/*.png ", pdfBoxOutput)) |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
69 } |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
70 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
71 # @author G. Le Corguille |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
72 # The function create a zip archive from the different png generated by diffreport |
18
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
73 diffreport_png2zip <- function() { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
74 zip("eic.zip", dir(pattern = "_eic"), zip = Sys.which("zip")) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
75 zip("box.zip", dir(pattern = "_box"), zip = Sys.which("zip")) |
18
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
76 } |
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
77 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
78 # The function create a zip archive from the different tabular generated by diffreport |
18
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
79 diffreport_tabular2zip <- function() { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
80 zip("tabular.zip", dir(pattern = "tabular/*"), zip = Sys.which("zip")) |
18
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
81 } |
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
82 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
83 # @author G. Le Corguille |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
84 # This function convert if it is required the Retention Time in minutes |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
85 RTSecondToMinute <- function(variableMetadata, convertRTMinute) { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
86 if (convertRTMinute) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
87 # converting the retention times (seconds) into minutes |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
88 print("converting the retention times into minutes in the variableMetadata") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
89 variableMetadata[, "rt"] <- variableMetadata[, "rt"] / 60 |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
90 variableMetadata[, "rtmin"] <- variableMetadata[, "rtmin"] / 60 |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
91 variableMetadata[, "rtmax"] <- variableMetadata[, "rtmax"] / 60 |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
92 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
93 return(variableMetadata) |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
94 } |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
95 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
96 # @author G. Le Corguille |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
97 # This function format ions identifiers |
23
abf1775ac14d
"planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents:
20
diff
changeset
|
98 formatIonIdentifiers <- function(variableMetadata, numDigitsRT = 0, numDigitsMZ = 0) { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
99 splitDeco <- strsplit(as.character(variableMetadata$name), "_") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
100 idsDeco <- sapply(splitDeco, function(x) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
101 deco <- unlist(x)[2] |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
102 if (is.na(deco)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
103 return("") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
104 } else { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
105 return(paste0("_", deco)) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
106 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
107 }) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
108 namecustom <- make.unique(paste0("M", round(variableMetadata[, "mz"], numDigitsMZ), "T", round(variableMetadata[, "rt"], numDigitsRT), idsDeco)) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
109 variableMetadata <- cbind(name = variableMetadata$name, namecustom = namecustom, variableMetadata[, !(colnames(variableMetadata) %in% c("name"))]) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
110 return(variableMetadata) |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
111 } |
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
112 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
113 # The function annotateDiffreport without the corr function which bugs |
23
abf1775ac14d
"planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents:
20
diff
changeset
|
114 annotatediff <- function(xset = xset, args = args, variableMetadataOutput = "variableMetadata.tsv") { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
115 # Resolve the bug with x11, with the function png |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
116 options(bitmapType = "cairo") |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
117 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
118 # Check if the fillpeaks step has been done previously, if it hasn't, there is an error message and the execution is stopped. |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
119 res <- try(is.null(xset@filled)) |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
120 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
121 # ------ annot ------- |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
122 args$calcCiS <- as.logical(args$calcCiS) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
123 args$calcIso <- as.logical(args$calcIso) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
124 args$calcCaS <- as.logical(args$calcCaS) |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
125 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
126 # common parameters |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
127 args4annotate <- list( |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
128 object = xset, |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
129 nSlaves = args$nSlaves, sigma = args$sigma, perfwhm = args$perfwhm, |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
130 maxcharge = args$maxcharge, maxiso = args$maxiso, minfrac = args$minfrac, |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
131 ppm = args$ppm, mzabs = args$mzabs, quick = args$quick, |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
132 polarity = args$polarity, max_peaks = args$max_peaks, intval = args$intval |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
133 ) |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
134 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
135 if (args$quick == FALSE) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
136 args4annotate <- append( |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
137 args4annotate, |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
138 list( |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
139 graphMethod = args$graphMethod, cor_eic_th = args$cor_eic_th, pval = args$pval, |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
140 calcCiS = args$calcCiS, calcIso = args$calcIso, calcCaS = args$calcCaS |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
141 ) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
142 ) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
143 # no ruleset |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
144 if (!is.null(args$multiplier)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
145 args4annotate <- append( |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
146 args4annotate, |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
147 list(multiplier = args$multiplier) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
148 ) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
149 } else { # ruleset |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
150 rulset <- read.table(args$rules, h = TRUE, sep = ";") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
151 if (ncol(rulset) < 4) rulset <- read.table(args$rules, h = TRUE, sep = "\t") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
152 if (ncol(rulset) < 4) rulset <- read.table(args$rules, h = TRUE, sep = ",") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
153 if (ncol(rulset) < 4) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
154 error_message <- "Your ruleset file seems not well formatted. The column separators accepted are ; , and tabulation" |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
155 print(error_message) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
156 stop(error_message) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
157 } |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
158 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
159 args4annotate <- append( |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
160 args4annotate, |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
161 list(rules = rulset) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
162 ) |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
163 } |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
164 } |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
165 |
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
166 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
167 # launch annotate |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
168 xa <- do.call("annotate", args4annotate) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
169 peakList <- getPeaklist(xa, intval = args$intval) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
170 peakList <- cbind(groupnames(xa@xcmsSet), peakList) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
171 colnames(peakList)[1] <- c("name") |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
172 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
173 # --- Multi condition : diffreport --- |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
174 diffrepOri <- NULL |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
175 if (!is.null(args$runDiffreport) && nlevels(sampclass(xset)) >= 2) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
176 # Check if the fillpeaks step has been done previously, if it hasn't, there is an error message and the execution is stopped. |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
177 res <- try(is.null(xset@filled)) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
178 classes <- levels(sampclass(xset)) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
179 for (i in seq_len(length(classes) - 1)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
180 for (n in seq_len(length(classes))) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
181 if (i + n <= length(classes)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
182 filebase <- paste(classes[i], class2 = classes[i + n], sep = "-vs-") |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
183 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
184 diffrep <- diffreport( |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
185 object = xset, class1 = classes[i], class2 = classes[i + n], |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
186 filebase = filebase, eicmax = args$eicmax, eicwidth = args$eicwidth, |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
187 sortpval = TRUE, value = args$value, h = args$h, w = args$w, mzdec = args$mzdec, missing = 0 |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
188 ) |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
189 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
190 diffrepOri <- diffrep |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
191 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
192 # renamming of the column rtmed to rt to fit with camera peaklist function output |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
193 colnames(diffrep)[colnames(diffrep) == "rtmed"] <- "rt" |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
194 colnames(diffrep)[colnames(diffrep) == "mzmed"] <- "mz" |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
195 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
196 # combines results and reorder columns |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
197 diffrep <- merge(peakList, diffrep[, c("name", "fold", "tstat", "pvalue")], by.x = "name", by.y = "name", sort = FALSE) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
198 diffrep <- cbind(diffrep[, !(colnames(diffrep) %in% c(sampnames(xa@xcmsSet)))], diffrep[, (colnames(diffrep) %in% c(sampnames(xa@xcmsSet)))]) |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
199 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
200 diffrep <- RTSecondToMinute(diffrep, args$convertRTMinute) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
201 diffrep <- formatIonIdentifiers(diffrep, numDigitsRT = args$numDigitsRT, numDigitsMZ = args$numDigitsMZ) |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
202 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
203 if (args$sortpval) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
204 diffrep <- diffrep[order(diffrep$pvalue), ] |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
205 } |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
206 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
207 dir.create("tabular", showWarnings = FALSE) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
208 write.table(diffrep, sep = "\t", quote = FALSE, row.names = FALSE, file = paste("tabular/", filebase, "_tsv.tabular", sep = "")) |
16
a2c49996603e
planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents:
13
diff
changeset
|
209 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
210 if (args$eicmax != 0) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
211 if (args$png2 == "pdf") { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
212 diffreport_png2pdf(filebase) |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
213 } |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
214 if (args$png2 == "zip") { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
215 diffreport_png2zip() |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
216 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
217 } |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
218 } |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
219 } |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
220 } |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
221 if (args$tabular2 == "zip") { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
222 diffreport_tabular2zip() |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
223 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
224 } |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
225 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
226 # --- variableMetadata --- |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
227 variableMetadata <- peakList[, !(make.names(colnames(peakList)) %in% c(make.names(sampnames(xa@xcmsSet))))] |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
228 variableMetadata <- RTSecondToMinute(variableMetadata, args$convertRTMinute) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
229 variableMetadata <- formatIonIdentifiers(variableMetadata, numDigitsRT = args$numDigitsRT, numDigitsMZ = args$numDigitsMZ) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
230 # if we have 2 conditions, we keep stat of diffrep |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
231 if (!is.null(args$runDiffreport) && nlevels(sampclass(xset)) == 2) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
232 variableMetadata <- merge(variableMetadata, diffrep[, c("name", "fold", "tstat", "pvalue")], by.x = "name", by.y = "name", sort = FALSE) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
233 if (exists("args[[\"sortpval\"]]")) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
234 variableMetadata <- variableMetadata[order(variableMetadata$pvalue), ] |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
235 } |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
236 } |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
237 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
238 variableMetadataOri <- variableMetadata |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
239 write.table(variableMetadata, sep = "\t", quote = FALSE, row.names = FALSE, file = variableMetadataOutput) |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
240 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
241 return(list("xa" = xa, "diffrep" = diffrepOri, "variableMetadata" = variableMetadataOri)) |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
242 } |
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
243 |
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
244 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
245 combinexsAnnos_function <- function( |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
246 xaP, xaN, diffrepP = NULL, diffrepN = NULL, |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
247 pos = TRUE, tol = 2, ruleset = NULL, keep_meta = TRUE, convertRTMinute = FALSE, numDigitsMZ = 0, |
23
abf1775ac14d
"planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents:
20
diff
changeset
|
248 numDigitsRT = 0, variableMetadataOutput = "variableMetadata.tsv") { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
249 # Load the two Rdata to extract the xset objects from positive and negative mode |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
250 cat("\tObject xset from positive mode\n") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
251 print(xaP) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
252 cat("\n") |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
253 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
254 cat("\tObject xset from negative mode\n") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
255 print(xaN) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
256 cat("\n") |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
257 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
258 cat("\n") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
259 cat("\tCombining...\n") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
260 # Convert the string to numeric for creating matrix |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
261 row <- as.numeric(strsplit(ruleset, ",")[[1]][1]) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
262 column <- as.numeric(strsplit(ruleset, ",")[[1]][2]) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
263 ruleset <- cbind(row, column) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
264 # Test if the file comes from an older version tool |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
265 if ((!is.null(xaP)) && (!is.null(xaN))) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
266 # Launch the combinexsannos function from CAMERA |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
267 cAnnot <- combinexsAnnos(xaP, xaN, pos = pos, tol = tol, ruleset = ruleset) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
268 } else { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
269 stop("You must relauch the CAMERA.annotate step with the lastest version.") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
270 } |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
271 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
272 if (pos) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
273 xa <- xaP |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
274 mode <- "neg. Mode" |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
275 } else { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
276 xa <- xaN |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
277 mode <- "pos. Mode" |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
278 } |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
279 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
280 peakList <- getPeaklist(xa) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
281 peakList <- cbind(groupnames(xa@xcmsSet), peakList) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
282 colnames(peakList)[1] <- c("name") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
283 variableMetadata <- cbind(peakList, cAnnot[, c("isotopes", "adduct", "pcgroup", mode)]) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
284 variableMetadata <- variableMetadata[, !(colnames(variableMetadata) %in% c(sampnames(xa@xcmsSet)))] |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
285 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
286 # Test if there are more than two classes (conditions) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
287 if (nlevels(sampclass(xaP@xcmsSet)) == 2 && (!is.null(diffrepN)) && (!is.null(diffrepP))) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
288 diffrepP <- diffrepP[, c("name", "fold", "tstat", "pvalue")] |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
289 colnames(diffrepP) <- paste("P.", colnames(diffrepP), sep = "") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
290 diffrepN <- diffrepN[, c("name", "fold", "tstat", "pvalue")] |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
291 colnames(diffrepN) <- paste("N.", colnames(diffrepN), sep = "") |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
292 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
293 variableMetadata <- merge(variableMetadata, diffrepP, by.x = "name", by.y = "P.name") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
294 variableMetadata <- merge(variableMetadata, diffrepN, by.x = "name", by.y = "N.name") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
295 } |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
296 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
297 rownames(variableMetadata) <- NULL |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
298 # TODO: checker colnames(variableMetadata)[1:2] = c("name", "mz/rt"); |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
299 |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
300 variableMetadata <- RTSecondToMinute(variableMetadata, convertRTMinute) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
301 variableMetadata <- formatIonIdentifiers(variableMetadata, numDigitsRT = numDigitsRT, numDigitsMZ = numDigitsMZ) |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
302 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
303 # If the user want to keep only the metabolites which match a difference |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
304 if (keep_meta) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
305 variableMetadata <- variableMetadata[variableMetadata[, c(mode)] != "", ] |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
306 } |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
307 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
308 # Write the output into a tsv file |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
309 write.table(variableMetadata, sep = "\t", quote = FALSE, row.names = FALSE, file = variableMetadataOutput) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
310 return(variableMetadata) |
9
7da9252dd983
planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff
changeset
|
311 } |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
312 |
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
313 # This function get the raw file path from the arguments |
18
cb923396e70f
planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents:
17
diff
changeset
|
314 getRawfilePathFromArguments <- function(singlefile, zipfile, args) { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
315 if (!is.null(args$zipfile)) zipfile <- args$zipfile |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
316 if (!is.null(args$zipfilePositive)) zipfile <- args$zipfilePositive |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
317 if (!is.null(args$zipfileNegative)) zipfile <- args$zipfileNegative |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
318 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
319 if (!is.null(args$singlefile_galaxyPath)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
320 singlefile_galaxyPaths <- args$singlefile_galaxyPath |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
321 singlefile_sampleNames <- args$singlefile_sampleName |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
322 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
323 if (!is.null(args$singlefile_galaxyPathPositive)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
324 singlefile_galaxyPaths <- args$singlefile_galaxyPathPositive |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
325 singlefile_sampleNames <- args$singlefile_sampleNamePositive |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
326 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
327 if (!is.null(args$singlefile_galaxyPathNegative)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
328 singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
329 singlefile_sampleNames <- args$singlefile_sampleNameNegative |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
330 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
331 if (exists("singlefile_galaxyPaths")) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
332 singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths, ",")) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
333 singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames, ",")) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
334 |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
335 singlefile <- NULL |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
336 for (singlefile_galaxyPath_i in seq_len(length(singlefile_galaxyPaths))) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
337 singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
338 singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
339 singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
340 } |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
341 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
342 for (argument in c( |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
343 "zipfile", "zipfilePositive", "zipfileNegative", |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
344 "singlefile_galaxyPath", "singlefile_sampleName", |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
345 "singlefile_galaxyPathPositive", "singlefile_sampleNamePositive", |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
346 "singlefile_galaxyPathNegative", "singlefile_sampleNameNegative" |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
347 )) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
348 args[[argument]] <- NULL |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
349 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
350 return(list(zipfile = zipfile, singlefile = singlefile, args = args)) |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
351 } |
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
352 |
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
353 |
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
354 # This function retrieve the raw file in the working directory |
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
355 # - if zipfile: unzip the file with its directory tree |
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
356 # - if singlefiles: set symlink with the good filename |
23
abf1775ac14d
"planemo upload commit c1e276cf53b3c54d4702ab26d4f40a525a720998"
workflow4metabolomics
parents:
20
diff
changeset
|
357 retrieveRawfileInTheWorkingDir <- function(singlefile, zipfile) { |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
358 if (!is.null(singlefile) && (length("singlefile") > 0)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
359 for (singlefile_sampleName in names(singlefile)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
360 singlefile_galaxyPath <- singlefile[[singlefile_sampleName]] |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
361 if (!file.exists(singlefile_galaxyPath)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
362 error_message <- paste("Cannot access the sample:", singlefile_sampleName, "located:", singlefile_galaxyPath, ". Please, contact your administrator ... if you have one!") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
363 print(error_message) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
364 stop(error_message) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
365 } |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
366 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
367 file.symlink(singlefile_galaxyPath, singlefile_sampleName) |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
368 } |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
369 directory <- "." |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
370 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
371 if (!is.null(zipfile) && (zipfile != "")) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
372 if (!file.exists(zipfile)) { |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
373 error_message <- paste("Cannot access the Zip file:", zipfile, ". Please, contact your administrator ... if you have one!") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
374 print(error_message) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
375 stop(error_message) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
376 } |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
377 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
378 # unzip |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
379 suppressWarnings(unzip(zipfile, unzip = "unzip")) |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
380 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
381 # get the directory name |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
382 filesInZip <- unzip(zipfile, list = TRUE) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
383 directories <- unique(unlist(lapply(strsplit(filesInZip$Name, "/"), function(x) x[1]))) |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
384 directories <- directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir] |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
385 directory <- "." |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
386 if (length(directories) == 1) directory <- directories |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
387 |
25
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
388 cat("files_root_directory\t", directory, "\n") |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
389 } |
4b9ab71be05e
planemo upload commit cfad09eb4dd6b1439b7de6a0852cd8fa22210f58
workflow4metabolomics
parents:
23
diff
changeset
|
390 return(directory) |
13
1c30ff90f3ae
planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents:
9
diff
changeset
|
391 } |