Tengo Gzirishvili Claude Opus 4.8 commited on
Commit
4b21a7f
·
1 Parent(s): e6b4c6d

Plasmid Editor: double-stranded sequence + companion map with linked selection

Browse files

Benchling-style workspace in Sequence view:
- the sequence and a companion circular map now sit side by side (the editor
takes full card width; Features flow below). Stacks under 880px.
- complement (antisense) strand rendered under each line, 5'→3' over 3'→5'.
- selecting a region in the sequence highlights both strands AND mirrors the
span as a live arc on the circular map (updated during drag without a full
map rebuild); clicking the map jumps the caret to that position.

Refactored renderCircular into buildCircularSVG (reused by the full map and the
companion), added a #pmSelArc path + updateSelArc, and a seqcSpans track for the
complement. No backend change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Files changed (3) hide show
  1. dee/static/app.css +26 -0
  2. dee/static/app.js +71 -18
  3. dee/static/index.html +2 -2
dee/static/app.css CHANGED
@@ -5588,6 +5588,32 @@ h3, h4 {
5588
  @keyframes seqcaret { 0%, 49.9% { opacity: 1; } 50%, 100% { opacity: 0; } }
5589
  .seqed-ro-note { font-size: 11.5px; color: var(--ink-faint); font-style: italic; margin: 2px 0 10px; }
5590
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5591
  @media (max-width: 640px) {
5592
  .seqtool-input { width: 100%; }
5593
  .seqtool-find { width: 100%; }
 
5588
  @keyframes seqcaret { 0%, 49.9% { opacity: 1; } 50%, 100% { opacity: 0; } }
5589
  .seqed-ro-note { font-size: 11.5px; color: var(--ink-faint); font-style: italic; margin: 2px 0 10px; }
5590
 
5591
+ /* In Sequence view the editor takes the full card width (Features flow below)
5592
+ so the sequence + companion map get room to sit side by side. */
5593
+ .plasmid-layout.is-seq { grid-template-columns: 1fr; }
5594
+ .plasmid-layout.is-seq .plasmid-side { margin-top: 6px; }
5595
+
5596
+ /* ── Sequence editor + companion map, side by side ── */
5597
+ .seqmap { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
5598
+ .seqmap-seq { min-width: 0; overflow-x: auto; }
5599
+ .seqmap-aside { position: sticky; top: 8px; }
5600
+ .seqmap-aside-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--ink-faint); margin: 0 0 8px 2px; }
5601
+ .seqmap-mini { cursor: crosshair; }
5602
+ .seqmap-mini svg { width: 100%; height: auto; display: block; }
5603
+ @media (max-width: 880px) {
5604
+ .seqmap { grid-template-columns: 1fr; }
5605
+ .seqmap-aside { position: static; max-width: 340px; margin-top: 6px; }
5606
+ }
5607
+
5608
+ /* complement (antisense) strand */
5609
+ .seqed-line-comp { margin-bottom: 0.55em; }
5610
+ .seqed-comp { color: var(--ink-faint); }
5611
+ .seqc { display: inline-block; }
5612
+ .seqc.seqb-sel { background: color-mix(in srgb, var(--brand) 32%, transparent); border-radius: 1px; }
5613
+
5614
+ /* selection arc mirrored on the companion circular map */
5615
+ .pm-sel { stroke: var(--brand); stroke-width: 15; opacity: 0.42; stroke-linecap: round; }
5616
+
5617
  @media (max-width: 640px) {
5618
  .seqtool-input { width: 100%; }
5619
  .seqtool-find { width: 100%; }
dee/static/app.js CHANGED
@@ -6501,11 +6501,15 @@ function runOracle(opts){
6501
  return out;
6502
  }
6503
 
6504
- function renderCircular() {
 
6505
  const len = plasmid.length, cx = 210, cy = 210, R = 138;
6506
  const feats = plasmid.features || [];
6507
- let svg = `<svg viewBox="0 0 420 420" class="plasmid-svg" role="img" aria-label="Circular plasmid map">`;
6508
  svg += `<circle cx="${cx}" cy="${cy}" r="${R}" class="pm-backbone"/>`;
 
 
 
6509
  // ruler ticks
6510
  const ticks = 8;
6511
  for (let i = 0; i < ticks; i++) {
@@ -6543,7 +6547,28 @@ function runOracle(opts){
6543
  svg += `<text x="${cx}" y="${cy - 8}" class="pm-center-name" text-anchor="middle">${esc((plasmid.name || 'plasmid').slice(0, 22))}</text>`;
6544
  svg += `<text x="${cx}" y="${cy + 12}" class="pm-center-sub" text-anchor="middle">${len.toLocaleString()} bp · ${esc(plasmid.topology)}</text>`;
6545
  svg += `</svg>`;
6546
- mapWrap.innerHTML = svg;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6547
  }
6548
 
6549
  function renderLinear() {
@@ -6575,11 +6600,14 @@ function runOracle(opts){
6575
 
6576
  function renderMap() {
6577
  const tools = document.getElementById('plasmidSeqTools');
 
6578
  if (viewMode === 'sequence') {
6579
  if (tools) tools.hidden = false;
 
6580
  renderSequence();
6581
  } else {
6582
  if (tools) tools.hidden = true;
 
6583
  viewMode === 'linear' ? renderLinear() : renderCircular();
6584
  }
6585
  }
@@ -6922,6 +6950,7 @@ function runOracle(opts){
6922
  let selAnchor = null; // anchor for keyboard/drag selection extension
6923
  let dragging = false, dragAnchor = 0;
6924
  let seqSpans = null; // editable render: NodeList of per-base <span>, indexed by position
 
6925
  let curSel = null; // [a,b) 0-based currently painted on spans
6926
  let _rescanT = null; // debounce timer for restriction rescan during typing
6927
 
@@ -6947,14 +6976,22 @@ function runOracle(opts){
6947
  function renderSequence() {
6948
  const seq = plasmid.sequence, len = seq.length, feats = plasmid.features || [];
6949
  syncSelInputs();
6950
- seqSpans = null;
6951
  if (len > SEQ_RENDER_CAP) {
6952
  mapWrap.innerHTML = `<div class="seqed-toobig">This sequence is ${len.toLocaleString()} bp — too long to render in the browser. `
6953
  + `Use Find or the From/To fields to work on a region; export to view the full sequence.</div>`;
6954
  return;
6955
  }
6956
- if (len > EDIT_CAP) { renderSeqReadonly(seq, len, feats); return; }
6957
- renderSeqEditable(seq, len, feats);
 
 
 
 
 
 
 
 
6958
  }
6959
 
6960
  // First feature covering each base wins; one pass for the whole sequence.
@@ -6968,28 +7005,39 @@ function runOracle(opts){
6968
  return arr;
6969
  }
6970
 
6971
- // Editable, per-base render — click to place the caret, drag to select, type to edit.
 
 
 
6972
  function renderSeqEditable(seq, len, feats) {
 
6973
  const colors = _colorArray(len, feats);
6974
  const sF = sel ? sel.from - 1 : -1, sT = sel ? sel.to : -1;
6975
  const parts = ['<div class="seqed seqed-edit" tabindex="0" role="textbox" aria-multiline="true" '
6976
  + 'aria-label="DNA sequence — click to place the cursor, type A/C/G/T to edit, drag to select" spellcheck="false">'];
6977
  for (let ls = 0; ls < len; ls += SEQ_LINE) {
6978
  const le = Math.min(ls + SEQ_LINE, len);
 
6979
  parts.push(`<div class="seqed-line"><span class="seqed-pos">${(ls + 1).toLocaleString()}</span><span class="seqed-bases">`);
6980
  for (let i = ls; i < le; i++) {
6981
  const c = colors[i];
6982
  const cls = 'seqb' + (c ? ' seqb-feat' : '') + ((i >= sF && i < sT) ? ' seqb-sel' : '') + (_inFind(i) ? ' seqb-find' : '');
6983
- const st = c ? ` style="--featc:${c}"` : '';
6984
- parts.push(`<span class="${cls}" data-i="${i}"${st}>${seq[i]}</span>`);
 
 
 
 
 
6985
  }
6986
  parts.push('</span></div>');
6987
  }
6988
  if (len === 0) parts.push('<div class="seqed-line"><span class="seqed-pos">1</span><span class="seqed-bases"></span></div>');
6989
  parts.push('</div>');
6990
- mapWrap.innerHTML = parts.join('');
6991
- const container = mapWrap.querySelector('.seqed-edit');
6992
  seqSpans = container ? container.querySelectorAll('.seqb') : null;
 
6993
  curSel = sel ? [sel.from - 1, sel.to] : null;
6994
  placeCaretEl();
6995
  const anchorEl = mapWrap.querySelector('.seqed-caret') || mapWrap.querySelector('.seqb-sel');
@@ -7018,8 +7066,9 @@ function runOracle(opts){
7018
  html += '</span></div>';
7019
  }
7020
  html += '</div>';
7021
- mapWrap.innerHTML = html;
7022
- const selRun = mapWrap.querySelector('.seqed-sel');
 
7023
  if (selRun && sel) selRun.scrollIntoView({ block: 'nearest' });
7024
  }
7025
 
@@ -7029,7 +7078,8 @@ function runOracle(opts){
7029
  if (caret == null || !seqSpans) return;
7030
  const car = document.createElement('i'); car.className = 'seqed-caret'; car.setAttribute('aria-hidden', 'true');
7031
  if (caret >= seqSpans.length) {
7032
- const lines = mapWrap.querySelectorAll('.seqed-bases');
 
7033
  const last = lines[lines.length - 1]; if (last) last.appendChild(car);
7034
  } else {
7035
  const sp = seqSpans[caret]; sp.parentNode.insertBefore(car, sp);
@@ -7037,15 +7087,18 @@ function runOracle(opts){
7037
  }
7038
  function paintSel(a, b) {
7039
  if (!seqSpans) return;
7040
- if (curSel) for (let i = curSel[0]; i < curSel[1] && i < seqSpans.length; i++) { if (seqSpans[i]) seqSpans[i].classList.remove('seqb-sel'); }
7041
- if (a != null && b > a) { for (let i = a; i < b && i < seqSpans.length; i++) { if (seqSpans[i]) seqSpans[i].classList.add('seqb-sel'); } curSel = [a, b]; }
 
 
7042
  else curSel = null;
 
7043
  }
7044
  function idxFromEvent(e) {
7045
- const sp = e.target.closest && e.target.closest('.seqb');
7046
  if (sp) { let i = +sp.getAttribute('data-i'); const r = sp.getBoundingClientRect(); if (e.clientX > r.left + r.width / 2) i += 1; return i; }
7047
  const bl = e.target.closest && e.target.closest('.seqed-bases');
7048
- if (bl) { const ss = bl.querySelectorAll('.seqb'); if (ss.length) return (+ss[ss.length - 1].getAttribute('data-i')) + 1; }
7049
  return null;
7050
  }
7051
  function focusEditor() { const c = mapWrap.querySelector('.seqed-edit'); if (c) c.focus({ preventScroll: true }); }
 
6501
  return out;
6502
  }
6503
 
6504
+ function buildCircularSVG(opt) {
6505
+ opt = opt || {};
6506
  const len = plasmid.length, cx = 210, cy = 210, R = 138;
6507
  const feats = plasmid.features || [];
6508
+ let svg = `<svg viewBox="0 0 420 420" class="plasmid-svg${opt.mini ? ' plasmid-svg-mini' : ''}" role="img" aria-label="Circular plasmid map">`;
6509
  svg += `<circle cx="${cx}" cy="${cy}" r="${R}" class="pm-backbone"/>`;
6510
+ // selection arc — mirrors the sequence selection; updated live via updateSelArc()
6511
+ const selD = sel ? arcPath(sel.from - 1, sel.to, len, R, cx, cy) : '';
6512
+ svg += `<path id="pmSelArc" class="pm-sel" d="${selD}" fill="none"/>`;
6513
  // ruler ticks
6514
  const ticks = 8;
6515
  for (let i = 0; i < ticks; i++) {
 
6547
  svg += `<text x="${cx}" y="${cy - 8}" class="pm-center-name" text-anchor="middle">${esc((plasmid.name || 'plasmid').slice(0, 22))}</text>`;
6548
  svg += `<text x="${cx}" y="${cy + 12}" class="pm-center-sub" text-anchor="middle">${len.toLocaleString()} bp · ${esc(plasmid.topology)}</text>`;
6549
  svg += `</svg>`;
6550
+ return svg;
6551
+ }
6552
+ function renderCircular() { mapWrap.innerHTML = buildCircularSVG(); }
6553
+ // Companion map shown beside the sequence editor.
6554
+ function renderCompanionMap() {
6555
+ const host = document.getElementById('seqMini'); if (!host) return;
6556
+ host.innerHTML = buildCircularSVG({ mini: true });
6557
+ // click the companion map → place the caret / jump there in the sequence
6558
+ const svg = host.querySelector('svg');
6559
+ if (svg) svg.addEventListener('click', (e) => {
6560
+ const r = svg.getBoundingClientRect();
6561
+ const px = (e.clientX - r.left) / r.width * 420, py = (e.clientY - r.top) / r.height * 420;
6562
+ const ang = Math.atan2(px - 210, -(py - 210)); // 0 at top, clockwise
6563
+ let pos = Math.round(((ang < 0 ? ang + TAU : ang) / TAU) * plasmid.length);
6564
+ setSel(pos + 1, pos + 1);
6565
+ });
6566
+ }
6567
+ // Cheap live update of just the selection arc (no full map rebuild).
6568
+ function updateSelArc() {
6569
+ const p = document.getElementById('pmSelArc'); if (!p) return;
6570
+ const r = curSel ? curSel : (sel ? [sel.from - 1, sel.to] : null);
6571
+ p.setAttribute('d', r && r[1] > r[0] ? arcPath(r[0], r[1], plasmid.length, 138, 210, 210) : '');
6572
  }
6573
 
6574
  function renderLinear() {
 
6600
 
6601
  function renderMap() {
6602
  const tools = document.getElementById('plasmidSeqTools');
6603
+ const layout = mapWrap.closest('.plasmid-layout');
6604
  if (viewMode === 'sequence') {
6605
  if (tools) tools.hidden = false;
6606
+ if (layout) layout.classList.add('is-seq'); // give the editor full width
6607
  renderSequence();
6608
  } else {
6609
  if (tools) tools.hidden = true;
6610
+ if (layout) layout.classList.remove('is-seq');
6611
  viewMode === 'linear' ? renderLinear() : renderCircular();
6612
  }
6613
  }
 
6950
  let selAnchor = null; // anchor for keyboard/drag selection extension
6951
  let dragging = false, dragAnchor = 0;
6952
  let seqSpans = null; // editable render: NodeList of per-base <span>, indexed by position
6953
+ let seqcSpans = null; // complement-strand spans, indexed by position
6954
  let curSel = null; // [a,b) 0-based currently painted on spans
6955
  let _rescanT = null; // debounce timer for restriction rescan during typing
6956
 
 
6976
  function renderSequence() {
6977
  const seq = plasmid.sequence, len = seq.length, feats = plasmid.features || [];
6978
  syncSelInputs();
6979
+ seqSpans = null; seqcSpans = null;
6980
  if (len > SEQ_RENDER_CAP) {
6981
  mapWrap.innerHTML = `<div class="seqed-toobig">This sequence is ${len.toLocaleString()} bp — too long to render in the browser. `
6982
  + `Use Find or the From/To fields to work on a region; export to view the full sequence.</div>`;
6983
  return;
6984
  }
6985
+ // Split workspace: sequence on the left, a companion circular map on the
6986
+ // right that mirrors the current selection as a highlighted arc.
6987
+ mapWrap.innerHTML = '<div class="seqmap">'
6988
+ + '<div class="seqmap-seq" id="seqHost"></div>'
6989
+ + '<aside class="seqmap-aside"><div class="seqmap-aside-label">Map · selection mirrored</div>'
6990
+ + '<div id="seqMini" class="seqmap-mini"></div></aside>'
6991
+ + '</div>';
6992
+ if (len > EDIT_CAP) renderSeqReadonly(seq, len, feats);
6993
+ else renderSeqEditable(seq, len, feats);
6994
+ renderCompanionMap();
6995
  }
6996
 
6997
  // First feature covering each base wins; one pass for the whole sequence.
 
7005
  return arr;
7006
  }
7007
 
7008
+ // Editable per-base render. Top strand (5'→3') is click/type-editable; the
7009
+ // complement (3'→5') is shown beneath each line, Benchling-style. Selection
7010
+ // highlights both strands.
7011
+ const _COMP = { A: 'T', T: 'A', G: 'C', C: 'G', N: 'N' };
7012
  function renderSeqEditable(seq, len, feats) {
7013
+ const host = document.getElementById('seqHost') || mapWrap;
7014
  const colors = _colorArray(len, feats);
7015
  const sF = sel ? sel.from - 1 : -1, sT = sel ? sel.to : -1;
7016
  const parts = ['<div class="seqed seqed-edit" tabindex="0" role="textbox" aria-multiline="true" '
7017
  + 'aria-label="DNA sequence — click to place the cursor, type A/C/G/T to edit, drag to select" spellcheck="false">'];
7018
  for (let ls = 0; ls < len; ls += SEQ_LINE) {
7019
  const le = Math.min(ls + SEQ_LINE, len);
7020
+ // top strand (editable)
7021
  parts.push(`<div class="seqed-line"><span class="seqed-pos">${(ls + 1).toLocaleString()}</span><span class="seqed-bases">`);
7022
  for (let i = ls; i < le; i++) {
7023
  const c = colors[i];
7024
  const cls = 'seqb' + (c ? ' seqb-feat' : '') + ((i >= sF && i < sT) ? ' seqb-sel' : '') + (_inFind(i) ? ' seqb-find' : '');
7025
+ parts.push(`<span class="${cls}" data-i="${i}"${c ? ` style="--featc:${c}"` : ''}>${seq[i]}</span>`);
7026
+ }
7027
+ parts.push('</span></div>');
7028
+ // complement strand (display only, mirrors selection)
7029
+ parts.push('<div class="seqed-line seqed-line-comp"><span class="seqed-pos seqed-pos-comp"></span><span class="seqed-bases seqed-comp">');
7030
+ for (let i = ls; i < le; i++) {
7031
+ parts.push(`<span class="seqc${(i >= sF && i < sT) ? ' seqb-sel' : ''}" data-i="${i}">${_COMP[seq[i]] || 'N'}</span>`);
7032
  }
7033
  parts.push('</span></div>');
7034
  }
7035
  if (len === 0) parts.push('<div class="seqed-line"><span class="seqed-pos">1</span><span class="seqed-bases"></span></div>');
7036
  parts.push('</div>');
7037
+ host.innerHTML = parts.join('');
7038
+ const container = host.querySelector('.seqed-edit');
7039
  seqSpans = container ? container.querySelectorAll('.seqb') : null;
7040
+ seqcSpans = container ? container.querySelectorAll('.seqc') : null;
7041
  curSel = sel ? [sel.from - 1, sel.to] : null;
7042
  placeCaretEl();
7043
  const anchorEl = mapWrap.querySelector('.seqed-caret') || mapWrap.querySelector('.seqb-sel');
 
7066
  html += '</span></div>';
7067
  }
7068
  html += '</div>';
7069
+ const host = document.getElementById('seqHost') || mapWrap;
7070
+ host.innerHTML = html;
7071
+ const selRun = host.querySelector('.seqed-sel');
7072
  if (selRun && sel) selRun.scrollIntoView({ block: 'nearest' });
7073
  }
7074
 
 
7078
  if (caret == null || !seqSpans) return;
7079
  const car = document.createElement('i'); car.className = 'seqed-caret'; car.setAttribute('aria-hidden', 'true');
7080
  if (caret >= seqSpans.length) {
7081
+ // append to the LAST top-strand bases row (not a complement row)
7082
+ const lines = mapWrap.querySelectorAll('.seqed-bases:not(.seqed-comp)');
7083
  const last = lines[lines.length - 1]; if (last) last.appendChild(car);
7084
  } else {
7085
  const sp = seqSpans[caret]; sp.parentNode.insertBefore(car, sp);
 
7087
  }
7088
  function paintSel(a, b) {
7089
  if (!seqSpans) return;
7090
+ const clr = (i) => { if (seqSpans[i]) seqSpans[i].classList.remove('seqb-sel'); if (seqcSpans && seqcSpans[i]) seqcSpans[i].classList.remove('seqb-sel'); };
7091
+ const set = (i) => { if (seqSpans[i]) seqSpans[i].classList.add('seqb-sel'); if (seqcSpans && seqcSpans[i]) seqcSpans[i].classList.add('seqb-sel'); };
7092
+ if (curSel) for (let i = curSel[0]; i < curSel[1] && i < seqSpans.length; i++) clr(i);
7093
+ if (a != null && b > a) { for (let i = a; i < b && i < seqSpans.length; i++) set(i); curSel = [a, b]; }
7094
  else curSel = null;
7095
+ updateSelArc(); // mirror onto the companion circular map
7096
  }
7097
  function idxFromEvent(e) {
7098
+ const sp = e.target.closest && e.target.closest('.seqb, .seqc');
7099
  if (sp) { let i = +sp.getAttribute('data-i'); const r = sp.getBoundingClientRect(); if (e.clientX > r.left + r.width / 2) i += 1; return i; }
7100
  const bl = e.target.closest && e.target.closest('.seqed-bases');
7101
+ if (bl) { const ss = bl.querySelectorAll('.seqb, .seqc'); if (ss.length) return (+ss[ss.length - 1].getAttribute('data-i')) + 1; }
7102
  return null;
7103
  }
7104
  function focusEditor() { const c = mapWrap.querySelector('.seqed-edit'); if (c) c.focus({ preventScroll: true }); }
dee/static/index.html CHANGED
@@ -28,7 +28,7 @@
28
  <!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
29
  app.js change. Bump these numbers whenever you ship a frontend update —
30
  without them, users keep getting the stale file for up to a week. -->
31
- <link rel="stylesheet" href="/static/app.css?v=20260609-mono2" />
32
  <link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
33
  <link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
34
  <!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
@@ -1817,6 +1817,6 @@
1817
  <!-- Cloning reference data must load before app.js so the Designer
1818
  can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
1819
  <script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
1820
- <script src="/static/app.js?v=20260609-mono2" defer></script>
1821
  </body>
1822
  </html>
 
28
  <!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
29
  app.js change. Bump these numbers whenever you ship a frontend update —
30
  without them, users keep getting the stale file for up to a week. -->
31
+ <link rel="stylesheet" href="/static/app.css?v=20260609-ds2" />
32
  <link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
33
  <link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
34
  <!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
 
1817
  <!-- Cloning reference data must load before app.js so the Designer
1818
  can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
1819
  <script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
1820
+ <script src="/static/app.js?v=20260609-ds2" defer></script>
1821
  </body>
1822
  </html>