annotate lib.r @ 17:73d82de36369 draft

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