annotate lib.r @ 10:479a83f62863 draft

planemo upload commit 98f8d5d3e1a4356b411f16644ffa4da444ac2bdb
author lecorguille
date Thu, 01 Mar 2018 08:29:55 -0500
parents 198b035d4848
children 837c6955e4e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
1 # lib.r
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
2
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
3 #@author G. Le Corguille
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
4 #The function create a pdf from the different png generated by diffreport
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
5 diffreport_png2pdf <- function(filebase) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
6 dir.create("pdf")
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
7
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
8 pdfEicOutput = paste0("pdf/",filebase,"-eic_pdf.pdf")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
9 pdfBoxOutput = paste0("pdf/",filebase,"-box_pdf.pdf")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
10
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
11 system(paste0("gm convert ",filebase,"_eic/*.png ",pdfEicOutput))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
12 system(paste0("gm convert ",filebase,"_box/*.png ",pdfBoxOutput))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
13
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
14 }
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
15
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
16 #@author G. Le Corguille
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
17 #This function convert if it is required the Retention Time in minutes
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
18 RTSecondToMinute <- function(variableMetadata, convertRTMinute) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
19 if (convertRTMinute){
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
20 #converting the retention times (seconds) into minutes
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
21 print("converting the retention times into minutes in the variableMetadata")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
22 variableMetadata[,"rt"]=variableMetadata[,"rt"]/60
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
23 variableMetadata[,"rtmin"]=variableMetadata[,"rtmin"]/60
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
24 variableMetadata[,"rtmax"]=variableMetadata[,"rtmax"]/60
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
25 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
26 return (variableMetadata)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
27 }
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
28
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
29 #@author G. Le Corguille
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
30 #This function format ions identifiers
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
31 formatIonIdentifiers <- function(variableMetadata, numDigitsRT=0, numDigitsMZ=0) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
32 splitDeco = strsplit(as.character(variableMetadata$name),"_")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
33 idsDeco = sapply(splitDeco, function(x) { deco=unlist(x)[2]; if (is.na(deco)) return ("") else return(paste0("_",deco)) })
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
34 namecustom = make.unique(paste0("M",round(variableMetadata[,"mz"],numDigitsMZ),"T",round(variableMetadata[,"rt"],numDigitsRT),idsDeco))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
35 variableMetadata=cbind(name=variableMetadata$name, namecustom=namecustom, variableMetadata[,!(colnames(variableMetadata) %in% c("name"))])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
36 return(variableMetadata)
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
37 }
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
38
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
39 #The function annotateDiffreport without the corr function which bugs
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
40 annotatediff <- function(xset=xset, listArguments=listArguments, variableMetadataOutput="variableMetadata.tsv", dataMatrixOutput="dataMatrix.tsv") {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
41 # Resolve the bug with x11, with the function png
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
42 options(bitmapType='cairo')
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
43
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
44 #Check if the fillpeaks step has been done previously, if it hasn't, there is an error message and the execution is stopped.
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
45 res=try(is.null(xset@filled))
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
46
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
47 # ------ annot -------
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
48 listArguments[["calcCiS"]]=as.logical(listArguments[["calcCiS"]])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
49 listArguments[["calcIso"]]=as.logical(listArguments[["calcIso"]])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
50 listArguments[["calcCaS"]]=as.logical(listArguments[["calcCaS"]])
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
51
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
52 # common parameters
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
53 listArguments4annotate = list(object=xset,
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
54 nSlaves=listArguments[["nSlaves"]],sigma=listArguments[["sigma"]],perfwhm=listArguments[["perfwhm"]],
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
55 maxcharge=listArguments[["maxcharge"]],maxiso=listArguments[["maxiso"]],minfrac=listArguments[["minfrac"]],
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
56 ppm=listArguments[["ppm"]],mzabs=listArguments[["mzabs"]],quick=listArguments[["quick"]],
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
57 polarity=listArguments[["polarity"]],max_peaks=listArguments[["max_peaks"]],intval=listArguments[["intval"]])
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
58
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
59 # quick == FALSE
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
60 if(listArguments[["quick"]]==FALSE) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
61 listArguments4annotate = append(listArguments4annotate,
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
62 list(graphMethod=listArguments[["graphMethod"]],cor_eic_th=listArguments[["cor_eic_th"]],pval=listArguments[["pval"]],
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
63 calcCiS=listArguments[["calcCiS"]],calcIso=listArguments[["calcIso"]],calcCaS=listArguments[["calcCaS"]]))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
64 # no ruleset
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
65 if (!is.null(listArguments[["multiplier"]])) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
66 listArguments4annotate = append(listArguments4annotate,
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
67 list(multiplier=listArguments[["multiplier"]]))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
68 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
69 # ruleset
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
70 else {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
71 rulset=read.table(listArguments[["rules"]], h=T, sep=";")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
72 if (ncol(rulset) < 4) rulset=read.table(listArguments[["rules"]], h=T, sep="\t")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
73 if (ncol(rulset) < 4) rulset=read.table(listArguments[["rules"]], h=T, sep=",")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
74 if (ncol(rulset) < 4) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
75 error_message="Your ruleset file seems not well formatted. The column separators accepted are ; , and tabulation"
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
76 print(error_message)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
77 stop(error_message)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
78 }
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
79
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
80 listArguments4annotate = append(listArguments4annotate,
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
81 list(rules=rulset))
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
82 }
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
83 }
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
84
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
85
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
86 # launch annotate
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
87 xa = do.call("annotate", listArguments4annotate)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
88 peakList=getPeaklist(xa,intval=listArguments[["intval"]])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
89 peakList=cbind(groupnames(xa@xcmsSet),peakList); colnames(peakList)[1] = c("name");
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
90
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
91 # --- dataMatrix ---
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
92 dataMatrix = peakList[,(make.names(colnames(peakList)) %in% c("name", make.names(sampnames(xa@xcmsSet))))]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
93 write.table(dataMatrix, sep="\t", quote=FALSE, row.names=FALSE, file=dataMatrixOutput)
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
94
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
95
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
96 # --- Multi condition : diffreport ---
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
97 diffrepOri=NULL
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
98 if (!is.null(listArguments[["runDiffreport"]]) & nlevels(sampclass(xset))>=2) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
99 #Check if the fillpeaks step has been done previously, if it hasn't, there is an error message and the execution is stopped.
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
100 res=try(is.null(xset@filled))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
101 classes=levels(sampclass(xset))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
102 x=1:(length(classes)-1)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
103 for (i in seq(along=x) ) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
104 y=1:(length(classes))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
105 for (n in seq(along=y)){
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
106 if(i+n <= length(classes)){
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
107 filebase=paste(classes[i],class2=classes[i+n],sep="-vs-")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
108
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
109 diffrep=diffreport(object=xset,class1=classes[i],class2=classes[i+n],filebase=filebase,eicmax=listArguments[["eicmax"]],eicwidth=listArguments[["eicwidth"]],sortpval=TRUE,value=listArguments[["value"]],h=listArguments[["h"]],w=listArguments[["w"]],mzdec=listArguments[["mzdec"]])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
110
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
111 diffrepOri = diffrep
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
112
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
113 # renamming of the column rtmed to rt to fit with camera peaklist function output
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
114 colnames(diffrep)[colnames(diffrep)=="rtmed"] <- "rt"
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
115 colnames(diffrep)[colnames(diffrep)=="mzmed"] <- "mz"
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
116
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
117 # combines results and reorder columns
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
118 diffrep = merge(peakList, diffrep[,c("name","fold","tstat","pvalue")], by.x="name", by.y="name", sort=F)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
119 diffrep = cbind(diffrep[,!(colnames(diffrep) %in% c(sampnames(xa@xcmsSet)))],diffrep[,(colnames(diffrep) %in% c(sampnames(xa@xcmsSet)))])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
120
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
121 diffrep = RTSecondToMinute(diffrep, listArguments[["convertRTMinute"]])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
122 diffrep = formatIonIdentifiers(diffrep, numDigitsRT=listArguments[["numDigitsRT"]], numDigitsMZ=listArguments[["numDigitsMZ"]])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
123
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
124 if(listArguments[["sortpval"]]){
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
125 diffrep=diffrep[order(diffrep$pvalue), ]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
126 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
127
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
128 dir.create("tabular")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
129 write.table(diffrep, sep="\t", quote=FALSE, row.names=FALSE, file=paste("tabular/",filebase,"_tsv.tabular",sep=""))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
130
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
131 if (listArguments[["eicmax"]] != 0) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
132 diffreport_png2pdf(filebase)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
133 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
134 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
135 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
136 }
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
137 }
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
138
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
139
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
140 # --- variableMetadata ---
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
141 variableMetadata=peakList[,!(make.names(colnames(peakList)) %in% c(make.names(sampnames(xa@xcmsSet))))]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
142 variableMetadata = RTSecondToMinute(variableMetadata, listArguments[["convertRTMinute"]])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
143 variableMetadata = formatIonIdentifiers(variableMetadata, numDigitsRT=listArguments[["numDigitsRT"]], numDigitsMZ=listArguments[["numDigitsMZ"]])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
144 # if we have 2 conditions, we keep stat of diffrep
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
145 if (!is.null(listArguments[["runDiffreport"]]) & nlevels(sampclass(xset))==2) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
146 variableMetadata = merge(variableMetadata, diffrep[,c("name","fold","tstat","pvalue")],by.x="name", by.y="name", sort=F)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
147 if(exists("listArguments[[\"sortpval\"]]")){
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
148 variableMetadata=variableMetadata[order(variableMetadata$pvalue), ]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
149 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
150 }
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
151
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
152 variableMetadataOri=variableMetadata
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
153 write.table(variableMetadata, sep="\t", quote=FALSE, row.names=FALSE, file=variableMetadataOutput)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
154
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
155 return(list("xa"=xa,"diffrep"=diffrepOri,"variableMetadata"=variableMetadataOri));
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
156
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
157 }
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
158
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
159
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
160 combinexsAnnos_function <- function(xaP, xaN, listOFlistArgumentsP,listOFlistArgumentsN, diffrepP=NULL,diffrepN=NULL,pos=TRUE,tol=2,ruleset=NULL,keep_meta=TRUE, convertRTMinute=F, numDigitsMZ=0, numDigitsRT=0, variableMetadataOutput="variableMetadata.tsv"){
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
161
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
162 #Load the two Rdata to extract the xset objects from positive and negative mode
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
163 cat("\tObject xset from positive mode\n")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
164 print(xaP)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
165 cat("\n")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
166
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
167 cat("\tObject xset from negative mode\n")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
168 print(xaN)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
169 cat("\n")
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
170
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
171 cat("\n")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
172 cat("\tCombining...\n")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
173 #Convert the string to numeric for creating matrix
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
174 row=as.numeric(strsplit(ruleset,",")[[1]][1])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
175 column=as.numeric(strsplit(ruleset,",")[[1]][2])
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
176 ruleset=cbind(row,column)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
177 #Test if the file comes from an older version tool
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
178 if ((!is.null(xaP)) & (!is.null(xaN))) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
179 #Launch the combinexsannos function from CAMERA
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
180 cAnnot=combinexsAnnos(xaP, xaN,pos=pos,tol=tol,ruleset=ruleset)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
181 } else {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
182 stop("You must relauch the CAMERA.annotate step with the lastest version.")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
183 }
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
184
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
185 if(pos){
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
186 xa=xaP
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
187 listOFlistArgumentsP=listOFlistArguments
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
188 mode="neg. Mode"
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
189 } else {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
190 xa=xaN
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
191 listOFlistArgumentsN=listOFlistArguments
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
192 mode="pos. Mode"
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
193 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
194
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
195 peakList=getPeaklist(xa)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
196 peakList=cbind(groupnames(xa@xcmsSet),peakList); colnames(peakList)[1] = c("name");
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
197 variableMetadata=cbind(peakList, cAnnot[, c("isotopes", "adduct", "pcgroup",mode)]);
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
198 variableMetadata=variableMetadata[,!(colnames(variableMetadata) %in% c(sampnames(xa@xcmsSet)))]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
199
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
200 #Test if there are more than two classes (conditions)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
201 if ( nlevels(sampclass(xaP@xcmsSet))==2 & (!is.null(diffrepN)) & (!is.null(diffrepP))) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
202 diffrepP = diffrepP[,c("name","fold","tstat","pvalue")]; colnames(diffrepP) = paste("P.",colnames(diffrepP),sep="")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
203 diffrepN = diffrepN[,c("name","fold","tstat","pvalue")]; colnames(diffrepN) = paste("N.",colnames(diffrepN),sep="")
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
204
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
205 variableMetadata = merge(variableMetadata, diffrepP, by.x="name", by.y="P.name")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
206 variableMetadata = merge(variableMetadata, diffrepN, by.x="name", by.y="N.name")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
207 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
208
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
209 rownames(variableMetadata) = NULL
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
210 #TODO: checker
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
211 #colnames(variableMetadata)[1:2] = c("name","mz/rt");
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
212
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
213 variableMetadata = RTSecondToMinute(variableMetadata, convertRTMinute)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
214 variableMetadata = formatIonIdentifiers(variableMetadata, numDigitsRT=numDigitsRT, numDigitsMZ=numDigitsMZ)
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
215
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
216 #If the user want to keep only the metabolites which match a difference
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
217 if(keep_meta){
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
218 variableMetadata=variableMetadata[variableMetadata[,c(mode)]!="",]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
219 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
220
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
221 #Write the output into a tsv file
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
222 write.table(variableMetadata, sep="\t", quote=FALSE, row.names=FALSE, file=variableMetadataOutput)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
223 return(variableMetadata);
4
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
224
87570e9b71f5 planemo upload commit 9d47e3b467dbbe0af0d90a937c5e9f2c4b958c4b
lecorguille
parents:
diff changeset
225 }
8
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
226
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
227 # This function get the raw file path from the arguments
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
228 getRawfilePathFromArguments <- function(singlefile, zipfile, listArguments) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
229 if (!is.null(listArguments[["zipfile"]])) zipfile = listArguments[["zipfile"]]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
230 if (!is.null(listArguments[["zipfilePositive"]])) zipfile = listArguments[["zipfilePositive"]]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
231 if (!is.null(listArguments[["zipfileNegative"]])) zipfile = listArguments[["zipfileNegative"]]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
232
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
233 if (!is.null(listArguments[["singlefile_galaxyPath"]])) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
234 singlefile_galaxyPaths = listArguments[["singlefile_galaxyPath"]];
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
235 singlefile_sampleNames = listArguments[["singlefile_sampleName"]]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
236 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
237 if (!is.null(listArguments[["singlefile_galaxyPathPositive"]])) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
238 singlefile_galaxyPaths = listArguments[["singlefile_galaxyPathPositive"]];
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
239 singlefile_sampleNames = listArguments[["singlefile_sampleNamePositive"]]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
240 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
241 if (!is.null(listArguments[["singlefile_galaxyPathNegative"]])) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
242 singlefile_galaxyPaths = listArguments[["singlefile_galaxyPathNegative"]];
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
243 singlefile_sampleNames = listArguments[["singlefile_sampleNameNegative"]]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
244 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
245 if (exists("singlefile_galaxyPaths")){
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
246 singlefile_galaxyPaths = unlist(strsplit(singlefile_galaxyPaths,","))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
247 singlefile_sampleNames = unlist(strsplit(singlefile_sampleNames,","))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
248
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
249 singlefile=NULL
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
250 for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
251 singlefile_galaxyPath=singlefile_galaxyPaths[singlefile_galaxyPath_i]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
252 singlefile_sampleName=singlefile_sampleNames[singlefile_galaxyPath_i]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
253 singlefile[[singlefile_sampleName]] = singlefile_galaxyPath
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
254 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
255 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
256 for (argument in c("zipfile","zipfilePositive","zipfileNegative","singlefile_galaxyPath","singlefile_sampleName","singlefile_galaxyPathPositive","singlefile_sampleNamePositive","singlefile_galaxyPathNegative","singlefile_sampleNameNegative")) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
257 listArguments[[argument]]=NULL
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
258 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
259 return(list(zipfile=zipfile, singlefile=singlefile, listArguments=listArguments))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
260 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
261
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
262
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
263 # This function retrieve the raw file in the working directory
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
264 # - if zipfile: unzip the file with its directory tree
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
265 # - if singlefiles: set symlink with the good filename
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
266 retrieveRawfileInTheWorkingDirectory <- function(singlefile, zipfile) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
267 if(!is.null(singlefile) && (length("singlefile")>0)) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
268 for (singlefile_sampleName in names(singlefile)) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
269 singlefile_galaxyPath = singlefile[[singlefile_sampleName]]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
270 if(!file.exists(singlefile_galaxyPath)){
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
271 error_message=paste("Cannot access the sample:",singlefile_sampleName,"located:",singlefile_galaxyPath,". Please, contact your administrator ... if you have one!")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
272 print(error_message); stop(error_message)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
273 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
274
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
275 file.symlink(singlefile_galaxyPath,singlefile_sampleName)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
276 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
277 directory = "."
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
278
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
279 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
280 if(!is.null(zipfile) && (zipfile!="")) {
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
281 if(!file.exists(zipfile)){
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
282 error_message=paste("Cannot access the Zip file:",zipfile,". Please, contact your administrator ... if you have one!")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
283 print(error_message)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
284 stop(error_message)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
285 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
286
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
287 #list all file in the zip file
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
288 #zip_files=unzip(zipfile,list=T)[,"Name"]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
289
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
290 #unzip
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
291 suppressWarnings(unzip(zipfile, unzip="unzip"))
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
292
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
293 #get the directory name
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
294 filesInZip=unzip(zipfile, list=T);
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
295 directories=unique(unlist(lapply(strsplit(filesInZip$Name,"/"), function(x) x[1])));
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
296 directories=directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir]
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
297 directory = "."
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
298 if (length(directories) == 1) directory = directories
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
299
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
300 cat("files_root_directory\t",directory,"\n")
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
301
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
302 }
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
303 return (directory)
198b035d4848 planemo upload commit 301d42e88026afdac618f4ec56fc6cbe19e3e419
lecorguille
parents: 4
diff changeset
304 }