-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_table_md.py
900 lines (704 loc) · 34.1 KB
/
make_table_md.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 8 12:49:19 2023
@author: willi
"""
import pandas as pd
import os
import pickle
import numpy as np
md_dir = './_mds/'
display_dir = './'
def make_md2(gene, master_str_tuple, i, merge_exists):
#<! ![](../../alns_9.28.22/%s?raw=true)>
with open(md_dir + '%s.md'%gene,'w') as f:
md_text = '''---
layout: page
title: "%s"
permalink: /_mds/%s/
exclude: true
---
<link rel="stylesheet" href="../../custom.css">
<div> Detected as a riboswitch by %s out of 20 classifiers </div>
<div class="row" >
<div class="column">
<a href="../../_mds/%s/"><span title="Previous 5 prime UTR"><img src="../../icons/arrow_left.png" alt="arrow left to previous 5prime UTR page" style="width:100%%"></span></a>
</div>
<div class="column_center">
<table>
<tr>
<th>%s</th>
<th>Similarity: %s</th>
<th>Similarity: %s</th>
<th>Similarity: %s</th>
</tr>
<tr>
<td>
UTR: %s<br>
Gene: %s<br>
MFE: %s<br>
ENS: %s<br>
Length: %s<br>
Predicted Ligands:<br>
%s<br>
%s<br>
%s<br>
</td>
<td>
RS: %s<br>
MFE: %s<br>
Ligand: %s<br>
%s<br>
</td>
<td>
RS: %s<br>
MFE: %s<br>
Ligand: %s<br>
%s<br>
</td>
<td>
RS: %s<br>
MFE: %s<br>
Ligand: %s<br>
%s<br>
</td>
</tr>
<tr>
<td><span title="NUPACK MFE secondary structure of the 5 prime UTR (100 folding simulations)"><img src="../../alns/dot/UTR_%s_%s.png" alt="image of 5prime UTR secondary structure" style="width:100%%"></span></td>
<td><span title="NUPACK MFE secondary structure of the first riboswitch match (100 folding simulations)"><img src="../../alns/dot/RS_%s_%s.png" alt="image of the secondary structure of the first Riboswitch match" style="width:100%%"></span></td>
<td><span title="NUPACK MFE secondary structure of the second riboswitch match (100 folding simulations)"><img src="../../alns/dot/RS_%s_%s.png" alt="image of the secondary structure of the second Riboswitch match" style="width:100%%"></span></td>
<td><span title="NUPACK MFE secondary structure of the third riboswitch match (100 folding simulations)"><img src="../../alns/dot/RS_%s_%s.png" alt="image of the secondary structure of the third Riboswitch match" style="width:100%%"></span></td>
</tr>
<tr>
<td><span title="Base pair chord plot overlay of the 5 prime UTR."><img src="../../alns/circ/circ_%s_%s.png" alt="circular plot of the 5prime UTR base pairs" style="width:100%%"></span></td>
<td><span title="Base pair chord plot overlay of the 5 prime UTR and the first riboswitch match, with the riboswitch in blue and 5 prime UTR in red."><img src="../../alns/circ/circ_%s_%s.png" alt="circular plot of the 5prime UTR base pairs compared with the first Riboswitch base pairs" style="width:100%%"></span></td>
<td><span title="Base pair chord plot overlay of the 5 prime UTR and the second riboswitch match, with the riboswitch in blue and 5 prime UTR in red."><img src="../../alns/circ/circ_%s_%s.png" alt="circular plot of the 5prime UTR base pairs compared with the second Riboswitch base pairs" style="width:100%%"></span></td>
<td><span title="Base pair chord plot overlay of the 5 prime UTR and the third riboswitch match, with the riboswitch in blue and 5 prime UTR in red."><img src="../../alns/circ/circ_%s_%s.png" alt="circular plot of the 5prime UTR base pairs compared with the third Riboswitch base pairs" style="width:100%%"></span></td>
</tr>
<tr>
<td></td>
<td><span title="Structural feature alignment of the 5 prime UTR and the first riboswitch match, from left to right the structural features are: Unbranched stacks (UBS), Branched stacks (BS), Internal Loops Left (ILL), Internal Loops Right (ILR), Hairpins (H), Bulges Left (BL), Bulges Right (BR), Unpaired nucleotides (UN)."><img src="../../alns/feat/feat_%s_%s.png" alt="line plot comparing the structural features of the 5prime UTR with its first riboswitch match" style="width:100%%"></span></td>
<td><span title="Structural feature alignment of the 5 prime UTR and the second riboswitch match, from left to right the structural features are: Unbranched stacks (UBS), Branched stacks (BS), Internal Loops Left (ILL), Internal Loops Right (ILR), Hairpins (H), Bulges Left (BL), Bulges Right (BR), Unpaired nucleotides (UN)."><img src="../../alns/feat/feat_%s_%s.png" alt="line plot comparing the structural features of the 5prime UTR with its second riboswitch match" style="width:100%%"></span></td>
<td><span title="Structural feature alignment of the 5 prime UTR and the third riboswitch match, from left to right the structural features are: Unbranched stacks (UBS), Branched stacks (BS), Internal Loops Left (ILL), Internal Loops Right (ILR), Hairpins (H), Bulges Left (BL), Bulges Right (BR), Unpaired nucleotides (UN)."><img src="../../alns/feat/feat_%s_%s.png" alt="line plot comparing the structural features of the 5prime UTR with its third riboswitch match" style="width:100%%"></span></td>
</tr>
</table>
</div>
<div class="column">
<a href="../../_mds/%s/"><span title="Next 5 prime UTR"><img src="../../icons/arrow_right.png" alt="arrow right to the next 5prime UTR page" style="width:100%%"></span></a>
</div>
</div>
<div class="row" >
<div class="column_center">
<span title="Sequence feature comparison across the 5 prime UTR and its top three riboswitch matches via a heatmap (64 nucleotide triplets)."><img src="../../alns/feat/featcomp_%s.png" alt="heatmap comparing sequence features of the 5prime UTR and top three riboswitch matches" style="width:60%%; display:block; margin-left:auto; margin-right:auto;"></span>
</div>
</div>
<div class="row" >
<div class="column_center">
<span title="Probability that a given base pair LxL is bound within the 1000 folding simulations. Diagonal represents the overall probability that a given base is unpaired."><img src="../../alns/bpp/bpp_%s.png" alt="Heatmap of base pair probabilities for 1000 computational NUPACK foldings of the 5prime UTR" style="width:50%%; display:block; margin-left:auto; margin-right:auto;"></span>
</div>
</div>
'''%master_str_tuple[:53]
if merge_exists:
md_text2 = '''
<div class="row" >
<div class="column">
<span title="Probability that a given base pair is bound when all three nucleotides of the start codon is unbound."><img src="../../alns/bpp/bpp_%s_unbound.png" alt="Heatmap of base pair probabilities for computational NUPACK foldings of the 5prime UTR that leave the start codon unbound" style="width:100%%; display:block; margin-left:auto; margin-right:auto;"></span>
</div>
<div class="column">
<span title="Probability that a given base pair is bound when all three nucleotides of the start codon is bound."><img src="../../alns/bpp/bpp_%s_bound.png" alt="Heatmap of base pair probabilities for computational NUPACK foldings of the 5prime UTR that leave the start codon bound" style="width:100%%; display:block; margin-left:auto; margin-right:auto;"></span>
</div>
<div class="column">
<span title="Merged base pair probability plot by unbound/bound start codons."><img src="../../alns/bpp/bpp_%s_merge.png" alt="Heatmap of base pair probabilities for computational NUPACK foldings of the 5prime UTR with the bound and unbound conformers overlaid" style="width:100%%; display:block; margin-left:auto; margin-right:auto;"></span>
</div>
</div>
'''%master_str_tuple[53:56]
else:
md_text2 = '''
<div class="row" >
<div class="column">
<span title="Probability that a given base pair is bound when all three nucleotides of the start codon is unbound."><img src="../../alns/bpp/bpp_%s_unbound.png" alt="Heatmap of base pair probabilities for computational NUPACK foldings of the 5prime UTR that leave the start codon unbound" style="width:100%%; display:block; margin-left:auto; margin-right:auto;"></span>
</div>
<div class="column">
<span title="Probability that a given base pair is bound when all three nucleotides of the start codon is bound."><img src="../../alns/bpp/bpp_%s_bound.png" alt="Heatmap of base pair probabilities for computational NUPACK foldings of the 5prime UTR that leave the start codon bound" style="width:100%%; display:block; margin-left:auto; margin-right:auto;"></span>
</div>
</div>
'''%master_str_tuple[53:55]
md_text3 = '''
<div class="row">
<div class="column_center">
<span title="Normalized ensemble output probabilities for each classifier, green highlights represent classifiers that are above a non-normalized 0.95 output threshold (selected as RS)."><img src="../../alns/ens/ens_%s.png" alt="ML ensemble output for the 5prime UTR" style="width:60%%; display:block; margin-left:auto; margin-right:auto;"></span>
</div>
</div>
**Information**
| | 5'UTR | RS match 1 | RS match 2 | RS match 3 |
| ---- | ----------- | ----------- | ----------- | ----------- |
| <span title="Link to the sequence source">Link</span> | - | <a href="%s" target="_blank" rel="noopener noreferrer">RNAcentral</a> |<a href="%s" target="_blank" rel="noopener noreferrer">RNAcentral</a> | <a href="%s" target="_blank" rel="noopener noreferrer">RNAcentral</a> |
| <span title="ID within respective databases">ID</span> | %s | %s | %s | %s |
| <span title="Length of the sequence in question">Length</span> | %s | %s | %s | %s |
| <span title="Similarity score calculated from all similarity metrics">Similarity</span> | - | %s | %s | %s |
| <span title="Ensemble classification via all 19 ML classifiers">Ensemble Norm</span> | %s | - | - | - |
| <span title="Nupack Mean Free Energy of the secondary structure">MFE</span> | %s | %s | %s | %s |
| <span title="Reported Ligand match on RNAcentral or via RFAM">Ligands</span> | - | %s | %s | %s |
| <span title="Homo Sapiens gene abbreviation">Gene</span> | %s | - | - | - |
| <span title="Link to the sequence source">Downstream protein</span> | <a href="https://www.genecards.org/cgi-bin/carddisp.pl?gene=%s" target="_blank" rel="noopener noreferrer"> Genecard </a> | - | - | - |
**Similarity metrics**
| | 5'UTR | RS match 1 | RS match 2 | RS match 3 |
| ---- | ----------- | ----------- | ----------- | ----------- |
| <span title="Structural feature squared error">Struct SE</span> | - | %s | %s | %s |
| <span title="Length difference squared error">Length SE</span> | - | %s | %s | %s |
| <span title="Edit distance of both dot structures">Lev Distance</span> | - | %s | %s | %s |
| <span title="Unbranched stack count">UBS</span>| %s | %s | %s | %s |
| <span title="Branched stack counts">BS</span> | %s | %s | %s | %s |
| <span title="Inner loop left count">ILL</span> | %s | %s | %s | %s |
| <span title="Inner loop right count">ILR</span> | %s | %s | %s | %s |
| <span title="Hairpin counts">H</span> | %s | %s | %s | %s |
| <span title="Bulges left count">BL</span> | %s | %s | %s | %s |
| <span title="Bulges right count">BR</span> | %s | %s | %s | %s |
| <span title="Unpaired nucleotide %%">UN</span> | %s | %s | %s | %s |
**Sequences**
<div style="overflow-x:auto;">
<table>
<colgroup>
<col width="30%%" />
<col width="70%%" />
</colgroup>
<thead>
<tr class="header">
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td markdown="span">UTR seq + 25 </td>
<td markdown="span"> %s </td>
</tr>
<tr>
<td markdown="span">UTR dot + 25 </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 1 seq </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 1 dot </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 2 seq </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 2 dot </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 3 seq </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 3 dot </td>
<td markdown="span"> %s
</td>
</tr>
</tbody>
</table>
</div>
[Back to Ensemble of 20 Table](../../display_436)
[Back to Ensemble of 1 Table](../../display_1533)
'''%master_str_tuple[56:]
f.writelines(md_text)
f.writelines(md_text2)
f.writelines(md_text3)
def make_md(gene, master_str_tuple):
#<! ![](../../alns_9.28.22/%s?raw=true)>
with open(md_dir + '%s.md'%gene,'w') as f:
md_text = '''---
layout: page
title: "%s"
permalink: /_mds/%s/
exclude: true
---
<link rel="stylesheet" href="../../custom.css">
<div> Detected as riboswitch by %s out of 20 classifiers </div>
<div class="row" >
<div class="column">
<a href="../../_mds/%s/"><img src="../../icons/arrow_left.png" alt="arrow left" style="width:100%%"></a>
</div>
<div class="column_center">
<img src="../../alns_10.27.23/%s?raw=true" alt="UTR-RS hit comparison" style="width:100%%">
</div>
<div class="column">
<a href="../../_mds/%s/"><img src="../../icons/arrow_right.png" alt="arrow right" style="width:100%%"></a>
</div>
</div>
**Information**
| | 5'UTR | RS match 1 | RS match 2 | RS match 3 |
| ---- | ----------- | ----------- | ----------- | ----------- |
| <span title="Link to the sequence source">Link</span> | <a href="%s" target="_blank" rel="noopener noreferrer">UTRdb</a> | <a href="%s" target="_blank" rel="noopener noreferrer">RNAcentral</a> |<a href="%s" target="_blank" rel="noopener noreferrer">RNAcentral</a> | <a href="%s" target="_blank" rel="noopener noreferrer">RNAcentral</a> |
| <span title="ID within respective databases">ID</span> | %s | %s | %s | %s |
| <span title="Length of the sequence in question">Length</span> | %s | %s | %s | %s |
| <span title="Similarity score calculated from all similarity metrics">Similarity</span> | - | %s | %s | %s |
| <span title="Ensemble classification via all 19 ML classifiers">Ensemble Norm</span> | %s | - | - | - |
| <span title="Nupack Mean Free Energy of the secondary structure">MFE</span> | %s | %s | %s | %s |
| <span title="Reported Ligand match on RNAcentral or via RFAM">Ligands</span> | - | %s | %s | %s |
| <span title="Homo Sapiens gene abbreviation">Gene</span> | %s | - | - | - |
| <span title="Link to the sequence source">Downstream protein</span> | <a href="https://www.genecards.org/cgi-bin/carddisp.pl?gene=%s" target="_blank" rel="noopener noreferrer"> Genecard </a> | - | - | - |
**Similarity metrics**
| | 5'UTR | RS match 1 | RS match 2 | RS match 3 |
| ---- | ----------- | ----------- | ----------- | ----------- |
| <span title="Structural feature squared error">Struct SE</span> | - | %s | %s | %s |
| <span title="Length difference squared error">Length SE</span> | - | %s | %s | %s |
| <span title="Edit distance of both dot structures">Lev Distance</span> | - | %s | %s | %s |
| <span title="Unbranched stack count">UBS</span>| %s | %s | %s | %s |
| <span title="Branched stack counts">BS</span> | %s | %s | %s | %s |
| <span title="Inner loop left count">ILL</span> | %s | %s | %s | %s |
| <span title="Inner loop right count">ILR</span> | %s | %s | %s | %s |
| <span title="Hairpin counts">H</span> | %s | %s | %s | %s |
| <span title="Bulges left count">BL</span> | %s | %s | %s | %s |
| <span title="Bulges right count">BR</span> | %s | %s | %s | %s |
| <span title="Unpaired nucleotide %%">UN</span> | %s | %s | %s | %s |
**Sequences**
<div style="overflow-x:auto;">
<table>
<colgroup>
<col width="30%%" />
<col width="70%%" />
</colgroup>
<thead>
<tr class="header">
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td markdown="span">UTR seq + 25 </td>
<td markdown="span"> %s </td>
</tr>
<tr>
<td markdown="span">UTR dot + 25 </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 1 seq </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 1 dot </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 2 seq </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 2 dot </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 3 seq </td>
<td markdown="span"> %s
</td>
</tr>
<tr>
<td markdown="span">RS 3 dot </td>
<td markdown="span"> %s
</td>
</tr>
</tbody>
</table>
</div>
[Back to Ensemble of 20 Table](../../display_436)
[Back to Ensemble of 1 Table](../../display_1533)
'''%master_str_tuple
f.writelines(md_text)
def make_md_table(utr_list, genes, best_RSs, utr_probas, algn_scores, MFEs, norm_algn, classifier_count, table_name='display'):
with open(display_dir + '%s.md'%table_name,'w') as f:
x = '''
---
layout: page
title: "Ensemble of 1"
permalink: /display/
datatable: true
---
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.6.0/dt-1.11.3/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.6.0/dt-1.11.3/datatables.min.js"></script>
<script>
$(document).ready(function(){
$('table.display').DataTable( {
paging: true,
stateSave: true,
searching: true
}
);
});
</script>
<table id="maintable" class="display">
<thead>
<tr>
<th> <div title="What gene is this transcript associated with?"> Gene </div></th>
<th> <div title="ID in original UTRdb"> 5'UTR UTRdb 1.0 ID </div></th>
<th> <div title="Defunct link to original UTRdb"> UTRdb 1.0 link </div></th>
<th> <div title="ID on RNA central of closest RS match"> Closest RS ID</div></th>
<th> <div title="Link to closest RS match on RNA central "> Closest RS link </div></th>
<th> <div title="Average RS probability reported by the classifiers"> Ensemble Norm </div></th>
<th> <div title="How many classifiers found this 5'UTR to be a RS?"> Ensemble Count </div></th>
<th> <div title="Best similarity metric between 5'UTR hit and RS normalized(length distance + edit distance + structural feature vector MSE)/3"> Similarity </div></th>
<th> <div title="Mean free energy of the NUPACK predicted dot structure"> MFE </div></th>
<th><div title="Link to the visualization page of this hit"> Visualization </div></th>
</tr>
</thead>
<tbody>
'''
f.writelines(x)
for i in range(len(utr_list)):
UTR = utr_list[i]
MFE = MFEs[i]
utr_probability = utr_probas[i]
algn_score = norm_algn[i]
gene = genes[i]
best_RS = best_RSs[i]
best_RS_url = best_RS.replace('_','/')
lines = [
'<tr>\n',
'<td>%s</td>\n'%gene,
'<td>%s</td>\n'%UTR,
'<td><a href="http://utrdb.ba.itb.cnr.it/getutr/%s/1">UTR</a></td>\n'%UTR,
'<td>%s</td>\n'%best_RS,
'<td><a href="https://rnacentral.org/rna/%s">RS</a></td>\n'%best_RS_url,
'<td>%.4f</td>\n'%utr_probability,
'<td>%i</td>\n'%classifier_count[i],
'<td>%.4f</td>\n'%algn_score,
'<td>%.3f</td>\n'%MFE,
'<td><a href="/human_riboswitch_hits_gallery/_mds/%s">=></a></td>\n'%gene,
'</tr>\n',
]
f.writelines(lines)
f.write('</tbody>')
f.write('</table>')
path = './data_files/'
with open(path + 'utr_probas.pkl', 'rb') as f:
utr_probas = pickle.load(f)
ENS_count = np.load(path + 'ENS_count.npy')
with open(path + 'ulist.pkl', 'rb') as f:
ulist = pickle.load(f)
with open(path + 'genes.pkl', 'rb') as f:
genes = pickle.load(f)
with open(path + 'best_RSs.pkl', 'rb') as f:
best_RSs = pickle.load(f)
with open(path + 'MFEs.pkl', 'rb') as f:
MFEs = pickle.load(f)
with open(path + 'fpaths.pkl', 'rb') as f:
fpaths = pickle.load(f)
with open(path + 'norm_algn.pkl', 'rb') as f:
norm_algn = pickle.load(f)
with open(path + 'algn_scores_1.pkl', 'rb') as f:
algn_scores_1 = pickle.load(f)
with open(path + 'algn_scores_2.pkl', 'rb') as f:
algn_scores_2 = pickle.load(f)
with open(path + 'algn_scores_3.pkl', 'rb') as f:
algn_scores_3 = pickle.load(f)
with open(path + 'rs1_ids.pkl', 'rb') as f:
rs1_ids = pickle.load(f)
with open(path + 'rs2_ids.pkl', 'rb') as f:
rs2_ids = pickle.load(f)
with open(path + 'rs3_ids.pkl', 'rb') as f:
rs3_ids = pickle.load(f)
with open(path + 'rs1_seqs.pkl', 'rb') as f:
rs1_seqs = pickle.load(f)
with open(path + 'rs2_seqs.pkl', 'rb') as f:
rs2_seqs = pickle.load(f)
with open(path + 'rs3_seqs.pkl', 'rb') as f:
rs3_seqs = pickle.load(f)
with open(path + 'utr_seqs_l.pkl', 'rb') as f:
utr_seqs = pickle.load(f)
with open(path + 'rs1_dots.pkl', 'rb') as f:
rs1_dots = pickle.load(f)
with open(path + 'rs2_dots.pkl', 'rb') as f:
rs2_dots = pickle.load(f)
with open(path + 'rs3_dots.pkl', 'rb') as f:
rs3_dots = pickle.load(f)
with open(path + 'utr_dots_l.pkl', 'rb') as f:
utr_dots = pickle.load(f)
with open(path + 'rs1_MFEs.pkl', 'rb') as f:
rs1_mfes = pickle.load(f)
with open(path + 'rs2_MFEs.pkl', 'rb') as f:
rs2_mfes = pickle.load(f)
with open(path + 'rs3_MFEs.pkl', 'rb') as f:
rs3_mfes = pickle.load(f)
with open(path + 'MFEs.pkl', 'rb') as f:
utr_mfes = pickle.load(f)
with open(path + 'rs1_ligands.pkl', 'rb') as f:
rs1_ligands = pickle.load(f)
with open(path + 'rs2_ligands.pkl', 'rb') as f:
rs2_ligands = pickle.load(f)
with open(path + 'rs3_ligands.pkl', 'rb') as f:
rs3_ligands = pickle.load(f)
with open(path + 'rs1_length_MSE.pkl', 'rb') as f:
rs1_length_MSE = pickle.load(f)
with open(path + 'rs2_length_MSE.pkl', 'rb') as f:
rs2_length_MSE = pickle.load(f)
with open(path + 'rs3_length_MSE.pkl', 'rb') as f:
rs3_length_MSE = pickle.load(f)
with open(path + 'rs1_lev_dist.pkl', 'rb') as f:
rs1_lev_dist = pickle.load(f)
with open(path + 'rs2_lev_dist.pkl', 'rb') as f:
rs2_lev_dist = pickle.load(f)
with open(path + '/rs3_lev_dist.pkl', 'rb') as f:
rs3_lev_dist = pickle.load(f)
with open(path + 'rs1_struct_mse.pkl', 'rb') as f:
rs1_struct_mse = pickle.load(f)
with open(path + 'rs2_struct_mse.pkl', 'rb') as f:
rs2_struct_mse = pickle.load(f)
with open(path + 'rs3_struct_mse.pkl', 'rb') as f:
rs3_struct_mse = pickle.load(f)
with open(path + 'rs1_feats.pkl', 'rb') as f:
rs1_feats = pickle.load(f)
with open(path + 'rs2_feats.pkl', 'rb') as f:
rs2_feats = pickle.load(f)
with open(path + 'rs3_feats.pkl', 'rb') as f:
rs3_feats = pickle.load(f)
with open(path + 'utr_feats.pkl', 'rb') as f:
utr_feats = pickle.load(f)
with open(path + 'rs1_mfe.pkl', 'rb') as f:
rs1_mfes = pickle.load(f)
with open(path + 'rs2_mfe.pkl', 'rb') as f:
rs2_mfes = pickle.load(f)
with open(path + 'rs3_mfe.pkl', 'rb') as f:
rs3_mfes = pickle.load(f)
with open(path + 'rs1_desc.pkl', 'rb') as f:
rs1_descs = pickle.load(f)
with open(path + 'rs2_desc.pkl', 'rb') as f:
rs2_descs = pickle.load(f)
with open(path + 'rs3_desc.pkl', 'rb') as f:
rs3_descs = pickle.load(f)
with open(path + 'utr_ligands.pkl', 'rb') as f:
utr_pls = pickle.load(f)
used_genes = []
for i in range(len(ulist)):
gene = genes[i]
if gene not in used_genes:
used_genes.append(gene)
else:
k = 0
while gene in used_genes:
if k == 0:
gene = gene + '_' + str(k)
k+=1
else:
gene = gene[:-1] + str(k)
k+=1
used_genes.append(gene)
ens20 = False
if ens20 == True:
ulist_keep = []
keep_indexes = []
for i in range(len(ulist)):
if ENS_count[i] == 20:
ulist_keep.append(ulist[i])
keep_indexes.append(i)
ulist2 = [ulist[i] for i in range(len(ulist)) if i in keep_indexes]
utr_probas = [utr_probas[i] for i in range(len(ulist)) if i in keep_indexes]
used_genes = [used_genes[i] for i in range(len(ulist)) if i in keep_indexes]
best_RSs = [best_RSs[i] for i in range(len(ulist)) if i in keep_indexes]
MFEs = [MFEs[i] for i in range(len(ulist)) if i in keep_indexes]
fpaths = [fpaths[i] for i in range(len(ulist)) if i in keep_indexes]
norm_algn = [norm_algn[i] for i in range(len(ulist)) if i in keep_indexes]
algn_scores_1 = [algn_scores_1[i] for i in range(len(ulist)) if i in keep_indexes]
algn_scores_2 = [algn_scores_2[i] for i in range(len(ulist)) if i in keep_indexes]
algn_scores_3 = [algn_scores_3[i] for i in range(len(ulist)) if i in keep_indexes]
rs1_ids = [rs1_ids[i] for i in range(len(ulist)) if i in keep_indexes]
rs2_ids = [rs2_ids[i] for i in range(len(ulist)) if i in keep_indexes]
rs3_ids = [rs3_ids[i] for i in range(len(ulist)) if i in keep_indexes]
rs1_seqs = [rs1_seqs[i] for i in range(len(ulist)) if i in keep_indexes]
rs2_seqs = [rs2_seqs[i] for i in range(len(ulist)) if i in keep_indexes]
rs3_seqs = [rs3_seqs[i] for i in range(len(ulist)) if i in keep_indexes]
utr_seqs = [utr_seqs[i] for i in range(len(ulist)) if i in keep_indexes]
rs1_mfes = [rs1_mfes[i] for i in range(len(ulist)) if i in keep_indexes]
rs2_mfes = [rs2_mfes[i] for i in range(len(ulist)) if i in keep_indexes]
rs3_mfes = [rs3_mfes[i] for i in range(len(ulist)) if i in keep_indexes]
utr_mfes = [utr_mfes[i] for i in range(len(ulist)) if i in keep_indexes]
rs1_ligands = [rs1_ligands[i] for i in range(len(ulist)) if i in keep_indexes]
rs2_ligands = [rs2_ligands[i] for i in range(len(ulist)) if i in keep_indexes]
rs3_ligands = [rs3_ligands[i] for i in range(len(ulist)) if i in keep_indexes]
rs1_length_MSE = [rs1_length_MSE[i] for i in range(len(ulist)) if i in keep_indexes]
rs2_length_MSE = [rs2_length_MSE[i] for i in range(len(ulist)) if i in keep_indexes]
rs3_length_MSE = [rs3_length_MSE[i] for i in range(len(ulist)) if i in keep_indexes]
rs1_lev_dist = [rs1_lev_dist[i] for i in range(len(ulist)) if i in keep_indexes]
rs2_lev_dist = [rs2_lev_dist[i] for i in range(len(ulist)) if i in keep_indexes]
rs3_lev_dist = [rs3_lev_dist[i] for i in range(len(ulist)) if i in keep_indexes]
rs1_struct_mse = [rs1_struct_mse[i] for i in range(len(ulist)) if i in keep_indexes]
rs2_struct_mse = [rs2_struct_mse[i] for i in range(len(ulist)) if i in keep_indexes]
rs3_struct_mse = [rs3_struct_mse[i] for i in range(len(ulist)) if i in keep_indexes]
rs1_feats = [rs1_feats[i] for i in range(len(ulist)) if i in keep_indexes]
rs2_feats = [rs2_feats[i] for i in range(len(ulist)) if i in keep_indexes]
rs3_feats = [rs3_feats[i] for i in range(len(ulist)) if i in keep_indexes]
utr_feats = [utr_feats[i] for i in range(len(ulist)) if i in keep_indexes]
rs1_mfes = [rs1_mfes[i] for i in range(len(ulist)) if i in keep_indexes]
rs2_mfes = [rs2_mfes[i] for i in range(len(ulist)) if i in keep_indexes]
rs3_mfes = [rs3_mfes[i] for i in range(len(ulist)) if i in keep_indexes]
rs1_descs = [rs1_descs[i] for i in range(len(ulist)) if i in keep_indexes]
rs2_descs = [rs2_descs[i] for i in range(len(ulist)) if i in keep_indexes]
rs3_descs = [rs3_descs[i] for i in range(len(ulist)) if i in keep_indexes]
utr_pls = [utr_pls[i] for i in range(len(ulist)) if i in keep_indexes]
utr_pls = utr_pls[1::2]
sorted_genes = sorted(used_genes)
sort_proba = np.sort(utr_probas)[::-1]
sort_index = np.argsort(utr_probas)[::-1].tolist()
page_order = [used_genes[i] for i in sort_index]
'''
make_md_table(ulist, used_genes, best_RSs, utr_probas, algn_scores_1, MFEs, norm_algn, ENS_count, table_name='display_1533')
'''
previously_used_indexes = []
for i in range(len(ulist)):
print(used_genes[i])
file = fpaths[i]
gis = page_order.index(used_genes[i])
if gis != 0:
previous_file = page_order[gis-1]
else:
previous_file = page_order[gis]
if gis != 1532:
next_file = page_order[gis+1]
else:
next_file = page_order[gis]
enscount = ENS_count[i]
gene = used_genes[i]
utr_id = ulist[i]
protein = genes[i]
rs1_id = rs1_ids[i]
rs2_id = rs2_ids[i]
rs3_id = rs3_ids[i]
rs1_link = "https://rnacentral.org/rna/%s"%rs1_id.replace('_','/')
rs2_link = "https://rnacentral.org/rna/%s"%rs2_id.replace('_','/')
rs3_link = "https://rnacentral.org/rna/%s"%rs3_id.replace('_','/')
utr_link = "http://utrdb.ba.itb.cnr.it/getutr/%s/1"%utr_id
uniprot_link = protein
utr_seq = utr_seqs[i]
rs1_seq = rs1_seqs[i]
rs2_seq = rs2_seqs[i]
rs3_seq = rs3_seqs[i]
utr_dot = utr_dots[i]
rs1_dot = rs1_dots[i]
rs2_dot = rs2_dots[i]
rs3_dot = rs3_dots[i]
utr_l = len(utr_seq)
rs1_l = len(rs1_seq)
rs2_l = len(rs2_seq)
rs3_l = len(rs3_seq)
rs1_sim = algn_scores_1[i]
rs2_sim = algn_scores_2[i]
rs3_sim = algn_scores_3[i]
ens = utr_probas[i]
utr_mfe = utr_mfes[i]
rs1_mfe = rs1_mfes[i]
rs2_mfe = rs2_mfes[i]
rs3_mfe = rs3_mfes[i]
rs1_ligand = rs1_ligands[i]
rs2_ligand = rs2_ligands[i]
rs3_ligand = rs3_ligands[i]
rs1_lmse = rs1_length_MSE[i]
rs2_lmse = rs2_length_MSE[i]
rs3_lmse = rs3_length_MSE[i]
rs1_lev = rs1_lev_dist[i]
rs2_lev = rs2_lev_dist[i]
rs3_lev = rs3_lev_dist[i]
rs1_mse = rs1_struct_mse[i]
rs2_mse = rs2_struct_mse[i]
rs3_mse = rs3_struct_mse[i]
rs1_mfe = rs1_mfes[i]
rs2_mfe = rs2_mfes[i]
rs3_mfe = rs3_mfes[i]
rs1_desc = rs1_descs[i]
rs2_desc = rs2_descs[i]
rs3_desc = rs3_descs[i]
utr_pl = utr_pls[i]
if len(utr_pl) == 1:
utr_pl = [utr_pl[0] + ' - 20/20', '', '']
if len(utr_pl) == 2:
utr_pl = [utr_pl[0], utr_pl[1], '']
if len(utr_pl) == 3:
utr_pl = [utr_pl[0], utr_pl[1], utr_pl[2]]
utr_UBS, utr_BS, utr_ILL, utr_ILR, utr_H, utr_BL, utr_BR, utr_UN = utr_feats[i]
rs1_UBS, rs1_BS, rs1_ILL, rs1_ILR, rs1_H, rs1_BL, rs1_BR, rs1_UN = rs1_feats[i]
rs2_UBS, rs2_BS, rs2_ILL, rs2_ILR, rs2_H, rs2_BL, rs2_BR, rs2_UN = rs2_feats[i]
rs3_UBS, rs3_BS, rs3_ILL, rs3_ILR, rs3_H, rs3_BL, rs3_BR, rs3_UN = rs3_feats[i]
'''
mst = [gene.upper(), gene.upper(), enscount, previous_file, file, next_file, utr_link, rs1_link, rs2_link,
rs3_link, utr_id, rs1_id, rs2_id, rs3_id,
utr_l, rs1_l, rs2_l, rs3_l, rs1_sim, rs2_sim, rs3_sim, ens,
utr_mfe, rs1_mfe, rs2_mfe, rs3_mfe,
rs1_ligand, rs2_ligand, rs3_ligand,
protein, uniprot_link,
rs1_lmse, rs2_lmse, rs3_lmse,
rs1_lev, rs2_lev, rs3_lev,
rs1_mse, rs2_mse, rs3_mse,
utr_UBS, rs1_UBS, rs2_UBS, rs3_UBS,
utr_BS, rs1_BS, rs2_BS, rs3_BS,
utr_ILL, rs1_ILL, rs2_ILL, rs3_ILL,
utr_ILR, rs1_ILR, rs2_ILR, rs3_ILR,
utr_H, rs1_H, rs2_H, rs3_H,
utr_BL, rs1_BL, rs2_BL, rs3_BL,
utr_BR, rs1_BR, rs2_BR, rs3_BR,
utr_UN, rs1_UN, rs2_UN, rs3_UN, utr_seq, utr_dot,
rs1_seq, rs1_dot, rs2_seq, rs2_dot, rs3_seq, rs3_dot]
'''
k = str(i)
merge_exists = os.path.exists('./alns/bpp/bpp_%s_merge.png'%k)
mst = [gene.upper(), gene.upper(), str(enscount), previous_file, utr_id, rs1_sim,
rs2_sim, rs3_sim,
utr_id, gene.upper(), utr_mfe, ens, utr_l, utr_pl[0], utr_pl[1], utr_pl[2],
rs1_id, rs1_mfe, rs1_ligand, rs1_desc.replace('-\n',''),#text
rs2_id, rs2_mfe, rs2_ligand, rs2_desc.replace('-\n',''),#text
rs3_id, rs3_mfe, rs3_ligand, rs3_desc.replace('-\n',''),#text
utr_id, k, rs1_id, k, rs2_id, k, rs3_id, k, # ss
utr_id, k, rs1_id, k, rs2_id, k, rs3_id, k, # circ
rs1_id, k, rs2_id, k, rs3_id, k, # feat
next_file, k, k, k, k, k, k,#utr_link
rs1_link, rs2_link,
rs3_link, utr_id, rs1_id, rs2_id, rs3_id,
utr_l, rs1_l, rs2_l, rs3_l, '{:.3f}'.format(rs1_sim), '{:.3f}'.format(rs2_sim), '{:.3f}'.format(rs3_sim), ens,
utr_mfe, rs1_mfe, rs2_mfe, rs3_mfe,
rs1_ligand, rs2_ligand, rs3_ligand,
protein, uniprot_link,
rs1_lmse, rs2_lmse, rs3_lmse,
rs1_lev, rs2_lev, rs3_lev,
rs1_mse, rs2_mse, rs3_mse,
utr_UBS, rs1_UBS, rs2_UBS, rs3_UBS,
utr_BS, rs1_BS, rs2_BS, rs3_BS,
utr_ILL, rs1_ILL, rs2_ILL, rs3_ILL,
utr_ILR, rs1_ILR, rs2_ILR, rs3_ILR,
utr_H, rs1_H, rs2_H, rs3_H,
utr_BL, rs1_BL, rs2_BL, rs3_BL,
utr_BR, rs1_BR, rs2_BR, rs3_BR,
utr_UN, rs1_UN, rs2_UN, rs3_UN, utr_seq, utr_dot,
rs1_seq, rs1_dot, rs2_seq, rs2_dot, rs3_seq, rs3_dot]
master_str_tuple = []
for j in range(len(mst)):
if isinstance(mst[j],str):
master_str_tuple.append(mst[j])
else:
ss = '{:.3f}'.format(mst[j])
if ss[-2:] == '00':
ss = ss[:-3]
master_str_tuple.append(ss)
make_md2(gene, tuple(master_str_tuple), i, merge_exists)
'''
from PIL import Image
for f in os.listdir('./alns_10.27.23/'):
img = Image.open('./alns_10.27.23/' + f)
img.crop((460,330, 3480,2660)).save('./alns_10.27.23/' + f)
'''