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