Spaces:
Sleeping
Fix reported production bugs: stuck dropdowns, blocked SNP, session loop
Browse filesFrom a user bug report (4 issues):
(4) Stuck/overlapping toolbar dropdowns — opening "GenBank ▾" then "Use in ▾"
left BOTH open and overlapping: each button's stopPropagation blocked the
other menu's outside-click close. Now opening one closes the other
(operate on all .plasmid-export-menu); outside-click closes all. Verified.
(2) "Couldn't do a single-nucleotide mutation" on the DE engine — a SNP that
creates a stop codon was hard-blocked at BOTH layers (client save disabled;
server 400) with a FALSE "synthesis vendors will reject this" claim. A
premature stop is a legitimate nonsense/truncation mutation; vendors
synthesize it fine. Now allowed: server truncates the product at the first
stop (no raise); client downgrades the warning high→medium so Save works.
Frame-break (non-×3) and non-ACGT still correctly block. +4 tests.
(1) "Session out of sync" that reload/re-signin won't clear — confirmed a
stale-token loop (works in a fresh/incognito session). auth.js now CLEARS
the cached access/refresh tokens before the reload + sign-in recovery
actions, so a dead token can't keep masking a fresh login (the wrapper
re-injects, or the user falls through to a clean sign-in — no loop).
(3) Intro-screen hang is in the landing /app wrapper (separate Hostinger
deploy) — fixed there separately.
214 pytest pass; (2) + (4) verified live in preview; (1) auth.js token-clear
in place. Cache-buster → v=20260604-bugfix (app.js/css + auth.js).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- dee/server.py +15 -22
- dee/static/app.js +23 -5
- dee/static/auth.js +20 -1
- dee/static/index.html +3 -3
- tests/test_rederive.py +44 -0
|
@@ -985,8 +985,9 @@ def create_app() -> Flask:
|
|
| 985 |
calls return the edited sequence. Returns the full updated row so
|
| 986 |
the frontend can replace its local copy without a second fetch.
|
| 987 |
|
| 988 |
-
Rejects with 400 if the DNA isn't ACGT
|
| 989 |
-
|
|
|
|
| 990 |
"""
|
| 991 |
job = _get_job(job_id)
|
| 992 |
if not job:
|
|
@@ -2579,9 +2580,10 @@ def _rederive_variant_row(
|
|
| 2579 |
"""Recompute every derived column of a variant row from a new DNA string.
|
| 2580 |
|
| 2581 |
The user's edit is treated as authoritative. We validate (ACGT only,
|
| 2582 |
-
length multiple of 3,
|
| 2583 |
-
|
| 2584 |
-
|
|
|
|
| 2585 |
|
| 2586 |
Raises ValueError with a user-readable message on validation failure —
|
| 2587 |
callers should turn that into HTTP 400 so the frontend can display it.
|
|
@@ -2605,24 +2607,15 @@ def _rederive_variant_row(
|
|
| 2605 |
"is divisible by 3 before saving."
|
| 2606 |
)
|
| 2607 |
|
| 2608 |
-
# Translate
|
| 2609 |
-
#
|
| 2610 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2611 |
raw_protein = str(Seq(cleaned).translate(table=1, to_stop=False))
|
| 2612 |
-
|
| 2613 |
-
protein = raw_protein[:-1]
|
| 2614 |
-
else:
|
| 2615 |
-
protein = raw_protein
|
| 2616 |
-
|
| 2617 |
-
# Premature-stop check — anything other than a single terminal stop is
|
| 2618 |
-
# a frame-shift / lab disaster, refuse the save.
|
| 2619 |
-
if "*" in protein:
|
| 2620 |
-
idx = protein.find("*")
|
| 2621 |
-
raise ValueError(
|
| 2622 |
-
f"Edited DNA contains a premature stop codon at amino-acid "
|
| 2623 |
-
f"position {idx + 1}. Synthesis vendors will reject this; "
|
| 2624 |
-
"remove the stop before saving."
|
| 2625 |
-
)
|
| 2626 |
|
| 2627 |
# Mutations label — diff against WT. For length-changing edits this
|
| 2628 |
# prefixes a 'length:...' marker so the frontend can warn loudly.
|
|
|
|
| 985 |
calls return the edited sequence. Returns the full updated row so
|
| 986 |
the frontend can replace its local copy without a second fetch.
|
| 987 |
|
| 988 |
+
Rejects with 400 if the DNA isn't ACGT or isn't a multiple of 3.
|
| 989 |
+
A premature stop is allowed (nonsense/truncation mutation) and simply
|
| 990 |
+
truncates the encoded product.
|
| 991 |
"""
|
| 992 |
job = _get_job(job_id)
|
| 993 |
if not job:
|
|
|
|
| 2580 |
"""Recompute every derived column of a variant row from a new DNA string.
|
| 2581 |
|
| 2582 |
The user's edit is treated as authoritative. We validate (ACGT only,
|
| 2583 |
+
length multiple of 3), translate (a premature stop is allowed — it
|
| 2584 |
+
truncates the product, e.g. an intentional nonsense/knockout mutation),
|
| 2585 |
+
diff against WT for the Mutations_AA label, recompute PCR metrics, and
|
| 2586 |
+
report restriction-site presence honestly.
|
| 2587 |
|
| 2588 |
Raises ValueError with a user-readable message on validation failure —
|
| 2589 |
callers should turn that into HTTP 400 so the frontend can display it.
|
|
|
|
| 2607 |
"is divisible by 3 before saving."
|
| 2608 |
)
|
| 2609 |
|
| 2610 |
+
# Translate. Stop codons appear as '*'. A premature stop is a LEGITIMATE
|
| 2611 |
+
# edit — a nonsense / truncation mutation (e.g. an intentional knockout or
|
| 2612 |
+
# a single-base SNP that happens to create a stop). We don't block it:
|
| 2613 |
+
# synthesis vendors synthesize the DNA as-is, they don't reject internal
|
| 2614 |
+
# stops. The encoded protein simply ends at the first stop; the user's
|
| 2615 |
+
# client shows a non-blocking heads-up. (Previously this hard-rejected the
|
| 2616 |
+
# save with a false "vendors will reject this" claim — an audit finding.)
|
| 2617 |
raw_protein = str(Seq(cleaned).translate(table=1, to_stop=False))
|
| 2618 |
+
protein = raw_protein.split("*")[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2619 |
|
| 2620 |
# Mutations label — diff against WT. For length-changing edits this
|
| 2621 |
# prefixes a 'length:...' marker so the frontend can warn loudly.
|
|
@@ -3810,7 +3810,12 @@ function validateDnaEdit(raw) {
|
|
| 3810 |
if (STOP_CODONS_SET.has(codon)) { firstPrematureStop = i; break; }
|
| 3811 |
}
|
| 3812 |
if (firstPrematureStop >= 0) {
|
| 3813 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3814 |
}
|
| 3815 |
// Terminal stop check — if the final codon isn't TAA/TAG/TGA, warn but
|
| 3816 |
// don't block (some users edit out the stop intentionally for fusion
|
|
@@ -6493,9 +6498,17 @@ function runOracle(opts){
|
|
| 6493 |
menu.className = 'plasmid-export-menu'; menu.hidden = true;
|
| 6494 |
menu.innerHTML = '<button type="button" data-fmt="genbank">GenBank (.gb)</button><button type="button" data-fmt="fasta">FASTA (.fasta)</button>';
|
| 6495 |
exportBtn.parentNode.appendChild(menu);
|
| 6496 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6497 |
menu.addEventListener('click', (e) => { const b = e.target.closest('[data-fmt]'); if (b) { menu.hidden = true; doExport(b.getAttribute('data-fmt')); } });
|
| 6498 |
-
document.addEventListener('click', () => { menu.hidden = true; });
|
| 6499 |
}
|
| 6500 |
|
| 6501 |
// ───────────────────────── M3: sequence editor ─────────────────────────
|
|
@@ -6844,7 +6857,12 @@ function runOracle(opts){
|
|
| 6844 |
menu.innerHTML = '<button type="button" data-use="crispr">CRISPR guides</button>'
|
| 6845 |
+ '<button type="button" data-use="primers">Primer Picker (template)</button>';
|
| 6846 |
useBtn.parentNode.appendChild(menu);
|
| 6847 |
-
useBtn.addEventListener('click', (e) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6848 |
menu.addEventListener('click', (e) => {
|
| 6849 |
const b = e.target.closest('[data-use]'); if (!b || !plasmid) return;
|
| 6850 |
menu.hidden = true;
|
|
@@ -6852,7 +6870,7 @@ function runOracle(opts){
|
|
| 6852 |
if (b.getAttribute('data-use') === 'crispr') sendToCrispr(plasmid.sequence, nm);
|
| 6853 |
else sendToPrimers(plasmid.sequence, nm);
|
| 6854 |
});
|
| 6855 |
-
document.addEventListener('click', () => { menu.hidden = true; });
|
| 6856 |
}
|
| 6857 |
|
| 6858 |
// Sequence-editor region hand-offs — act on the current selection (or whole).
|
|
|
|
| 3810 |
if (STOP_CODONS_SET.has(codon)) { firstPrematureStop = i; break; }
|
| 3811 |
}
|
| 3812 |
if (firstPrematureStop >= 0) {
|
| 3813 |
+
// A premature stop is a legitimate nonsense / truncation mutation
|
| 3814 |
+
// (e.g. a single-base SNP that creates a stop, or an intentional
|
| 3815 |
+
// knockout). Warn, don't block — the variant encodes the truncated
|
| 3816 |
+
// product and synthesis is unaffected.
|
| 3817 |
+
const aaPos = Math.floor(firstPrematureStop / 3) + 1;
|
| 3818 |
+
warnings.push({ severity: 'medium', text: `Premature stop (${clean.slice(firstPrematureStop, firstPrematureStop + 3)}) at codon ${aaPos} — truncates the protein (nonsense mutation). Allowed.` });
|
| 3819 |
}
|
| 3820 |
// Terminal stop check — if the final codon isn't TAA/TAG/TGA, warn but
|
| 3821 |
// don't block (some users edit out the stop intentionally for fusion
|
|
|
|
| 6498 |
menu.className = 'plasmid-export-menu'; menu.hidden = true;
|
| 6499 |
menu.innerHTML = '<button type="button" data-fmt="genbank">GenBank (.gb)</button><button type="button" data-fmt="fasta">FASTA (.fasta)</button>';
|
| 6500 |
exportBtn.parentNode.appendChild(menu);
|
| 6501 |
+
// Toggle THIS menu, closing any other toolbar dropdown first (otherwise
|
| 6502 |
+
// opening the second one leaves the first stuck open + overlapping —
|
| 6503 |
+
// each button's stopPropagation blocked the other's outside-click close).
|
| 6504 |
+
exportBtn.addEventListener('click', (e) => {
|
| 6505 |
+
e.stopPropagation();
|
| 6506 |
+
const open = menu.hidden;
|
| 6507 |
+
document.querySelectorAll('.plasmid-export-menu').forEach((m) => { m.hidden = true; });
|
| 6508 |
+
menu.hidden = !open;
|
| 6509 |
+
});
|
| 6510 |
menu.addEventListener('click', (e) => { const b = e.target.closest('[data-fmt]'); if (b) { menu.hidden = true; doExport(b.getAttribute('data-fmt')); } });
|
| 6511 |
+
document.addEventListener('click', () => { document.querySelectorAll('.plasmid-export-menu').forEach((m) => { m.hidden = true; }); });
|
| 6512 |
}
|
| 6513 |
|
| 6514 |
// ───────────────────────── M3: sequence editor ─────────────────────────
|
|
|
|
| 6857 |
menu.innerHTML = '<button type="button" data-use="crispr">CRISPR guides</button>'
|
| 6858 |
+ '<button type="button" data-use="primers">Primer Picker (template)</button>';
|
| 6859 |
useBtn.parentNode.appendChild(menu);
|
| 6860 |
+
useBtn.addEventListener('click', (e) => {
|
| 6861 |
+
e.stopPropagation();
|
| 6862 |
+
const open = menu.hidden;
|
| 6863 |
+
document.querySelectorAll('.plasmid-export-menu').forEach((m) => { m.hidden = true; });
|
| 6864 |
+
menu.hidden = !open;
|
| 6865 |
+
});
|
| 6866 |
menu.addEventListener('click', (e) => {
|
| 6867 |
const b = e.target.closest('[data-use]'); if (!b || !plasmid) return;
|
| 6868 |
menu.hidden = true;
|
|
|
|
| 6870 |
if (b.getAttribute('data-use') === 'crispr') sendToCrispr(plasmid.sequence, nm);
|
| 6871 |
else sendToPrimers(plasmid.sequence, nm);
|
| 6872 |
});
|
| 6873 |
+
document.addEventListener('click', () => { document.querySelectorAll('.plasmid-export-menu').forEach((m) => { m.hidden = true; }); });
|
| 6874 |
}
|
| 6875 |
|
| 6876 |
// Sequence-editor region hand-offs — act on the current selection (or whole).
|
|
@@ -90,6 +90,16 @@
|
|
| 90 |
try { return sessionStorage.getItem(USER_EMAIL_KEY) || null; }
|
| 91 |
catch (_) { return null; }
|
| 92 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
// If the user was already signed in (sessionStorage carried over from a
|
| 95 |
// prior load in this tab), wipe the legacy trial state too. Same
|
|
@@ -373,6 +383,13 @@
|
|
| 373 |
const reloadBtn = card.querySelector('#td-session-expired-reload');
|
| 374 |
if (reloadBtn) {
|
| 375 |
reloadBtn.addEventListener('click', function () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
try {
|
| 377 |
if (window.top && window.top !== window.self) {
|
| 378 |
window.top.location.reload();
|
|
@@ -383,11 +400,13 @@
|
|
| 383 |
});
|
| 384 |
}
|
| 385 |
// Sign-in fallback: explicit top-window navigation so the user
|
| 386 |
-
// can choose to re-authenticate from scratch.
|
|
|
|
| 387 |
const signinLink = card.querySelector('#td-session-expired-signin');
|
| 388 |
if (signinLink) {
|
| 389 |
signinLink.addEventListener('click', function (e) {
|
| 390 |
e.preventDefault();
|
|
|
|
| 391 |
_redirectToSignup(signinLink.getAttribute('href'));
|
| 392 |
});
|
| 393 |
}
|
|
|
|
| 90 |
try { return sessionStorage.getItem(USER_EMAIL_KEY) || null; }
|
| 91 |
catch (_) { return null; }
|
| 92 |
}
|
| 93 |
+
// Wipe the cached session so a dead token can't keep masking a fresh
|
| 94 |
+
// sign-in (the "session out of sync that won't clear" loop).
|
| 95 |
+
function _clearTokens() {
|
| 96 |
+
try {
|
| 97 |
+
sessionStorage.removeItem(TOKEN_KEY);
|
| 98 |
+
sessionStorage.removeItem(REFRESH_KEY);
|
| 99 |
+
sessionStorage.removeItem(USER_ID_KEY);
|
| 100 |
+
sessionStorage.removeItem(USER_EMAIL_KEY);
|
| 101 |
+
} catch (_) { /* private mode — nothing to clear */ }
|
| 102 |
+
}
|
| 103 |
|
| 104 |
// If the user was already signed in (sessionStorage carried over from a
|
| 105 |
// prior load in this tab), wipe the legacy trial state too. Same
|
|
|
|
| 383 |
const reloadBtn = card.querySelector('#td-session-expired-reload');
|
| 384 |
if (reloadBtn) {
|
| 385 |
reloadBtn.addEventListener('click', function () {
|
| 386 |
+
// Drop the dead token FIRST. Otherwise, if the wrapper re-uses
|
| 387 |
+
// a cached iframe URL (no fresh #access_token fragment), the
|
| 388 |
+
// iframe re-reads the same stale token from sessionStorage and
|
| 389 |
+
// loops on "session out of sync." Cleared → worst case the user
|
| 390 |
+
// is treated as anonymous and gets the normal sign-in flow, no
|
| 391 |
+
// dead-token loop. (This is the "reload doesn't fix it" bug.)
|
| 392 |
+
_clearTokens();
|
| 393 |
try {
|
| 394 |
if (window.top && window.top !== window.self) {
|
| 395 |
window.top.location.reload();
|
|
|
|
| 400 |
});
|
| 401 |
}
|
| 402 |
// Sign-in fallback: explicit top-window navigation so the user
|
| 403 |
+
// can choose to re-authenticate from scratch. Clear the stale token so
|
| 404 |
+
// the fresh sign-in isn't masked by a cached dead session.
|
| 405 |
const signinLink = card.querySelector('#td-session-expired-signin');
|
| 406 |
if (signinLink) {
|
| 407 |
signinLink.addEventListener('click', function (e) {
|
| 408 |
e.preventDefault();
|
| 409 |
+
_clearTokens();
|
| 410 |
_redirectToSignup(signinLink.getAttribute('href'));
|
| 411 |
});
|
| 412 |
}
|
|
@@ -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=
|
| 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
|
|
@@ -1437,10 +1437,10 @@
|
|
| 1437 |
Authorization header on every same-origin /api/* call. Without
|
| 1438 |
this, signed-in users would still hit the anonymous-quota
|
| 1439 |
gate. -->
|
| 1440 |
-
<script src="/static/auth.js?v=
|
| 1441 |
<!-- Cloning reference data must load before app.js so the Designer
|
| 1442 |
can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
|
| 1443 |
<script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
|
| 1444 |
-
<script src="/static/app.js?v=
|
| 1445 |
</body>
|
| 1446 |
</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=20260604-bugfix" />
|
| 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
|
|
|
|
| 1437 |
Authorization header on every same-origin /api/* call. Without
|
| 1438 |
this, signed-in users would still hit the anonymous-quota
|
| 1439 |
gate. -->
|
| 1440 |
+
<script src="/static/auth.js?v=20260604-bugfix"></script>
|
| 1441 |
<!-- Cloning reference data must load before app.js so the Designer
|
| 1442 |
can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
|
| 1443 |
<script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
|
| 1444 |
+
<script src="/static/app.js?v=20260604-bugfix" defer></script>
|
| 1445 |
</body>
|
| 1446 |
</html>
|
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for the DE-engine variant DNA re-derive (_rederive_variant_row).
|
| 2 |
+
|
| 3 |
+
Audit fix: a premature stop is a legitimate nonsense/truncation mutation and
|
| 4 |
+
must be ALLOWED (it used to hard-reject the save with a false "vendors will
|
| 5 |
+
reject this" claim — the "can't do a single-nucleotide mutation" bug). Frame
|
| 6 |
+
breaks and non-ACGT are still rejected."""
|
| 7 |
+
import pytest
|
| 8 |
+
|
| 9 |
+
from dee import server
|
| 10 |
+
|
| 11 |
+
WT_DNA = "ATG" + "GCT" * 10 + "TAA" # M + 10×A
|
| 12 |
+
WT_PROT = "M" + "A" * 10
|
| 13 |
+
ROW = {"Variant_ID": "V1", "Predicted_Fitness_Score": 0.5}
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _rederive(dna):
|
| 17 |
+
return server._rederive_variant_row(
|
| 18 |
+
variant_id="V1", edited_dna=dna, wt_protein=WT_PROT, original_row=ROW)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_premature_stop_is_allowed_and_truncates():
|
| 22 |
+
# SNP/edit that installs a stop at codon 6 → protein truncates, NO raise.
|
| 23 |
+
edited = "ATG" + "GCT" * 4 + "TAA" + "GCT" * 5 + "TAA" # M AAAA *(stop) ...
|
| 24 |
+
row = _rederive(edited)
|
| 25 |
+
assert row["Mutant_AA_Seq"] == "MAAAA" # truncated at the stop
|
| 26 |
+
assert row["Optimized_DNA_Seq"] == edited # DNA kept as-is
|
| 27 |
+
assert row["Edited"] is True
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def test_point_substitution_changes_one_residue():
|
| 31 |
+
# change codon 2 GCT(A) → GAT(D): a clean single-residue missense
|
| 32 |
+
edited = "ATG" + "GAT" + "GCT" * 9 + "TAA"
|
| 33 |
+
row = _rederive(edited)
|
| 34 |
+
assert row["Mutant_AA_Seq"] == "MD" + "A" * 9
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_frame_break_still_rejected():
|
| 38 |
+
with pytest.raises(ValueError):
|
| 39 |
+
_rederive("ATGGC") # 5 bp, not a multiple of 3
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def test_non_acgt_still_rejected():
|
| 43 |
+
with pytest.raises(ValueError):
|
| 44 |
+
_rederive("ATGGCNGCTTAA") # contains N
|