Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cff-version: 1.2.0
message: "Si usas este software, por favor cítalo así. / If you use this software, please cite it as below."
title: "Vector editor: in-browser cloning simulator with REBASE enzymes"
type: software
version: 0.3.1
version: 0.4.0
authors:
- family-names: "Quintero López"
given-names: "Oscar Alexis"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Simulador de clonación en el navegador: elige enzimas de restricción comercial
- **Digestión y ligación** con extremos reales (5', 3' o romos): comprueba la compatibilidad de ambas uniones, prueba las dos orientaciones del inserto y avisa si el vector puede religarse o si las enzimas cortan dentro del inserto. Funciona con enzimas tipo IIS (Golden Gate).
- **Archivos**: FASTA, GenBank y SnapGene (`.dna`), leídos localmente con [seqparse](https://github.com/Lattice-Automation/seqparse).
- **Mapa y FASTA vinculados**: el FASTA se colorea igual que el mapa circular ([SeqViz](https://github.com/Lattice-Automation/seqviz)) — vector, inserto y sitios de corte —; seleccionar bases en el FASTA marca el arco en el mapa, hacer clic en el mapa o en la leyenda resalta y lleva a esa secuencia. Copia o descarga el FASTA completo o solo la selección.
- **Edición manual coloreada**: pega o escribe una secuencia (FASTA o sola) y el mapa, los sitios de corte, la longitud y el %GC se actualizan en vivo; vector, inserto y sitios conservan su color y se desplazan con cada edición. Formatear y reverso complementario.
- **Móvil y pantallas verticales**: pestañas Mapa · Secuencia · Construir; en horizontal, riel lateral para dar toda la altura al mapa.
- **Búsqueda de enzimas** en un desplegable con teclado (↑ ↓ Enter Esc), filtrable por proveedor y por si cortan vector e inserto.
- **Exporta GenBank anotado** (vector, inserto con su orientación y sitios de restricción), listo para SnapGene, Benchling, ApE o Biopython, además de FASTA.
- **Atajos**: `/` buscar enzima · `C` copiar (la selección si hay una) · `D` FASTA · `G` GenBank · `Esc` quitar selección.
Expand All @@ -30,6 +32,8 @@ Simulador de clonación en el navegador: elige enzimas de restricción comercial
- **Digestion and ligation** with real ends (5', 3' or blunt): checks both junctions, tries both insert orientations, and warns when the vector can self-ligate or the enzymes cut inside the insert. Works with type IIS enzymes (Golden Gate).
- **Files**: FASTA, GenBank and SnapGene (`.dna`), parsed locally with [seqparse](https://github.com/Lattice-Automation/seqparse).
- **Linked map and FASTA**: the FASTA is coloured like the circular map ([SeqViz](https://github.com/Lattice-Automation/seqviz)) — vector, insert and cut sites —; selecting bases in the FASTA marks the arc on the map, and clicking the map or the legend highlights and scrolls to that sequence. Copy or download the whole FASTA or just the selection.
- **Coloured manual editing**: paste or type a sequence (FASTA or plain) and the map, cut sites, length and GC% update live; vector, insert and sites keep their colours and move with every edit. Format and reverse complement.
- **Phones and portrait screens**: Map · Sequence · Build tabs; in landscape, a side rail gives the map the full height.
- **Enzyme search** in a keyboard-friendly dropdown (↑ ↓ Enter Esc), filterable by supplier and by whether enzymes cut vector and insert.
- **Annotated GenBank export** (vector, insert with its orientation and restriction sites), ready for SnapGene, Benchling, ApE or Biopython, plus FASTA.
- **Shortcuts**: `/` search enzyme · `C` copy (the selection if any) · `D` FASTA · `G` GenBank · `Esc` clear selection.
Expand Down
69 changes: 63 additions & 6 deletions app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ body {
color: var(--bp-sterile);
font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track,
::-webkit-scrollbar-corner {
background: transparent;
}
::-webkit-scrollbar-button {
display: none;
}
::-webkit-scrollbar-thumb {
border: 2px solid transparent;
border-radius: 999px;
background: var(--bp-tissue);
background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
background: var(--bp-boundary);
background-clip: padding-box;
}
@supports not selector(::-webkit-scrollbar) {
html {
scrollbar-width: thin;
scrollbar-color: var(--bp-tissue) transparent;
}
}
::selection {
background: var(--bp-bio);
color: var(--bp-ink);
Expand All @@ -33,6 +60,10 @@ body {
display: grid;
grid-template-rows: minmax(0, 1fr) auto;
height: 100%;
/* Dynamic viewport height: the mobile browser bar never hides the tab bar. */
height: 100dvh;
padding-left: env(safe-area-inset-left);
padding-right: env(safe-area-inset-right);
}
.ve {
--ve-theme-bg: var(--bp-ink);
Expand All @@ -51,6 +82,8 @@ body {
--ve-theme-map-muted: var(--bp-boundary);
--ve-theme-map-cut: var(--bp-pink);
--ve-theme-map-selection: rgb(164 230 109 / 0.16);
--ve-theme-scroll-thumb: var(--bp-tissue);
--ve-theme-scroll-thumb-hover: var(--bp-boundary);
}
/* The map as a specimen under the microscope: reticle grid, vignette, glowing arcs. */
.ve-map {
Expand Down Expand Up @@ -128,13 +161,37 @@ body {
.app-footer a:hover {
color: var(--bp-bio);
}
@media (max-width: 1100px) {
/* On smaller screens the page scrolls instead of fitting the viewport. */
@media (max-width: 640px) {
.app-tagline {
display: none;
}
.app-brand {
flex: 1;
border-right: 0;
}
.app-lang {
margin-left: auto;
}
.app-footer {
gap: 0.2rem 0.5rem;
padding: 0.35rem 0.75rem calc(0.35rem + env(safe-area-inset-bottom));
font-size: 0.68rem;
}
}
@media (max-height: 520px) and (orientation: landscape) {
/* Every pixel of height goes to the map; the credit stays on the full layout. */
.app-footer {
display: none;
}
.app-shell {
height: auto;
min-height: 100%;
grid-template-rows: minmax(0, 1fr);
}
.app-tagline,
.app-brand strong {
display: none;
}
.ve--app {
height: auto;
.app-brand {
border-right: 0;
padding-right: 0;
}
}
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="es">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>Vector Editor — simulador de clonación</title>
<meta
name="description"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oquinterol/vector-editor",
"version": "0.3.1",
"version": "0.4.0",
"description": "In-browser cloning simulator: choose commercial or custom restriction enzymes, digest and ligate, and get a live FASTA and plasmid map.",
"license": "MIT",
"author": "Oscar Alexis Quintero López (https://oquinterol.com)",
Expand Down
34 changes: 34 additions & 0 deletions src/core/fasta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,37 @@ export function toFasta(name: string, seq: string, description = '', width = 70)
const lines = seq.match(new RegExp(`.{1,${width}}`, 'g')) ?? []
return [header, ...lines].join('\n') + '\n'
}

/** Fraction of G and C among unambiguous bases (0–1); NaN when there are none. */
export function gcContent(seq: string): number {
let gc = 0
let acgt = 0
for (const base of seq) {
if (base === 'G' || base === 'C') gc++
if (base === 'A' || base === 'C' || base === 'G' || base === 'T') acgt++
}
return acgt ? gc / acgt : Number.NaN
}

/**
* Maps a character offset in FASTA (or raw) text to a 0-based base index,
* skipping header lines, whitespace, digits and invalid characters.
*/
export function baseIndexAt(text: string, offset: number): number {
let index = 0
let inHeader = false
let lineStart = true
const valid = new RegExp(`[${IUPAC_LETTERS}]`, 'i')
for (let i = 0; i < Math.min(offset, text.length); i++) {
const char = text[i]!
if (lineStart && char === '>') inHeader = true
if (char === '\n') {
inHeader = false
lineStart = true
continue
}
lineStart = false
if (!inHeader && valid.test(char)) index++
}
return index
}
5 changes: 3 additions & 2 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export * from './types'
export { reverseComplement } from './iupac'
export { reverseComplement, IUPAC_LETTERS } from './iupac'
export { commercialEnzymes, suppliers, rebaseVersion, parseEnzyme, formatSite } from './enzymes'
export { findSites, findCuts, findAllCuts } from './sites'
export { digest, topStrand, fragmentLength, leftEnd, rightEnd, flip } from './digest'
export { ligate, compatible, canSelfLigate } from './ligate'
export { parseSequence, toFasta } from './fasta'
export { parseSequence, toFasta, gcContent, baseIndexAt } from './fasta'
export { toGenBank, type Feature } from './genbank'
export { shiftSpans, type Span } from './regions'
34 changes: 34 additions & 0 deletions src/core/regions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export interface Span {
start: number
end: number
}

/**
* Moves half-open spans after an edit that turned `before` into `after`.
* The edit is the part between their common prefix and suffix: text typed
* inside a span grows it, deleted text shrinks it, spans after it shift.
*/
export function shiftSpans<T extends Span>(spans: T[], before: string, after: string): T[] {
let prefix = 0
const shortest = Math.min(before.length, after.length)
while (prefix < shortest && before[prefix] === after[prefix]) prefix++
let suffix = 0
while (
suffix < shortest - prefix &&
before[before.length - 1 - suffix] === after[after.length - 1 - suffix]
)
suffix++
const oldEnd = before.length - suffix
const newEnd = after.length - suffix
const delta = after.length - before.length
// Boundaries before the edit stay; text typed at a boundary joins the span that starts
// there; boundaries inside the replaced stretch move to its new end.
const move = (position: number) => {
if (position <= prefix) return position
if (position >= oldEnd) return position + delta
return newEnd
}
return spans
.map((span) => ({ ...span, start: move(span.start), end: move(span.end) }))
.filter((span) => span.end > span.start)
}
44 changes: 37 additions & 7 deletions src/ui/FastaView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface Props {
range: SeqRange | null
rangeSource: RangeSource | null
onRange: (range: SeqRange) => void
/** False while the panel is hidden (compact layout); re-scrolls when shown again. */
active?: boolean
/** Fixed bases per line; by default it fits the panel width (multiples of 10). */
width?: number
label: string
Expand All @@ -44,6 +46,7 @@ export function FastaView({
rangeSource,
onRange,
width: fixedWidth,
active = true,
label
}: Props) {
const box = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -119,13 +122,13 @@ export function FastaView({

// Follow selections made on the map or the legend.
useEffect(() => {
if (!range || rangeSource === 'fasta' || !box.current) return
if (!active || !range || rangeSource === 'fasta' || !box.current) return
const line = box.current.querySelector<HTMLElement>(
`[data-line="${Math.floor(range.start / width) * width}"]`
)
// The view is the offsetParent of its lines (position: relative).
if (line) box.current.scrollTop = line.offsetTop - 24
}, [range, rangeSource, width])
}, [range, rangeSource, width, active])

const positionOf = (node: Node | null, offset: number): number | null => {
const element = node instanceof Element ? node : node?.parentElement
Expand All @@ -134,16 +137,43 @@ export function FastaView({
return Number(run.dataset.start) + (node instanceof Text ? offset : 0)
}

const onMouseUp = () => {
const readSelection = (): SeqRange | null => {
const selection = window.getSelection()
if (!selection || selection.isCollapsed) return
if (!selection || selection.isCollapsed) return null
const a = positionOf(selection.anchorNode, selection.anchorOffset)
const b = positionOf(selection.focusNode, selection.focusOffset)
if (a === null || b === null || a === b) return
onRange({ start: Math.min(a, b), end: Math.max(a, b) })
selection.removeAllRanges()
if (a === null || b === null || a === b) return null
return { start: Math.min(a, b), end: Math.max(a, b) }
}

const onMouseUp = () => {
const next = readSelection()
if (!next) return
onRange(next)
window.getSelection()?.removeAllRanges()
}

// Touch: long-press selection has no mouseup, and its handles keep moving, so follow
// selection changes (debounced) and leave the native selection in place.
const latest = useRef(onRange)
latest.current = onRange
useEffect(() => {
if (!window.matchMedia('(pointer: coarse)').matches) return
let timer = 0
const onChange = () => {
window.clearTimeout(timer)
timer = window.setTimeout(() => {
const next = readSelection()
if (next) latest.current(next)
}, 250)
}
document.addEventListener('selectionchange', onChange)
return () => {
window.clearTimeout(timer)
document.removeEventListener('selectionchange', onChange)
}
}, [])

return (
<div className='ve-fasta-view' ref={box} onMouseUp={onMouseUp} aria-label={label} tabIndex={0}>
<div className='ve-fasta-header'>{header}</div>
Expand Down
Loading
Loading