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