annotate lib.r @ 17:602acc32b549 draft

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