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