comparison lib.r @ 33:3b2b642542f6 draft

planemo upload commit 896ef116e72008394779322f65137c632af5f4d2
author lecorguille
date Wed, 05 Apr 2017 11:27:56 -0400
parents fce12d692a41
children b02797fbead1
comparison
equal deleted inserted replaced
32:23e33e354bb7 33:3b2b642542f6
1 # lib.r version="2.2.1" 1 # lib.r
2 2
3 #@author G. Le Corguille 3 #@author G. Le Corguille
4 #The function create a pdf from the different png generated by diffreport 4 #The function create a pdf from the different png generated by diffreport
5 diffreport_png2pdf <- function(filebase, new_file_path) { 5 diffreport_png2pdf <- function(filebase) {
6 6 dir.create("pdf")
7 pdfEicOutput = paste(new_file_path,filebase,"-eic_visible_pdf",sep="") 7
8 pdfBoxOutput = paste(new_file_path,filebase,"-box_visible_pdf",sep="") 8 pdfEicOutput = paste0("pdf/",filebase,"-eic_pdf.pdf")
9 9 pdfBoxOutput = paste0("pdf/",filebase,"-box_pdf.pdf")
10 system(paste("gm convert ",filebase,"_eic/*.png ",filebase,"_eic.pdf",sep="")) 10
11 system(paste("gm convert ",filebase,"_box/*.png ",filebase,"_box.pdf",sep="")) 11 system(paste0("gm convert ",filebase,"_eic/*.png ",pdfEicOutput))
12 12 system(paste0("gm convert ",filebase,"_box/*.png ",pdfBoxOutput))
13 file.copy(paste(filebase,"_eic.pdf",sep=""), pdfEicOutput) 13
14 file.copy(paste(filebase,"_box.pdf",sep=""), pdfBoxOutput)
15 } 14 }
16 15
17 #@author G. Le Corguille 16 #@author G. Le Corguille
18 #This function convert if it is required the Retention Time in minutes 17 #This function convert if it is required the Retention Time in minutes
19 RTSecondToMinute <- function(variableMetadata, convertRTMinute) { 18 RTSecondToMinute <- function(variableMetadata, convertRTMinute) {
36 variableMetadata=cbind(name=variableMetadata$name, namecustom=namecustom, variableMetadata[,!(colnames(variableMetadata) %in% c("name"))]) 35 variableMetadata=cbind(name=variableMetadata$name, namecustom=namecustom, variableMetadata[,!(colnames(variableMetadata) %in% c("name"))])
37 return(variableMetadata) 36 return(variableMetadata)
38 } 37 }
39 38
40 #The function annotateDiffreport without the corr function which bugs 39 #The function annotateDiffreport without the corr function which bugs
41 annotatediff <- function(xset=xset, listArguments=listArguments, variableMetadataOutput="variableMetadata.tsv", dataMatrixOutput="dataMatrix.tsv",new_file_path=NULL) { 40 annotatediff <- function(xset=xset, listArguments=listArguments, variableMetadataOutput="variableMetadata.tsv", dataMatrixOutput="dataMatrix.tsv") {
42 # Resolve the bug with x11, with the function png 41 # Resolve the bug with x11, with the function png
43 options(bitmapType='cairo') 42 options(bitmapType='cairo')
44 43
45 #Check if the fillpeaks step has been done previously, if it hasn't, there is an error message and the execution is stopped. 44 #Check if the fillpeaks step has been done previously, if it hasn't, there is an error message and the execution is stopped.
46 res=try(is.null(xset@filled)) 45 res=try(is.null(xset@filled))
95 94
96 95
97 # --- Multi condition : diffreport --- 96 # --- Multi condition : diffreport ---
98 diffrepOri=NULL 97 diffrepOri=NULL
99 if (!is.null(listArguments[["runDiffreport"]]) & nlevels(sampclass(xset))>=2) { 98 if (!is.null(listArguments[["runDiffreport"]]) & nlevels(sampclass(xset))>=2) {
100 #Check if the fillpeaks step has been done previously, if it hasn't, there is an error message and the execution is stopped. 99 #Check if the fillpeaks step has been done previously, if it hasn't, there is an error message and the execution is stopped.
101 res=try(is.null(xset@filled)) 100 res=try(is.null(xset@filled))
102 classes=levels(sampclass(xset)) 101 classes=levels(sampclass(xset))
103 x=1:(length(classes)-1) 102 x=1:(length(classes)-1)
104 for (i in seq(along=x) ) { 103 for (i in seq(along=x) ) {
105 y=1:(length(classes)) 104 y=1:(length(classes))
106 for (n in seq(along=y)){ 105 for (n in seq(along=y)){
107 if(i+n <= length(classes)){ 106 if(i+n <= length(classes)){
108 filebase=paste(classes[i],class2=classes[i+n],sep="-vs-") 107 filebase=paste(classes[i],class2=classes[i+n],sep="-vs-")
109 108
110 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"]]) 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"]])
111 110
112 diffrepOri = diffrep 111 diffrepOri = diffrep
113 112
114 # renamming of the column rtmed to rt to fit with camera peaklist function output 113 # renamming of the column rtmed to rt to fit with camera peaklist function output
115 colnames(diffrep)[colnames(diffrep)=="rtmed"] <- "rt" 114 colnames(diffrep)[colnames(diffrep)=="rtmed"] <- "rt"
116 colnames(diffrep)[colnames(diffrep)=="mzmed"] <- "mz" 115 colnames(diffrep)[colnames(diffrep)=="mzmed"] <- "mz"
117 116
118 # combines results and reorder columns 117 # combines results and reorder columns
119 diffrep = merge(peakList, diffrep[,c("name","fold","tstat","pvalue")], by.x="name", by.y="name", sort=F) 118 diffrep = merge(peakList, diffrep[,c("name","fold","tstat","pvalue")], by.x="name", by.y="name", sort=F)
120 diffrep = cbind(diffrep[,!(colnames(diffrep) %in% c(sampnames(xa@xcmsSet)))],diffrep[,(colnames(diffrep) %in% c(sampnames(xa@xcmsSet)))]) 119 diffrep = cbind(diffrep[,!(colnames(diffrep) %in% c(sampnames(xa@xcmsSet)))],diffrep[,(colnames(diffrep) %in% c(sampnames(xa@xcmsSet)))])
121 120
122 diffrep = RTSecondToMinute(diffrep, listArguments[["convertRTMinute"]]) 121 diffrep = RTSecondToMinute(diffrep, listArguments[["convertRTMinute"]])
123 diffrep = formatIonIdentifiers(diffrep, numDigitsRT=listArguments[["numDigitsRT"]], numDigitsMZ=listArguments[["numDigitsMZ"]]) 122 diffrep = formatIonIdentifiers(diffrep, numDigitsRT=listArguments[["numDigitsRT"]], numDigitsMZ=listArguments[["numDigitsMZ"]])
124 123
125 if(listArguments[["sortpval"]]){ 124 if(listArguments[["sortpval"]]){
126 diffrep=diffrep[order(diffrep$pvalue), ] 125 diffrep=diffrep[order(diffrep$pvalue), ]
127 } 126 }
128 127
129 write.table(diffrep, sep="\t", quote=FALSE, row.names=FALSE, file=paste(new_file_path,filebase,"-tabular_visible_tabular",sep="")) 128 dir.create("tabular")
130 129 write.table(diffrep, sep="\t", quote=FALSE, row.names=FALSE, file=paste("tabular/",filebase,"_tsv.tabular",sep=""))
131 if (listArguments[["eicmax"]] != 0) { 130
132 diffreport_png2pdf(filebase, new_file_path) 131 if (listArguments[["eicmax"]] != 0) {
132 diffreport_png2pdf(filebase)
133 }
133 } 134 }
134 } 135 }
135 }
136 } 136 }
137 } 137 }
138 138
139 139
140 # --- variableMetadata --- 140 # --- variableMetadata ---
143 variableMetadata = formatIonIdentifiers(variableMetadata, numDigitsRT=listArguments[["numDigitsRT"]], numDigitsMZ=listArguments[["numDigitsMZ"]]) 143 variableMetadata = formatIonIdentifiers(variableMetadata, numDigitsRT=listArguments[["numDigitsRT"]], numDigitsMZ=listArguments[["numDigitsMZ"]])
144 # if we have 2 conditions, we keep stat of diffrep 144 # if we have 2 conditions, we keep stat of diffrep
145 if (!is.null(listArguments[["runDiffreport"]]) & nlevels(sampclass(xset))==2) { 145 if (!is.null(listArguments[["runDiffreport"]]) & nlevels(sampclass(xset))==2) {
146 variableMetadata = merge(variableMetadata, diffrep[,c("name","fold","tstat","pvalue")],by.x="name", by.y="name", sort=F) 146 variableMetadata = merge(variableMetadata, diffrep[,c("name","fold","tstat","pvalue")],by.x="name", by.y="name", sort=F)
147 if(exists("listArguments[[\"sortpval\"]]")){ 147 if(exists("listArguments[[\"sortpval\"]]")){
148 variableMetadata=variableMetadata[order(variableMetadata$pvalue), ] 148 variableMetadata=variableMetadata[order(variableMetadata$pvalue), ]
149 } 149 }
150 } 150 }
151 151
152 variableMetadataOri=variableMetadata 152 variableMetadataOri=variableMetadata
153 write.table(variableMetadata, sep="\t", quote=FALSE, row.names=FALSE, file=variableMetadataOutput) 153 write.table(variableMetadata, sep="\t", quote=FALSE, row.names=FALSE, file=variableMetadataOutput)