annotate xcms_export_samplemetadata.r @ 9:94eb263cfab4 draft

"planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
author workflow4metabolomics
date Wed, 07 Apr 2021 09:53:54 +0000
parents 8c62030a1136
children cdab04a1d1d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
1 #!/usr/bin/env Rscript
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
2
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
3 #Import the different functions
9
94eb263cfab4 "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
workflow4metabolomics
parents: 4
diff changeset
4 source_local <- function(fname) {
94eb263cfab4 "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
workflow4metabolomics
parents: 4
diff changeset
5 argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/"))
94eb263cfab4 "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
workflow4metabolomics
parents: 4
diff changeset
6 }
0
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
7 source_local("lib.r")
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
8
9
94eb263cfab4 "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
workflow4metabolomics
parents: 4
diff changeset
9 pkgs <- c("xcms", "batch")
0
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
10 loadAndDisplayPackages(pkgs)
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
11 cat("\n\n");
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
12
9
94eb263cfab4 "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
workflow4metabolomics
parents: 4
diff changeset
13 args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects
0
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
14
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
15
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
16 sampleMetadata <- NULL
9
94eb263cfab4 "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
workflow4metabolomics
parents: 4
diff changeset
17 for (image in args$images) {
0
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
18 load(image)
2
942ffa3c38b8 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit ba2a5c2e962a95155c344dc1864a9c76eb565e9c
lecorguille
parents: 1
diff changeset
19 if (exists("raw_data")) xdata <- raw_data
942ffa3c38b8 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit ba2a5c2e962a95155c344dc1864a9c76eb565e9c
lecorguille
parents: 1
diff changeset
20 if (!exists("xdata")) stop("\n\nERROR: The RData doesn't contain any object called 'xdata'. This RData should have been created by an old version of XMCS 2.*")
0
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
21 if (is.null(sampleMetadata))
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
22 sampleMetadata <- xdata@phenoData@data
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
23 else
9
94eb263cfab4 "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
workflow4metabolomics
parents: 4
diff changeset
24 sampleMetadata <- rbind(sampleMetadata, xdata@phenoData@data)
0
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
25 }
9
94eb263cfab4 "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
workflow4metabolomics
parents: 4
diff changeset
26 colnames(sampleMetadata) <- c("sample_name", "class")
1
008aceb33627 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86-dirty
lecorguille
parents: 0
diff changeset
27 sampleMetadata$sample_name <- make.names(sampleMetadata$sample_name)
0
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
28
e3c06320f884 planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 67da3bb19bde72d5e78397e5627c176896234f86
lecorguille
parents:
diff changeset
29 # Create a sampleMetada file
9
94eb263cfab4 "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
workflow4metabolomics
parents: 4
diff changeset
30 write.table(sampleMetadata, file = "sampleMetadata.tsv", sep = "\t", row.names = FALSE, quote = FALSE)