annotate RM_html_report.R @ 21:f4ed6a65a2ff draft

Uploaded
author petr-novak
date Thu, 27 Jul 2023 09:46:13 +0000
parents a4cd8608ef6b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
1 #!/usr/bin/env Rscript
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
2 ### this script is expected to run from clustering directory! ######
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
3
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
4 ## assume RM-custom_output_tablesummary.csv file in active directory
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
5
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
6 suppressPackageStartupMessages(library(R2HTML))
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
7 ######################################################################################
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
8 htmlheader="
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
9 <html xmlns:mml=\"http://www.w3.org/1998/Math/MathML\">
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
10 <head>
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
11 <title> Clustering summary </title>
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
12 <style>
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
13 <!--
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
14 table { background:#FFFFFF;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
15 border:1px solid gray;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
16 border-collapse:collapse;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
17 color:#fff;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
18 font:normal 10px verdana, arial, helvetica, sans-serif;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
19 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
20 caption { border:1px solid #5C443A;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
21 color:#5C443A;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
22 font-weight:bold;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
23 font-size:20pt
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
24 padding:6px 4px 8px 0px;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
25 text-align:center;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
26
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
27 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
28 td, th { color:#363636;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
29 padding:.4em;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
30 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
31 tr { border:1px dotted gray;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
32 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
33 thead th, tfoot th { background:#5C443A;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
34 color:#FFFFFF;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
35 padding:3px 10px 3px 10px;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
36 text-align:left;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
37 text-transform:uppercase;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
38 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
39 tbody td a { color:#3636FF;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
40 text-decoration:underline;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
41 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
42 tbody td a:visited { color:gray;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
43 text-decoration:line-through;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
44 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
45 tbody td a:hover { text-decoration:underline;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
46 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
47 tbody th a { color:#3636FF;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
48 font-weight:normal;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
49 text-decoration:none;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
50 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
51 tbody th a:hover { color:#363636;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
52 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
53 tbody td+td+td+td a { background-image:url('bullet_blue.png');
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
54 background-position:left center;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
55 background-repeat:no-repeat;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
56 color:#FFFFFF;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
57 padding-left:15px;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
58 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
59 tbody td+td+td+td a:visited { background-image:url('bullet_white.png');
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
60 background-position:left center;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
61 background-repeat:no-repeat;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
62 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
63 tbody th, tbody td { text-align:left;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
64 vertical-align:top;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
65 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
66 tfoot td { background:#5C443A;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
67 color:#FFFFFF;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
68 padding-top:3px;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
69 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
70 .odd { background:#fff;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
71 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
72 tbody tr:hover { background:#EEEEEE;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
73 border:1px solid #03476F;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
74 color:#000000;
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
75 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
76 -->
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
77 </style>
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
78
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
79 </head>
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
80
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
81 "
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
82 ######################################################################################
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
83 ######################################################################################
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
84
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
85
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
86
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
87 #basic statistics:
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
88 # Number of reads used for clustering
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
89
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
90 RM=read.table("RM-custom_output_tablesummary.csv",sep="\t",header=TRUE,as.is=TRUE,check.names=FALSE)
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
91
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
92 #Any hits to RM database?
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
93 N=NA
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
94
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
95 # convert to legible format:
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
96 RM2=data.frame(
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
97 'total length [bp]'=RM$All_Reads_Length[c(T,F,F)],
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
98 'number of reads'=RM$All_Reads_Number[c(T,F,F)],
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
99 check.names=FALSE,stringsAsFactors=FALSE
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
100 )
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
101
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
102 RMpart1=RM[c(T,F,F),-c(1:3),drop=FALSE] #counts
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
103 RMpart2=RM[c(F,T,F),-c(1:3),drop=FALSE] #percent
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
104
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
105 RMjoined=list()
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
106
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
107 for (i in colnames(RMpart1)){
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
108 RMjoined[[i]]=paste(RMpart1[,i],"hits, ",signif(RMpart2[,i],3),"%",sep='')
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
109 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
110
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
111
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
112
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
113 if (ncol(RM)>3){ # not emppty
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
114 RM2=cbind(cluster=paste("CL",1:nrow(RM2),sep=''),
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
115 RM2,
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
116 "Genome proportion[%]"=signif(RM2$'number of reads'/N*100,3),
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
117 "cumulative GP [%]"=signif(cumsum(RM2$'number of reads'/N*100),3),
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
118 as.data.frame(RMjoined,stringsAsFactors=FALSE))
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
119
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
120 ##### RM2 formating for html output: #####
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
121 ##########################################
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
122 bold=RMpart2>3
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
123 for (i in 6:ncol(RM2)){
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
124 rmcol=RM2[,i]
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
125 RM2[,i]=ifelse(bold[,i-5],paste("<b>",rmcol,"</b>",sep=''),rmcol)
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
126 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
127
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
128 # join hits to one column
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
129 RMstring=character(nrow(RM2))
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
130 for (i in 1:nrow(RM2)){
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
131 x=ifelse(RMpart2[i,]>0,paste(colnames(RM2[,-(1:5),drop=FALSE])," (",RM2[i,-(1:5),drop=FALSE],")",sep=''),"")
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
132 # reorder based on GR
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
133 x=x[order(RMpart2[i,],decreasing=TRUE)]
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
134
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
135 RMstring[i]=paste(x[x!=''],collapse="<br />")
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
136 if (nchar(RMstring[i])>240){
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
137 RMstring[i]=paste(substring(RMstring[i],1,220),"......",sep='')
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
138 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
139
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
140 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
141 }else{ # no RM hits
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
142 RM2=cbind(cluster=paste("CL",1:nrow(RM2),sep=''),
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
143 RM2,
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
144 "Genome proportion[%]"=signif(RM2$'number of reads'/N*100,3),
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
145 "cumulative GP [%]"=signif(cumsum(RM2$'number of reads'/N*100),3))
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
146 RMstring=rep("",nrow(RM)/3)
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
147 }
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
148
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
149
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
150 # RM2 add link to subpage
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
151
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
152
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
153 RM2=data.frame(RM2[,1:3],'Repeat Masker'=RMstring,check.names=FALSE)
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
154
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
155
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
156 ##################################################################################################
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
157 #################### HTML output #####
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
158 ##################################################################################################
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
159
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
160
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
161 htmlout=commandArgs(T)[1] # full absolute path
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
162
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
163 cat(htmlheader,file=htmlout)
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
164
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
165 HTML.title("RepeatMasker search against custom database",file=htmlout,HR=1)
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
166
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
167 HTML(RM2,file=htmlout,align='left',caption="",captionalign='')
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
168 HTMLEndFile(htmlout)
a4cd8608ef6b Uploaded
petr-novak
parents:
diff changeset
169