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