Mercurial > repos > workflow4metabolomics > camera_groupcorr
annotate CAMERA_groupCorr.R @ 0:cb57be5de070 draft default tip
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
author | workflow4metabolomics |
---|---|
date | Sun, 24 Nov 2024 21:29:48 +0000 |
parents | |
children |
rev | line source |
---|---|
0
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
1 #!/usr/bin/env Rscript |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
2 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
3 # ----- PACKAGE ----- |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
4 cat("\tSESSION INFO\n") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
5 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
6 # Import the different functions |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
7 source_local <- function(fname) { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
8 argv <- commandArgs(trailingOnly = FALSE) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
9 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
10 source(paste(base_dir, fname, sep = "/")) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
11 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
12 source_local("lib.r") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
13 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
14 pkgs <- c("CAMERA", "xcms", "multtest", "batch") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
15 loadAndDisplayPackages(pkgs) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
16 cat("\n\n") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
17 # ----- ARGUMENTS ----- |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
18 cat("\tARGUMENTS INFO\n") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
19 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
20 args <- parseCommandArgs(evaluate = FALSE) # interpretation of arguments given in command line as an R list of objects |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
21 write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
22 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
23 cat("\n\n") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
24 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
25 print("Arguments retrieved from the command line:") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
26 print(args) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
27 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
28 # Function to convert "NULL" strings to actual NULL values |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
29 convertNullString <- function(x) { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
30 if (x == "NULL") { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
31 return(NULL) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
32 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
33 return(x) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
34 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
35 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
36 # Function to convert string to numeric lists |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
37 convert_psg_list <- function(x) { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
38 # Check if x is NULL or has zero length before further processing |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
39 if (is.null(x) || length(x) == 0) { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
40 return(NULL) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
41 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
42 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
43 # Force conversion to character |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
44 x <- as.character(x) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
45 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
46 if (grepl("^[0-9]+$", x)) { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
47 # If the string represents a single numeric value |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
48 return(as.numeric(x)) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
49 } else { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
50 # Convert string representation of a list to a numeric vector |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
51 # Use a regular expression to split by common separators |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
52 return(as.numeric(unlist(strsplit(x, "[,;\\s]+")))) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
53 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
54 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
55 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
56 for (arg in names(args)) { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
57 args[[arg]] <- convertNullString(args[[arg]]) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
58 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
59 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
60 # Convert only the 'psg_list' element in args |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
61 args$psg_list <- convert_psg_list(args$psg_list) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
62 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
63 print("Argument types:") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
64 print(sapply(args, class)) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
65 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
66 # Check if the image file exists |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
67 if (!file.exists(args$image)) { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
68 stop("The RData file does not exist: ", args$image) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
69 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
70 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
71 # ----- PROCESSING INFILE ----- |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
72 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
73 # Load the RData file |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
74 load(args$image) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
75 args$image <- NULL |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
76 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
77 # Save arguments to generate a report |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
78 if (!exists("listOFlistArguments")) listOFlistArguments <- list() |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
79 listOFlistArguments[[format(Sys.time(), "%y%m%d-%H:%M:%S_groupCorr")]] <- args |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
80 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
81 # We unzip automatically the chromatograms from the zip files. |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
82 if (!exists("zipfile")) zipfile <- NULL |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
83 if (!exists("singlefile")) singlefile <- NULL |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
84 rawFilePath <- getRawfilePathFromArguments(singlefile, zipfile, args) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
85 zipfile <- rawFilePath$zipfile |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
86 singlefile <- rawFilePath$singlefile |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
87 args <- rawFilePath$args |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
88 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
89 print(paste("singlefile :", singlefile)) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
90 if (!is.null(singlefile)) { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
91 directory <- retrieveRawfileInTheWorkingDir(singlefile, zipfile) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
92 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
93 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
94 # Ensure the xa object is loaded |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
95 if (!exists("xa")) { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
96 stop("The xa object was not found in the RData file.") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
97 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
98 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
99 print("xa object loaded:") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
100 print(xa) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
101 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
102 # Apply the groupCorr function to the xsAnnotate object |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
103 print("Calling groupCorr function:") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
104 xa <- groupCorr(xa, cor_eic_th = args$cor_eic_th, pval = args$pval, graphMethod = args$graphMethod, calcIso = args$calcIso, calcCiS = args$calcCiS, calcCaS = args$calcCaS, psg_list = args$psg_list, cor_exp_th = args$cor_exp_th, intval = args$intval) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
105 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
106 print("Result of groupCorr function:") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
107 print(xa) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
108 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
109 # Extract the list of annotated peaks |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
110 peakList <- getPeaklist(xa, intval = args$intval) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
111 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
112 if (length(phenoData@data$sample_name) == 1) { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
113 peakList$name <- make.unique(paste0("M", round(peakList[, "mz"], 0), "T", round(peakList[, "rt"], 0)), "_") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
114 variableMetadata <- peakList[, c("name", setdiff(names(peakList), "name"))] |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
115 variableMetadata <- formatIonIdentifiers(variableMetadata, numDigitsRT = args$numDigitsRT, numDigitsMZ = args$numDigitsMZ) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
116 } else { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
117 names_default <- groupnames(xa@xcmsSet, mzdec = 0, rtdec = 0) # Names without decimals |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
118 names_custom <- groupnames(xa@xcmsSet, mzdec = args$numDigitsMZ, rtdec = args$numDigitsRT) # Names with "x" decimals |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
119 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
120 variableMetadata <- data.frame( |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
121 name = names_default, |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
122 name_custom = names_custom, |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
123 stringsAsFactors = FALSE |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
124 ) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
125 variableMetadata <- cbind(variableMetadata, peakList[, !(make.names(colnames(peakList)) %in% c(make.names(sampnames(xa@xcmsSet))))]) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
126 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
127 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
128 if (!exists("RTinMinute")) RTinMinute <- FALSE |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
129 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
130 if (args$convertRTMinute == TRUE && RTinMinute == FALSE) { |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
131 RTinMinute <- TRUE |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
132 variableMetadata <- RTSecondToMinute(variableMetadata = variableMetadata, convertRTMinute = args$convertRTMinute) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
133 } |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
134 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
135 # Save the extracted peak list as a TSV file named 'variableMetadata.tsv' |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
136 output_file_tsv <- "variableMetadata.tsv" |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
137 write.table(variableMetadata, file = output_file_tsv, sep = "\t", row.names = FALSE, quote = FALSE) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
138 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
139 # Save the updated xsAnnotate object |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
140 output_file_RData <- "camera_groupCorr.RData" |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
141 objects2save <- c("xa", "variableMetadata", "listOFlistArguments", "zipfile", "singlefile", "RTinMinute", "phenoData") |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
142 save(list = objects2save[objects2save %in% ls()], file = output_file_RData) |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
143 |
cb57be5de070
planemo upload commit 24d44ee26b7c23380c2b42fae2f7f6e58472100d
workflow4metabolomics
parents:
diff
changeset
|
144 cat("Output files generated:", output_file_tsv, "and", output_file_RData, "\n") |