-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdimer.html
More file actions
3189 lines (2856 loc) · 155 KB
/
dimer.html
File metadata and controls
3189 lines (2856 loc) · 155 KB
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
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LIVIA — AlphaFold DB Dimer Analysis</title>
<link rel="stylesheet" href="css/livia.css?v=20260604">
<style>
/* ── Page-specific styles for Dimer ── */
.step-link { color: #2471A3; text-decoration: none; }
.step-link:hover { text-decoration: underline; }
/* Status */
.status { font-size: 0.85rem; color: #666; min-height: 1.5rem; margin-top: 0.8rem; }
.status.loading { color: #2471A3; }
.status.error { color: #c0392b; }
.status.success { color: #27ae60; }
/* Page-specific button styles */
.btn-primary { margin-top: 0.8rem; }
.btn-secondary { background: white; color: #2471A3; border: 2px solid #2471A3; padding: 0.5rem 1rem; border-radius: 8px; font-size: 0.85rem; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.btn-secondary:hover { background: #eaf2f8; }
.btn-row { display: flex; gap: 0.5rem; margin-top: 0.8rem; flex-wrap: wrap; }
.btn-download.cif { background: white; color: #E67E22; border-color: #E67E22; }
.btn-download.cif:hover { background: #fef5ec; }
/* Page-specific overrides */
.step-header { flex-wrap: wrap; }
.preset-strip { display: flex; width: 60px; height: 12px; border-radius: 3px; overflow: hidden; flex-shrink: 0; }
.preset-strip span { flex: 1; }
.script-preview { font-size: 0.72rem; line-height: 1.4; }
.metrics-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
/* Map rows */
.map-row { display: flex; gap: 0.4rem; flex-wrap: nowrap; justify-content: center; margin-bottom: 0.8rem; }
.map-item { text-align: center; }
.map-item canvas { border-radius: 4px; display: block; }
.map-item .map-label { font-size: 0.75rem; color: #666; margin-bottom: 0.2rem; }
.colorbar-row { display: flex; flex-direction: column; align-items: center; margin-top: 0.5rem; }
.colorbar-row canvas { border-radius: 3px; }
.colorbar-labels { display: flex; justify-content: space-between; width: 300px; font-size: 0.72rem; color: #888; margin-top: 2px; }
.colorbar-labels span:nth-child(2) { color: #555; font-weight: 500; }
/* Dimer table */
.dimer-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-bottom: 1rem; }
.dimer-table th { text-align: left; padding: 0.5rem 0.8rem; background: #f8f9fa; font-weight: 600; font-size: 0.8rem; color: #666; }
.dimer-table td { padding: 0.5rem 0.8rem; border-top: 1px solid #eee; }
.dimer-table tr.clickable { cursor: pointer; }
.dimer-table tr.clickable:hover { background: #f0f7fc; }
.dimer-table tr.selected { background: #d4e6f6; box-shadow: inset 4px 0 0 #c4a35a; font-weight: 600; }
/* Autocomplete */
.ac-wrap { position: relative; flex: 1; min-width: 250px; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; background: white; border: 2px solid #e0e0e0; border-top: none; border-radius: 0 0 8px 8px; max-height: 260px; overflow-y: auto; z-index: 100; display: none; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.ac-list.active { display: block; }
.ac-item { padding: 0.5rem 0.8rem; cursor: pointer; font-size: 0.85rem; border-bottom: 1px solid #f0f0f0; }
.ac-item:hover, .ac-item.selected { background: #eaf2f8; }
.ac-item .ac-id { font-weight: 700; color: #2471A3; margin-right: 0.5rem; }
.ac-item .ac-gene { font-weight: 600; color: #333; margin-right: 0.4rem; }
.ac-item .ac-name { color: #666; }
.ac-item .ac-org { color: #999; font-size: 0.78rem; font-style: italic; }
/* Tag */
.tag { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.72rem; font-weight: 600; }
.tag-homo { background: #d5f5e3; color: #1e8449; }
.tag-hetero { background: #fdebd0; color: #d35400; }
/* Dimer-specific sortable headers */
.dimer-table th.sortable { cursor: pointer; user-select: none; position: relative; }
.dimer-table th.sortable:hover { background: #e8f0fe; }
.dimer-table th.sortable::after { content: ' C5'; font-size: 0.7em; color: #aaa; }
.dimer-table th.sort-asc::after { content: ' B2'; color: #2471A3; }
.dimer-table th.sort-desc::after { content: ' BC'; color: #2471A3; }
.help-content {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
padding-left: 2.3rem;
}
.help-col h4 { font-size: 0.9rem; color: #1a5276; margin-bottom: 0.5rem; }
.help-col ol { padding-left: 1.2rem; font-size: 0.85rem; color: #555; line-height: 1.7; }
.help-col a { color: #2471A3; text-decoration: none; }
.help-col a:hover { text-decoration: underline; }
.help-table { font-size: 0.85rem; }
.help-table td { padding: 0.25rem 0.5rem 0.25rem 0; vertical-align: top; color: #555; }
.ref-list { list-style: none; padding: 0; font-size: 0.85rem; }
.ref-list li { margin-bottom: 0.3rem; color: #555; }
.ref-list a { color: #2471A3; text-decoration: none; font-weight: 600; }
.ref-list a:hover { text-decoration: underline; }
.color-presets { display: flex; flex-direction: column; gap: 0.4rem; }
.preset {
display: flex;
align-items: center;
gap: 0.6rem;
padding: 0.35rem 0.5rem;
border-radius: 6px;
cursor: pointer;
transition: background 0.2s;
}
.preset:hover { background: #f0f0f0; }
@media (max-width: 768px) {
.map-row { flex-wrap: wrap; justify-content: center; flex-direction: column; align-items: center; }
.map-item { width: 100%; }
.map-item canvas { width: 100%; height: auto; }
canvas { max-width: 100%; height: auto; }
.dimer-table th, .dimer-table td { white-space: nowrap; padding: 0.3rem 0.5rem; font-size: 0.75rem; }
#maps-flex { flex-wrap: wrap !important; overflow: visible !important; flex-direction: column; }
.colorbar-labels { width: 100%; max-width: 300px; }
}
</style>
</head>
<body>
<div class="header">
<div class="container">
<h1><span style="color:#2471A3;">LIVIA</span> — AlphaFold DB Dimer Analysis</h1>
<p>Analyze dimer predictions from the <a href="https://alphafold.ebi.ac.uk" target="_blank" style="color:#2471A3;">AlphaFold Protein Structure Database</a> (<a href="https://doi.org/10.64898/2026.03.27.714458" target="_blank" style="color:#2471A3;">Han et al., 2026</a>)</p>
<div class="header-links">
<a href="index.html">Home</a>
<a href="universal.html">Prediction Analysis</a>
<a href="flypredictome.html">FlyPredictome</a>
<a href="ortholog_predictome.html">Ortholog Interactome</a>
<a href="dimer.html" class="active">AFDB Dimer</a>
<a href="monomer.html">AFDB Monomer Subdomain</a>
<a href="tutorials.html">Tutorials</a>
<a href="about.html">About</a>
<a href="bookmarklet.html" style="background:#2471A3; color:white; border-color:#2471A3; font-weight:600;">Bookmarklet ★</a>
<a href="https://github.com/flyark/LIVIA" target="_blank">GitHub</a>
</div>
</div>
</div>
<div class="container">
<!-- Step 1: Fetch Dimer -->
<div class="card">
<div class="step-header">Fetch Dimer Prediction <span style="font-weight:400; font-size:0.8rem; color:#888;">(data fetched from AlphaFold Database — all analysis runs locally in your browser)</span></div>
<label>UniProt ID, AlphaFold Model ID, or AlphaFold DB URL</label>
<div style="display:flex; gap:0.5rem; align-items:center; max-width:600px;">
<div class="ac-wrap" style="flex:1;">
<input type="text" id="uniprot-input" placeholder="e.g. P69905, AF-0000000066214167, or protein name" autocomplete="off" style="width:100%; padding:0.5rem 0.8rem; border:2px solid #e0e0e0; border-radius:8px; font-size:0.9rem;">
<div class="ac-list" id="ac-list"></div>
</div>
<button class="btn btn-primary" style="margin:0;" id="btn-fetch" onclick="fetchDimers()">Search</button>
</div>
<div style="display:flex; gap:0.4rem; flex-wrap:wrap; margin-top:0.5rem; align-items:center;">
<span style="font-size:0.8rem; color:#888;">Heterodimer:</span>
<button class="example-btn" onclick="tryExample('AF-0000000205399062')">Prpf39–C6orf52</button>
<button class="example-btn" onclick="tryExample('AF-0000000204799972')">Atg6–Uvrag</button>
<span style="font-size:0.8rem; color:#888; margin-left:0.4rem;">Homodimer:</span>
<button class="example-btn" onclick="tryExample('AF-0000000066214167')">Fiber protein 2</button>
<button class="example-btn" onclick="tryExample('AF-0000000066082551')">pp71</button>
<button class="example-btn" onclick="tryExample('AF-0000000065862457')">dj-1beta</button>
</div>
<div style="font-size:0.8rem; color:#888; margin-top:0.4rem;">Not all proteins have dimer predictions. Browse <a href="https://alphafold.ebi.ac.uk" target="_blank" style="color:#2471A3;">AlphaFold DB</a> to find available complexes, then paste the URL or model ID here.</div>
<div class="status" id="status"></div>
<div id="external-links" style="display:none; font-size:0.82rem; margin-top:0.3rem;"></div>
<div id="protein-info" style="display:none; margin-top:0.5rem; padding:0.6rem 0.8rem; background:#f8f9fa; border-radius:8px; font-size:0.82rem; line-height:1.5; border:1px solid #e8e8e8;"></div>
<!-- Dimer results table -->
<div id="dimer-results" style="display:none; margin-top:1rem;">
<label>Found Dimers — click a row to load</label>
<div style="overflow-x:auto;">
<table class="dimer-table" id="dimer-table">
<thead><tr><th>Complex</th><th>Type</th><th>Gene(s)</th><th>pLDDT</th><th>ipTM</th><th>ipSAE</th><th>pDockQ2</th><th>LIS</th></tr></thead>
<tbody id="dimer-tbody"></tbody>
</table>
</div>
</div>
</div>
<!-- Error -->
<div class="error-msg" id="error-msg"></div>
<!-- Results -->
<div class="results" id="results">
<!-- Interaction Analysis Summary -->
<div class="card result-card">
<h2>Interaction Analysis Summary</h2>
<table class="data-table" id="pairs-table">
<thead><tr><th>Protein A</th><th>Protein B</th><th>iLIS</th><th>iLIA</th><th>iLISA</th><th>ipSAE</th><th>actifpTM</th><th>ipTM</th><th>LIS</th><th>cLIS</th><th>LIR (A/B)</th><th>cLIR (A/B)</th></tr></thead>
<tbody id="pairs-tbody"></tbody>
</table>
<div style="margin-top:0.5rem;">
<a class="btn-download cxc" style="background:#27ae60; border-color:#27ae60; font-size:0.82rem; cursor:pointer;" onclick="downloadCSV()">↓ Download CSV</a>
</div>
<div style="margin-top:0.6rem; font-size:0.75rem; color:#999; line-height:1.8;">
<div style="display:flex; gap:0.8rem; flex-wrap:wrap; align-items:center;">
<strong>iLIS:</strong>
<span><span style="color:#6B21A8; font-weight:700;">≥0.551</span> (1% FPR)</span>
<span><span style="color:#0e8a6e; font-weight:700;">≥0.339</span> (5% FPR)</span>
<span><span style="color:#bf8700; font-weight:700;">≥0.223</span> (10% FPR)</span>
<span><span style="color:#8b949e; font-weight:700;"><0.223</span> (below threshold)</span>
</div>
<div>Thresholds based on large-scale Y2H reference sets in yeast, fly, and human predicted using ColabFold. See <a href="https://doi.org/10.64898/2026.04.14.718529" target="_blank" style="color:#2471A3;">Kim et al., 2026</a>, for iLIS benchmark details.</div>
</div>
</div>
<!-- PAE / LIS / cLIS Maps -->
<div class="card result-card">
<h2>Maps</h2>
<div id="maps-flex" style="display:flex; gap:0.4rem; justify-content:center; overflow:hidden;"></div>
</div>
<!-- Dimer vs Monomer Comparison -->
<div class="card result-card" id="comparison-card" style="display:none;">
<h2>Dimer vs Monomer Comparison (Intra-chain LIS & pLDDT)</h2>
<div style="font-size:0.82rem; color:#888; margin-bottom:0.5rem;">
Compares per-residue metrics when the chain is predicted alone (monomer) vs. as part of a complex (dimer). Intra-chain LIS measures internal folding confidence within the same chain. Green shading = gain in dimer context; red = loss.
</div>
<div id="comparison-status" style="font-size:0.82rem; color:#2471A3; margin-bottom:0.5rem;"></div>
<div id="comparison-charts"></div>
</div>
<!-- Sequence Viewer -->
<div class="card result-card" id="seq-viewer-card" style="display:none;">
<h2>Sequence Viewer</h2>
<div style="font-size:0.82rem; color:#888; margin-bottom:0.5rem;">
Light background = LIR (PAE ≤ 12 Å). Dark background with white text = cLIR (PAE ≤ 12 Å & Cβ ≤ 8 Å). Each chain uses its own color.
</div>
<div id="seq-viewer" style="font-family:'SF Mono','Fira Code',monospace; overflow-x:auto;"></div>
</div>
<!-- Linear Contact Map -->
<div class="card result-card" id="contact-map-card" style="display:none;">
<h2>Linear Contact Map</h2>
<div style="font-size:0.82rem; color:#888; margin-bottom:0.5rem;">
Lines connect cLIR residue pairs within Cβ distance in the 3D structure. Color gradient from chain A to chain B. UniProt domain annotations shown when available.
</div>
<canvas id="contact-canvas"></canvas>
<div id="contact-domain-legend" style="margin-top:0.4rem; font-size:0.72rem; color:#666; display:flex; gap:0.8rem; flex-wrap:wrap;"></div>
</div>
<!-- Circular Contact Map (circular) -->
<div class="card result-card" id="chord-card" style="display:none;">
<h2>Circular Contact Map</h2>
<div style="font-size:0.82rem; color:#888; margin-bottom:0.5rem;">
Arcs represent chains (proportional to length). Lines connect cLIR residue pairs in physical contact.
</div>
<div style="text-align:center;">
<canvas id="chord-canvas"></canvas>
</div>
</div>
<!-- 3D Structure Viewer -->
<div class="card result-card" id="viewer3d-card" style="display:none;">
<h2>3D Structure Viewer</h2>
<div style="font-size:0.82rem; color:#888; margin-bottom:0.5rem;">
Interactive 3D preview powered by <a href="https://molstar.org" target="_blank" style="color:#2471A3;">Mol*</a> (<a href="https://doi.org/10.1093/nar/gkab314" target="_blank" style="color:#2471A3;">Sehnal et al. 2021</a>). LIR regions shown as cartoons; cLIR residues highlighted. Drag to rotate, scroll to zoom. <span style="color:#999;">If the viewer appears empty, refresh the page.</span>
</div>
<iframe id="viewer3d-frame" style="width:100%; height:660px; border:1px solid #e0e0e0; border-radius:8px; background:#fff;" sandbox="allow-scripts allow-same-origin allow-downloads" allowfullscreen></iframe>
<div style="text-align:right; margin-top:0.3rem;">
<button onclick="document.getElementById('viewer3d-frame').requestFullscreen()" style="padding:0.25rem 0.6rem; border:1px solid #ddd; border-radius:4px; background:#f8f9fa; cursor:pointer; font-size:0.78rem; color:#555;">Fullscreen</button>
</div>
</div>
<!-- Script -->
<div class="card result-card" id="script-card">
<h2>Visualization Script</h2>
<div style="margin-bottom:1rem;">
<label>Local Interaction Residue (LIR) Display</label>
<div style="display:flex; align-items:baseline; gap:0.6rem; margin-bottom:0.5rem; font-size:0.85rem; color:#555; flex-wrap:wrap;">
<span>Fill gaps ≤</span>
<input type="number" id="gap-fill-input" value="10" min="0" max="200" style="width:55px; padding:0.3rem 0.4rem; border:2px solid #e0e0e0; border-radius:6px; font-size:0.85rem; text-align:center;">
<span>residues</span>
<span style="color:#ccc;">|</span>
<span>Min segment ≥</span>
<input type="number" id="min-segment-input" value="3" min="1" max="50" style="width:55px; padding:0.3rem 0.4rem; border:2px solid #e0e0e0; border-radius:6px; font-size:0.85rem; text-align:center;">
<span>residues</span>
<button class="btn btn-primary" style="font-size:0.82rem; padding:0.3rem 0.8rem;" onclick="updateGapFill()">Apply</button>
</div>
<div style="font-size:0.78rem; color:#999; margin-bottom:0.5rem;">Gap filling bridges short breaks for continuous cartoon. Min segment removes isolated LIR fragments shorter than the threshold.</div>
<label style="display:flex; align-items:center; gap:0.3rem; font-size:0.85rem; color:#555; cursor:pointer; user-select:none; margin-bottom:0.3rem;">
<input type="checkbox" class="show-complete-cb" onchange="toggleShowComplete(this)"> Show complete structure <span style="font-size:0.78rem; color:#999;">(display all residues instead of LIR only)</span>
</label>
<label style="display:flex; align-items:center; gap:0.3rem; font-size:0.85rem; color:#555; cursor:pointer; user-select:none; margin-bottom:1rem; padding-left:1.2rem;">
<input type="checkbox" class="gray-nonlir-cb" onchange="toggleGrayNonLir(this)"> Gray non-LIR <span style="font-size:0.78rem; color:#999;">(color non-interacting residues gray)</span>
</label>
<label>Cutoffs</label>
<div style="display:flex; gap:1.5rem; margin-bottom:1rem; flex-wrap:wrap;">
<div>
<span style="font-size:0.85rem; color:#555;">PAE cutoff (Å):</span>
<input type="number" id="pae-cutoff" value="12" min="1" max="30" step="1" style="width:60px; padding:0.3rem; border:2px solid #e0e0e0; border-radius:6px; font-size:0.9rem;">
</div>
<div>
<span style="font-size:0.85rem; color:#555;">Cβ cutoff (Å):</span>
<input type="number" id="cb-cutoff" value="8" min="1" max="20" step="1" style="width:60px; padding:0.3rem; border:2px solid #e0e0e0; border-radius:6px; font-size:0.9rem;">
</div>
</div>
<label>Presets — gradient (LIR light, cLIR dark)</label>
<div class="presets-row">
<div class="preset-chip active" onclick="applyPreset('#80CBC4','#00897B','#FFAB91','#E64A19',this)"><div class="preset-strip"><span style="background:#80CBC4"></span><span style="background:#00897B"></span><span style="background:#E64A19"></span><span style="background:#FFAB91"></span></div>Teal / Coral</div>
<div class="preset-chip" onclick="applyPreset('#b3d4e8','#2471A3','#f5cba7','#E67E22',this)"><div class="preset-strip"><span style="background:#b3d4e8"></span><span style="background:#2471A3"></span><span style="background:#E67E22"></span><span style="background:#f5cba7"></span></div>Blue / Orange</div>
<div class="preset-chip" onclick="applyPreset('#d1c4e9','#5e35b1','#fff3b0','#f9a825',this)"><div class="preset-strip"><span style="background:#d1c4e9"></span><span style="background:#5e35b1"></span><span style="background:#f9a825"></span><span style="background:#fff3b0"></span></div>Purple / Gold</div>
<div class="preset-chip" onclick="applyPreset('#cfd8dc','#546e7a','#f8bbd0','#c2185b',this)"><div class="preset-strip"><span style="background:#cfd8dc"></span><span style="background:#546e7a"></span><span style="background:#c2185b"></span><span style="background:#f8bbd0"></span></div>Slate / Rose</div>
<div class="preset-chip" onclick="applyPreset('#c5cae9','#303f9f','#ffe0b2','#e65100',this)"><div class="preset-strip"><span style="background:#c5cae9"></span><span style="background:#303f9f"></span><span style="background:#e65100"></span><span style="background:#ffe0b2"></span></div>Indigo / Tangerine</div>
<div class="preset-chip" onclick="applyPreset('#a8d5ba','#2e7d32','#ef9a9a','#c62828',this)"><div class="preset-strip"><span style="background:#a8d5ba"></span><span style="background:#2e7d32"></span><span style="background:#c62828"></span><span style="background:#ef9a9a"></span></div>Green / Red</div>
</div>
<label style="margin-top:0.5rem">Presets — high contrast (all 4 colors distinct)</label>
<div class="presets-row">
<div class="preset-chip" onclick="applyPreset('#4DD0E1','#1A237E','#FFAB91','#B71C1C',this)"><div class="preset-strip"><span style="background:#4DD0E1"></span><span style="background:#1A237E"></span><span style="background:#B71C1C"></span><span style="background:#FFAB91"></span></div>Cyan / Navy / Peach / Crimson</div>
<div class="preset-chip" onclick="applyPreset('#81D4FA','#283593','#EF9A9A','#C62828',this)"><div class="preset-strip"><span style="background:#81D4FA"></span><span style="background:#283593"></span><span style="background:#C62828"></span><span style="background:#EF9A9A"></span></div>Sky / Indigo / Salmon / Red</div>
<div class="preset-chip" onclick="applyPreset('#AED581','#1B5E20','#FFD54F','#B71C1C',this)"><div class="preset-strip"><span style="background:#AED581"></span><span style="background:#1B5E20"></span><span style="background:#B71C1C"></span><span style="background:#FFD54F"></span></div>Lime / Forest / Gold / Maroon</div>
<div class="preset-chip" onclick="applyPreset('#80CBC4','#004D40','#FFCC80','#BF360C',this)"><div class="preset-strip"><span style="background:#80CBC4"></span><span style="background:#004D40"></span><span style="background:#BF360C"></span><span style="background:#FFCC80"></span></div>Mint / DarkTeal / Apricot / Burnt</div>
<div class="preset-chip" onclick="applyPreset('#CE93D8','#4A148C','#FFF176','#E65100',this)"><div class="preset-strip"><span style="background:#CE93D8"></span><span style="background:#4A148C"></span><span style="background:#E65100"></span><span style="background:#FFF176"></span></div>Orchid / Purple / Yellow / Fire</div>
<div class="preset-chip" onclick="applyPreset('#BBDEFB','#0D47A1','#A5D6A7','#F4511E',this)"><div class="preset-strip"><span style="background:#BBDEFB"></span><span style="background:#0D47A1"></span><span style="background:#F4511E"></span><span style="background:#A5D6A7"></span></div>Blue / Navy / Sage / Ember</div>
</div>
<label style="margin-top:0.5rem">Presets — solid</label>
<div class="presets-row">
<div class="preset-chip" onclick="applyPreset('#00897B','#00897B','#E64A19','#E64A19',this)"><div class="preset-strip"><span style="background:#00897B"></span><span style="background:#00897B"></span><span style="background:#E64A19"></span><span style="background:#E64A19"></span></div>Teal / Coral</div>
<div class="preset-chip" onclick="applyPreset('#2471A3','#2471A3','#E67E22','#E67E22',this)"><div class="preset-strip"><span style="background:#2471A3"></span><span style="background:#2471A3"></span><span style="background:#E67E22"></span><span style="background:#E67E22"></span></div>Blue / Orange</div>
<div class="preset-chip" onclick="applyPreset('#5e35b1','#5e35b1','#f9a825','#f9a825',this)"><div class="preset-strip"><span style="background:#5e35b1"></span><span style="background:#5e35b1"></span><span style="background:#f9a825"></span><span style="background:#f9a825"></span></div>Purple / Gold</div>
<div class="preset-chip" onclick="applyPreset('#546e7a','#546e7a','#c2185b','#c2185b',this)"><div class="preset-strip"><span style="background:#546e7a"></span><span style="background:#546e7a"></span><span style="background:#c2185b"></span><span style="background:#c2185b"></span></div>Slate / Rose</div>
<div class="preset-chip" onclick="applyPreset('#6A9EC6','#6A9EC6','#D4A76A','#D4A76A',this)"><div class="preset-strip"><span style="background:#6A9EC6"></span><span style="background:#6A9EC6"></span><span style="background:#D4A76A"></span><span style="background:#D4A76A"></span></div>Steel / Wheat</div>
<div class="preset-chip" onclick="applyPreset('#6495ED','#6495ED','#FF6347','#FF6347',this)"><div class="preset-strip"><span style="background:#6495ED"></span><span style="background:#6495ED"></span><span style="background:#FF6347"></span><span style="background:#FF6347"></span></div>Cornflower / Tomato</div>
<div class="preset-chip" onclick="applyPreset('#87CEEB','#87CEEB','#FFD700','#FFD700',this)"><div class="preset-strip"><span style="background:#87CEEB"></span><span style="background:#87CEEB"></span><span style="background:#FFD700"></span><span style="background:#FFD700"></span></div>SkyBlue / Gold</div>
<div class="preset-chip" onclick="applyPreset('#90EE90','#90EE90','#DDA0DD','#DDA0DD',this)"><div class="preset-strip"><span style="background:#90EE90"></span><span style="background:#90EE90"></span><span style="background:#DDA0DD"></span><span style="background:#DDA0DD"></span></div>LightGreen / Plum</div>
<div class="preset-chip" onclick="applyPreset('#FFA07A','#FFA07A','#20B2AA','#20B2AA',this)"><div class="preset-strip"><span style="background:#FFA07A"></span><span style="background:#FFA07A"></span><span style="background:#20B2AA"></span><span style="background:#20B2AA"></span></div>Salmon / Teal</div>
</div>
<label style="margin-top:0.5rem">Presets — coloring modes</label>
<div class="presets-row">
<div class="preset-chip" onclick="applyCxcPreset('plddt',this)"><div class="preset-strip"><span style="background:#0053D6"></span><span style="background:#65CBF3"></span><span style="background:#FFDB13"></span><span style="background:#FF7D45"></span></div>pLDDT</div>
<div class="preset-chip" onclick="applyCxcPreset('bychain',this)"><div class="preset-strip"><span style="background:#6495ED"></span><span style="background:#FF6347"></span><span style="background:#90EE90"></span><span style="background:#DDA0DD"></span></div>bychain</div>
<div class="preset-chip" onclick="applyCxcPreset('bypolymer',this)"><div class="preset-strip"><span style="background:#87CEEB"></span><span style="background:#FFA07A"></span><span style="background:#98FB98"></span><span style="background:#DDA0DD"></span></div>bypolymer</div>
</div>
<label style="margin-top:1rem">Color Scheme</label>
<div class="color-section">
<div class="color-group">
<h3>Chain A</h3>
<div class="color-pair">
<input type="color" id="color-lir-a" value="#80CBC4">
<div><div class="color-label">LIR</div><div class="color-hex" id="hex-lir-a">#80CBC4</div></div>
</div>
<div class="color-pair">
<input type="color" id="color-clir-a" value="#00897B">
<div><div class="color-label">cLIR</div><div class="color-hex" id="hex-clir-a">#00897B</div></div>
</div>
</div>
<div class="color-group">
<h3>Chain B</h3>
<div class="color-pair">
<input type="color" id="color-lir-b" value="#FFAB91">
<div><div class="color-label">LIR</div><div class="color-hex" id="hex-lir-b">#FFAB91</div></div>
</div>
<div class="color-pair">
<input type="color" id="color-clir-b" value="#E64A19">
<div><div class="color-label">cLIR</div><div class="color-hex" id="hex-clir-b">#E64A19</div></div>
</div>
</div>
</div>
<div style="display:flex; align-items:center; gap:0.8rem; margin-top:0.5rem;">
<div class="color-preview-strip" id="color-strip" style="flex:1; margin:0;">
<div style="background:#80CBC4"></div><div style="background:#00897B"></div><div style="background:#E64A19"></div><div style="background:#FFAB91"></div>
</div>
<button onclick="swapColors()" style="padding:0.3rem 0.8rem; border:2px solid #e0e0e0; border-radius:6px; background:white; cursor:pointer; font-size:0.82rem; color:#666; white-space:nowrap;">Swap A ↔ B</button>
</div>
</div>
<hr style="border:none; border-top:1px solid #e0e0e0; margin-bottom:1rem;">
<div class="input-tabs" style="margin-bottom:0.8rem;">
<button class="input-tab active" data-tab="chimerax" onclick="switchScriptTab('chimerax')">ChimeraX</button>
<button class="input-tab" data-tab="pymol" onclick="switchScriptTab('pymol')">PyMOL</button>
</div>
<div class="script-preview" id="script-preview"></div>
<div class="download-row">
<a class="btn-download cxc" id="dl-script" download>↓ Download <span id="dl-script-ext">.cxc</span></a>
<a class="btn-download cif" id="dl-cif" download>↓ Download .cif</a>
<button class="btn-download" id="btn-copy" style="background:white; color:#2471A3; border:2px solid #2471A3; cursor:pointer;" onclick="copyScript()">Copy to Clipboard</button>
</div>
<div class="info-box" style="margin-top:1rem;">Place the script and .cif files in the same folder, then open the script in ChimeraX or PyMOL.</div>
</div>
</div>
<!-- How to Use -->
<div class="card">
<div class="step-header">How to Use <a href="about.html" style="font-size:0.8rem; font-weight:400; color:#2471A3;">(Full guide)</a></div>
<div style="display:grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap:1.5rem; padding-left:2.3rem;">
<div>
<h4 style="font-size:0.9rem; color:#1a5276; margin-bottom:0.5rem;">Quick Start</h4>
<ol style="padding-left:1.2rem; font-size:0.85rem; color:#555; line-height:1.7;" start="0">
<li>Enter a UniProt ID and click <strong>Search Dimers</strong></li>
<li>Select a dimer from the results table</li>
<li>Explore PAE, LIS, and cLIS maps</li>
<li>Review metrics (iLIS, LIS, cLIS, ipTM, pDockQ2, pLDDT) and maps</li>
<li>Download the script and .cif file, place in the same folder, then open the script in ChimeraX (.cxc) or PyMOL (.pml)</li>
</ol>
</div>
<div>
<h4 style="font-size:0.9rem; color:#1a5276; margin-bottom:0.5rem;"><a href="https://github.com/flyark/AFM-LIS" target="_blank" style="color:#2471A3; text-decoration:underline;">AFM-LIS</a> Metrics (<a href="https://doi.org/10.1101/2024.02.19.580970" target="_blank" style="color:#2471A3;">Kim et al. 2024</a>; <a href="https://doi.org/10.64898/2026.04.14.718529" target="_blank" style="color:#2471A3;">Kim et al. 2026</a>)</h4>
<table style="font-size:0.85rem;">
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>iLIS</strong></td><td style="padding:0.25rem 0; color:#555;">integrated LIS — √(LIS × cLIS)</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>iLIA</strong></td><td style="padding:0.25rem 0; color:#555;">integrated LIA — √(LIA × cLIA), geometric mean of interface area counts</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>iLISA</strong></td><td style="padding:0.25rem 0; color:#555;">integrated LISA — iLIS × iLIA, overall binding strength</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>LIS</strong></td><td style="padding:0.25rem 0; color:#555;">Local Interaction Score — normalized PAE confidence (0–1)</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>cLIS</strong></td><td style="padding:0.25rem 0; color:#555;">contact-filtered LIS — restricted to direct contacts</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>LIR</strong></td><td style="padding:0.25rem 0; color:#555;">Local Interaction Residues (PAE ≤ 12 Å)</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>cLIR</strong></td><td style="padding:0.25rem 0; color:#555;">contact-filtered LIR (PAE ≤ 12 Å & Cβ ≤ 8 Å)</td></tr>
</table>
<h4 style="font-size:0.9rem; color:#1a5276; margin-top:0.8rem; margin-bottom:0.5rem;">Confidence Metrics (from AlphaFold DB)</h4>
<table style="font-size:0.85rem;">
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>ipTM</strong></td><td style="padding:0.25rem 0; color:#555;">interface predicted TM-score — global interface confidence from the prediction model</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>ipSAE</strong></td><td style="padding:0.25rem 0; color:#555;">interaction prediction Score from Aligned Errors (<a href="https://www.biorxiv.org/content/10.1101/2025.02.10.637595" target="_blank" style="color:#2471A3;">Dunbrack, 2025</a>)</td></tr>
<tr><td style="padding:0.25rem 0.5rem 0.25rem 0; vertical-align:top; color:#555;"><strong>actifpTM</strong></td><td style="padding:0.25rem 0; color:#555;">actual interface pTM (<a href="https://doi.org/10.1093/bioinformatics/btaf107" target="_blank" style="color:#2471A3;">Varga et al., 2025</a>)</td></tr>
</table>
<p style="font-size:0.78rem; color:#888; margin-top:0.4rem; line-height:1.4;">PAE (Predicted Aligned Error) measures how confidently the model predicts the relative position of two residues — lower values indicate higher confidence.</p>
</div>
</div>
</div>
<div class="footer">
<a href="https://github.com/flyark/LIVIA" target="_blank">LIVIA GitHub</a> · <a href="https://github.com/flyark/AFM-LIS" target="_blank">AFM-LIS GitHub</a>
<br>
<a href="https://doi.org/10.64898/2026.05.01.721633" target="_blank">Kim & Perrimon (2026)</a>
<br>
Ah-Ram Kim · Harvard Medical School
</div>
</div>
<script src="js/livia-core.js"></script>
<script src="js/livia-scripts.js"></script>
<script src="js/livia-viewer.js"></script>
<script src="js/livia-colors.js"></script>
<script>
// ── Callbacks for shared modules ──
onColorChange = () => { if (dimerPairResult) { generateAndDisplayScript(); buildDimerSequenceViewer(); buildDimerContactMap(); buildChordDiagram(); buildComparisonCharts(); updateViewer3d(); } };
onScriptTabSwitch = () => { if (dimerPairResult) generateAndDisplayScript(); };
document.addEventListener('DOMContentLoaded', () => {
initColorPickers();
// Deep link: ?id=AF-... or ?id=<UniProt acc> loads the entry on page open
const params = new URLSearchParams(window.location.search);
const id = params.get('id');
if (id) tryExample(id);
});
// ============================================================================
// GLOBAL STATE
// ============================================================================
let dimerList = []; // fetched dimer entries
let selectedDimer = null; // currently selected dimer entry
let dimerCifText = null; // fetched CIF content
let dimerPaeData = null; // fetched PAE data
let dimerChains = null; // chain info from PAE JSON
let dimerPairResult = null; // computed pair metrics
let dimerCifFilename = ''; // filename for download
let viewer3dBlobUrl = null; // blob URL for current Mol* iframe page
let viewer3dStructText = null; // cached structure text — postMessage fast-path detection
let domainCache = new Map(); // UniProt ID -> domain array cache
let tedCache = new Map(); // UniProt ID -> TED domain array cache
let chainDomains = { A: [], B: [] }; // domain annotations per chain
let chainTedDomains = { A: [], B: [] }; // TED domain annotations per chain
let monomerData = {}; // { uniprotId: { pdbText, paeData, plddt: Map } }
// ============================================================================
// CORS PROXY (AlphaFold DB complex API lacks CORS headers)
// ============================================================================
async function fetchViaProxy(url) {
// Race all proxies — use whichever responds first
return new Promise((resolve, reject) => {
let resolved = false;
let pending = CORS_PROXIES.length;
CORS_PROXIES.forEach(makeProxy => {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 15000);
fetch(makeProxy(url), { signal: controller.signal })
.then(resp => {
clearTimeout(timeout);
if (resp.ok && !resolved) {
resolved = true;
resolve(resp);
}
})
.catch(() => {})
.finally(() => {
pending--;
if (pending === 0 && !resolved) reject(new Error('All CORS proxies failed'));
});
});
});
}
async function fetchJsonViaProxy(url) {
// Try direct first (in case CORS is added), then proxy
try {
const resp = await fetch(url);
if (resp.ok) return await resp.json();
} catch {}
const proxyResp = await fetchViaProxy(url);
return await proxyResp.json();
}
async function fetchTextViaProxy(url) {
try {
const resp = await fetch(url);
if (resp.ok) return await resp.text();
} catch {}
const proxyResp = await fetchViaProxy(url);
return await proxyResp.text();
}
// ============================================================================
// STATUS
// ============================================================================
function setStatus(msg, type = '') {
const el = document.getElementById('status');
el.textContent = msg;
el.className = 'status' + (type ? ' ' + type : '');
}
// ============================================================================
// EXAMPLE
// ============================================================================
function tryExample(id) {
document.getElementById('uniprot-input').value = id || 'AF-0000000066214167';
fetchDimers();
}
// ============================================================================
// AUTOCOMPLETE (UniProt search)
// ============================================================================
let acDebounce = null;
let acSelected = -1;
(function initAutocomplete() {
const input = document.getElementById('uniprot-input');
const list = document.getElementById('ac-list');
input.addEventListener('input', () => {
clearTimeout(acDebounce);
const q = input.value.trim();
if (q.length < 2 || q.startsWith('http') || q.startsWith('AF-')) { hideAc(); return; }
if (/^[A-Z][0-9][A-Z0-9]{3}[0-9]$/i.test(q)) { hideAc(); return; }
acDebounce = setTimeout(() => searchUniprot(q), 300);
});
input.addEventListener('keydown', (e) => {
const items = list.querySelectorAll('.ac-item');
if (!list.classList.contains('active') || items.length === 0) {
if (e.key === 'Enter') { e.preventDefault(); fetchDimers(); }
return;
}
if (e.key === 'ArrowDown') { e.preventDefault(); acSelected = Math.min(acSelected + 1, items.length - 1); updateAcHL(items); }
else if (e.key === 'ArrowUp') { e.preventDefault(); acSelected = Math.max(acSelected - 1, 0); updateAcHL(items); }
else if (e.key === 'Enter' || e.key === 'Tab') {
e.preventDefault();
if (acSelected >= 0 && acSelected < items.length) items[acSelected].click();
else if (e.key === 'Enter') { hideAc(); fetchDimers(); }
} else if (e.key === 'Escape') { hideAc(); }
});
document.addEventListener('click', (e) => { if (!e.target.closest('.ac-wrap')) hideAc(); });
})();
function hideAc() { document.getElementById('ac-list').classList.remove('active'); acSelected = -1; }
function updateAcHL(items) {
items.forEach((it, i) => it.classList.toggle('selected', i === acSelected));
if (acSelected >= 0) items[acSelected].scrollIntoView({ block: 'nearest' });
}
async function searchUniprot(query) {
try {
const url = `https://rest.uniprot.org/uniprotkb/search?query=${encodeURIComponent('"' + query + '"')}&fields=accession,gene_names,protein_name,organism_name&size=8&format=json`;
const resp = await fetch(url);
if (!resp.ok) return;
const data = await resp.json();
const results = data.results || [];
const list = document.getElementById('ac-list');
list.innerHTML = '';
acSelected = -1;
if (results.length === 0) { hideAc(); return; }
for (const r of results) {
const acc = r.primaryAccession || '';
const gene = (r.genes || [{}])[0]?.geneName?.value || '';
const name = r.proteinDescription?.recommendedName?.fullName?.value
|| r.proteinDescription?.submissionNames?.[0]?.fullName?.value || '';
const org = r.organism?.scientificName || '';
const item = document.createElement('div');
item.className = 'ac-item';
item.innerHTML = `<span class="ac-id">${acc}</span><span class="ac-gene">${esc(gene)}</span><span class="ac-name">${esc(name.substring(0, 50))}</span><br><span class="ac-org">${esc(org)}</span>`;
item.addEventListener('click', () => {
document.getElementById('uniprot-input').value = acc;
hideAc();
fetchDimers();
});
list.appendChild(item);
}
list.classList.add('active');
} catch (e) { console.warn('Autocomplete error:', e); }
}
// ============================================================================
// INPUT PARSING
// ============================================================================
function parseInput(raw) {
raw = raw.trim();
// Full AlphaFold DB URL: https://alphafold.ebi.ac.uk/entry/AF-0000000066660593
const urlMatch = raw.match(/alphafold\.ebi\.ac\.uk\/entry\/(AF-\d+)/i);
if (urlMatch) return { type: 'model', id: urlMatch[1] };
// Model entity ID: AF-0000000066660593
if (/^AF-\d+$/i.test(raw)) return { type: 'model', id: raw };
// UniProt ID: P69905, Q5VSL9, etc.
if (/^[A-Za-z0-9_-]+$/.test(raw)) return { type: 'uniprot', id: raw.toUpperCase() };
return null;
}
function showExternalLinks(entry) {
const el = document.getElementById('external-links');
const parts = [];
if (entry.complexName) parts.push(`<strong>${entry.complexName}</strong>`);
if (entry.gene && entry.gene.length > 0) parts.push(`(${entry.gene.join(', ')})`);
const uniprotIds = entry.uniprotAccession || [];
if (uniprotIds.length > 0) {
for (const uid of uniprotIds) {
parts.push(`<a href="https://www.uniprot.org/uniprot/${uid}" target="_blank" style="color:#2471A3;">UniProt: ${uid}</a>`);
}
}
if (entry.modelEntityId) {
parts.push(`<a href="https://alphafold.ebi.ac.uk/entry/${entry.modelEntityId}" target="_blank" style="color:#2471A3;">AlphaFold Database</a>`);
}
el.innerHTML = parts.join(' · ');
el.style.display = parts.length > 0 ? '' : 'none';
}
async function showProteinInfo(entry) {
const el = document.getElementById('protein-info');
el.style.display = 'none';
el.innerHTML = '';
const uniprotIds = [...new Set(entry.uniprotAccession || [])];
if (uniprotIds.length === 0) return;
try {
const infos = await Promise.all(uniprotIds.map(async uid => {
const resp = await fetch(`https://rest.uniprot.org/uniprotkb/${uid}.json`);
if (!resp.ok) return null;
return resp.json();
}));
const parts = [];
for (const data of infos) {
if (!data) continue;
const acc = data.primaryAccession;
const entryName = data.uniProtkbId || '';
const protName = data.proteinDescription?.recommendedName?.fullName?.value
|| data.proteinDescription?.submissionNames?.[0]?.fullName?.value || '';
const org = data.organism?.scientificName || '';
const len = data.sequence?.length || '';
const funcComment = (data.comments || []).find(c => c.commentType === 'FUNCTION');
let funcText = funcComment?.texts?.[0]?.value || '';
// Strip "(By similarity)" etc. and truncate
funcText = funcText.replace(/\s*\(By similarity\)/gi, '').replace(/\s*\(PubMed:\d+\)/gi, '');
const lines = [];
lines.push(`<strong>${esc(entryName)}</strong> · ${esc(protName)}`);
const meta = [];
if (org) meta.push(`<strong>${esc(org)}</strong>`);
if (len) meta.push(`${len} aa`);
if (meta.length > 0) lines.push(`<span style="color:#666;">${meta.join(' · ')}</span>`);
if (funcText) lines.push(`<span style="color:#555;">${esc(funcText)}</span>`);
parts.push(lines.join('<br>'));
}
if (parts.length > 0) {
el.innerHTML = parts.join('<div style="border-top:1px solid #e0e0e0; margin:0.4rem 0;"></div>');
el.style.display = '';
}
} catch (e) { console.warn('Protein info fetch error:', e); }
}
// ============================================================================
// FETCH DIMERS
// ============================================================================
async function fetchDimers() {
const rawInput = document.getElementById('uniprot-input').value.trim();
if (!rawInput) { setStatus('Please enter a UniProt ID, model ID, or URL.', 'error'); return; }
const parsed = parseInput(rawInput);
if (!parsed) { setStatus('Invalid input. Enter a UniProt ID, AF model ID, or AlphaFold DB URL.', 'error'); return; }
document.getElementById('btn-fetch').disabled = true;
document.getElementById('results').classList.remove('active');
document.getElementById('error-msg').classList.remove('active');
document.getElementById('dimer-results').style.display = 'none';
document.getElementById('protein-info').style.display = 'none';
try {
if (parsed.type === 'model') {
// Direct model entity ID — fetch its metadata and load directly
setStatus(`Fetching model ${parsed.id}...`, 'loading');
const data = await fetchJsonViaProxy(`https://alphafold.ebi.ac.uk/api/complex/${parsed.id}`);
const entry = Array.isArray(data) ? data[0] : data;
if (!entry || !entry.modelEntityId) throw new Error(`Invalid response for "${parsed.id}".`);
dimerList = [entry];
setStatus(`Found: ${entry.complexName || parsed.id}. Loading...`, 'success');
// Single result — skip dimer selection table, load directly
selectDimer(0, null);
} else {
// UniProt ID — search for complexes
setStatus(`Searching AlphaFold DB for complexes involving ${parsed.id}...`, 'loading');
const data = await fetchJsonViaProxy(`https://alphafold.ebi.ac.uk/api/complex/${parsed.id}`);
if (!Array.isArray(data) || data.length === 0) {
throw new Error(`No complexes found for "${parsed.id}". Not all proteins have dimer predictions in AlphaFold DB yet. Try searching on alphafold.ebi.ac.uk and paste the model URL here.`);
}
// Filter to dimers only
dimerList = data.filter(entry => entry.oligomericState === 'dimer');
if (dimerList.length === 0) {
// Show all complexes if no dimers found
dimerList = data;
setStatus(`No dimers found, showing all ${data.length} complex(es). Click a row to load.`, 'success');
} else {
setStatus(`Found ${dimerList.length} dimer(s). Click a row to load.`, 'success');
}
displayDimerTable();
if (dimerList.length === 1) {
// Single result — skip dimer selection table, load directly
selectDimer(0, null);
}
}
} catch (e) {
setStatus(e.message + ' — AlphaFold DB may be temporarily slow. Try again.', 'error');
console.error(e);
}
document.getElementById('btn-fetch').disabled = false;
}
function displayDimerTable() {
const tbody = document.getElementById('dimer-tbody');
tbody.innerHTML = '';
for (let i = 0; i < dimerList.length; i++) {
const entry = dimerList[i];
const accessions = entry.uniprotAccession || [];
const typeTag = entry.assemblyType === 'Homo'
? '<span class="tag tag-homo">homo</span>'
: '<span class="tag tag-hetero">hetero</span>';
const name = entry.complexName || entry.modelEntityId || 'Unknown';
const genes = (entry.gene || []).join(', ') || accessions.join(', ');
const plddt = entry.globalMetricValue != null ? entry.globalMetricValue.toFixed(1) : '—';
const lis = entry.complexPredictionAccuracy_LIS != null ? entry.complexPredictionAccuracy_LIS.toFixed(3) : '—';
const iptm = entry.complexPredictionAccuracy_ipTM != null ? entry.complexPredictionAccuracy_ipTM.toFixed(3) : '—';
const ipsae = entry.complexPredictionAccuracy_ipSAE != null ? entry.complexPredictionAccuracy_ipSAE.toFixed(3) : '—';
const pdockq2 = entry.complexPredictionAccuracy_pDockQ2 != null ? entry.complexPredictionAccuracy_pDockQ2.toFixed(3) : '—';
const tr = document.createElement('tr');
tr.className = 'clickable';
tr.innerHTML = `<td>${esc(name)}</td><td>${typeTag}</td><td>${esc(genes)}</td><td>${plddt}</td><td>${iptm}</td><td>${ipsae}</td><td>${pdockq2}</td><td>${lis}</td>`;
tr.onclick = () => selectDimer(i, tr);
tbody.appendChild(tr);
}
document.getElementById('dimer-results').style.display = '';
makeSortable(document.getElementById('dimer-table'));
}
async function selectDimer(idx, trEl) {
const entry = dimerList[idx];
selectedDimer = entry;
// Show external links and protein info
showExternalLinks(entry);
showProteinInfo(entry);
// Highlight row
document.querySelectorAll('#dimer-tbody tr').forEach(tr => tr.classList.remove('selected'));
if (trEl) trEl.classList.add('selected');
document.getElementById('results').classList.remove('active');
document.getElementById('error-msg').classList.remove('active');
// Reset Mol* viewer
if (viewer3dBlobUrl) { URL.revokeObjectURL(viewer3dBlobUrl); viewer3dBlobUrl = null; }
const v3frame = document.getElementById('viewer3d-frame');
if (v3frame) v3frame.src = 'about:blank';
const v3card = document.getElementById('viewer3d-card');
if (v3card) v3card.style.display = 'none';
const modelEntityId = entry.modelEntityId;
const version = entry.latestVersion || entry.modelVersion || 1;
// Sync URL so the page can be shared / reloaded back to this dimer
if (modelEntityId) {
const url = new URL(window.location);
url.searchParams.set('id', modelEntityId);
history.replaceState({}, '', url);
}
try {
setStatus(`Fetching CIF for ${modelEntityId}...`, 'loading');
const cifUrl = `https://alphafold.ebi.ac.uk/files/${modelEntityId}-model_v${version}.cif`;
dimerCifText = await fetchTextViaProxy(cifUrl);
dimerCifFilename = `${modelEntityId}-model_v${version}.cif`;
setStatus(`Fetching PAE for ${modelEntityId}...`, 'loading');
const paeUrl = `https://alphafold.ebi.ac.uk/files/${modelEntityId}-predicted_aligned_error_v${version}.json`;
dimerPaeData = await fetchJsonViaProxy(paeUrl);
// Fetch UniProt domain annotations and gene symbols per chain
const uniprotIds = entry.uniprotAccession || [];
chainDomains = { A: [], B: [] };
chainTedDomains = { A: [], B: [] };
const domainPromises = [];
if (uniprotIds[0]) domainPromises.push(fetchDomains(uniprotIds[0]).then(d => { chainDomains.A = d;}));
if (uniprotIds[1]) domainPromises.push(fetchDomains(uniprotIds[1]).then(d => { chainDomains.B = d;}));
else if (uniprotIds[0]) domainPromises.push(fetchDomains(uniprotIds[0]).then(d => { chainDomains.B = d; })); // homodimer
// Fetch TED domains in parallel
if (uniprotIds[0]) domainPromises.push(fetchTedDomains(uniprotIds[0]).then(d => { chainTedDomains.A = d; }));
if (uniprotIds[1]) domainPromises.push(fetchTedDomains(uniprotIds[1]).then(d => { chainTedDomains.B = d; }));
else if (uniprotIds[0]) domainPromises.push(fetchTedDomains(uniprotIds[0]).then(d => { chainTedDomains.B = d; })); // homodimer
// Fetch gene symbols from UniProt if not provided by AlphaFold DB
if (!entry.gene || entry.gene.length === 0) {
const genePromises = [...new Set(uniprotIds)].map(async uid => {
try {
const resp = await fetch(`https://rest.uniprot.org/uniprotkb/${uid}.json`);
if (resp.ok) {
const data = await resp.json();
return data.genes?.[0]?.geneName?.value || data.uniProtkbId || uid;
}
} catch {}
return uid;
});
domainPromises.push(Promise.all(genePromises).then(symbols => {
// Map UniProt accessions to gene symbols
const symbolMap = {};
[...new Set(uniprotIds)].forEach((uid, i) => { symbolMap[uid] = symbols[i]; });
entry.gene = uniprotIds.map(uid => symbolMap[uid]);
}));
}
await Promise.allSettled(domainPromises);
// Fetch monomer predictions in background (non-blocking)
monomerData = {};
const uniqueIds = [...new Set(uniprotIds.filter(Boolean))];
fetchMonomerData(uniqueIds);
setStatus('Analyzing...', 'loading');
await new Promise(r => setTimeout(r, 10));
processDimer();
} catch (e) {
setStatus(e.message + ' — AlphaFold DB may be temporarily slow. Try again.', 'error');
console.error(e);
}
}
// ============================================================================
// CIF PARSING
// ============================================================================
function parseCifSequence(cifText) {
// Extract per-chain sequences from CIF CA atoms
const chains = new Map(); // chain -> [{resnum, aa}]
const lines = cifText.split('\n');
let inAtomSite = false;
const colNames = [];
for (const line of lines) {
if (line.startsWith('_atom_site.')) {
inAtomSite = true;
colNames.push(line.trim().split('.')[1]);
continue;
}
if (inAtomSite && !line.startsWith('_atom_site.') && !line.startsWith('#') && line.trim()) {
if (line.startsWith('loop_') || line.startsWith('_')) { inAtomSite = false; continue; }
const parts = line.trim().split(/\s+/);
if (parts.length < colNames.length) continue;
const getCol = (name) => parts[colNames.indexOf(name)] || '';
if (getCol('group_PDB') !== 'ATOM') continue;
if (getCol('label_atom_id') !== 'CA') continue;
const chain = getCol('label_asym_id');
const resSeq = parseInt(getCol('label_seq_id'));
const resName = getCol('label_comp_id');
if (isNaN(resSeq)) continue;
if (!chains.has(chain)) chains.set(chain, []);
const arr = chains.get(chain);
if (!arr.find(r => r.resnum === resSeq)) {
arr.push({ resnum: resSeq, aa: AA3TO1[resName] || 'X' });
}
}
}
return chains; // Map<string, [{resnum, aa}]>
}
// ============================================================================
// UNIPROT DOMAIN ANNOTATIONS
// ============================================================================
async function fetchDomains(uniprotId) {
if (!uniprotId) return [];
if (domainCache.has(uniprotId)) return domainCache.get(uniprotId);
let domains = [];
try {
// Try UniProt curated domains first
const resp = await fetch(`https://rest.uniprot.org/uniprotkb/${uniprotId}.json`);
if (resp.ok) {
const data = await resp.json();
domains = (data.features || [])
.filter(f => f.type === 'Domain')
.map(f => ({ name: f.description || 'Domain', start: f.location?.start?.value, end: f.location?.end?.value }))
.filter(d => d.start != null && d.end != null);
}
// Fallback: InterPro/Pfam if no UniProt domains
if (domains.length === 0) {
const iprResp = await fetch(`https://www.ebi.ac.uk/interpro/api/entry/pfam/protein/uniprot/${uniprotId}?format=json`);
if (iprResp.ok) {
const iprData = await iprResp.json();
for (const entry of (iprData.results || [])) {
const name = entry.metadata?.name || 'Pfam domain';
for (const prot of (entry.proteins || [])) {
for (const loc of (prot.entry_protein_locations || [])) {
for (const frag of (loc.fragments || [])) {
if (frag.start != null && frag.end != null) {
domains.push({ name, start: frag.start, end: frag.end });
}
}
}
}
}
// Sort by start position
domains.sort((a, b) => a.start - b.start);
}
}
} catch (e) {
console.warn(`Failed to fetch domains for ${uniprotId}:`, e);
}
domainCache.set(uniprotId, domains);
return domains;
}
// ============================================================================
// TED DOMAIN ANNOTATIONS (from AlphaFold DB)
// ============================================================================
async function fetchTedDomains(uniprotId) {
if (!uniprotId) return [];
if (tedCache.has(uniprotId)) return tedCache.get(uniprotId);
let domains = [];
try {
const resp = await fetch(`https://alphafold.ebi.ac.uk/api/domains/${uniprotId}`);
if (resp.ok) {
const data = await resp.json();
for (const ann of (data.annotations || [])) {
const segments = (ann.segments || []).map(s => ({ start: s.af_start, end: s.af_end }));
if (segments.length === 0) continue;
const start = Math.min(...segments.map(s => s.start));
const end = Math.max(...segments.map(s => s.end));
const cath = ann.cath_label || '';
const cathLevel = ann.cath_assignment_level || '';
const name = cath ? `TED ${ann.ted_domain_no} (${cath})` : `TED ${ann.ted_domain_no}`;
domains.push({
name, start, end, segments,
cath, cathLevel,
plddt: ann.plddt || 0,
qscore: ann.qscore || 0,
nres: ann.nres_domain || 0,
tedNo: ann.ted_domain_no
});
}
domains.sort((a, b) => a.start - b.start);
}
} catch (e) {
console.warn(`Failed to fetch TED domains for ${uniprotId}:`, e);
}
tedCache.set(uniprotId, domains);
return domains;
}
function buildDimerContactMap() {
const v = dimerPairResult;
const card = document.getElementById('contact-map-card');
const canvas = document.getElementById('contact-canvas');
if (!v || !card || !canvas || !dimerCifText) { if (card) card.style.display = 'none'; return; }
// Apply Min segment filter to both chains; cLIR restricted to filtered LIR
const lirI_f = filterSmallSegments(v.lirI);
const lirJ_f = filterSmallSegments(v.lirJ);
const clirI_f = new Set([...v.clirI].filter(r => lirI_f.has(r)));
const clirJ_f = new Set([...v.clirJ].filter(r => lirJ_f.has(r)));
if (clirI_f.size === 0 || clirJ_f.size === 0) { card.style.display = 'none'; return; }
// Parse Cβ coordinates from CIF
const coords = parseCifCoords(dimerCifText);
const chainCoordMap = new Map();
for (const c of coords) {
if (!chainCoordMap.has(c.chain)) chainCoordMap.set(c.chain, new Map());
chainCoordMap.get(c.chain).set(c.resnum, c);
}