Spaces:
Sleeping
Sleeping
Mark liability residues magenta in the sequence tracks (match 3D)
Browse files
app.py
CHANGED
|
@@ -359,21 +359,31 @@ def format_flags(flags, h3_len, ok):
|
|
| 359 |
|
| 360 |
|
| 361 |
# -------------------------------------------------------------------- viewer
|
| 362 |
-
# Per-residue colors for the clickable sequence tracks (CDRs reuse the 3D colors
|
|
|
|
| 363 |
TRACK_COLORS = {
|
| 364 |
"H1": CDR_COLORS["H"]["1"], "H2": CDR_COLORS["H"]["2"], "H3": CDR_COLORS["H"]["3"],
|
| 365 |
"L1": CDR_COLORS["L"]["1"], "L2": CDR_COLORS["L"]["2"], "L3": CDR_COLORS["L"]["3"],
|
| 366 |
-
"fw": "#eceff1",
|
| 367 |
}
|
| 368 |
|
| 369 |
|
| 370 |
-
def build_track(chain_label: str, residues):
|
| 371 |
"""Numbered residues -> (HighlightedText tokens, index->imgt map).
|
| 372 |
-
Each residue is its own token (combine_adjacent=False) so it clicks individually.
|
|
|
|
|
|
|
| 373 |
tokens, idxmap = [], []
|
|
|
|
| 374 |
for imgt, _ins, aa in residues:
|
| 375 |
cdr = cdr_of(imgt)
|
| 376 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
idxmap.append(imgt)
|
| 378 |
return tokens, idxmap
|
| 379 |
|
|
@@ -511,8 +521,8 @@ def fold(heavy: str, light: str):
|
|
| 511 |
f"CDRs highlighted (H: yellow/orange/red, L: cyan/blue).")
|
| 512 |
flags_md = format_flags(flags, h3_len, ok)
|
| 513 |
|
| 514 |
-
h_tokens, h_idx = build_track("H", number_chain(heavy) or [])
|
| 515 |
-
l_tokens, l_idx = build_track("L", number_chain(light) or [])
|
| 516 |
idxmap = {"H": h_idx, "L": l_idx}
|
| 517 |
payload = build_payload(pdb, highlights) # -> client-side viewer via .change bridge
|
| 518 |
return (status, flags_md, "myabs_fold.pdb", payload,
|
|
@@ -582,7 +592,8 @@ with gr.Blocks(title="MyAbs") as demo: # theme moved to launch() in Gradio 6
|
|
| 582 |
)
|
| 583 |
gr.Markdown(
|
| 584 |
"**Click a residue below to highlight it on the structure (lime stick).** "
|
| 585 |
-
"Click it again to remove it. CDR residues are pre-colored
|
|
|
|
| 586 |
)
|
| 587 |
h_track = gr.HighlightedText(label="Heavy chain (VH)", combine_adjacent=False,
|
| 588 |
show_legend=False, color_map=TRACK_COLORS)
|
|
|
|
| 359 |
|
| 360 |
|
| 361 |
# -------------------------------------------------------------------- viewer
|
| 362 |
+
# Per-residue colors for the clickable sequence tracks (CDRs reuse the 3D colors;
|
| 363 |
+
# "liab" is the same magenta as the liability sticks on the structure).
|
| 364 |
TRACK_COLORS = {
|
| 365 |
"H1": CDR_COLORS["H"]["1"], "H2": CDR_COLORS["H"]["2"], "H3": CDR_COLORS["H"]["3"],
|
| 366 |
"L1": CDR_COLORS["L"]["1"], "L2": CDR_COLORS["L"]["2"], "L3": CDR_COLORS["L"]["3"],
|
| 367 |
+
"liab": "#ff00ff", "fw": "#eceff1",
|
| 368 |
}
|
| 369 |
|
| 370 |
|
| 371 |
+
def build_track(chain_label: str, residues, liab_imgts=()):
|
| 372 |
"""Numbered residues -> (HighlightedText tokens, index->imgt map).
|
| 373 |
+
Each residue is its own token (combine_adjacent=False) so it clicks individually.
|
| 374 |
+
Liability residues (same set shown as magenta sticks in 3D) are tagged 'liab'
|
| 375 |
+
so they read magenta in the sequence, matching the structure."""
|
| 376 |
tokens, idxmap = [], []
|
| 377 |
+
liab = set(liab_imgts)
|
| 378 |
for imgt, _ins, aa in residues:
|
| 379 |
cdr = cdr_of(imgt)
|
| 380 |
+
if imgt in liab:
|
| 381 |
+
cat = "liab"
|
| 382 |
+
elif cdr:
|
| 383 |
+
cat = f"{chain_label}{cdr}"
|
| 384 |
+
else:
|
| 385 |
+
cat = "fw"
|
| 386 |
+
tokens.append((aa, cat))
|
| 387 |
idxmap.append(imgt)
|
| 388 |
return tokens, idxmap
|
| 389 |
|
|
|
|
| 521 |
f"CDRs highlighted (H: yellow/orange/red, L: cyan/blue).")
|
| 522 |
flags_md = format_flags(flags, h3_len, ok)
|
| 523 |
|
| 524 |
+
h_tokens, h_idx = build_track("H", number_chain(heavy) or [], highlights.get("H", []))
|
| 525 |
+
l_tokens, l_idx = build_track("L", number_chain(light) or [], highlights.get("L", []))
|
| 526 |
idxmap = {"H": h_idx, "L": l_idx}
|
| 527 |
payload = build_payload(pdb, highlights) # -> client-side viewer via .change bridge
|
| 528 |
return (status, flags_md, "myabs_fold.pdb", payload,
|
|
|
|
| 592 |
)
|
| 593 |
gr.Markdown(
|
| 594 |
"**Click a residue below to highlight it on the structure (lime stick).** "
|
| 595 |
+
"Click it again to remove it. CDR residues are pre-colored; "
|
| 596 |
+
"**liability residues are magenta** (same as the sticks in 3D)."
|
| 597 |
)
|
| 598 |
h_track = gr.HighlightedText(label="Heavy chain (VH)", combine_adjacent=False,
|
| 599 |
show_legend=False, color_map=TRACK_COLORS)
|