3
|
1 #!/usr/bin/env Rscript
|
|
2 library(R2HTML, quietly=T)
|
|
3 library(base64enc, quietly=T)
|
|
4
|
|
5
|
|
6 htmlheader="
|
|
7 <html xmlns:mml=\"http://www.w3.org/1998/Math/MathML\">
|
|
8 <head>
|
|
9 <title> ChIP-Seq Mapper Output </title>
|
|
10 <style>
|
|
11 <!--
|
|
12 table { background:#FFFFFF;
|
|
13 border:1px solid gray;
|
|
14 border-collapse:collapse;
|
|
15 color:#fff;
|
|
16 font:normal 13px verdana, arial, helvetica, sans-serif;
|
|
17 width: 100%;
|
|
18
|
|
19 }
|
|
20 caption { border:1px solid #5C443A;
|
|
21 color:#5C443A;
|
|
22 font-weight:bold;
|
|
23 font-size:20pt
|
|
24 padding:6px 4px 8px 0px;
|
|
25 text-align:center;
|
|
26
|
|
27 }
|
|
28 td, th { color:#363636;
|
|
29 padding:.4em;
|
|
30 }
|
|
31 tr { border:1px dotted gray;
|
|
32 }
|
|
33 thead th, tfoot th { background:#5C443A;
|
|
34 color:#FFFFFF;
|
|
35 padding:3px 10px 3px 10px;
|
|
36 text-align:left;
|
|
37 text-transform:uppercase;
|
|
38 }
|
|
39 tbody td a { color:#3636FF;
|
|
40 text-decoration:underline;
|
|
41 }
|
|
42 tbody td a:visited { color:gray;
|
|
43 text-decoration:line-through;
|
|
44 }
|
|
45 tbody td a:hover { text-decoration:underline;
|
|
46 }
|
|
47 tbody th a { color:#3636FF;
|
|
48 font-weight:normal;
|
|
49 text-decoration:none;
|
|
50 }
|
|
51 tbody th a:hover { color:#363636;
|
|
52 }
|
|
53 tbody td+td+td+td a { background-image:url('bullet_blue.png');
|
|
54 background-position:left center;
|
|
55 background-repeat:no-repeat;
|
|
56 color:#FFFFFF;
|
|
57 padding-left:15px;
|
|
58 }
|
|
59 tbody td+td+td+td a:visited { background-image:url('bullet_white.png');
|
|
60 background-position:left center;
|
|
61 background-repeat:no-repeat;
|
|
62 }
|
|
63 tbody th, tbody td { text-align:left;
|
|
64 vertical-align:top;
|
|
65 }
|
|
66 tfoot td { background:#5C443A;
|
|
67 color:#FFFFFF;
|
|
68 padding-top:3px;
|
|
69 }
|
|
70 .odd { background:#fff;
|
|
71 }
|
|
72 tbody tr:hover { background:#EEEEEE;
|
|
73 border:1px solid #03476F;
|
|
74 color:#000000;
|
|
75 }
|
|
76 -->
|
|
77 </style>
|
|
78
|
|
79 </head>
|
|
80
|
|
81 "
|
|
82
|
|
83
|
|
84 #arguments
|
|
85 args <- commandArgs(trailingOnly = TRUE)
|
|
86 input <- args[1]
|
|
87 HTMLfile <- args[2]
|
|
88 threshld <- 2/(2+1)
|
|
89 inputN=as.numeric(args[3])
|
|
90 chipN=as.numeric(args[4])
|
|
91 #dataframe preprocessing and table creation
|
|
92 df <- read.delim(input, comment.char="#")
|
|
93
|
|
94 df$"Ratio Chip/Input"=df$Chip_Hits/df$Input_Hits
|
|
95 df$"Normalized ratio Chip/Input"=(df$Chip_Hits/chipN)/(df$Input_Hits/inputN)
|
|
96
|
|
97 df$"Ratio Chip/(Chip+Input)"=df$Chip_Hits/(df$Chip_Hits + df$Input_Hits)
|
|
98 df$"Normalized ratio Chip/(Chip+Input)"=(df$Chip_Hits/chipN)/((df$Input_Hits/inputN)+(df$Chip_Hits/chipN))
|
|
99
|
|
100 outputTable = df[df$"Normalized ratio Chip/(Chip+Input)" > threshld,]
|
|
101 outputTable = outputTable[!is.na(outputTable$Cluster),]
|
|
102 save.image("tmp.RData") #Plot creation
|
|
103 pngfile <- tempfile()
|
|
104 png(pngfile, width = 1000, height = 1200, pointsize=20)
|
|
105 par(mfrow=c(3,1))
|
|
106 lims=range(df$"Normalized ratio Chip/Input"[df$"Normalized ratio Chip/Input">0], finite = TRUE)
|
|
107 suppressWarnings(plot(df$Cluster,df$"Normalized ratio Chip/Input", log="y", xlab="Cluster Nr.", ylab="Normalized ChiP/Seq ratio", pch=20, ylim=lims))
|
|
108 abline(h=1,col='#00000080', lwd = 2)
|
|
109 abline(h=2,col='#FF000080', lwd = 2)
|
|
110
|
|
111 lims=range(df$"Normalized ratio Chip/Input", finite = TRUE)
|
|
112 suppressWarnings(plot(df$Cluster,df$"Normalized ratio Chip/Input", xlab="Cluster Nr.", ylab="Normalize ChiP/Seq ratio", pch=20, ylim=lims))
|
|
113 abline(h=1,col='#00000080', lwd = 2)
|
|
114 abline(h=2,col='#FF000080', lwd = 2)
|
|
115
|
|
116 suppressWarnings(plot(df$Cluster,df$"Normalized ratio Chip/(Chip+Input)", xlab="Cluster Nr.", ylab="Normalized Chip/(Chip+Input)", pch=20))
|
|
117 abline(h=0.5,col='#00000080', lwd = 2)
|
|
118 abline(h=threshld,col='#FF000080', lwd = 2)
|
|
119
|
|
120
|
|
121 dev.off()
|
|
122 graph <- paste('<img src="data:image/png;base64 ,',
|
|
123 base64encode(pngfile),
|
|
124 '" alt="image" />'
|
|
125 )
|
|
126
|
|
127 #HMTL report creation + writing final output
|
|
128 directory=dirname(HTMLfile)
|
|
129 filename=basename(HTMLfile)
|
|
130 ## create HTML header
|
|
131 cat(htmlheader, file = filename)
|
|
132
|
|
133
|
|
134 HTML(graph, file=filename)
|
|
135 if (nrow(outputTable)>0){
|
|
136 HTML(outputTable, file=filename, classtable = "dataframe", row.names=FALSE, Align='left')
|
|
137 }
|
|
138 HTMLEndFile(filename)
|
|
139 file.rename(from=filename, to=HTMLfile)
|
|
140 write.table(df, file=input, sep="\t", row.names = FALSE)
|