annotate lib.r @ 16:5f61570177e2 draft

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