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