Spaces:
Sleeping
DE engine: add AlphaFold next to ESMFold for large proteins
Browse filesESMFold folds the exact variant but its free public endpoint caps at
~400 aa, so for larger proteins the Fold button was a dead end (disabled
with a "use BLAST → AlphaFold" tooltip and no way to act on it).
Add a second per-variant structure button — "AlphaFold" — beside the
ESMFold one. AlphaFold-DB can't fold a novel sequence (it only serves
precomputed models keyed by UniProt), so this honestly shows the CLOSEST
KNOWN structure: it BLASTs the wild-type (reusing /api/identify, cached
by sequence hash) to find the nearest UniProt match and renders its
AlphaFold-DB model. No length cap, so it's the structure path for
proteins too large for ESMFold.
- Row actions: ESMFold + AlphaFold buttons; for >400 aa the ESMFold
button stays disabled and the AlphaFold one gets a brand-tinted
"suggested" accent so the eye lands on the working path. Tooltips on
both explain exact-variant (ESMFold) vs closest-known (AlphaFold).
- openAlphaFoldModal(): reuses the shared #foldModal, adds an in-modal
BLAST consent step (per-session, same opt-in as page-level Identify),
polls /api/identify with live progress, and mounts the AlphaFold-DB
model into #foldViewer via the existing version-resilient Mol* loader.
- _setFoldModalMode() swaps the modal title + disclaimer between the two
engines; openFoldModal resets to ESMFold and cancels any AF poll.
- mountAlphaFoldViewer(hit, host) generalized to accept a target host so
the page-level embed and the modal share one loader. Disclaimer is
explicit: a reference scaffold for the family, NOT a fold of this
variant's mutations.
- CSS: .alphafold-btn mirrors .fold-btn; .alphafold-btn-suggested accent;
mobile lets .row-actions wrap so two buttons + chevron never overflow.
Cache-buster → v=20260602-foldaf.
Verified in preview at 375px with a synthetic library: 431-aa variant →
ESMFold disabled + AlphaFold suggested; 99-aa → ESMFold enabled; modal
mode-swap + consent + /api/identify body + Mol* mount (TP53/P04637) +
reset-to-ESMFold; no page horizontal overflow. 126 pytest pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- dee/static/app.css +14 -4
- dee/static/app.js +226 -13
- dee/static/index.html +3 -3
|
@@ -1717,7 +1717,8 @@ input:focus, textarea:focus, select:focus {
|
|
| 1717 |
gap: 6px;
|
| 1718 |
white-space: nowrap;
|
| 1719 |
}
|
| 1720 |
-
.fold-btn
|
|
|
|
| 1721 |
/* Inherits .ghost-btn for color + border; tighten the box so it fits
|
| 1722 |
inline with the chevron at the table row height. */
|
| 1723 |
padding: 3px 9px;
|
|
@@ -1725,6 +1726,13 @@ input:focus, textarea:focus, select:focus {
|
|
| 1725 |
line-height: 1.1;
|
| 1726 |
letter-spacing: 0.02em;
|
| 1727 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1728 |
|
| 1729 |
.expand-toggle {
|
| 1730 |
border: 1px solid var(--line-strong);
|
|
@@ -3500,9 +3508,11 @@ body.sidebar-open .sidebar-scrim {
|
|
| 3500 |
.result-table td.rank, .result-table th.rank-h { min-width: 56px; }
|
| 3501 |
.result-table td.num, .result-table th.num { padding-left: 8px; padding-right: 8px; }
|
| 3502 |
|
| 3503 |
-
/*
|
| 3504 |
-
*
|
| 3505 |
-
.result-table .
|
|
|
|
|
|
|
| 3506 |
padding: 4px 8px;
|
| 3507 |
font-size: 10px;
|
| 3508 |
min-width: 0;
|
|
|
|
| 1717 |
gap: 6px;
|
| 1718 |
white-space: nowrap;
|
| 1719 |
}
|
| 1720 |
+
.fold-btn,
|
| 1721 |
+
.alphafold-btn {
|
| 1722 |
/* Inherits .ghost-btn for color + border; tighten the box so it fits
|
| 1723 |
inline with the chevron at the table row height. */
|
| 1724 |
padding: 3px 9px;
|
|
|
|
| 1726 |
line-height: 1.1;
|
| 1727 |
letter-spacing: 0.02em;
|
| 1728 |
}
|
| 1729 |
+
/* When ESMFold can't run (sequence > its length cap), the AlphaFold button is
|
| 1730 |
+
the live alternative — give it a brand-tinted outline so the eye lands on it. */
|
| 1731 |
+
.alphafold-btn-suggested {
|
| 1732 |
+
border-color: var(--brand);
|
| 1733 |
+
color: var(--brand-deep);
|
| 1734 |
+
}
|
| 1735 |
+
.alphafold-btn-suggested:hover { background: var(--brand-50); }
|
| 1736 |
|
| 1737 |
.expand-toggle {
|
| 1738 |
border: 1px solid var(--line-strong);
|
|
|
|
| 3508 |
.result-table td.rank, .result-table th.rank-h { min-width: 56px; }
|
| 3509 |
.result-table td.num, .result-table th.num { padding-left: 8px; padding-right: 8px; }
|
| 3510 |
|
| 3511 |
+
/* Two structure buttons (ESMFold + AlphaFold) share the actions cell on
|
| 3512 |
+
* phones, so shrink them and let the cell wrap instead of overflowing. */
|
| 3513 |
+
.result-table .row-actions { flex-wrap: wrap; gap: 4px; }
|
| 3514 |
+
.result-table .fold-btn,
|
| 3515 |
+
.result-table .alphafold-btn {
|
| 3516 |
padding: 4px 8px;
|
| 3517 |
font-size: 10px;
|
| 3518 |
min-width: 0;
|
|
@@ -1293,19 +1293,28 @@ function renderVariantRows() {
|
|
| 1293 |
<td class="num">${escapeHtml(String(v.Length_bp ?? '—'))}</td>
|
| 1294 |
<td class="row-actions">
|
| 1295 |
${(() => {
|
| 1296 |
-
//
|
| 1297 |
-
//
|
| 1298 |
-
//
|
| 1299 |
-
//
|
| 1300 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1301 |
const aaLen = (v.Mutant_AA_Seq || '').length;
|
| 1302 |
const tooLong = aaLen > ESMFOLD_MAX_RES;
|
| 1303 |
-
|
| 1304 |
? `<button class="fold-btn ghost-btn fold-btn-disabled" data-idx="${idx}" type="button"
|
| 1305 |
disabled aria-label="Sequence too long for ESMFold"
|
| 1306 |
-
title="ESMFold
|
| 1307 |
: `<button class="fold-btn ghost-btn" data-idx="${idx}" type="button"
|
| 1308 |
-
aria-label="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1309 |
})()}
|
| 1310 |
<button class="expand-toggle" data-idx="${idx}" aria-label="Show PCR details">›</button>
|
| 1311 |
</td>
|
|
@@ -1340,6 +1349,15 @@ function renderVariantRows() {
|
|
| 1340 |
openFoldModal(v);
|
| 1341 |
});
|
| 1342 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1343 |
});
|
| 1344 |
}
|
| 1345 |
|
|
@@ -2766,10 +2784,13 @@ function _afShowError(host, transient, retry) {
|
|
| 2766 |
// Mol* viewer mount. Loads the AlphaFold model from the EBI CDN and renders
|
| 2767 |
// it inside #alphafoldViewer. We wait for the molstar global to appear
|
| 2768 |
// (script is loaded async) before mounting.
|
| 2769 |
-
async function mountAlphaFoldViewer(hit) {
|
| 2770 |
-
|
|
|
|
|
|
|
|
|
|
| 2771 |
if (!host) return;
|
| 2772 |
-
const pdbUrl = host.dataset.pdbUrl;
|
| 2773 |
if (!pdbUrl) return;
|
| 2774 |
|
| 2775 |
const molstar = await _afWaitMolstar();
|
|
@@ -2784,13 +2805,13 @@ async function mountAlphaFoldViewer(hit) {
|
|
| 2784 |
if (!await _afTryLoad(viewer, candidates)) {
|
| 2785 |
// exists === false → genuinely no model; otherwise treat as a
|
| 2786 |
// transient EBI blip and offer a retry.
|
| 2787 |
-
_afShowError(host, exists !== false, () => mountAlphaFoldViewer(hit));
|
| 2788 |
return;
|
| 2789 |
}
|
| 2790 |
const overlay = host.querySelector('.alphafold-loading');
|
| 2791 |
if (overlay) overlay.remove();
|
| 2792 |
} catch (err) {
|
| 2793 |
-
_afShowError(host, true, () => mountAlphaFoldViewer(hit));
|
| 2794 |
}
|
| 2795 |
}
|
| 2796 |
|
|
@@ -2908,6 +2929,11 @@ async function openFoldModal(variant) {
|
|
| 2908 |
const host = document.getElementById('foldViewer');
|
| 2909 |
if (!modal || !host) return;
|
| 2910 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2911 |
const aaLen = (variant.Mutant_AA_Seq || '').length;
|
| 2912 |
|
| 2913 |
// First-time gate: ESMFold sends the variant's protein sequence to Meta.
|
|
@@ -3045,6 +3071,193 @@ function closeFoldModal() {
|
|
| 3045 |
// Mark the in-flight fold as orphaned so its response (if it eventually
|
| 3046 |
// arrives) won't try to mount into a hidden host.
|
| 3047 |
foldInFlightVariant = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3048 |
}
|
| 3049 |
|
| 3050 |
function showToast(message, level = 'info') {
|
|
|
|
| 1293 |
<td class="num">${escapeHtml(String(v.Length_bp ?? '—'))}</td>
|
| 1294 |
<td class="row-actions">
|
| 1295 |
${(() => {
|
| 1296 |
+
// Two structure engines, side by side:
|
| 1297 |
+
// • ESMFold folds THIS exact variant, but its free public
|
| 1298 |
+
// endpoint caps at ~400 aa — so it's pre-gated (disabled
|
| 1299 |
+
// with a tooltip) for longer proteins instead of dead-
|
| 1300 |
+
// ending on click.
|
| 1301 |
+
// • AlphaFold has NO length cap, but can't fold a novel
|
| 1302 |
+
// sequence: it shows the closest KNOWN structure found by
|
| 1303 |
+
// BLAST → AlphaFold-DB. That makes it the path for large
|
| 1304 |
+
// proteins ESMFold can't handle, so we flag it as such.
|
| 1305 |
const aaLen = (v.Mutant_AA_Seq || '').length;
|
| 1306 |
const tooLong = aaLen > ESMFOLD_MAX_RES;
|
| 1307 |
+
const esm = tooLong
|
| 1308 |
? `<button class="fold-btn ghost-btn fold-btn-disabled" data-idx="${idx}" type="button"
|
| 1309 |
disabled aria-label="Sequence too long for ESMFold"
|
| 1310 |
+
title="ESMFold folds the exact variant but its free endpoint caps at ${ESMFOLD_MAX_RES} aa (this protein is ${aaLen} aa). Use AlphaFold → for larger proteins.">ESMFold</button>`
|
| 1311 |
: `<button class="fold-btn ghost-btn" data-idx="${idx}" type="button"
|
| 1312 |
+
aria-label="Fold this exact variant with ESMFold (≤${ESMFOLD_MAX_RES} aa)"
|
| 1313 |
+
title="ESMFold · folds this exact variant (≤${ESMFOLD_MAX_RES} aa)">ESMFold</button>`;
|
| 1314 |
+
const af = `<button class="alphafold-btn ghost-btn${tooLong ? ' alphafold-btn-suggested' : ''}" data-idx="${idx}" type="button"
|
| 1315 |
+
aria-label="Closest known structure via AlphaFold-DB — no length cap, best for large proteins"
|
| 1316 |
+
title="AlphaFold · closest known structure (BLAST → AlphaFold-DB). No length cap — the path for proteins too large for ESMFold.">AlphaFold</button>`;
|
| 1317 |
+
return esm + af;
|
| 1318 |
})()}
|
| 1319 |
<button class="expand-toggle" data-idx="${idx}" aria-label="Show PCR details">›</button>
|
| 1320 |
</td>
|
|
|
|
| 1349 |
openFoldModal(v);
|
| 1350 |
});
|
| 1351 |
}
|
| 1352 |
+
// Per-row AlphaFold button → closest-known-structure modal (BLAST →
|
| 1353 |
+
// AlphaFold-DB). The structure path for proteins too large for ESMFold.
|
| 1354 |
+
const afBtn = tr.querySelector('.alphafold-btn');
|
| 1355 |
+
if (afBtn) {
|
| 1356 |
+
afBtn.addEventListener('click', (e) => {
|
| 1357 |
+
e.stopPropagation();
|
| 1358 |
+
openAlphaFoldModal(v);
|
| 1359 |
+
});
|
| 1360 |
+
}
|
| 1361 |
});
|
| 1362 |
}
|
| 1363 |
|
|
|
|
| 2784 |
// Mol* viewer mount. Loads the AlphaFold model from the EBI CDN and renders
|
| 2785 |
// it inside #alphafoldViewer. We wait for the molstar global to appear
|
| 2786 |
// (script is loaded async) before mounting.
|
| 2787 |
+
async function mountAlphaFoldViewer(hit, host) {
|
| 2788 |
+
// `host` defaults to the page-level identify embed, but the per-variant
|
| 2789 |
+
// AlphaFold modal passes its own host (#foldViewer) so the same resilient
|
| 2790 |
+
// loader serves both embeds.
|
| 2791 |
+
host = host || document.getElementById('alphafoldViewer');
|
| 2792 |
if (!host) return;
|
| 2793 |
+
const pdbUrl = host.dataset.pdbUrl || (hit && hit.alphafold_url);
|
| 2794 |
if (!pdbUrl) return;
|
| 2795 |
|
| 2796 |
const molstar = await _afWaitMolstar();
|
|
|
|
| 2805 |
if (!await _afTryLoad(viewer, candidates)) {
|
| 2806 |
// exists === false → genuinely no model; otherwise treat as a
|
| 2807 |
// transient EBI blip and offer a retry.
|
| 2808 |
+
_afShowError(host, exists !== false, () => mountAlphaFoldViewer(hit, host));
|
| 2809 |
return;
|
| 2810 |
}
|
| 2811 |
const overlay = host.querySelector('.alphafold-loading');
|
| 2812 |
if (overlay) overlay.remove();
|
| 2813 |
} catch (err) {
|
| 2814 |
+
_afShowError(host, true, () => mountAlphaFoldViewer(hit, host));
|
| 2815 |
}
|
| 2816 |
}
|
| 2817 |
|
|
|
|
| 2929 |
const host = document.getElementById('foldViewer');
|
| 2930 |
if (!modal || !host) return;
|
| 2931 |
|
| 2932 |
+
// The modal is shared with the AlphaFold path — reset its chrome to
|
| 2933 |
+
// ESMFold and cancel any AlphaFold BLAST poll that was still running.
|
| 2934 |
+
_setFoldModalMode('esm', null);
|
| 2935 |
+
if (alphaFoldPollHandle) { clearTimeout(alphaFoldPollHandle); alphaFoldPollHandle = null; }
|
| 2936 |
+
|
| 2937 |
const aaLen = (variant.Mutant_AA_Seq || '').length;
|
| 2938 |
|
| 2939 |
// First-time gate: ESMFold sends the variant's protein sequence to Meta.
|
|
|
|
| 3071 |
// Mark the in-flight fold as orphaned so its response (if it eventually
|
| 3072 |
// arrives) won't try to mount into a hidden host.
|
| 3073 |
foldInFlightVariant = null;
|
| 3074 |
+
if (alphaFoldPollHandle) { clearTimeout(alphaFoldPollHandle); alphaFoldPollHandle = null; }
|
| 3075 |
+
}
|
| 3076 |
+
|
| 3077 |
+
// ── AlphaFold path: closest known structure, for proteins ESMFold can't fold ─
|
| 3078 |
+
// ESMFold (above) folds the EXACT variant but its public endpoint caps at
|
| 3079 |
+
// ~400 aa. AlphaFold-DB can't fold a novel sequence at all — it serves only
|
| 3080 |
+
// precomputed models keyed by UniProt accession. So for large (or any)
|
| 3081 |
+
// proteins we BLAST the wild-type to find the nearest KNOWN protein and show
|
| 3082 |
+
// ITS AlphaFold-DB model: a reference scaffold for the family, at any length —
|
| 3083 |
+
// honestly NOT a fold of this variant's specific mutations. We reuse the
|
| 3084 |
+
// /api/identify BLAST job (cached by sequence hash, so a prior Identify run
|
| 3085 |
+
// returns instantly) and the same version-resilient Mol* loader as the
|
| 3086 |
+
// page-level embed.
|
| 3087 |
+
let alphaFoldPollHandle = null;
|
| 3088 |
+
|
| 3089 |
+
// Swap the shared #foldModal between its two engines (chrome only — title +
|
| 3090 |
+
// disclaimer). `subText === null` leaves the sub-line for the caller to manage.
|
| 3091 |
+
function _setFoldModalMode(mode, subText) {
|
| 3092 |
+
const title = document.getElementById('foldModalTitle');
|
| 3093 |
+
const sub = document.getElementById('foldModalSub');
|
| 3094 |
+
const disc = document.getElementById('foldModalDisclaimer');
|
| 3095 |
+
if (mode === 'alphafold') {
|
| 3096 |
+
if (title) title.textContent = 'Closest known structure · AlphaFold-DB';
|
| 3097 |
+
if (disc) disc.innerHTML =
|
| 3098 |
+
'Closest known protein to your <strong>wild-type</strong>, found via ' +
|
| 3099 |
+
'<a href="https://blast.ncbi.nlm.nih.gov" target="_blank" rel="noopener">NCBI BLAST</a> ' +
|
| 3100 |
+
'and rendered from <a href="https://alphafold.ebi.ac.uk" target="_blank" rel="noopener">AlphaFold-DB</a>. ' +
|
| 3101 |
+
'No length cap — the structure path for proteins too large for ESMFold. ' +
|
| 3102 |
+
'<strong>This is a reference scaffold for the protein family, not a fold of this variant’s mutations.</strong> ' +
|
| 3103 |
+
'Drag to rotate · scroll to zoom · double-click to fit. ' +
|
| 3104 |
+
'Backbone confidence colored by pLDDT (blue = high, orange = low).';
|
| 3105 |
+
} else {
|
| 3106 |
+
if (title) title.textContent = 'Predicted structure · ESMFold';
|
| 3107 |
+
if (disc) disc.innerHTML =
|
| 3108 |
+
'Predicted by <a href="https://esmatlas.com/about" target="_blank" rel="noopener">ESMFold</a> (Meta AI). ' +
|
| 3109 |
+
'<strong>The variant’s amino-acid sequence is sent to <code>api.esmatlas.com</code></strong> ' +
|
| 3110 |
+
'over HTTPS — encrypted in transit, visible to Meta’s servers. Do not fold ' +
|
| 3111 |
+
'confidential or pre-publication sequences. ' +
|
| 3112 |
+
'Drag to rotate · scroll to zoom · double-click to fit. ' +
|
| 3113 |
+
'Backbone confidence colored by pLDDT (blue = high, orange = low).';
|
| 3114 |
+
}
|
| 3115 |
+
if (sub && subText != null) sub.textContent = subText;
|
| 3116 |
+
}
|
| 3117 |
+
|
| 3118 |
+
async function openAlphaFoldModal(variant) {
|
| 3119 |
+
const modal = document.getElementById('foldModal');
|
| 3120 |
+
const host = document.getElementById('foldViewer');
|
| 3121 |
+
if (!modal || !host) return;
|
| 3122 |
+
|
| 3123 |
+
if (!state.sessionId) {
|
| 3124 |
+
showToast('Load and run a sequence first — AlphaFold needs the wild-type to search.', 'warn');
|
| 3125 |
+
return;
|
| 3126 |
+
}
|
| 3127 |
+
|
| 3128 |
+
// BLAST consent (same per-session opt-in as the page-level Identify): the
|
| 3129 |
+
// wild-type sequence is sent to NCBI. Show an in-modal consent step the
|
| 3130 |
+
// first time, then remember it for the session.
|
| 3131 |
+
if (!hasBlastConsent()) {
|
| 3132 |
+
_setFoldModalMode('alphafold', 'awaiting consent');
|
| 3133 |
+
host.innerHTML = `
|
| 3134 |
+
<div class="fold-consent">
|
| 3135 |
+
<p class="fold-consent-kicker">§ Consent</p>
|
| 3136 |
+
<h3 class="fold-consent-title"><em>Search NCBI for a known structure?</em></h3>
|
| 3137 |
+
<p class="fold-consent-body">
|
| 3138 |
+
AlphaFold-DB only holds models for <em>known</em> proteins, so to show
|
| 3139 |
+
one we send your <strong>wild-type</strong> protein sequence to
|
| 3140 |
+
<code>blast.ncbi.nlm.nih.gov</code> to find the closest match, then load
|
| 3141 |
+
its structure from <code>alphafold.ebi.ac.uk</code>. Takes ~30–90 s.
|
| 3142 |
+
</p>
|
| 3143 |
+
<p class="fold-consent-body">
|
| 3144 |
+
<em>Skip this if your sequence is confidential or pre-publication IP.</em>
|
| 3145 |
+
Scoring, search and codon optimization stay on-server; only this opt-in
|
| 3146 |
+
BLAST leaves the machine.
|
| 3147 |
+
</p>
|
| 3148 |
+
<div class="fold-consent-actions">
|
| 3149 |
+
<button class="ghost-btn" type="button" data-af-cancel>Cancel</button>
|
| 3150 |
+
<button class="primary" type="button" data-af-consent>
|
| 3151 |
+
Continue · remember for this session
|
| 3152 |
+
</button>
|
| 3153 |
+
</div>
|
| 3154 |
+
</div>
|
| 3155 |
+
`;
|
| 3156 |
+
modal.hidden = false;
|
| 3157 |
+
bindFoldModalDismiss();
|
| 3158 |
+
const cancelBtn = host.querySelector('[data-af-cancel]');
|
| 3159 |
+
const consentBtn = host.querySelector('[data-af-consent]');
|
| 3160 |
+
if (cancelBtn) cancelBtn.addEventListener('click', closeFoldModal);
|
| 3161 |
+
if (consentBtn) consentBtn.addEventListener('click', () => {
|
| 3162 |
+
grantBlastConsent();
|
| 3163 |
+
openAlphaFoldModal(variant); // re-enter now that consent is recorded
|
| 3164 |
+
});
|
| 3165 |
+
return;
|
| 3166 |
+
}
|
| 3167 |
+
|
| 3168 |
+
// Orphan any pending ESMFold response so it can't mount over this one.
|
| 3169 |
+
foldInFlightVariant = null;
|
| 3170 |
+
if (alphaFoldPollHandle) { clearTimeout(alphaFoldPollHandle); alphaFoldPollHandle = null; }
|
| 3171 |
+
|
| 3172 |
+
_setFoldModalMode('alphafold', 'Searching NCBI for the closest known structure…');
|
| 3173 |
+
host.innerHTML = `
|
| 3174 |
+
<div class="alphafold-loading">
|
| 3175 |
+
<span class="identify-spinner"></span>
|
| 3176 |
+
Searching NCBI for the closest known protein… (30–90 s)
|
| 3177 |
+
</div>
|
| 3178 |
+
`;
|
| 3179 |
+
modal.hidden = false;
|
| 3180 |
+
bindFoldModalDismiss();
|
| 3181 |
+
|
| 3182 |
+
try {
|
| 3183 |
+
const res = await fetch('/api/identify', {
|
| 3184 |
+
method: 'POST',
|
| 3185 |
+
headers: { 'Content-Type': 'application/json' },
|
| 3186 |
+
body: JSON.stringify({
|
| 3187 |
+
session_id: state.sessionId,
|
| 3188 |
+
cds_feature: state.chosenCds,
|
| 3189 |
+
blast_consent: hasBlastConsent(),
|
| 3190 |
+
}),
|
| 3191 |
+
});
|
| 3192 |
+
const data = await res.json();
|
| 3193 |
+
if (!res.ok) throw new Error(data.error || 'BLAST submission failed.');
|
| 3194 |
+
if (data.cached && data.status === 'done') { _renderFoldAlphaFold(data, host); return; }
|
| 3195 |
+
_pollAlphaFoldModal(data.job_id, host);
|
| 3196 |
+
} catch (err) {
|
| 3197 |
+
host.innerHTML =
|
| 3198 |
+
`<div class="alphafold-loading"><strong>Couldn’t reach NCBI BLAST.</strong><br>` +
|
| 3199 |
+
`<span style="opacity:.75">${escapeHtml(err.message || String(err))}</span></div>`;
|
| 3200 |
+
}
|
| 3201 |
+
}
|
| 3202 |
+
|
| 3203 |
+
function _pollAlphaFoldModal(jobId, host) {
|
| 3204 |
+
if (alphaFoldPollHandle) clearTimeout(alphaFoldPollHandle);
|
| 3205 |
+
alphaFoldPollHandle = setTimeout(async () => {
|
| 3206 |
+
const modal = document.getElementById('foldModal');
|
| 3207 |
+
if (!modal || modal.hidden) return; // user closed the modal — stop
|
| 3208 |
+
try {
|
| 3209 |
+
const res = await fetch(`/api/identify/${jobId}`);
|
| 3210 |
+
const data = await res.json();
|
| 3211 |
+
if (!res.ok) throw new Error(data.error || 'Lost the BLAST job.');
|
| 3212 |
+
if (data.status === 'done') { _renderFoldAlphaFold(data, host); return; }
|
| 3213 |
+
if (data.status === 'error') {
|
| 3214 |
+
host.innerHTML =
|
| 3215 |
+
`<div class="alphafold-loading"><strong>BLAST failed.</strong><br>` +
|
| 3216 |
+
`<span style="opacity:.75">${escapeHtml(data.error || 'unknown error')}</span></div>`;
|
| 3217 |
+
return;
|
| 3218 |
+
}
|
| 3219 |
+
const elapsed = data.elapsed_seconds != null ? data.elapsed_seconds.toFixed(0) : '0';
|
| 3220 |
+
const phase = { pending: 'Queued', submitting: 'Submitting to NCBI',
|
| 3221 |
+
running: 'NCBI is searching nr', parsing: 'Parsing results' }[data.status] || data.status;
|
| 3222 |
+
host.innerHTML =
|
| 3223 |
+
`<div class="alphafold-loading"><span class="identify-spinner"></span> ` +
|
| 3224 |
+
`${escapeHtml(phase)} · ${escapeHtml(elapsed)}s (NCBI queues can take 30–90 s)</div>`;
|
| 3225 |
+
_pollAlphaFoldModal(jobId, host);
|
| 3226 |
+
} catch (err) {
|
| 3227 |
+
host.innerHTML =
|
| 3228 |
+
`<div class="alphafold-loading"><strong>Lost the BLAST job.</strong><br>` +
|
| 3229 |
+
`<span style="opacity:.75">${escapeHtml(err.message || String(err))}</span></div>`;
|
| 3230 |
+
}
|
| 3231 |
+
}, 2000);
|
| 3232 |
+
}
|
| 3233 |
+
|
| 3234 |
+
function _renderFoldAlphaFold(data, host) {
|
| 3235 |
+
const hits = (data && data.hits) || [];
|
| 3236 |
+
// First UniProt-mapped hit in the top 5 (the very top may be RefSeq-only).
|
| 3237 |
+
const afHit = hits.slice(0, 5).find(h => h.uniprot && h.alphafold_url);
|
| 3238 |
+
const sub = document.getElementById('foldModalSub');
|
| 3239 |
+
if (!afHit) {
|
| 3240 |
+
const top = hits[0];
|
| 3241 |
+
host.innerHTML = `
|
| 3242 |
+
<div class="alphafold-loading">
|
| 3243 |
+
<strong>No known structure to show.</strong><br>
|
| 3244 |
+
<span style="opacity:.8">${hits.length
|
| 3245 |
+
? 'The closest NCBI match' + (top && top.description ? ' (' + escapeHtml(top.description) + ')' : '') +
|
| 3246 |
+
' has no UniProt / AlphaFold-DB entry. '
|
| 3247 |
+
: 'No significant NCBI matches — this sequence may be de novo or heavily engineered. '}
|
| 3248 |
+
For sequences ≤ ${ESMFOLD_MAX_RES} aa you can fold the exact variant with <em>ESMFold</em>.</span>
|
| 3249 |
+
</div>`;
|
| 3250 |
+
if (sub) sub.textContent = 'No AlphaFold model available';
|
| 3251 |
+
return;
|
| 3252 |
+
}
|
| 3253 |
+
if (sub) sub.textContent =
|
| 3254 |
+
`Closest known: UniProt ${afHit.uniprot}${afHit.organism ? ' · ' + afHit.organism : ''}`;
|
| 3255 |
+
// Mount straight into #foldViewer (it already carries .alphafold-viewer).
|
| 3256 |
+
host.dataset.pdbUrl = afHit.alphafold_url;
|
| 3257 |
+
host.dataset.uniprot = afHit.uniprot;
|
| 3258 |
+
host.innerHTML =
|
| 3259 |
+
'<div class="alphafold-loading"><span class="identify-spinner"></span> Loading AlphaFold-DB structure…</div>';
|
| 3260 |
+
mountAlphaFoldViewer(afHit, host);
|
| 3261 |
}
|
| 3262 |
|
| 3263 |
function showToast(message, level = 'info') {
|
|
@@ -22,7 +22,7 @@
|
|
| 22 |
<!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
|
| 23 |
app.js change. Bump these numbers whenever you ship a frontend update —
|
| 24 |
without them, users keep getting the stale file for up to a week. -->
|
| 25 |
-
<link rel="stylesheet" href="/static/app.css?v=20260602-
|
| 26 |
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
|
| 27 |
<link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
|
| 28 |
<!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
|
|
@@ -1074,7 +1074,7 @@
|
|
| 1074 |
Submitting sequence to ESMFold…
|
| 1075 |
</div>
|
| 1076 |
</div>
|
| 1077 |
-
<div class="alphafold-disclaimer">
|
| 1078 |
Predicted by <a href="https://esmatlas.com/about" target="_blank" rel="noopener">ESMFold</a> (Meta AI).
|
| 1079 |
<strong>The variant's amino-acid sequence is sent to <code>api.esmatlas.com</code></strong>
|
| 1080 |
over HTTPS — encrypted in transit, visible to Meta's servers. Do not fold
|
|
@@ -1187,6 +1187,6 @@
|
|
| 1187 |
<!-- Cloning reference data must load before app.js so the Designer
|
| 1188 |
can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
|
| 1189 |
<script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
|
| 1190 |
-
<script src="/static/app.js?v=20260602-
|
| 1191 |
</body>
|
| 1192 |
</html>
|
|
|
|
| 22 |
<!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
|
| 23 |
app.js change. Bump these numbers whenever you ship a frontend update —
|
| 24 |
without them, users keep getting the stale file for up to a week. -->
|
| 25 |
+
<link rel="stylesheet" href="/static/app.css?v=20260602-foldaf" />
|
| 26 |
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
|
| 27 |
<link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
|
| 28 |
<!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
|
|
|
|
| 1074 |
Submitting sequence to ESMFold…
|
| 1075 |
</div>
|
| 1076 |
</div>
|
| 1077 |
+
<div class="alphafold-disclaimer" id="foldModalDisclaimer">
|
| 1078 |
Predicted by <a href="https://esmatlas.com/about" target="_blank" rel="noopener">ESMFold</a> (Meta AI).
|
| 1079 |
<strong>The variant's amino-acid sequence is sent to <code>api.esmatlas.com</code></strong>
|
| 1080 |
over HTTPS — encrypted in transit, visible to Meta's servers. Do not fold
|
|
|
|
| 1187 |
<!-- Cloning reference data must load before app.js so the Designer
|
| 1188 |
can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
|
| 1189 |
<script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
|
| 1190 |
+
<script src="/static/app.js?v=20260602-foldaf" defer></script>
|
| 1191 |
</body>
|
| 1192 |
</html>
|