annotate lib.r @ 12:961089e21ae2 draft default tip

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