Mercurial > repos > petr-novak > re_utils
comparison ChipSeqRatioAnalysis.R @ 5:378565f5a875 draft
Uploaded
author | petr-novak |
---|---|
date | Fri, 22 Nov 2019 07:56:48 -0500 |
parents | e320ef2d105a |
children | f224513123a1 |
comparison
equal
deleted
inserted
replaced
4:d397f5a85464 | 5:378565f5a875 |
---|---|
1 #!/usr/bin/env Rscript | 1 #!/usr/bin/env Rscript |
2 library(R2HTML, quietly=T) | 2 library(R2HTML, quietly=T) |
3 library(base64enc, quietly=T) | 3 library(base64enc, quietly=T) |
4 | 4 |
5 | 5 |
6 htmlheader=" | 6 htmlheader= |
7 <html xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"> | 7 " <html xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"> |
8 <head> | 8 <head> |
9 <title> ChIP-Seq Mapper Output </title> | 9 <title> ChIP-Seq Mapper Output </title> |
10 <style> | 10 <style> |
11 <!-- | 11 html,body{font-family:Verdana,sans-serif;font-size:15px;line-height:1.5} |
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 | 12 |
19 } | 13 table { |
20 caption { border:1px solid #5C443A; | 14 border-collapse: collapse; |
21 color:#5C443A; | 15 border: 1px solid black; |
22 font-weight:bold; | 16 width: 1000pt |
23 font-size:20pt | 17 } |
24 padding:6px 4px 8px 0px; | 18 table, th, td { |
25 text-align:center; | 19 border: 1px solid black; |
26 | 20 } |
27 } | 21 </style> |
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 | 22 |
79 </head> | 23 </head> |
80 | 24 |
81 " | 25 |
26 | |
27 " | |
82 | 28 |
83 | 29 |
84 #arguments | 30 #arguments |
85 args <- commandArgs(trailingOnly = TRUE) | 31 args <- commandArgs(trailingOnly = TRUE) |
86 input <- args[1] | 32 input <- args[1] |
95 df$"Normalized ratio Chip/Input"=(df$Chip_Hits/chipN)/(df$Input_Hits/inputN) | 41 df$"Normalized ratio Chip/Input"=(df$Chip_Hits/chipN)/(df$Input_Hits/inputN) |
96 | 42 |
97 df$"Ratio Chip/(Chip+Input)"=df$Chip_Hits/(df$Chip_Hits + df$Input_Hits) | 43 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)) | 44 df$"Normalized ratio Chip/(Chip+Input)"=(df$Chip_Hits/chipN)/((df$Input_Hits/inputN)+(df$Chip_Hits/chipN)) |
99 | 45 |
100 outputTable = df[df$"Normalized ratio Chip/(Chip+Input)" > threshld,] | 46 outputTable = df[df$"Normalized ratio Chip/(Chip+Input)" > threshld, |
101 outputTable = outputTable[!is.na(outputTable$Cluster),] | 47 ] |
48 outputTable = outputTable[!is.na(outputTable$Cluster), | |
49 c('Cluster', 'Chip_Hits', 'Input_Hits', | |
50 'Normalized ratio Chip/Input','Normalized ratio Chip/(Chip+Input)')] | |
102 save.image("tmp.RData") #Plot creation | 51 save.image("tmp.RData") #Plot creation |
103 pngfile <- tempfile() | 52 pngfile <- tempfile() |
104 png(pngfile, width = 1000, height = 1200, pointsize=20) | 53 png(pngfile, width = 1000, height = 1200, pointsize=20) |
105 par(mfrow=c(3,1)) | 54 par(mfrow=c(2,1)) |
106 lims=range(df$"Normalized ratio Chip/Input"[df$"Normalized ratio Chip/Input">0], finite = TRUE) | 55 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)) | 56 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) | 57 abline(h=1,col='#00000080', lwd = 2) |
109 abline(h=2,col='#FF000080', lwd = 2) | 58 abline(h=2,col='#FF000080', lwd = 2) |
110 | 59 |
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 | 60 |
116 suppressWarnings(plot(df$Cluster,df$"Normalized ratio Chip/(Chip+Input)", xlab="Cluster Nr.", ylab="Normalized Chip/(Chip+Input)", pch=20)) | 61 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) | 62 abline(h=0.5,col='#00000080', lwd = 2) |
118 abline(h=threshld,col='#FF000080', lwd = 2) | 63 abline(h=threshld,col='#FF000080', lwd = 2) |
119 | 64 |
131 cat(htmlheader, file = filename) | 76 cat(htmlheader, file = filename) |
132 | 77 |
133 | 78 |
134 HTML(graph, file=filename) | 79 HTML(graph, file=filename) |
135 if (nrow(outputTable)>0){ | 80 if (nrow(outputTable)>0){ |
136 HTML(outputTable, file=filename, classtable = "dataframe", row.names=FALSE, Align='left') | 81 HTML(outputTable, file=filename, classtable = "dataframe", |
82 row.names=FALSE, align='left', caption="Clusters with Normalized ChIP/Input ratio > 2", captionalign="top") | |
137 } | 83 } |
138 HTMLEndFile(filename) | 84 HTMLEndFile(filename) |
139 file.rename(from=filename, to=HTMLfile) | 85 file.rename(from=filename, to=HTMLfile) |
140 write.table(df, file=input, sep="\t", row.names = FALSE) | 86 write.table(df, file=input, sep="\t", row.names = FALSE) |