Mercurial > repos > lecorguille > xcms_retcor
annotate lib.r @ 14:55923d170538 draft
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
author | lecorguille |
---|---|
date | Thu, 22 Dec 2016 05:59:54 -0500 |
parents | fcd93f47dcbf |
children | c04568596f40 |
rev | line source |
---|---|
14
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
1 # lib.r version="2.3" |
6
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
2 #Authors ABiMS TEAM |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
3 #Lib.r for Galaxy Workflow4Metabo |
14
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
4 #version 2.3 |
6
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
5 #Based on lib.r 2.1 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
6 #Modifications made by Guitton Yann |
14
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
7 #2.3 Note |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
8 #correction for empty PDF when only 1 class |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
9 #2.2 Note |
6
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
10 #correct bug in Base Peak Chromatogram (BPC) option, not only TIC when scanrange used in xcmsSet |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
11 #Note if scanrange is used a warning is prompted in R console but do not stop PDF generation |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
12 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
13 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
14 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
15 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
16 #@author Y. Guitton |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
17 getBPC <- function(file,rtcor=NULL, ...) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
18 object <- xcmsRaw(file) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
19 sel <- profRange(object, ...) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
20 cbind(if (is.null(rtcor)) object@scantime[sel$scanidx] else rtcor ,xcms:::colMax(object@env$profile[sel$massidx,sel$scanidx,drop=FALSE])) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
21 #plotChrom(xcmsRaw(file), base=T) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
22 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
23 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
24 #@author Y. Guitton |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
25 getBPCs <- function (xcmsSet=NULL, pdfname="BPCs.pdf",rt=c("raw","corrected"), scanrange=NULL) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
26 cat("Creating BIC pdf...\n") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
27 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
28 if (is.null(xcmsSet)) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
29 cat("Enter an xcmsSet \n") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
30 stop() |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
31 } else { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
32 files <- filepaths(xcmsSet) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
33 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
34 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
35 class<-as.vector(levels(xcmsSet@phenoData[,1])) #sometime phenoData have more than 1 column use first as class |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
36 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
37 classnames<-vector("list",length(class)) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
38 for (i in 1:length(class)){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
39 classnames[[i]]<-which( xcmsSet@phenoData[,1]==class[i]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
40 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
41 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
42 N <- dim(phenoData(xcmsSet))[1] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
43 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
44 TIC <- vector("list",N) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
45 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
46 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
47 for (j in 1:N) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
48 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
49 TIC[[j]] <- getBPC(files[j]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
50 #good for raw |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
51 # seems strange for corrected |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
52 #errors if scanrange used in xcmsSetgeneration |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
53 if (!is.null(xcmsSet) && rt == "corrected") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
54 rtcor <- xcmsSet@rt$corrected[[j]] else |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
55 rtcor <- NULL |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
56 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
57 TIC[[j]] <- getBPC(files[j],rtcor=rtcor) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
58 # TIC[[j]][,1]<-rtcor |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
59 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
60 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
61 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
62 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
63 pdf(pdfname,w=16,h=10) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
64 cols <- rainbow(N) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
65 lty = 1:N |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
66 pch = 1:N |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
67 #search for max x and max y in BPCs |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
68 xlim = range(sapply(TIC, function(x) range(x[,1]))) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
69 ylim = range(sapply(TIC, function(x) range(x[,2]))) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
70 ylim = c(-ylim[2], ylim[2]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
71 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
72 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
73 ##plot start |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
74 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
75 if (length(class)>2){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
76 for (k in 1:(length(class)-1)){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
77 for (l in (k+1):length(class)){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
78 #print(paste(class[k],"vs",class[l],sep=" ")) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
79 plot(0, 0, type="n", xlim = xlim/60, ylim = ylim, main = paste("Base Peak Chromatograms \n","BPCs_",class[k]," vs ",class[l], sep=""), xlab = "Retention Time (min)", ylab = "BPC") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
80 colvect<-NULL |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
81 for (j in 1:length(classnames[[k]])) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
82 tic <- TIC[[classnames[[k]][j]]] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
83 # points(tic[,1]/60, tic[,2], col = cols[i], pch = pch[i], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
84 points(tic[,1]/60, tic[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
85 colvect<-append(colvect,cols[classnames[[k]][j]]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
86 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
87 for (j in 1:length(classnames[[l]])) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
88 # i=class2names[j] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
89 tic <- TIC[[classnames[[l]][j]]] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
90 points(tic[,1]/60, -tic[,2], col = cols[classnames[[l]][j]], pch = pch[classnames[[l]][j]], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
91 colvect<-append(colvect,cols[classnames[[l]][j]]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
92 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
93 legend("topright",paste(basename(files[c(classnames[[k]],classnames[[l]])])), col = colvect, lty = lty, pch = pch) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
94 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
95 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
96 }#end if length >2 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
97 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
98 if (length(class)==2){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
99 k=1 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
100 l=2 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
101 colvect<-NULL |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
102 plot(0, 0, type="n", xlim = xlim/60, ylim = ylim, main = paste("Base Peak Chromatograms \n","BPCs_",class[k],"vs",class[l], sep=""), xlab = "Retention Time (min)", ylab = "BPC") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
103 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
104 for (j in 1:length(classnames[[k]])) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
105 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
106 tic <- TIC[[classnames[[k]][j]]] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
107 # points(tic[,1]/60, tic[,2], col = cols[i], pch = pch[i], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
108 points(tic[,1]/60, tic[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
109 colvect<-append(colvect,cols[classnames[[k]][j]]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
110 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
111 for (j in 1:length(classnames[[l]])) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
112 # i=class2names[j] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
113 tic <- TIC[[classnames[[l]][j]]] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
114 points(tic[,1]/60, -tic[,2], col = cols[classnames[[l]][j]], pch = pch[classnames[[l]][j]], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
115 colvect<-append(colvect,cols[classnames[[l]][j]]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
116 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
117 legend("topright",paste(basename(files[c(classnames[[k]],classnames[[l]])])), col = colvect, lty = lty, pch = pch) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
118 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
119 }#end length ==2 |
14
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
120 |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
121 #case where only one class |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
122 if (length(class)==1){ |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
123 k=1 |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
124 ylim = range(sapply(TIC, function(x) range(x[,2]))) |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
125 colvect<-NULL |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
126 plot(0, 0, type="n", xlim = xlim/60, ylim = ylim, main = paste("Base Peak Chromatograms \n","BPCs_",class[k], sep=""), xlab = "Retention Time (min)", ylab = "BPC") |
6
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
127 |
14
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
128 for (j in 1:length(classnames[[k]])) { |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
129 tic <- TIC[[classnames[[k]][j]]] |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
130 # points(tic[,1]/60, tic[,2], col = cols[i], pch = pch[i], type="l") |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
131 points(tic[,1]/60, tic[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
132 colvect<-append(colvect,cols[classnames[[k]][j]]) |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
133 } |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
134 |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
135 legend("topright",paste(basename(files[c(classnames[[k]])])), col = colvect, lty = lty, pch = pch) |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
136 |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
137 }#end length ==1 |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
138 |
6
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
139 dev.off() #pdf(pdfname,w=16,h=10) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
140 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
141 invisible(TIC) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
142 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
143 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
144 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
145 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
146 #@author Y. Guitton |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
147 getTIC <- function(file,rtcor=NULL) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
148 object <- xcmsRaw(file) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
149 cbind(if (is.null(rtcor)) object@scantime else rtcor, rawEIC(object,mzrange=range(object@env$mz))$intensity) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
150 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
151 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
152 ## |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
153 ## overlay TIC from all files in current folder or from xcmsSet, create pdf |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
154 ## |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
155 #@author Y. Guitton |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
156 getTICs <- function(xcmsSet=NULL,files=NULL, pdfname="TICs.pdf",rt=c("raw","corrected")) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
157 cat("Creating TIC pdf...\n") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
158 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
159 if (is.null(xcmsSet)) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
160 filepattern <- c("[Cc][Dd][Ff]", "[Nn][Cc]", "([Mm][Zz])?[Xx][Mm][Ll]", "[Mm][Zz][Dd][Aa][Tt][Aa]", "[Mm][Zz][Mm][Ll]") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
161 filepattern <- paste(paste("\\.", filepattern, "$", sep = ""), collapse = "|") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
162 if (is.null(files)) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
163 files <- getwd() |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
164 info <- file.info(files) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
165 listed <- list.files(files[info$isdir], pattern = filepattern, recursive = TRUE, full.names = TRUE) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
166 files <- c(files[!info$isdir], listed) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
167 } else { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
168 files <- filepaths(xcmsSet) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
169 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
170 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
171 class<-as.vector(levels(xcmsSet@phenoData[,1])) #sometime phenoData have more than 1 column use first as class |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
172 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
173 classnames<-vector("list",length(class)) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
174 for (i in 1:length(class)){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
175 classnames[[i]]<-which( xcmsSet@phenoData[,1]==class[i]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
176 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
177 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
178 N <- length(files) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
179 TIC <- vector("list",N) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
180 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
181 for (i in 1:N) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
182 if (!is.null(xcmsSet) && rt == "corrected") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
183 rtcor <- xcmsSet@rt$corrected[[i]] else |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
184 rtcor <- NULL |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
185 TIC[[i]] <- getTIC(files[i],rtcor=rtcor) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
186 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
187 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
188 pdf(pdfname,w=16,h=10) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
189 cols <- rainbow(N) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
190 lty = 1:N |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
191 pch = 1:N |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
192 #search for max x and max y in TICs |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
193 xlim = range(sapply(TIC, function(x) range(x[,1]))) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
194 ylim = range(sapply(TIC, function(x) range(x[,2]))) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
195 ylim = c(-ylim[2], ylim[2]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
196 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
197 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
198 ##plot start |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
199 if (length(class)>2){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
200 for (k in 1:(length(class)-1)){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
201 for (l in (k+1):length(class)){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
202 #print(paste(class[k],"vs",class[l],sep=" ")) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
203 plot(0, 0, type="n", xlim = xlim/60, ylim = ylim, main = paste("Total Ion Chromatograms \n","TICs_",class[k]," vs ",class[l], sep=""), xlab = "Retention Time (min)", ylab = "TIC") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
204 colvect<-NULL |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
205 for (j in 1:length(classnames[[k]])) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
206 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
207 tic <- TIC[[classnames[[k]][j]]] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
208 # points(tic[,1]/60, tic[,2], col = cols[i], pch = pch[i], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
209 points(tic[,1]/60, tic[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
210 colvect<-append(colvect,cols[classnames[[k]][j]]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
211 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
212 for (j in 1:length(classnames[[l]])) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
213 # i=class2names[j] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
214 tic <- TIC[[classnames[[l]][j]]] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
215 points(tic[,1]/60, -tic[,2], col = cols[classnames[[l]][j]], pch = pch[classnames[[l]][j]], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
216 colvect<-append(colvect,cols[classnames[[l]][j]]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
217 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
218 legend("topright",paste(basename(files[c(classnames[[k]],classnames[[l]])])), col = colvect, lty = lty, pch = pch) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
219 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
220 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
221 }#end if length >2 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
222 if (length(class)==2){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
223 k=1 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
224 l=2 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
225 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
226 plot(0, 0, type="n", xlim = xlim/60, ylim = ylim, main = paste("Total Ion Chromatograms \n","TICs_",class[k],"vs",class[l], sep=""), xlab = "Retention Time (min)", ylab = "TIC") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
227 colvect<-NULL |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
228 for (j in 1:length(classnames[[k]])) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
229 tic <- TIC[[classnames[[k]][j]]] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
230 # points(tic[,1]/60, tic[,2], col = cols[i], pch = pch[i], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
231 points(tic[,1]/60, tic[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
232 colvect<-append(colvect,cols[classnames[[k]][j]]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
233 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
234 for (j in 1:length(classnames[[l]])) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
235 # i=class2names[j] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
236 tic <- TIC[[classnames[[l]][j]]] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
237 points(tic[,1]/60, -tic[,2], col = cols[classnames[[l]][j]], pch = pch[classnames[[l]][j]], type="l") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
238 colvect<-append(colvect,cols[classnames[[l]][j]]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
239 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
240 legend("topright",paste(basename(files[c(classnames[[k]],classnames[[l]])])), col = colvect, lty = lty, pch = pch) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
241 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
242 }#end length ==2 |
14
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
243 |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
244 #case where only one class |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
245 if (length(class)==1){ |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
246 k=1 |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
247 ylim = range(sapply(TIC, function(x) range(x[,2]))) |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
248 |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
249 plot(0, 0, type="n", xlim = xlim/60, ylim = ylim, main = paste("Total Ion Chromatograms \n","TICs_",class[k], sep=""), xlab = "Retention Time (min)", ylab = "TIC") |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
250 colvect<-NULL |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
251 for (j in 1:length(classnames[[k]])) { |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
252 tic <- TIC[[classnames[[k]][j]]] |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
253 # points(tic[,1]/60, tic[,2], col = cols[i], pch = pch[i], type="l") |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
254 points(tic[,1]/60, tic[,2], col = cols[classnames[[k]][j]], pch = pch[classnames[[k]][j]], type="l") |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
255 colvect<-append(colvect,cols[classnames[[k]][j]]) |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
256 } |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
257 |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
258 legend("topright",paste(basename(files[c(classnames[[k]])])), col = colvect, lty = lty, pch = pch) |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
259 |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
260 }#end length ==1 |
55923d170538
planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 92dd69e5b063aad05a9b2b75e21c78bfa46c4b94
lecorguille
parents:
6
diff
changeset
|
261 |
6
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
262 dev.off() #pdf(pdfname,w=16,h=10) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
263 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
264 invisible(TIC) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
265 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
266 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
267 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
268 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
269 ## |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
270 ## Get the polarities from all the samples of a condition |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
271 #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
272 #@author Gildas Le Corguille lecorguille@sb-roscoff.fr ABiMS TEAM |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
273 getSampleMetadata <- function(xcmsSet=NULL, sampleMetadataOutput="sampleMetadata.tsv") { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
274 cat("Creating the sampleMetadata file...\n") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
275 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
276 #Create the sampleMetada dataframe |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
277 sampleMetadata=xset@phenoData |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
278 sampleNamesOrigin=rownames(sampleMetadata) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
279 sampleNamesMakeNames=make.names(sampleNamesOrigin) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
280 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
281 if (any(duplicated(sampleNamesMakeNames))) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
282 write("\n\nERROR: Usually, R has trouble to deal with special characters in its column names, so it rename them using make.names().\nIn your case, at least two columns after the renaming obtain the same name, thus XCMS will collapse those columns per name.", stderr()) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
283 for (sampleName in sampleNamesOrigin) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
284 write(paste(sampleName,"\t->\t",make.names(sampleName)),stderr()) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
285 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
286 stop("\n\nERROR: One or more of your files will not be import by xcmsSet. It may due to bad characters in their filenames.") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
287 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
288 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
289 if (!all(sampleNamesOrigin == sampleNamesMakeNames)) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
290 cat("\n\nWARNING: Usually, R has trouble to deal with special characters in its column names, so it rename them using make.names()\nIn your case, one or more sample names will be renamed in the sampleMetadata and dataMatrix files:\n") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
291 for (sampleName in sampleNamesOrigin) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
292 cat(paste(sampleName,"\t->\t",make.names(sampleName),"\n")) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
293 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
294 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
295 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
296 sampleMetadata$sampleMetadata=sampleNamesMakeNames |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
297 sampleMetadata=cbind(sampleMetadata["sampleMetadata"],sampleMetadata["class"]) #Reorder columns |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
298 rownames(sampleMetadata)=NULL |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
299 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
300 #Create a list of files name in the current directory |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
301 list_files=xset@filepaths |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
302 #For each sample file, the following actions are done |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
303 for (file in list_files){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
304 #Check if the file is in the CDF format |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
305 if (!mzR:::netCDFIsFile(file)){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
306 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
307 # If the column isn't exist, with add one filled with NA |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
308 if (is.null(sampleMetadata$polarity)) sampleMetadata$polarity=NA |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
309 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
310 #Create a simple xcmsRaw object for each sample |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
311 xcmsRaw=xcmsRaw(file) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
312 #Extract the polarity (a list of polarities) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
313 polarity=xcmsRaw@polarity |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
314 #Verify if all the scans have the same polarity |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
315 uniq_list=unique(polarity) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
316 if (length(uniq_list)>1){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
317 polarity="mixed" |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
318 } else { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
319 polarity=as.character(uniq_list) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
320 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
321 #Transforms the character to obtain only the sample name |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
322 filename=basename(file) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
323 library(tools) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
324 samplename=file_path_sans_ext(filename) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
325 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
326 #Set the polarity attribute |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
327 sampleMetadata$polarity[sampleMetadata$sampleMetadata==samplename]=polarity |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
328 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
329 #Delete xcmsRaw object because it creates a bug for the fillpeaks step |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
330 rm(xcmsRaw) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
331 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
332 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
333 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
334 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
335 write.table(sampleMetadata, sep="\t", quote=FALSE, row.names=FALSE, file=sampleMetadataOutput) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
336 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
337 return(list("sampleNamesOrigin"=sampleNamesOrigin,"sampleNamesMakeNames"=sampleNamesMakeNames)) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
338 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
339 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
340 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
341 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
342 ## |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
343 ## This function check if xcms will found all the files |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
344 ## |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
345 #@author Gildas Le Corguille lecorguille@sb-roscoff.fr ABiMS TEAM |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
346 checkFilesCompatibilityWithXcms <- function(directory) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
347 cat("Checking files filenames compatibilities with xmcs...\n") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
348 # WHAT XCMS WILL FIND |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
349 filepattern <- c("[Cc][Dd][Ff]", "[Nn][Cc]", "([Mm][Zz])?[Xx][Mm][Ll]","[Mm][Zz][Dd][Aa][Tt][Aa]", "[Mm][Zz][Mm][Ll]") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
350 filepattern <- paste(paste("\\.", filepattern, "$", sep = ""),collapse = "|") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
351 info <- file.info(directory) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
352 listed <- list.files(directory[info$isdir], pattern = filepattern,recursive = TRUE, full.names = TRUE) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
353 files <- c(directory[!info$isdir], listed) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
354 files_abs <- file.path(getwd(), files) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
355 exists <- file.exists(files_abs) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
356 files[exists] <- files_abs[exists] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
357 files[exists] <- sub("//","/",files[exists]) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
358 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
359 # WHAT IS ON THE FILESYSTEM |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
360 filesystem_filepaths=system(paste("find $PWD/",directory," -not -name '\\.*' -not -path '*conda-env*' -type f -name \"*\"", sep=""), intern=T) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
361 filesystem_filepaths=filesystem_filepaths[grep(filepattern, filesystem_filepaths, perl=T)] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
362 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
363 # COMPARISON |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
364 if (!is.na(table(filesystem_filepaths %in% files)["FALSE"])) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
365 write("\n\nERROR: List of the files which will not be imported by xcmsSet",stderr()) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
366 write(filesystem_filepaths[!(filesystem_filepaths %in% files)],stderr()) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
367 stop("\n\nERROR: One or more of your files will not be import by xcmsSet. It may due to bad characters in their filenames.") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
368 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
369 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
370 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
371 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
372 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
373 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
374 ## |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
375 ## This function check if XML contains special caracters. It also checks integrity and completness. |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
376 ## |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
377 #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
378 checkXmlStructure <- function (directory) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
379 cat("Checking XML structure...\n") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
380 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
381 cmd=paste("IFS=$'\n'; for xml in $(find",directory,"-not -name '\\.*' -not -path '*conda-env*' -type f -iname '*.*ml*'); do if [ $(xmllint --nonet --noout \"$xml\" 2> /dev/null; echo $?) -gt 0 ]; then echo $xml;fi; done;") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
382 capture=system(cmd,intern=TRUE) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
383 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
384 if (length(capture)>0){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
385 #message=paste("The following mzXML or mzML file is incorrect, please check these files first:",capture) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
386 write("\n\nERROR: The following mzXML or mzML file(s) are incorrect, please check these files first:", stderr()) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
387 write(capture, stderr()) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
388 stop("ERROR: xcmsSet cannot continue with incorrect mzXML or mzML files") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
389 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
390 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
391 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
392 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
393 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
394 ## |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
395 ## This function check if XML contain special characters |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
396 ## |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
397 #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
398 deleteXmlBadCharacters<- function (directory) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
399 cat("Checking Non ASCII characters in the XML...\n") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
400 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
401 processed=F |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
402 l=system( paste("find",directory, "-not -name '\\.*' -not -path '*conda-env*' -type f -iname '*.*ml*'"),intern=TRUE) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
403 for (i in l){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
404 cmd=paste("LC_ALL=C grep '[^ -~]' \"",i,"\"",sep="") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
405 capture=suppressWarnings(system(cmd,intern=TRUE)) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
406 if (length(capture)>0){ |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
407 cmd=paste("perl -i -pe 's/[^[:ascii:]]//g;'",i) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
408 print( paste("WARNING: Non ASCII characters have been removed from the ",i,"file") ) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
409 c=system(cmd,intern=TRUE) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
410 capture="" |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
411 processed=T |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
412 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
413 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
414 if (processed) cat("\n\n") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
415 return(processed) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
416 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
417 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
418 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
419 ## |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
420 ## This function will compute MD5 checksum to check the data integrity |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
421 ## |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
422 #@author Gildas Le Corguille lecorguille@sb-roscoff.fr |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
423 getMd5sum <- function (directory) { |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
424 cat("Compute md5 checksum...\n") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
425 # WHAT XCMS WILL FIND |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
426 filepattern <- c("[Cc][Dd][Ff]", "[Nn][Cc]", "([Mm][Zz])?[Xx][Mm][Ll]","[Mm][Zz][Dd][Aa][Tt][Aa]", "[Mm][Zz][Mm][Ll]") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
427 filepattern <- paste(paste("\\.", filepattern, "$", sep = ""),collapse = "|") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
428 info <- file.info(directory) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
429 listed <- list.files(directory[info$isdir], pattern = filepattern,recursive = TRUE, full.names = TRUE) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
430 files <- c(directory[!info$isdir], listed) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
431 exists <- file.exists(files) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
432 files <- files[exists] |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
433 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
434 library(tools) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
435 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
436 #cat("\n\n") |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
437 |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
438 return(as.matrix(md5sum(files))) |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
439 } |
fcd93f47dcbf
planemo upload commit a3229faad6949bbca965d1d7e138cb3c0550780e
lecorguille
parents:
diff
changeset
|
440 |