-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_html_output.py
222 lines (193 loc) · 6.97 KB
/
create_html_output.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from functions import *
text = ""
def html_body(fasta_file, tsv_file, result_dictionary, table_list):
global text
# Counting the number of sequences
keys = result_dictionary.keys()
number_of_sequeces = 0
for everykey in keys:
number_of_sequeces += 1
# Using "s" it there are two or more sequences
plural = "s"
if number_of_sequeces == 1 or number_of_sequeces == 0:
plural = ""
# Counting the number of domains
number_of_domains = 0
for everyrow in table_list:
number_of_domains += everyrow[2]
# Create one row (in a html table) for every domain
# Structure: [IP_ACCESSION | DOMAIN_NAME | COUNTER]
one_line_for_every_domain = ''''''
for everyrow in table_list:
one_line_for_every_domain += f'''\n\t\t\t\t<tr><td>{everyrow[0]}</td><td>{everyrow[1]}</td><td>{everyrow[2]}</td></tr>'''
protein_list_html = protein_list_maker(fasta_file)
single_protein_information = '''
'''
for everyprotein in protein_list_html:
t_domains_found = result_dictionary[everyprotein]["Domains_found"]
domain_sorted_list = top_five_domains(result_dictionary, everyprotein)
t_sequence_len = len(result_dictionary[everyprotein]["Sequence"])
image = ""
if t_domains_found > 0:
image = f'''<img class="preview" src="./preview/prev_{everyprotein}.jpg" alt="Preview of the protein image; if you can read this, then re-run cuterle with -draw_image option">'''
elif t_domains_found == 0:
image = '''<p class="preview" align="center"> This protein has no domain to draw. </p>'''
single_protein_information += f'''
\n\t\t\t
<details open>
<summary class="summary_sequence">
<b>{everyprotein}</b>
</summary>
<table>
<tbody>
<tr>
<td>
<table>
<tr>
<td style="min-width:400px"> Sequence name: </td>
<td>{everyprotein}</td>
</tr>
<tr>
<td> Length: </td>
<td>{t_sequence_len}</td>
</tr>
<tr>
<td> Domains found: </td>
<td>{t_domains_found}</td></tr>
<tr>
<td><br></td><td><br></td>
</tr>
<tr>
<td><b> Domain's name </b></td>
<td><b>Quantity:</b></td>
</tr>
{domain_sorted_list}
</table>
</td>
<td>
{image}
</td>
</tr>
</tbody>
</table>
<details>
<summary class="summary_domain_details">
<i>Click me for detailed information about domains</i>
</summary>
<table>'''
domains_dict = {}
for everydomain in result_dictionary[everyprotein]["Extracted_domains"]:
protein_accession = everyprotein
t_domain_name = everydomain["DOMAIN_NAME"]
t_domain_order = everydomain["DOMAIN_ORDER"]
t_start_location = everydomain["START"]
t_stop_location = everydomain["STOP"]
t_domain_length = everydomain["LENGTH"]
t_ip_accession = everydomain["IP_ACCESSION"]
t_protein_sequence = result_dictionary[everyprotein]["Sequence"]
t_domain_sequence = t_protein_sequence[t_start_location:t_stop_location]
single_protein_information += f'''
<tr><td>Domain name: </td><td>{t_domain_name}</td></tr>
<tr><td>Domain order: </td><td>{t_domain_order}</td></tr>
<tr><td>Domain length: </td><td>{t_domain_length}</td></tr>
<tr><td>Start location: </td><td>{t_start_location}</td></tr>
<tr><td>Stop location: </td><td>{t_stop_location}</td></tr>
<tr><td>IP accession: </td><td>{t_ip_accession}</td></tr>
<tr><td><details><summary>Domain sequence (click to open)</summary>{t_domain_sequence}</details></td></tr>
'''
single_protein_information += f'''
</table>
</details>
<br>
</details>
'''
text = f'''
<html>
<head>
<meta charset="UTF-8">
<title>Cuterle</title>
<link rel="icon" href="../images/favicon.ico">
</head>
<style>
body {{
margin: 1%;
font-family: Arial;
}}
table, th, td {{
border: 0px solid black;
border-collapse: collapse;
}}
.sub_head {{
}}
.preview {{
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
min-width: 350px;
}}
.summary_summary {{
cursor: pointer;
color: rgb(17, 48, 78);
background: rgb(219, 226, 239);
padding: 8px;
}}
.summary_sequence {{
cursor: pointer;
color: rgb(17, 48, 78);
background: rgb(219, 226, 239);
padding: 8px;
}}
.summary_domain_details {{
cursor: pointer;
padding: 8px;
}}
.caption_mod {{
}}
</style>
<body>
<img style="max-width:35%;" src="../images/00_logo.png" alt="CUTERLE'S LOGO"><br>
<details open>
<br>
<summary class="summary_summary">
<b>SUMMARY</b>
</summary>
<table>
<tr>
<td><b>Fasta file input:</b></td>
<td>{fasta_file}</td>
</tr>
<tr>
<td><b>TSV file input:</b></td>
<td>{tsv_file}</td>
</tr>
<tr>
<td><b>Sequence{plural}:</b></td>
<td>{number_of_sequeces}</td>
</tr>
<tr>
<td><b>Domains found:</td>
<td>{number_of_domains}</td>
</tr>
<tr>
<td><br></td><td><br></td>
<td><br></td>
</tr>
<tr>
<td style="min-width:200px"><p class="sub_head"><b>Accession ID</b></p></td>
<td style="min-width:500px"><p class="sub_head"><b>DOMAIN NAME</b></p></td>
<td><p class="sub_head"><b>NUMBER OF DOMAINS</b></p></td>
</tr>
{one_line_for_every_domain}
</table>
<br>
</details>
{single_protein_information}
</body>
</html>
'''
return text
def create_html_output(folder_name, fasta_file, tsv_file, result_dictionary, table_list):
with open(f"{folder_name}/graphical_output.html", "w") as file:
texts_to_write = html_body(fasta_file, tsv_file, result_dictionary, table_list)
file.write(texts_to_write)