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