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