annotate lib.r @ 0:ae9ef9219aae draft default tip

"planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
author eschen42
date Fri, 12 Feb 2021 18:05:29 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
1 #@authors ABiMS TEAM, Y. Guitton
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
2 # lib.r for Galaxy Workflow4Metabolomics xcms tools
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
3
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
4 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
5 # solve an issue with batch if arguments are logical TRUE/FALSE
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
6 parseCommandArgs <- function(...) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
7 args <- batch::parseCommandArgs(...)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
8 for (key in names(args)) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
9 if (args[key] %in% c("TRUE","FALSE"))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
10 args[key] = as.logical(args[key])
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
11 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
12 return(args)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
13 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
14
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
15 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
16 # This function will
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
17 # - load the packages
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
18 # - display the sessionInfo
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
19 loadAndDisplayPackages <- function(pkgs) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
20 for(pkg in pkgs) suppressPackageStartupMessages( stopifnot( library(pkg, quietly=TRUE, logical.return=TRUE, character.only=TRUE)))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
21
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
22 sessioninfo = sessionInfo()
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
23 cat(sessioninfo$R.version$version.string,"\n")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
24 cat("Main packages:\n")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
25 for (pkg in names(sessioninfo$otherPkgs)) { cat(paste(pkg,packageVersion(pkg)),"\t") }; cat("\n")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
26 cat("Other loaded packages:\n")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
27 for (pkg in names(sessioninfo$loadedOnly)) { cat(paste(pkg,packageVersion(pkg)),"\t") }; cat("\n")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
28 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
29
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
30 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
31 # This function merge several chromBPI or chromTIC into one.
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
32 mergeChrom <- function(chrom_merged, chrom) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
33 if (is.null(chrom_merged)) return(NULL)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
34 chrom_merged@.Data <- cbind(chrom_merged@.Data, chrom@.Data)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
35 return(chrom_merged)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
36 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
37
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
38 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
39 # This function merge several xdata into one.
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
40 mergeXData <- function(args) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
41 chromTIC <- NULL
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
42 chromBPI <- NULL
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
43 chromTIC_adjusted <- NULL
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
44 chromBPI_adjusted <- NULL
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
45 md5sumList <- NULL
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
46 for(image in args$images) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
47
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
48 load(image)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
49 # Handle infiles
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
50 if (!exists("singlefile")) singlefile <- NULL
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
51 if (!exists("zipfile")) zipfile <- NULL
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
52 rawFilePath <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile, args)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
53 zipfile <- rawFilePath$zipfile
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
54 singlefile <- rawFilePath$singlefile
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
55
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
56 if (exists("raw_data")) xdata <- raw_data
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
57 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.*")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
58
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
59 cat(sampleNamesList$sampleNamesOrigin,"\n")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
60
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
61 if (!exists("xdata_merged")) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
62 xdata_merged <- xdata
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
63 singlefile_merged <- singlefile
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
64 md5sumList_merged <- md5sumList
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
65 sampleNamesList_merged <- sampleNamesList
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
66 chromTIC_merged <- chromTIC
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
67 chromBPI_merged <- chromBPI
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
68 chromTIC_adjusted_merged <- chromTIC_adjusted
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
69 chromBPI_adjusted_merged <- chromBPI_adjusted
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
70 } else {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
71 if (is(xdata, "XCMSnExp")) xdata_merged <- c(xdata_merged,xdata)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
72 else if (is(xdata, "OnDiskMSnExp")) xdata_merged <- xcms:::.concatenate_OnDiskMSnExp(xdata_merged,xdata)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
73 else stop("\n\nERROR: The RData either a OnDiskMSnExp object called raw_data or a XCMSnExp object called xdata")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
74
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
75 singlefile_merged <- c(singlefile_merged,singlefile)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
76 md5sumList_merged$origin <- rbind(md5sumList_merged$origin,md5sumList$origin)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
77 sampleNamesList_merged$sampleNamesOrigin <- c(sampleNamesList_merged$sampleNamesOrigin,sampleNamesList$sampleNamesOrigin)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
78 sampleNamesList_merged$sampleNamesMakeNames <- c(sampleNamesList_merged$sampleNamesMakeNames,sampleNamesList$sampleNamesMakeNames)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
79 chromTIC_merged <- mergeChrom(chromTIC_merged, chromTIC)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
80 chromBPI_merged <- mergeChrom(chromBPI_merged, chromBPI)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
81 chromTIC_adjusted_merged <- mergeChrom(chromTIC_adjusted_merged, chromTIC_adjusted)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
82 chromBPI_adjusted_merged <- mergeChrom(chromBPI_adjusted_merged, chromBPI_adjusted)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
83 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
84 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
85 rm(image)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
86 xdata <- xdata_merged; rm(xdata_merged)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
87 singlefile <- singlefile_merged; rm(singlefile_merged)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
88 md5sumList <- md5sumList_merged; rm(md5sumList_merged)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
89 sampleNamesList <- sampleNamesList_merged; rm(sampleNamesList_merged)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
90
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
91 if (!is.null(args$sampleMetadata)) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
92 cat("\tXSET PHENODATA SETTING...\n")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
93 sampleMetadataFile <- args$sampleMetadata
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
94 sampleMetadata <- getDataFrameFromFile(sampleMetadataFile, header=F)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
95 xdata@phenoData@data$sample_group=sampleMetadata$V2[match(xdata@phenoData@data$sample_name,sampleMetadata$V1)]
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
96
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
97 if (any(is.na(pData(xdata)$sample_group))) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
98 sample_missing <- pData(xdata)$sample_name[is.na(pData(xdata)$sample_group)]
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
99 error_message <- paste("Those samples are missing in your sampleMetadata:", paste(sample_missing, collapse=" "))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
100 print(error_message)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
101 stop(error_message)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
102 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
103 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
104
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
105 if (!is.null(chromTIC_merged)) { chromTIC <- chromTIC_merged; chromTIC@phenoData <- xdata@phenoData }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
106 if (!is.null(chromBPI_merged)) { chromBPI <- chromBPI_merged; chromBPI@phenoData <- xdata@phenoData }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
107 if (!is.null(chromTIC_adjusted_merged)) { chromTIC_adjusted <- chromTIC_adjusted_merged; chromTIC_adjusted@phenoData <- xdata@phenoData }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
108 if (!is.null(chromBPI_adjusted_merged)) { chromBPI_adjusted <- chromBPI_adjusted_merged; chromBPI_adjusted@phenoData <- xdata@phenoData }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
109
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
110 return(list("xdata"=xdata, "singlefile"=singlefile, "md5sumList"=md5sumList,"sampleNamesList"=sampleNamesList, "chromTIC"=chromTIC, "chromBPI"=chromBPI, "chromTIC_adjusted"=chromTIC_adjusted, "chromBPI_adjusted"=chromBPI_adjusted))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
111 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
112
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
113 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
114 # This function convert if it is required the Retention Time in minutes
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
115 RTSecondToMinute <- function(variableMetadata, convertRTMinute) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
116 if (convertRTMinute){
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
117 #converting the retention times (seconds) into minutes
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
118 print("converting the retention times into minutes in the variableMetadata")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
119 variableMetadata[,"rt"] <- variableMetadata[,"rt"]/60
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
120 variableMetadata[,"rtmin"] <- variableMetadata[,"rtmin"]/60
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
121 variableMetadata[,"rtmax"] <- variableMetadata[,"rtmax"]/60
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
122 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
123 return (variableMetadata)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
124 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
125
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
126 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
127 # This function format ions identifiers
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
128 formatIonIdentifiers <- function(variableMetadata, numDigitsRT=0, numDigitsMZ=0) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
129 splitDeco <- strsplit(as.character(variableMetadata$name),"_")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
130 idsDeco <- sapply(splitDeco, function(x) { deco=unlist(x)[2]; if (is.na(deco)) return ("") else return(paste0("_",deco)) })
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
131 namecustom <- make.unique(paste0("M",round(variableMetadata[,"mz"],numDigitsMZ),"T",round(variableMetadata[,"rt"],numDigitsRT),idsDeco))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
132 variableMetadata <- cbind(name=variableMetadata$name, namecustom=namecustom, variableMetadata[,!(colnames(variableMetadata) %in% c("name"))])
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
133 return(variableMetadata)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
134 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
135
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
136 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
137 # This function convert the remain NA to 0 in the dataMatrix
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
138 naTOzeroDataMatrix <- function(dataMatrix, naTOzero) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
139 if (naTOzero){
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
140 dataMatrix[is.na(dataMatrix)] <- 0
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
141 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
142 return (dataMatrix)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
143 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
144
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
145 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
146 # Draw the plotChromPeakDensity 3 per page in a pdf file
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
147 getPlotChromPeakDensity <- function(xdata, param = NULL, mzdigit=4) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
148 pdf(file="plotChromPeakDensity.pdf", width=16, height=12)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
149
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
150 par(mfrow = c(3, 1), mar = c(4, 4, 1, 0.5))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
151
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
152 if(length(unique(xdata$sample_group))<10){
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
153 group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
154 }else{
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
155 group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
156 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
157 names(group_colors) <- unique(xdata$sample_group)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
158 col_per_samp <- as.character(xdata$sample_group)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
159 for(i in 1:length(group_colors)){col_per_samp[col_per_samp==(names(group_colors)[i])]<-group_colors[i]}
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
160
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
161 xlim <- c(min(featureDefinitions(xdata)$rtmin), max(featureDefinitions(xdata)$rtmax))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
162 for (i in 1:nrow(featureDefinitions(xdata))) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
163 mzmin = featureDefinitions(xdata)[i,]$mzmin
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
164 mzmax = featureDefinitions(xdata)[i,]$mzmax
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
165 plotChromPeakDensity(xdata, param = param, mz=c(mzmin,mzmax), col=col_per_samp, pch=16, xlim=xlim, main=paste(round(mzmin,mzdigit),round(mzmax,mzdigit)))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
166 legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
167 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
168
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
169 dev.off()
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
170 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
171
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
172 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
173 # Draw the plotChromPeakDensity 3 per page in a pdf file
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
174 getPlotAdjustedRtime <- function(xdata) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
175
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
176 pdf(file="raw_vs_adjusted_rt.pdf", width=16, height=12)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
177
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
178 # Color by group
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
179 if(length(unique(xdata$sample_group))<10){
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
180 group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
181 }else{
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
182 group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
183 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
184 if (length(group_colors) > 1) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
185 names(group_colors) <- unique(xdata$sample_group)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
186 plotAdjustedRtime(xdata, col = group_colors[xdata$sample_group])
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
187 legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
188 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
189
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
190 # Color by sample
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
191 plotAdjustedRtime(xdata, col = rainbow(length(xdata@phenoData@data$sample_name)))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
192 legend("topright", legend=xdata@phenoData@data$sample_name, col=rainbow(length(xdata@phenoData@data$sample_name)), cex=0.8, lty=1)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
193
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
194 dev.off()
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
195 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
196
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
197 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
198 # value: intensity values to be used into, maxo or intb
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
199 getPeaklistW4M <- function(xdata, intval="into", convertRTMinute=F, numDigitsMZ=4, numDigitsRT=0, naTOzero=T, variableMetadataOutput, dataMatrixOutput, sampleNamesList) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
200 dataMatrix <- featureValues(xdata, method="medret", value=intval)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
201 colnames(dataMatrix) <- make.names(tools::file_path_sans_ext(colnames(dataMatrix)))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
202 dataMatrix = cbind(name=groupnames(xdata), dataMatrix)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
203 variableMetadata <- featureDefinitions(xdata)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
204 colnames(variableMetadata)[1] = "mz"; colnames(variableMetadata)[4] = "rt"
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
205 variableMetadata = data.frame(name=groupnames(xdata), variableMetadata)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
206
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
207 variableMetadata <- RTSecondToMinute(variableMetadata, convertRTMinute)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
208 variableMetadata <- formatIonIdentifiers(variableMetadata, numDigitsRT=numDigitsRT, numDigitsMZ=numDigitsMZ)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
209 dataMatrix <- naTOzeroDataMatrix(dataMatrix, naTOzero)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
210
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
211 # FIX: issue when the vector at peakidx is too long and is written in a new line during the export
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
212 variableMetadata[,"peakidx"] <- vapply(variableMetadata[,"peakidx"], FUN = paste, FUN.VALUE = character(1), collapse = ",")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
213
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
214 write.table(variableMetadata, file=variableMetadataOutput,sep="\t",quote=F,row.names=F)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
215 write.table(dataMatrix, file=dataMatrixOutput,sep="\t",quote=F,row.names=F)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
216
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
217 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
218
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
219 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
220 # It allow different of field separators
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
221 getDataFrameFromFile <- function(filename, header=T) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
222 myDataFrame <- read.table(filename, header=header, sep=";", stringsAsFactors=F)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
223 if (ncol(myDataFrame) < 2) myDataFrame <- read.table(filename, header=header, sep="\t", stringsAsFactors=F)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
224 if (ncol(myDataFrame) < 2) myDataFrame <- read.table(filename, header=header, sep=",", stringsAsFactors=F)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
225 if (ncol(myDataFrame) < 2) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
226 error_message="Your tabular file seems not well formatted. The column separators accepted are ; , and tabulation"
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
227 print(error_message)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
228 stop(error_message)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
229 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
230 return(myDataFrame)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
231 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
232
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
233 #@author G. Le Corguille
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
234 # Draw the BPI and TIC graphics
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
235 # colored by sample names or class names
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
236 getPlotChromatogram <- function(chrom, xdata, pdfname="Chromatogram.pdf", aggregationFun = "max") {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
237
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
238 if (aggregationFun == "sum")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
239 type="Total Ion Chromatograms"
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
240 else
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
241 type="Base Peak Intensity Chromatograms"
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
242
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
243 adjusted="Raw"
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
244 if (hasAdjustedRtime(xdata))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
245 adjusted="Adjusted"
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
246
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
247 main <- paste(type,":",adjusted,"data")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
248
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
249 pdf(pdfname, width=16, height=10)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
250
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
251 # Color by group
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
252 if(length(unique(xdata$sample_group))<10){
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
253 group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
254 }else{
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
255 group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
256 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
257 if (length(group_colors) > 1) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
258 names(group_colors) <- unique(xdata$sample_group)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
259 plot(chrom, col = group_colors[chrom$sample_group], main=main, peakType = "none")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
260 legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
261 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
262
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
263 # Color by sample
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
264 plot(chrom, col = rainbow(length(xdata@phenoData@data$sample_name)), main=main, peakType = "none")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
265 legend("topright", legend=xdata@phenoData@data$sample_name, col=rainbow(length(xdata@phenoData@data$sample_name)), cex=0.8, lty=1)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
266
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
267 dev.off()
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
268 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
269
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
270
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
271 # Get the polarities from all the samples of a condition
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
272 #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
273 #@author Gildas Le Corguille lecorguille@sb-roscoff.fr ABiMS TEAM
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
274 getSampleMetadata <- function(xdata=NULL, sampleMetadataOutput="sampleMetadata.tsv") {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
275 cat("Creating the sampleMetadata file...\n")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
276
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
277 #Create the sampleMetada dataframe
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
278 sampleMetadata <- xdata@phenoData@data
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
279 rownames(sampleMetadata) <- NULL
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
280 colnames(sampleMetadata) <- c("sample_name", "class")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
281
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
282 sampleNamesOrigin <- sampleMetadata$sample_name
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
283 sampleNamesMakeNames <- make.names(sampleNamesOrigin)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
284
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
285 if (any(duplicated(sampleNamesMakeNames))) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
286 write("\n\nERROR: Usually, R has trouble to deal with special characters in its column names, so it rename them using make.names().\nIn your case, at least two columns after the renaming obtain the same name, thus XCMS will collapse those columns per name.", stderr())
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
287 for (sampleName in sampleNamesOrigin) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
288 write(paste(sampleName,"\t->\t",make.names(sampleName)),stderr())
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
289 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
290 stop("\n\nERROR: One or more of your files will not be import by xcmsSet. It may due to bad characters in their filenames.")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
291 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
292
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
293 if (!all(sampleNamesOrigin == sampleNamesMakeNames)) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
294 cat("\n\nWARNING: Usually, R has trouble to deal with special characters in its column names, so it rename them using make.names()\nIn your case, one or more sample names will be renamed in the sampleMetadata and dataMatrix files:\n")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
295 for (sampleName in sampleNamesOrigin) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
296 cat(paste(sampleName,"\t->\t",make.names(sampleName),"\n"))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
297 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
298 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
299
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
300 sampleMetadata$sample_name <- sampleNamesMakeNames
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
301
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
302
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
303 #For each sample file, the following actions are done
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
304 for (fileIdx in 1:length(fileNames(xdata))) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
305 #Check if the file is in the CDF format
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
306 if (!mzR:::netCDFIsFile(fileNames(xdata))) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
307
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
308 # If the column isn't exist, with add one filled with NA
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
309 if (is.null(sampleMetadata$polarity)) sampleMetadata$polarity <- NA
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
310
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
311 #Extract the polarity (a list of polarities)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
312 polarity <- fData(xdata)[fData(xdata)$fileIdx == fileIdx,"polarity"]
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
313 #Verify if all the scans have the same polarity
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
314 uniq_list <- unique(polarity)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
315 if (length(uniq_list)>1){
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
316 polarity <- "mixed"
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
317 } else {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
318 polarity <- as.character(uniq_list)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
319 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
320
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
321 #Set the polarity attribute
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
322 sampleMetadata$polarity[fileIdx] <- polarity
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
323 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
324
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
325 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
326
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
327 write.table(sampleMetadata, sep="\t", quote=FALSE, row.names=FALSE, file=sampleMetadataOutput)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
328
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
329 return(list("sampleNamesOrigin"=sampleNamesOrigin, "sampleNamesMakeNames"=sampleNamesMakeNames))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
330
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
331 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
332
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
333
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
334 # This function will compute MD5 checksum to check the data integrity
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
335 #@author Gildas Le Corguille lecorguille@sb-roscoff.fr
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
336 getMd5sum <- function (files) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
337 cat("Compute md5 checksum...\n")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
338 library(tools)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
339 return(as.matrix(md5sum(files)))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
340 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
341
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
342 # This function retrieve the raw file in the working directory
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
343 # - if zipfile: unzip the file with its directory tree
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
344 # - if singlefiles: set symlink with the good filename
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
345 #@author Gildas Le Corguille lecorguille@sb-roscoff.fr
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
346 retrieveRawfileInTheWorkingDirectory <- function(singlefile, zipfile, args, prefix="") {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
347
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
348 if (!(prefix %in% c("","Positive","Negative","MS1","MS2"))) stop("prefix must be either '', 'Positive', 'Negative', 'MS1' or 'MS2'")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
349
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
350 # single - if the file are passed in the command arguments -> refresh singlefile
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
351 if (!is.null(args[[paste0("singlefile_galaxyPath",prefix)]])) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
352 singlefile_galaxyPaths <- unlist(strsplit(args[[paste0("singlefile_galaxyPath",prefix)]],"\\|"))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
353 singlefile_sampleNames <- unlist(strsplit(args[[paste0("singlefile_sampleName",prefix)]],"\\|"))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
354
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
355 singlefile <- NULL
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
356 for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
357 singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i]
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
358 singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i]
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
359 # In case, an url is used to import data within Galaxy
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
360 singlefile_sampleName <- tail(unlist(strsplit(singlefile_sampleName,"/")), n=1)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
361 singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
362 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
363 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
364 # zipfile - if the file are passed in the command arguments -> refresh zipfile
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
365 if (!is.null(args[[paste0("zipfile",prefix)]]))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
366 zipfile <- args[[paste0("zipfile",prefix)]]
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
367
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
368 # single
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
369 if(!is.null(singlefile) && (length("singlefile")>0)) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
370 files <- vector()
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
371 for (singlefile_sampleName in names(singlefile)) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
372 singlefile_galaxyPath <- singlefile[[singlefile_sampleName]]
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
373 if(!file.exists(singlefile_galaxyPath)){
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
374 error_message <- paste("Cannot access the sample:",singlefile_sampleName,"located:",singlefile_galaxyPath,". Please, contact your administrator ... if you have one!")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
375 print(error_message); stop(error_message)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
376 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
377
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
378 if (!suppressWarnings( try (file.link(singlefile_galaxyPath, singlefile_sampleName), silent=T)))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
379 file.copy(singlefile_galaxyPath, singlefile_sampleName)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
380 files <- c(files, singlefile_sampleName)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
381 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
382 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
383 # zipfile
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
384 if(!is.null(zipfile) && (zipfile != "")) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
385 if(!file.exists(zipfile)){
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
386 error_message <- paste("Cannot access the Zip file:",zipfile,". Please, contact your administrator ... if you have one!")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
387 print(error_message)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
388 stop(error_message)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
389 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
390 suppressWarnings(unzip(zipfile, unzip="unzip"))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
391
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
392 #get the directory name
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
393 suppressWarnings(filesInZip <- unzip(zipfile, list=T))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
394 directories <- unique(unlist(lapply(strsplit(filesInZip$Name,"/"), function(x) x[1])))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
395 directories <- directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir]
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
396 directory <- "."
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
397 if (length(directories) == 1) directory <- directories
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
398
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
399 cat("files_root_directory\t",directory,"\n")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
400
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
401 filepattern <- c("[Cc][Dd][Ff]", "[Nn][Cc]", "([Mm][Zz])?[Xx][Mm][Ll]","[Mm][Zz][Dd][Aa][Tt][Aa]", "[Mm][Zz][Mm][Ll]")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
402 filepattern <- paste(paste("\\.", filepattern, "$", sep=""),collapse="|")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
403 info <- file.info(directory)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
404 listed <- list.files(directory[info$isdir], pattern=filepattern,recursive=TRUE, full.names=TRUE)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
405 files <- c(directory[!info$isdir], listed)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
406 exists <- file.exists(files)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
407 files <- files[exists]
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
408
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
409 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
410 return(list(zipfile=zipfile, singlefile=singlefile, files=files))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
411
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
412 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
413
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
414
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
415 # This function retrieve a xset like object
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
416 #@author Gildas Le Corguille lecorguille@sb-roscoff.fr
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
417 getxcmsSetObject <- function(xobject) {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
418 # XCMS 1.x
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
419 if (class(xobject) == "xcmsSet")
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
420 return (xobject)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
421 # XCMS 3.x
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
422 if (class(xobject) == "XCMSnExp") {
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
423 # Get the legacy xcmsSet object
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
424 suppressWarnings(xset <- as(xobject, 'xcmsSet'))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
425 if (!is.null(xset@phenoData$sample_group))
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
426 sampclass(xset) <- xset@phenoData$sample_group
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
427 else
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
428 sampclass(xset) <- "."
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
429 return (xset)
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
430 }
ae9ef9219aae "planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 2f3f29dbaaa8568b40818d3476159c384f1a21d6-dirty"
eschen42
parents:
diff changeset
431 }