annotate lib.r @ 18:cb923396e70f draft

planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
author lecorguille
date Thu, 29 Aug 2019 11:38:21 -0400
parents 73d82de36369
children 01459b73daf9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
1 # lib.r
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
2
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
3 #@author G. Le Corguille
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
4 # solve an issue with batch if arguments are logical TRUE/FALSE
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
5 parseCommandArgs <- function(...) {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
6 args <- batch::parseCommandArgs(...)
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
7 for (key in names(args)) {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
8 if (args[key] %in% c("TRUE","FALSE"))
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
9 args[key] = as.logical(args[key])
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
10 }
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
11 return(args)
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
12 }
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
13
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
14 #@author G. Le Corguille
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
15 # This function will
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
16 # - load the packages
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
17 # - display the sessionInfo
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
18 loadAndDisplayPackages <- function(pkgs) {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
19 for(pkg in pkgs) suppressPackageStartupMessages( stopifnot( library(pkg, quietly=TRUE, logical.return=TRUE, character.only=TRUE)))
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
20
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
21 sessioninfo = sessionInfo()
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
22 cat(sessioninfo$R.version$version.string,"\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
23 cat("Main packages:\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
24 for (pkg in names(sessioninfo$otherPkgs)) { cat(paste(pkg,packageVersion(pkg)),"\t") }; cat("\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
25 cat("Other loaded packages:\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
26 for (pkg in names(sessioninfo$loadedOnly)) { cat(paste(pkg,packageVersion(pkg)),"\t") }; cat("\n")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
27 }
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
28
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
29 # This function retrieve a xset like object
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
30 #@author Gildas Le Corguille lecorguille@sb-roscoff.fr
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
31 getxcmsSetObject <- function(xobject) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
32 # XCMS 1.x
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
33 if (class(xobject) == "xcmsSet")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
34 return (xobject)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
35 # XCMS 3.x
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
36 if (class(xobject) == "XCMSnExp") {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
37 # Get the legacy xcmsSet object
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
38 suppressWarnings(xset <- as(xobject, 'xcmsSet'))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
39 if (is.null(xset@phenoData$sample_group))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
40 sampclass(xset) = "."
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
41 else
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
42 sampclass(xset) <- xset@phenoData$sample_group
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
43 if (!is.null(xset@phenoData$sample_name))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
44 rownames(xset@phenoData) = xset@phenoData$sample_name
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
45 return (xset)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
46 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
47 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
48
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
49 #@author G. Le Corguille
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
50 #The function create a pdf from the different png generated by diffreport
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
51 diffreport_png2pdf <- function(filebase) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
52 dir.create("pdf")
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
53
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
54 pdfEicOutput = paste0("pdf/",filebase,"-eic_pdf.pdf")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
55 pdfBoxOutput = paste0("pdf/",filebase,"-box_pdf.pdf")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
56
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
57 system(paste0("gm convert ",filebase,"_eic/*.png ",pdfEicOutput))
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
58 system(paste0("gm convert ",filebase,"_box/*.png ",pdfBoxOutput))
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
59
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
60 }
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
61
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
62 #@author G. Le Corguille
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
63 #The function create a zip archive from the different png generated by diffreport
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
64 diffreport_png2zip <- function() {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
65 zip("eic.zip", dir(pattern="_eic"), zip=Sys.which("zip"))
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
66 zip("box.zip", dir(pattern="_box"), zip=Sys.which("zip"))
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
67 }
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
68
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
69 #The function create a zip archive from the different tabular generated by diffreport
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
70 diffreport_tabular2zip <- function() {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
71 zip("tabular.zip", dir(pattern="tabular/*"), zip=Sys.which("zip"))
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
72 }
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
73
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
74 #@author G. Le Corguille
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
75 #This function convert if it is required the Retention Time in minutes
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
76 RTSecondToMinute <- function(variableMetadata, convertRTMinute) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
77 if (convertRTMinute){
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
78 #converting the retention times (seconds) into minutes
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
79 print("converting the retention times into minutes in the variableMetadata")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
80 variableMetadata[,"rt"]=variableMetadata[,"rt"]/60
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
81 variableMetadata[,"rtmin"]=variableMetadata[,"rtmin"]/60
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
82 variableMetadata[,"rtmax"]=variableMetadata[,"rtmax"]/60
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
83 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
84 return (variableMetadata)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
85 }
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
86
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
87 #@author G. Le Corguille
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
88 #This function format ions identifiers
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
89 formatIonIdentifiers <- function(variableMetadata, numDigitsRT=0, numDigitsMZ=0) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
90 splitDeco = strsplit(as.character(variableMetadata$name),"_")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
91 idsDeco = sapply(splitDeco, function(x) { deco=unlist(x)[2]; if (is.na(deco)) return ("") else return(paste0("_",deco)) })
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
92 namecustom = make.unique(paste0("M",round(variableMetadata[,"mz"],numDigitsMZ),"T",round(variableMetadata[,"rt"],numDigitsRT),idsDeco))
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
93 variableMetadata=cbind(name=variableMetadata$name, namecustom=namecustom, variableMetadata[,!(colnames(variableMetadata) %in% c("name"))])
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
94 return(variableMetadata)
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
95 }
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
96
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
97 #The function annotateDiffreport without the corr function which bugs
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
98 annotatediff <- function(xset=xset, args=args, variableMetadataOutput="variableMetadata.tsv") {
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
99 # Resolve the bug with x11, with the function png
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
100 options(bitmapType='cairo')
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
101
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
102 #Check if the fillpeaks step has been done previously, if it hasn't, there is an error message and the execution is stopped.
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
103 res=try(is.null(xset@filled))
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
104
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
105 # ------ annot -------
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
106 args$calcCiS=as.logical(args$calcCiS)
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
107 args$calcIso=as.logical(args$calcIso)
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
108 args$calcCaS=as.logical(args$calcCaS)
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
109
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
110 # common parameters
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
111 args4annotate = list(object=xset,
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
112 nSlaves=args$nSlaves,sigma=args$sigma,perfwhm=args$perfwhm,
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
113 maxcharge=args$maxcharge,maxiso=args$maxiso,minfrac=args$minfrac,
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
114 ppm=args$ppm,mzabs=args$mzabs,quick=args$quick,
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
115 polarity=args$polarity,max_peaks=args$max_peaks,intval=args$intval)
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
116
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
117 # quick == FALSE
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
118 if(args$quick==FALSE) {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
119 args4annotate = append(args4annotate,
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
120 list(graphMethod=args$graphMethod,cor_eic_th=args$cor_eic_th,pval=args$pval,
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
121 calcCiS=args$calcCiS,calcIso=args$calcIso,calcCaS=args$calcCaS))
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
122 # no ruleset
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
123 if (!is.null(args$multiplier)) {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
124 args4annotate = append(args4annotate,
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
125 list(multiplier=args$multiplier))
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
126 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
127 # ruleset
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
128 else {
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
129 rulset=read.table(args$rules, h=T, sep=";")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
130 if (ncol(rulset) < 4) rulset=read.table(args$rules, h=T, sep="\t")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
131 if (ncol(rulset) < 4) rulset=read.table(args$rules, h=T, sep=",")
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
132 if (ncol(rulset) < 4) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
133 error_message="Your ruleset file seems not well formatted. The column separators accepted are ; , and tabulation"
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
134 print(error_message)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
135 stop(error_message)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
136 }
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
137
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
138 args4annotate = append(args4annotate,
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
139 list(rules=rulset))
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
140 }
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
141 }
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
142
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
143
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
144 # launch annotate
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
145 xa = do.call("annotate", args4annotate)
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
146 peakList=getPeaklist(xa,intval=args$intval)
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
147 peakList=cbind(groupnames(xa@xcmsSet),peakList); colnames(peakList)[1] = c("name");
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
148
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
149 # --- Multi condition : diffreport ---
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
150 diffrepOri=NULL
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
151 if (!is.null(args$runDiffreport) & nlevels(sampclass(xset))>=2) {
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
152 #Check if the fillpeaks step has been done previously, if it hasn't, there is an error message and the execution is stopped.
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
153 res=try(is.null(xset@filled))
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
154 classes=levels(sampclass(xset))
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
155 x=1:(length(classes)-1)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
156 for (i in seq(along=x) ) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
157 y=1:(length(classes))
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
158 for (n in seq(along=y)){
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
159 if(i+n <= length(classes)){
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
160 filebase=paste(classes[i],class2=classes[i+n],sep="-vs-")
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
161
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
162 diffrep=diffreport(
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
163 object=xset,class1=classes[i],class2=classes[i+n],
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
164 filebase=filebase,eicmax=args$eicmax,eicwidth=args$eicwidth,
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
165 sortpval=TRUE,value=args$value,h=args$h,w=args$w,mzdec=args$mzdec,missing=0)
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
166
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
167 diffrepOri = diffrep
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
168
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
169 # renamming of the column rtmed to rt to fit with camera peaklist function output
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
170 colnames(diffrep)[colnames(diffrep)=="rtmed"] <- "rt"
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
171 colnames(diffrep)[colnames(diffrep)=="mzmed"] <- "mz"
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
172
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
173 # combines results and reorder columns
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
174 diffrep = merge(peakList, diffrep[,c("name","fold","tstat","pvalue")], by.x="name", by.y="name", sort=F)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
175 diffrep = cbind(diffrep[,!(colnames(diffrep) %in% c(sampnames(xa@xcmsSet)))],diffrep[,(colnames(diffrep) %in% c(sampnames(xa@xcmsSet)))])
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
176
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
177 diffrep = RTSecondToMinute(diffrep, args$convertRTMinute)
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
178 diffrep = formatIonIdentifiers(diffrep, numDigitsRT=args$numDigitsRT, numDigitsMZ=args$numDigitsMZ)
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
179
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
180 if(args$sortpval){
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
181 diffrep=diffrep[order(diffrep$pvalue), ]
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
182 }
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
183
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
184 dir.create("tabular", showWarnings = FALSE)
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
185 write.table(diffrep, sep="\t", quote=FALSE, row.names=FALSE, file=paste("tabular/",filebase,"_tsv.tabular",sep=""))
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
186
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
187 if (args$eicmax != 0) {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
188 if (args$png2 == "pdf")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
189 diffreport_png2pdf(filebase)
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
190 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
191 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
192 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
193 }
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
194 if (args$png2 == "zip")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
195 diffreport_png2zip()
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
196 if (args$tabular2 == "zip")
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
197 diffreport_tabular2zip()
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
198 }
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
199
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
200 # --- variableMetadata ---
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
201 variableMetadata=peakList[,!(make.names(colnames(peakList)) %in% c(make.names(sampnames(xa@xcmsSet))))]
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
202 variableMetadata = RTSecondToMinute(variableMetadata, args$convertRTMinute)
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
203 variableMetadata = formatIonIdentifiers(variableMetadata, numDigitsRT=args$numDigitsRT, numDigitsMZ=args$numDigitsMZ)
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
204 # if we have 2 conditions, we keep stat of diffrep
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
205 if (!is.null(args$runDiffreport) & nlevels(sampclass(xset))==2) {
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
206 variableMetadata = merge(variableMetadata, diffrep[,c("name","fold","tstat","pvalue")],by.x="name", by.y="name", sort=F)
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
207 if(exists("args[[\"sortpval\"]]")){
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
208 variableMetadata=variableMetadata[order(variableMetadata$pvalue), ]
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
209 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
210 }
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
211
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
212 variableMetadataOri=variableMetadata
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
213 write.table(variableMetadata, sep="\t", quote=FALSE, row.names=FALSE, file=variableMetadataOutput)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
214
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
215 return(list("xa"=xa,"diffrep"=diffrepOri,"variableMetadata"=variableMetadataOri));
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
216
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
217 }
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
218
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
219
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
220 combinexsAnnos_function <- function(xaP, xaN, diffrepP=NULL,diffrepN=NULL,
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
221 pos=TRUE,tol=2,ruleset=NULL,keep_meta=TRUE, convertRTMinute=F, numDigitsMZ=0,
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
222 numDigitsRT=0, variableMetadataOutput="variableMetadata.tsv"){
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
223
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
224 #Load the two Rdata to extract the xset objects from positive and negative mode
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
225 cat("\tObject xset from positive mode\n")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
226 print(xaP)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
227 cat("\n")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
228
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
229 cat("\tObject xset from negative mode\n")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
230 print(xaN)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
231 cat("\n")
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
232
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
233 cat("\n")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
234 cat("\tCombining...\n")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
235 #Convert the string to numeric for creating matrix
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
236 row=as.numeric(strsplit(ruleset,",")[[1]][1])
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
237 column=as.numeric(strsplit(ruleset,",")[[1]][2])
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
238 ruleset=cbind(row,column)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
239 #Test if the file comes from an older version tool
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
240 if ((!is.null(xaP)) & (!is.null(xaN))) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
241 #Launch the combinexsannos function from CAMERA
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
242 cAnnot=combinexsAnnos(xaP, xaN,pos=pos,tol=tol,ruleset=ruleset)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
243 } else {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
244 stop("You must relauch the CAMERA.annotate step with the lastest version.")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
245 }
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
246
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
247 if(pos){
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
248 xa=xaP
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
249 mode="neg. Mode"
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
250 } else {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
251 xa=xaN
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
252 mode="pos. Mode"
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
253 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
254
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
255 peakList=getPeaklist(xa)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
256 peakList=cbind(groupnames(xa@xcmsSet),peakList); colnames(peakList)[1] = c("name");
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
257 variableMetadata=cbind(peakList, cAnnot[, c("isotopes", "adduct", "pcgroup",mode)]);
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
258 variableMetadata=variableMetadata[,!(colnames(variableMetadata) %in% c(sampnames(xa@xcmsSet)))]
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
259
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
260 #Test if there are more than two classes (conditions)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
261 if ( nlevels(sampclass(xaP@xcmsSet))==2 & (!is.null(diffrepN)) & (!is.null(diffrepP))) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
262 diffrepP = diffrepP[,c("name","fold","tstat","pvalue")]; colnames(diffrepP) = paste("P.",colnames(diffrepP),sep="")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
263 diffrepN = diffrepN[,c("name","fold","tstat","pvalue")]; colnames(diffrepN) = paste("N.",colnames(diffrepN),sep="")
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
264
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
265 variableMetadata = merge(variableMetadata, diffrepP, by.x="name", by.y="P.name")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
266 variableMetadata = merge(variableMetadata, diffrepN, by.x="name", by.y="N.name")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
267 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
268
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
269 rownames(variableMetadata) = NULL
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
270 #TODO: checker
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
271 #colnames(variableMetadata)[1:2] = c("name","mz/rt");
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
272
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
273 variableMetadata = RTSecondToMinute(variableMetadata, convertRTMinute)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
274 variableMetadata = formatIonIdentifiers(variableMetadata, numDigitsRT=numDigitsRT, numDigitsMZ=numDigitsMZ)
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
275
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
276 #If the user want to keep only the metabolites which match a difference
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
277 if(keep_meta){
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
278 variableMetadata=variableMetadata[variableMetadata[,c(mode)]!="",]
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
279 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
280
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
281 #Write the output into a tsv file
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
282 write.table(variableMetadata, sep="\t", quote=FALSE, row.names=FALSE, file=variableMetadataOutput)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
283 return(variableMetadata);
9
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
284
7da9252dd983 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
285 }
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
286
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
287 # This function get the raw file path from the arguments
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
288 getRawfilePathFromArguments <- function(singlefile, zipfile, args) {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
289 if (!is.null(args$zipfile)) zipfile = args$zipfile
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
290 if (!is.null(args$zipfilePositive)) zipfile = args$zipfilePositive
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
291 if (!is.null(args$zipfileNegative)) zipfile = args$zipfileNegative
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
292
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
293 if (!is.null(args$singlefile_galaxyPath)) {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
294 singlefile_galaxyPaths = args$singlefile_galaxyPath;
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
295 singlefile_sampleNames = args$singlefile_sampleName
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
296 }
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
297 if (!is.null(args$singlefile_galaxyPathPositive)) {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
298 singlefile_galaxyPaths = args$singlefile_galaxyPathPositive;
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
299 singlefile_sampleNames = args$singlefile_sampleNamePositive
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
300 }
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
301 if (!is.null(args$singlefile_galaxyPathNegative)) {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
302 singlefile_galaxyPaths = args$singlefile_galaxyPathNegative;
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
303 singlefile_sampleNames = args$singlefile_sampleNameNegative
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
304 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
305 if (exists("singlefile_galaxyPaths")){
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
306 singlefile_galaxyPaths = unlist(strsplit(singlefile_galaxyPaths,","))
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
307 singlefile_sampleNames = unlist(strsplit(singlefile_sampleNames,","))
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
308
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
309 singlefile=NULL
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
310 for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
311 singlefile_galaxyPath=singlefile_galaxyPaths[singlefile_galaxyPath_i]
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
312 singlefile_sampleName=singlefile_sampleNames[singlefile_galaxyPath_i]
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
313 singlefile[[singlefile_sampleName]] = singlefile_galaxyPath
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
314 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
315 }
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
316 for (argument in c("zipfile", "zipfilePositive", "zipfileNegative",
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
317 "singlefile_galaxyPath", "singlefile_sampleName",
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
318 "singlefile_galaxyPathPositive", "singlefile_sampleNamePositive",
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
319 "singlefile_galaxyPathNegative","singlefile_sampleNameNegative")) {
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
320 args[[argument]]=NULL
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
321 }
18
cb923396e70f planemo upload commit 459ef7f63e313493aca32441bd821f09e36de48c
lecorguille
parents: 17
diff changeset
322 return(list(zipfile=zipfile, singlefile=singlefile, args=args))
13
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
323 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
324
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
325
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
326 # This function retrieve the raw file in the working directory
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
327 # - if zipfile: unzip the file with its directory tree
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
328 # - if singlefiles: set symlink with the good filename
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
329 retrieveRawfileInTheWorkingDirectory <- function(singlefile, zipfile) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
330 if(!is.null(singlefile) && (length("singlefile")>0)) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
331 for (singlefile_sampleName in names(singlefile)) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
332 singlefile_galaxyPath = singlefile[[singlefile_sampleName]]
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
333 if(!file.exists(singlefile_galaxyPath)){
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
334 error_message=paste("Cannot access the sample:",singlefile_sampleName,"located:",singlefile_galaxyPath,". Please, contact your administrator ... if you have one!")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
335 print(error_message); stop(error_message)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
336 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
337
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
338 file.symlink(singlefile_galaxyPath,singlefile_sampleName)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
339 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
340 directory = "."
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
341
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
342 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
343 if(!is.null(zipfile) && (zipfile!="")) {
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
344 if(!file.exists(zipfile)){
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
345 error_message=paste("Cannot access the Zip file:",zipfile,". Please, contact your administrator ... if you have one!")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
346 print(error_message)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
347 stop(error_message)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
348 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
349
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
350 #list all file in the zip file
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
351 #zip_files=unzip(zipfile,list=T)[,"Name"]
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
352
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
353 #unzip
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
354 suppressWarnings(unzip(zipfile, unzip="unzip"))
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
355
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
356 #get the directory name
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
357 filesInZip=unzip(zipfile, list=T);
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
358 directories=unique(unlist(lapply(strsplit(filesInZip$Name,"/"), function(x) x[1])));
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
359 directories=directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir]
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
360 directory = "."
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
361 if (length(directories) == 1) directory = directories
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
362
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
363 cat("files_root_directory\t",directory,"\n")
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
364
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
365 }
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
366 return (directory)
1c30ff90f3ae planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 9
diff changeset
367 }
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
368
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
369 #@TODO: remove this function as soon as we can use xcms 3.x.x from Bioconductor 3.7
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
370 # https://github.com/sneumann/CAMERA/issues/33#issuecomment-405168524
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
371 # https://github.com/sneumann/xcms/commit/950a3fe794cdb6b0fda88696e31aab3d97a3b7dd
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
372 ############################################################
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
373 ## getEIC
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
374 getEIC <- function(object, mzrange, rtrange = 200,
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
375 groupidx, sampleidx = sampnames(object),
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
376 rt = c("corrected", "raw")) {
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
377
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
378 files <- filepaths(object)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
379 grp <- groups(object)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
380 samp <- sampnames(object)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
381 prof <- profinfo(object)
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
382
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
383 rt <- match.arg(rt)
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
384
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
385 if (is.numeric(sampleidx))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
386 sampleidx <- sampnames(object)[sampleidx]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
387 sampidx <- match(sampleidx, sampnames(object))
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
388
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
389 if (!missing(groupidx)) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
390 if (is.numeric(groupidx))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
391 groupidx <- groupnames(object)[unique(as.integer(groupidx))]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
392 grpidx <- match(groupidx, groupnames(object, template = groupidx))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
393 }
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
394
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
395 if (missing(mzrange)) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
396 if (missing(groupidx))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
397 stop("No m/z range or groups specified")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
398 if (any(is.na(groupval(object, value = "mz"))))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
399 warning(
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
400 "`NA` values in xcmsSet. Use fillPeaks() on the object to fill",
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
401 "-in missing peak values. Note however that this will also ",
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
402 "insert intensities of 0 for peaks that can not be filled in.")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
403 mzmin <- apply(groupval(object, value = "mzmin"), 1, min, na.rm = TRUE)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
404 mzmax <- apply(groupval(object, value = "mzmax"), 1, max, na.rm = TRUE)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
405 mzrange <- matrix(c(mzmin[grpidx], mzmax[grpidx]), ncol = 2)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
406 ## if (any(is.na(groupval(object, value = "mz"))))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
407 ## stop('Please use fillPeaks() to fill up NA values !')
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
408 ## mzmin <- -rowMax(-groupval(object, value = "mzmin"))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
409 ## mzmax <- rowMax(groupval(object, value = "mzmax"))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
410 ## mzrange <- matrix(c(mzmin[grpidx], mzmax[grpidx]), ncol = 2)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
411 } else if (all(c("mzmin","mzmax") %in% colnames(mzrange)))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
412 mzrange <- mzrange[,c("mzmin", "mzmax"),drop=FALSE]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
413 else if (is.null(dim(mzrange)))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
414 stop("mzrange must be a matrix")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
415 colnames(mzrange) <- c("mzmin", "mzmax")
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
416
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
417 if (length(rtrange) == 1) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
418 if (missing(groupidx))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
419 rtrange <- matrix(rep(range(object@rt[[rt]][sampidx]), nrow(mzrange)),
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
420 ncol = 2, byrow = TRUE)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
421 else {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
422 rtrange <- retexp(grp[grpidx,c("rtmin","rtmax"),drop=FALSE], rtrange)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
423 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
424 } else if (is.null(dim(rtrange)))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
425 stop("rtrange must be a matrix or single number")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
426 colnames(rtrange) <- c("rtmin", "rtmax")
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
427
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
428 ## Ensure that we've got corrected retention time if requested.
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
429 if (is.null(object@rt[[rt]]))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
430 stop(rt, " retention times not present in 'object'!")
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
431
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
432 ## Ensure that the defined retention time range is within the rtrange of the
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
433 ## object: we're using the max minimal rt of all files and the min maximal rt
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
434 rtrs <- lapply(object@rt[[rt]], range)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
435 rtr <- c(max(unlist(lapply(rtrs, "[", 1))),
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
436 min(unlist(lapply(rtrs, "[", 2))))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
437 ## Check if we've got a range which is completely off:
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
438 if (any(rtrange[, "rtmin"] >= rtr[2] | rtrange[, "rtmax"] <= rtr[1])) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
439 outs <- which(rtrange[, "rtmin"] >= rtr[2] |
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
440 rtrange[, "rtmax"] <= rtr[1])
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
441 stop(length(outs), " of the specified 'rtrange' are completely outside ",
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
442 "of the retention time range of 'object' which is (", rtr[1], ", ",
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
443 rtr[2], "). The first was: (", rtrange[outs[1], "rtmin"], ", ",
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
444 rtrange[outs[1], "rtmax"], "!")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
445 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
446 lower_rt_outside <- rtrange[, "rtmin"] < rtr[1]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
447 upper_rt_outside <- rtrange[, "rtmax"] > rtr[2]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
448 if (any(lower_rt_outside) | any(upper_rt_outside)) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
449 ## Silently fix these ranges.
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
450 rtrange[lower_rt_outside, "rtmin"] <- rtr[1]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
451 rtrange[upper_rt_outside, "rtmax"] <- rtr[2]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
452 }
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
453
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
454 if (missing(groupidx))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
455 gnames <- character(0)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
456 else
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
457 gnames <- groupidx
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
458
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
459 eic <- vector("list", length(sampleidx))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
460 names(eic) <- sampleidx
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
461
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
462 for (i in seq(along = sampidx)) {
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
463
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
464 ## cat(sampleidx[i], "")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
465 flush.console()
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
466 ## getXcmsRaw takes care of rt correction, susetting to scanrage and other
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
467 ## stuff.
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
468 lcraw <- getXcmsRaw(object, sampleidx = sampidx[i], rt=rt)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
469 currenteic <- xcms::getEIC(lcraw, mzrange, rtrange, step = prof$step)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
470 eic[[i]] <- currenteic@eic[[1]]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
471 rm(lcraw)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
472 gc()
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
473 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
474 ## cat("\n")
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
475
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
476 invisible(new("xcmsEIC", eic = eic, mzrange = mzrange, rtrange = rtrange,
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
477 rt = rt, groupnames = gnames))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
478 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
479
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
480 #@TODO: remove this function as soon as we can use xcms 3.x.x from Bioconductor 3.7
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
481 # https://github.com/sneumann/CAMERA/issues/33#issuecomment-405168524
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
482 # https://github.com/sneumann/xcms/commit/950a3fe794cdb6b0fda88696e31aab3d97a3b7dd
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
483 ############################################################
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
484 ## diffreport
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
485 diffreport = function(object,
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
486 class1 = levels(sampclass(object))[1],
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
487 class2 = levels(sampclass(object))[2],
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
488 filebase = character(),
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
489 eicmax = 0, eicwidth = 200,
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
490 sortpval = TRUE,
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
491 classeic = c(class1,class2),
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
492 value = c("into","maxo","intb"),
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
493 metlin = FALSE,
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
494 h = 480, w = 640, mzdec=2,
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
495 missing = numeric(), ...) {
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
496
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
497 if ( nrow(object@groups)<1 || length(object@groupidx) <1) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
498 stop("No group information. Use group().")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
499 }
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
500
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
501 if (!is.numeric(w) || !is.numeric(h))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
502 stop("'h' and 'w' have to be numeric")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
503 ## require(multtest) || stop("Couldn't load multtest")
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
504
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
505 value <- match.arg(value)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
506 groupmat <- groups(object)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
507 if (length(groupmat) == 0)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
508 stop("No group information found")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
509 samples <- sampnames(object)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
510 n <- length(samples)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
511 classlabel <- sampclass(object)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
512 classlabel <- levels(classlabel)[as.vector(unclass(classlabel))]
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
513
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
514 values <- groupval(object, "medret", value=value)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
515 indecies <- groupval(object, "medret", value = "index")
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
516
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
517 if (!all(c(class1,class2) %in% classlabel))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
518 stop("Incorrect Class Labels")
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
519
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
520 ## c1 and c2 are column indices of class1 and class2 resp.
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
521 c1 <- which(classlabel %in% class1)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
522 c2 <- which(classlabel %in% class2)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
523 ceic <- which(classlabel %in% classeic)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
524 if (length(intersect(c1, c2)) > 0)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
525 stop("Intersecting Classes")
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
526
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
527 ## Optionally replace NA values with the value provided with missing
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
528 if (length(missing)) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
529 if (is.numeric(missing)) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
530 ## handles NA, Inf and -Inf
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
531 values[, c(c1, c2)][!is.finite(values[, c(c1, c2)])] <- missing[1]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
532 } else
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
533 stop("'missing' should be numeric")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
534 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
535 ## Check against missing Values
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
536 if (any(is.na(values[, c(c1, c2)])))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
537 warning("`NA` values in xcmsSet. Use fillPeaks() on the object to fill",
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
538 "-in missing peak values. Note however that this will also ",
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
539 "insert intensities of 0 for peaks that can not be filled in.")
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
540
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
541 mean1 <- rowMeans(values[,c1,drop=FALSE], na.rm = TRUE)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
542 mean2 <- rowMeans(values[,c2,drop=FALSE], na.rm = TRUE)
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
543
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
544 ## Calculate fold change.
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
545 ## For foldchange <1 set fold to 1/fold
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
546 ## See tstat to check which was higher
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
547 fold <- mean2 / mean1
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
548 fold[!is.na(fold) & fold < 1] <- 1/fold[!is.na(fold) & fold < 1]
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
549
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
550 testval <- values[,c(c1,c2)]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
551 ## Replace eventual infinite values with NA (CAMERA issue #33)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
552 testval[is.infinite(testval)] <- NA
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
553 testclab <- c(rep(0,length(c1)),rep(1,length(c2)))
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
554
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
555 if (min(length(c1), length(c2)) >= 2) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
556 tstat <- mt.teststat(testval, testclab, ...)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
557 pvalue <- xcms:::pval(testval, testclab, tstat)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
558 } else {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
559 message("Too few samples per class, skipping t-test.")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
560 tstat <- pvalue <- rep(NA,nrow(testval))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
561 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
562 stat <- data.frame(fold = fold, tstat = tstat, pvalue = pvalue)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
563 if (length(levels(sampclass(object))) >2) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
564 pvalAnova<-c()
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
565 for(i in 1:nrow(values)){
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
566 var<-as.numeric(values[i,])
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
567 ano<-summary(aov(var ~ sampclass(object)) )
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
568 pvalAnova<-append(pvalAnova, unlist(ano)["Pr(>F)1"])
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
569 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
570 stat<-cbind(stat, anova= pvalAnova)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
571 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
572 if (metlin) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
573 neutralmass <- groupmat[,"mzmed"] + ifelse(metlin < 0, 1, -1)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
574 metlin <- abs(metlin)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
575 digits <- ceiling(-log10(metlin))+1
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
576 metlinurl <-
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
577 paste("http://metlin.scripps.edu/simple_search_result.php?mass_min=",
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
578 round(neutralmass - metlin, digits), "&mass_max=",
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
579 round(neutralmass + metlin, digits), sep="")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
580 values <- cbind(metlin = metlinurl, values)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
581 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
582 twosamp <- cbind(name = groupnames(object), stat, groupmat, values)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
583 if (sortpval) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
584 tsidx <- order(twosamp[,"pvalue"])
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
585 twosamp <- twosamp[tsidx,]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
586 rownames(twosamp) <- 1:nrow(twosamp)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
587 values<-values[tsidx,]
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
588 } else
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
589 tsidx <- 1:nrow(values)
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
590
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
591 if (length(filebase))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
592 write.table(twosamp, paste(filebase, ".tsv", sep = ""), quote = FALSE, sep = "\t", col.names = NA)
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
593
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
594 if (eicmax > 0) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
595 if (length(unique(peaks(object)[,"rt"])) > 1) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
596 ## This looks like "normal" LC data
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
597
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
598 eicmax <- min(eicmax, length(tsidx))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
599 eics <- getEIC(object, rtrange = eicwidth*1.1, sampleidx = ceic,
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
600 groupidx = tsidx[seq(length = eicmax)])
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
601
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
602 if (length(filebase)) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
603 eicdir <- paste(filebase, "_eic", sep="")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
604 boxdir <- paste(filebase, "_box", sep="")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
605 dir.create(eicdir)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
606 dir.create(boxdir)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
607 if (capabilities("png")){
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
608 xcms:::xcmsBoxPlot(values[seq(length = eicmax),],
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
609 sampclass(object), dirpath=boxdir, pic="png", width=w, height=h)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
610 png(file.path(eicdir, "%003d.png"), width = w, height = h)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
611 } else {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
612 xcms:::xcmsBoxPlot(values[seq(length = eicmax),],
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
613 sampclass(object), dirpath=boxdir, pic="pdf", width=w, height=h)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
614 pdf(file.path(eicdir, "%003d.pdf"), width = w/72,
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
615 height = h/72, onefile = FALSE)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
616 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
617 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
618 plot(eics, object, rtrange = eicwidth, mzdec=mzdec)
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
619
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
620 if (length(filebase))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
621 dev.off()
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
622 } else {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
623 ## This looks like a direct-infusion single spectrum
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
624 if (length(filebase)) {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
625 eicdir <- paste(filebase, "_eic", sep="")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
626 boxdir <- paste(filebase, "_box", sep="")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
627 dir.create(eicdir)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
628 dir.create(boxdir)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
629 if (capabilities("png")){
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
630 xcmsBoxPlot(values[seq(length = eicmax),],
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
631 sampclass(object), dirpath=boxdir, pic="png",
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
632 width=w, height=h)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
633 png(file.path(eicdir, "%003d.png"), width = w, height = h,
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
634 units = "px")
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
635 } else {
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
636 xcmsBoxPlot(values[seq(length = eicmax),],
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
637 sampclass(object), dirpath=boxdir, pic="pdf",
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
638 width=w, height=h)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
639 pdf(file.path(eicdir, "%003d.pdf"), width = w/72,
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
640 height = h/72, onefile = FALSE)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
641 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
642 }
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
643
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
644 plotSpecWindow(object, gidxs = tsidx[seq(length = eicmax)], borderwidth=1)
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
645
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
646 if (length(filebase))
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
647 dev.off()
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
648 }
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
649 }
17
73d82de36369 planemo upload commit 1a5357c0e28103a0325b2df858504721f6266049
lecorguille
parents: 16
diff changeset
650
16
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
651 invisible(twosamp)
a2c49996603e planemo upload commit e440674afa3e58c46100b0ac7c305a6f46ecbbdc
lecorguille
parents: 13
diff changeset
652 }