@biolibs/bionet-tools 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +183 -5
- package/dist/digest-bench.d.ts +76 -0
- package/dist/digest-bench.d.ts.map +1 -0
- package/dist/digest-bench.js +127 -0
- package/dist/digest-bench.js.map +1 -0
- package/dist/digest-tool.d.ts.map +1 -1
- package/dist/digest-tool.js +2 -1
- package/dist/digest-tool.js.map +1 -1
- package/dist/digest-working.d.ts +155 -0
- package/dist/digest-working.d.ts.map +1 -0
- package/dist/digest-working.js +216 -0
- package/dist/digest-working.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/dist/ligate-bench.d.ts +92 -0
- package/dist/ligate-bench.d.ts.map +1 -0
- package/dist/ligate-bench.js +139 -0
- package/dist/ligate-bench.js.map +1 -0
- package/dist/ligate-working.d.ts +96 -0
- package/dist/ligate-working.d.ts.map +1 -0
- package/dist/ligate-working.js +145 -0
- package/dist/ligate-working.js.map +1 -0
- package/dist/ligate.d.ts +152 -0
- package/dist/ligate.d.ts.map +1 -0
- package/dist/ligate.js +161 -0
- package/dist/ligate.js.map +1 -0
- package/dist/map.d.ts +69 -0
- package/dist/map.d.ts.map +1 -0
- package/dist/map.js +80 -0
- package/dist/map.js.map +1 -0
- package/dist/pcr-bench.d.ts +103 -0
- package/dist/pcr-bench.d.ts.map +1 -0
- package/dist/pcr-bench.js +211 -0
- package/dist/pcr-bench.js.map +1 -0
- package/dist/pcr-scene.d.ts +249 -0
- package/dist/pcr-scene.d.ts.map +1 -0
- package/dist/pcr-scene.js +287 -0
- package/dist/pcr-scene.js.map +1 -0
- package/dist/pcr-tool.d.ts.map +1 -1
- package/dist/pcr-tool.js +2 -1
- package/dist/pcr-tool.js.map +1 -1
- package/dist/pcr-working.d.ts +126 -0
- package/dist/pcr-working.d.ts.map +1 -0
- package/dist/pcr-working.js +175 -0
- package/dist/pcr-working.js.map +1 -0
- package/dist/run.d.ts +103 -5
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +132 -12
- package/dist/run.js.map +1 -1
- package/dist/sequence-file.d.ts +108 -0
- package/dist/sequence-file.d.ts.map +1 -0
- package/dist/sequence-file.js +145 -0
- package/dist/sequence-file.js.map +1 -0
- package/dist/sequences-tool.d.ts +13 -0
- package/dist/sequences-tool.d.ts.map +1 -0
- package/dist/sequences-tool.js +61 -0
- package/dist/sequences-tool.js.map +1 -0
- package/dist/tools.d.ts +7 -3
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +11 -5
- package/dist/tools.js.map +1 -1
- package/dist/working.d.ts +58 -0
- package/dist/working.d.ts.map +1 -0
- package/dist/working.js +55 -0
- package/dist/working.js.map +1 -0
- package/package.json +6 -2
- package/src/digest-bench.tsx +307 -0
- package/src/digest-tool.tsx +2 -1
- package/src/digest-working.ts +288 -0
- package/src/index.ts +24 -0
- package/src/ligate-bench.tsx +293 -0
- package/src/ligate-working.ts +182 -0
- package/src/ligate.ts +243 -0
- package/src/map.tsx +170 -0
- package/src/pcr-bench.tsx +403 -0
- package/src/pcr-scene.ts +410 -0
- package/src/pcr-tool.tsx +2 -1
- package/src/pcr-working.ts +228 -0
- package/src/run.ts +186 -14
- package/src/sequence-file.ts +172 -0
- package/src/sequences-tool.tsx +109 -0
- package/src/tools.tsx +15 -9
- package/src/working.tsx +96 -0
- package/tools.css +82 -0
package/src/index.ts
CHANGED
|
@@ -8,17 +8,41 @@
|
|
|
8
8
|
* which run made it.
|
|
9
9
|
*
|
|
10
10
|
* - `pcr.ts` — what a PCR would make, worked out from sequences alone
|
|
11
|
+
* - `sequence-file.ts` — a sequence read from a SnapGene, GenBank, EMBL or FASTA file, and features carried onto a product
|
|
12
|
+
* - `pcr-scene.ts` — a PCR as met at the machine: the programme it shows, the checks, and what is in the tube
|
|
11
13
|
* - `digest.ts` — where enzymes cut, the pieces, and the gel they would give
|
|
12
14
|
* - `run.ts` — a PCR as a lab does one: which tubes, and what to record
|
|
13
15
|
* - `pcr-tool.tsx`, `digest-tool.tsx` — the tools
|
|
16
|
+
* - `pcr-bench.tsx` — a PCR at the machine: what is beside the scene, and what the scene is told to show
|
|
17
|
+
* - `pcr-working.ts` — the working behind what the PCR tool says: each figure with the steps that give it
|
|
18
|
+
* - `ligate.ts` — pieces that have already been cut, joined where their ends fit
|
|
19
|
+
* - `ligate-working.ts` — a ligation's working: each join in its bases, the length, how much to put in
|
|
20
|
+
* - `ligate-bench.tsx` — a ligation at the heat block: what is shown beside it, and what the scene draws
|
|
21
|
+
* - `digest-working.ts` — a digest looked at closely: each cut in its bases, each piece with its ends, the working
|
|
22
|
+
* - `digest-bench.tsx` — a digest at the gel station: what is shown beside it, and what the scene is told to draw
|
|
23
|
+
* - `working.tsx` — the working drawn: a figure that opens to show its steps
|
|
24
|
+
* - `map.tsx` — a sequence's map: a circle or a line, with what is marked on it
|
|
25
|
+
* - `sequences-tool.tsx` — bringing sequences in from files, and reading a part as a map
|
|
14
26
|
* - `tools.tsx` — getting to one: from an instrument, or from a list of them all
|
|
15
27
|
*
|
|
16
28
|
* The tools are drawn with the styles of `@biolibs/bionet-panels` and belong inside its `LabWindow`.
|
|
17
29
|
* Import `@biolibs/bionet-tools/tools.css` once.
|
|
18
30
|
*/
|
|
19
31
|
export * from "./pcr.js";
|
|
32
|
+
export * from "./sequence-file.js";
|
|
33
|
+
export * from "./pcr-scene.js";
|
|
20
34
|
export * from "./digest.js";
|
|
21
35
|
export * from "./run.js";
|
|
22
36
|
export * from "./pcr-tool.js";
|
|
23
37
|
export * from "./digest-tool.js";
|
|
38
|
+
export * from "./pcr-working.js";
|
|
39
|
+
export * from "./digest-working.js";
|
|
40
|
+
export * from "./ligate.js";
|
|
41
|
+
export * from "./ligate-working.js";
|
|
42
|
+
export * from "./ligate-bench.js";
|
|
43
|
+
export * from "./digest-bench.js";
|
|
44
|
+
export * from "./working.js";
|
|
45
|
+
export * from "./map.js";
|
|
46
|
+
export * from "./sequences-tool.js";
|
|
24
47
|
export * from "./tools.js";
|
|
48
|
+
export * from "./pcr-bench.js";
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A ligation at the heat block: what is shown beside it, and what the scene is told to draw.
|
|
5
|
+
*
|
|
6
|
+
* A heat block shows one number, the temperature, and nothing else. Everything that matters is in
|
|
7
|
+
* the tube and invisible: which ends found each other, which way round a piece went in, and whether
|
|
8
|
+
* anything closed into a circle. So the machine's views are short and the pictured ones carry it.
|
|
9
|
+
*/
|
|
10
|
+
import { useMemo, useState, type ReactNode } from "react";
|
|
11
|
+
import { useAct, useLab } from "@biolibs/bionet-react";
|
|
12
|
+
import { amountOf } from "@biolibs/bionet-panels";
|
|
13
|
+
import { Glossed } from "@biolibs/glossary-react";
|
|
14
|
+
import { endBases, type LigationPiece, type LigationProduct } from "./ligate.js";
|
|
15
|
+
import { joinWorking, ligationChecks, ligationLengthWorking, ratioWorking } from "./ligate-working.js";
|
|
16
|
+
import { SequenceMap } from "./map.js";
|
|
17
|
+
import { ligationRun, ligationTubes } from "./run.js";
|
|
18
|
+
import { moleculeOf, type DrawnMolecule } from "./sequence-file.js";
|
|
19
|
+
import { JoinBases, ShowWorking } from "./working.js";
|
|
20
|
+
|
|
21
|
+
/** The views of the heat block, by the names every instrument's stage uses. */
|
|
22
|
+
export type LigationView = "machine" | "block" | "screen" | "tube" | "result";
|
|
23
|
+
|
|
24
|
+
/** How each piece is coloured, in the theme's terms. The first is the one being cloned into. */
|
|
25
|
+
const TONES = ["yours", "theirs", "held", "good", "found"] as const;
|
|
26
|
+
|
|
27
|
+
/** What the scene is told to show. It is shaped to be spread onto `InstrumentStage`. */
|
|
28
|
+
export interface LigationStage {
|
|
29
|
+
model: "heat-block";
|
|
30
|
+
name: string;
|
|
31
|
+
view: LigationView;
|
|
32
|
+
onView: (view: LigationView) => void;
|
|
33
|
+
/** What the block's display says. */
|
|
34
|
+
screen: { text: string; lit?: boolean }[];
|
|
35
|
+
/** The well the tube is in. */
|
|
36
|
+
well?: { row: number; column: number };
|
|
37
|
+
/** The pieces being joined, for the view into the tube. */
|
|
38
|
+
joining?: { pieces: { name: string; length: number; flipped: boolean; tone: (typeof TONES)[number] }[]; joins: { label: string }[]; circular: boolean; joined: number };
|
|
39
|
+
/** What it makes, for the last view. */
|
|
40
|
+
molecule?: DrawnMolecule & { marks: { at: number; label: string }[] };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const count = (value: number): string => value.toLocaleString("en-US");
|
|
44
|
+
const whole = (text: string): number | undefined => (/^\d+$/.test(text.trim()) ? Number(text) : undefined);
|
|
45
|
+
|
|
46
|
+
/** How a product is said in one line. */
|
|
47
|
+
const productWords = (product: LigationProduct): string =>
|
|
48
|
+
`${count(product.length)} bp ${product.circular ? "circle" : "line"} · ${product.pieces.map((piece) => `${piece.name}${piece.flipped ? " ↺" : ""}`).join(" + ")}`;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A ligation, at the heat block it is left in.
|
|
52
|
+
*
|
|
53
|
+
* @param options - `instrument` is the block it is set up at, if the lab has one; `onDone` adds a way to leave.
|
|
54
|
+
* @returns `stage`, to spread onto `InstrumentStage` from `@biolibs/bionet-scene`, and `panel`, to put inside it.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* import { useLigationBench } from "@biolibs/bionet-tools";
|
|
59
|
+
*
|
|
60
|
+
* // `InstrumentStage` is the scene package's: it is handed what this gives and draws it.
|
|
61
|
+
* const bench = useLigationBench({ instrument });
|
|
62
|
+
* <InstrumentStage {...bench.stage}>{bench.panel}</InstrumentStage>
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export function useLigationBench({ instrument = null, onDone }: { instrument?: { id: string; name: string } | null; onDone?: () => void } = {}): { stage: LigationStage; panel: ReactNode } {
|
|
66
|
+
const lab = useLab()?.lab;
|
|
67
|
+
const act = useAct();
|
|
68
|
+
const [view, setView] = useState<LigationView>("machine");
|
|
69
|
+
const [tubes, setTubes] = useState<string[]>([]);
|
|
70
|
+
const [blunt, setBlunt] = useState(false);
|
|
71
|
+
const [linear, setLinear] = useState(false);
|
|
72
|
+
const [chosen, setChosen] = useState(0);
|
|
73
|
+
const [joined, setJoined] = useState(100);
|
|
74
|
+
const [celsius, setCelsius] = useState("16");
|
|
75
|
+
const [hours, setHours] = useState("16");
|
|
76
|
+
const [ratio, setRatio] = useState("3");
|
|
77
|
+
const [name, setName] = useState("");
|
|
78
|
+
const [amount, setAmount] = useState("20");
|
|
79
|
+
const [note, setNote] = useState("");
|
|
80
|
+
const [busy, setBusy] = useState(false);
|
|
81
|
+
const [said, setSaid] = useState<string | null>(null);
|
|
82
|
+
|
|
83
|
+
const offered = useMemo(() => (lab === null || lab === undefined ? [] : ligationTubes(lab)), [lab]);
|
|
84
|
+
const run = useMemo(() => (lab === null || lab === undefined ? null : ligationRun(lab, {
|
|
85
|
+
tubes, blunt, linear, chosen, instrument: instrument?.id ?? null, name, note, ...(whole(amount) === undefined ? {} : { amount: whole(amount)! }),
|
|
86
|
+
})), [lab, tubes, blunt, linear, chosen, instrument, name, note, amount]);
|
|
87
|
+
const plan = run?.plan ?? null;
|
|
88
|
+
const product = run?.product ?? null;
|
|
89
|
+
const pieces: LigationPiece[] = run?.pieces ?? [];
|
|
90
|
+
// A piece made by a PCR has no phosphate at its ends, which the log already knows from the run that made it.
|
|
91
|
+
const fromPcr = useMemo(() => pieces.filter((piece) => {
|
|
92
|
+
const made = lab?.items.find((one) => one.item === piece.id)?.from;
|
|
93
|
+
return made !== undefined && lab?.runs.find((one) => one.run === made)?.kind === "pcr";
|
|
94
|
+
}).map((piece) => piece.id), [pieces, lab]);
|
|
95
|
+
const checks = plan === null ? [] : ligationChecks(pieces, plan, { fromPcr });
|
|
96
|
+
const toneOf = (id: string): (typeof TONES)[number] => TONES[Math.max(0, pieces.findIndex((piece) => piece.id === id)) % TONES.length]!;
|
|
97
|
+
|
|
98
|
+
const stage: LigationStage = {
|
|
99
|
+
model: "heat-block", name: instrument?.name ?? "Heat block", view, onView: setView,
|
|
100
|
+
screen: [{ text: `${whole(celsius) ?? "—"} °C`, lit: true }, { text: `${whole(hours) ?? "—"} h` }],
|
|
101
|
+
...(pieces.length === 0 ? {} : { well: { row: 0, column: 1 } }),
|
|
102
|
+
...(product === null || view !== "tube" ? {} : { joining: {
|
|
103
|
+
circular: product.circular, joined: joined / 100,
|
|
104
|
+
pieces: product.pieces.map((piece) => ({ name: piece.name, length: piece.length, flipped: piece.flipped, tone: toneOf(piece.id) })),
|
|
105
|
+
joins: product.joins.map((join) => ({ label: join.kind === "blunt" ? "blunt" : join.bases })),
|
|
106
|
+
} }),
|
|
107
|
+
...(product === null || view !== "result" ? {} : { molecule: {
|
|
108
|
+
...moleculeOf({ name: run?.name ?? "product", length: product.length, circular: product.circular, features: product.features }),
|
|
109
|
+
marks: product.joins.map((join) => ({ at: join.at, label: join.kind === "blunt" ? "blunt" : join.bases })),
|
|
110
|
+
} }),
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const pick = (item: string): void => {
|
|
114
|
+
setTubes(tubes.includes(item) ? tubes.filter((one) => one !== item) : [...tubes, item]);
|
|
115
|
+
setChosen(0);
|
|
116
|
+
setSaid(null);
|
|
117
|
+
};
|
|
118
|
+
const record = async (what: Record<string, unknown> | null, done: string): Promise<void> => {
|
|
119
|
+
if (what === null) return;
|
|
120
|
+
setBusy(true);
|
|
121
|
+
const answer = await act("recordRun", what);
|
|
122
|
+
setBusy(false);
|
|
123
|
+
if (answer.ok) { setSaid(done); setNote(""); setName(""); setTubes([]); }
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const panel = lab === null || lab === undefined ? null : (
|
|
127
|
+
<div className="bionet benchpanel">
|
|
128
|
+
<section className="card">
|
|
129
|
+
<div className="toolhead">
|
|
130
|
+
<h2>Ligation</h2>
|
|
131
|
+
{onDone !== undefined && <button type="button" className="quiet" onClick={onDone}>Back to the lab</button>}
|
|
132
|
+
</div>
|
|
133
|
+
{offered.length === 0 ? <p className="empty">There are no cut pieces to join. Cut something at the gel station and keep a piece, or add a linear part on the Freezer tab.</p> : (
|
|
134
|
+
<fieldset disabled={busy} className="stack">
|
|
135
|
+
<p className="label">Pieces in the tube</p>
|
|
136
|
+
<div className="enzymes">
|
|
137
|
+
{offered.map((one) => {
|
|
138
|
+
const ends = endBases({ id: one.item, name: one.part.name, sequence: one.part.sequence, ends: one.part.ends ?? { left: 0, right: 0 } });
|
|
139
|
+
return (
|
|
140
|
+
<label key={one.item} className="check" title={one.label}>
|
|
141
|
+
<input type="checkbox" checked={tubes.includes(one.item)} onChange={() => pick(one.item)} /> {one.part.name}
|
|
142
|
+
<span className="dim small"> {count(one.part.length)} bp · {ends.left.kind === "blunt" ? "blunt" : ends.left.bases} … {ends.right.kind === "blunt" ? "blunt" : ends.right.bases}</span>
|
|
143
|
+
</label>
|
|
144
|
+
);
|
|
145
|
+
})}
|
|
146
|
+
</div>
|
|
147
|
+
<div className="row tight">
|
|
148
|
+
<label className="check small"><input type="checkbox" checked={blunt} onChange={(event) => { setBlunt(event.target.checked); setChosen(0); }} /> Let blunt ends join</label>
|
|
149
|
+
<label className="check small"><input type="checkbox" checked={linear} onChange={(event) => { setLinear(event.target.checked); setChosen(0); }} /> Show what does not close</label>
|
|
150
|
+
</div>
|
|
151
|
+
</fieldset>
|
|
152
|
+
)}
|
|
153
|
+
{plan !== null && plan.problem !== null && tubes.length > 0 && <p className="trouble" role="status">{plan.problem}</p>}
|
|
154
|
+
{plan !== null && plan.products.length > 1 && (
|
|
155
|
+
<label>What is being made
|
|
156
|
+
<select value={chosen} onChange={(event) => setChosen(Number(event.target.value))} aria-label="What is being made">
|
|
157
|
+
{plan.products.map((one, at) => <option key={at} value={at}>{productWords(one)}</option>)}
|
|
158
|
+
</select>
|
|
159
|
+
</label>
|
|
160
|
+
)}
|
|
161
|
+
</section>
|
|
162
|
+
|
|
163
|
+
{view === "machine" && (
|
|
164
|
+
<section className="card">
|
|
165
|
+
<h2>At the block</h2>
|
|
166
|
+
<p className="small"><Glossed text="Ligase joins the backbone of two pieces of DNA whose ends are held together, which is how cut pieces are made into one molecule again." /></p>
|
|
167
|
+
<p className="dim small">A heat block holds the tube at one temperature and shows that temperature. It shows nothing else: whether anything joined is found out days later, by what grows. The last two views are what you are picturing while it sits there.</p>
|
|
168
|
+
</section>
|
|
169
|
+
)}
|
|
170
|
+
|
|
171
|
+
{view === "block" && (
|
|
172
|
+
<section className="card">
|
|
173
|
+
<h2>The wells</h2>
|
|
174
|
+
<p className="voice">The machine</p>
|
|
175
|
+
<p className="small">A metal block with holes for tubes, held at the temperature below. The tube is in the second hole.</p>
|
|
176
|
+
<p className="voice">This run</p>
|
|
177
|
+
{pieces.length === 0 ? <p className="dim small">Nothing is in the tube yet. Choose the pieces above.</p> : (
|
|
178
|
+
<ul className="plainlist small">
|
|
179
|
+
{pieces.map((piece) => {
|
|
180
|
+
const held = lab.items.find((one) => one.item === piece.id);
|
|
181
|
+
return <li key={piece.id}>{piece.name} · {count(piece.sequence.length)} bp{held === undefined ? "" : ` · ${amountOf(held)} in the tube it came from`}</li>;
|
|
182
|
+
})}
|
|
183
|
+
<li className="dim">and ligase, with the buffer that carries the ATP it needs</li>
|
|
184
|
+
</ul>
|
|
185
|
+
)}
|
|
186
|
+
</section>
|
|
187
|
+
)}
|
|
188
|
+
|
|
189
|
+
{view === "screen" && (
|
|
190
|
+
<section className="card">
|
|
191
|
+
<h2>The temperature</h2>
|
|
192
|
+
<p className="voice">The machine</p>
|
|
193
|
+
<fieldset disabled={busy} className="programme">
|
|
194
|
+
<label>Hold at<input type="number" min={0} max={40} step={1} value={celsius} onChange={(event) => setCelsius(event.target.value)} /> °C</label>
|
|
195
|
+
<label>for<input type="number" min={1} max={72} step={1} value={hours} onChange={(event) => setHours(event.target.value)} /> h</label>
|
|
196
|
+
</fieldset>
|
|
197
|
+
<p className="voice">What is going on</p>
|
|
198
|
+
<p className="small">Two things are wanted at once and they want opposite temperatures. The ends have to stay stuck together long enough to be sealed, which is warmer the longer the overhang and colder the shorter it is; and ligase works faster the warmer it is. Sixteen degrees overnight is the usual answer to that, and an hour at room temperature often does for a sticky join.</p>
|
|
199
|
+
<p className="dim small">Nothing here works out what a given temperature and time will give. What is set is kept with the run.</p>
|
|
200
|
+
</section>
|
|
201
|
+
)}
|
|
202
|
+
|
|
203
|
+
{view === "tube" && (
|
|
204
|
+
<section className="card">
|
|
205
|
+
<h2>In the tube</h2>
|
|
206
|
+
{product === null ? <p className="dim small">{tubes.length === 0 ? "Choose the pieces to join." : "These pieces do not join into anything."}</p> : (
|
|
207
|
+
<>
|
|
208
|
+
<p className="voice">This run</p>
|
|
209
|
+
<p><strong>{product.pieces.length} {product.pieces.length === 1 ? "piece" : "pieces"}</strong> <span className="dim">{product.circular ? "closing into a circle" : "end to end"}</span></p>
|
|
210
|
+
<label className="small">How far along
|
|
211
|
+
<input type="range" min={0} max={100} step={1} value={joined} onChange={(event) => setJoined(Number(event.target.value))} aria-label="How far along the joining is" />
|
|
212
|
+
</label>
|
|
213
|
+
<p className="dim small">Drag it back to see the pieces apart, and forward to close them. Nothing in the tube can be seen while this is going on; this is the picture of it.</p>
|
|
214
|
+
<p className="small"><Glossed text="A sticky end holds to the end whose unpaired bases pair with it, and ligase seals the backbone on each strand. A blunt end has nothing to hold to, so the two ends must meet by chance." /></p>
|
|
215
|
+
<p className="voice">The working</p>
|
|
216
|
+
{product.joins.map((join) => {
|
|
217
|
+
const from = pieces.find((piece) => piece.id === join.from)!;
|
|
218
|
+
const to = pieces.find((piece) => piece.id === join.to)!;
|
|
219
|
+
const placedFrom = product.pieces.find((piece) => piece.id === join.from)!;
|
|
220
|
+
const placedTo = product.pieces.find((piece) => piece.id === join.to)!;
|
|
221
|
+
const out = placedFrom.flipped ? endBases(from).left : endBases(from).right;
|
|
222
|
+
const into = placedTo.flipped ? endBases(to).right : endBases(to).left;
|
|
223
|
+
const working = joinWorking({ name: placedFrom.name, end: out }, { name: placedTo.name, end: into });
|
|
224
|
+
return <ShowWorking key={`${join.from} ${join.to} ${join.at}`} working={working}><JoinBases bases={working.bases} /></ShowWorking>;
|
|
225
|
+
})}
|
|
226
|
+
</>
|
|
227
|
+
)}
|
|
228
|
+
</section>
|
|
229
|
+
)}
|
|
230
|
+
|
|
231
|
+
{view === "result" && (
|
|
232
|
+
<section className="card">
|
|
233
|
+
<h2>What it makes</h2>
|
|
234
|
+
{product === null ? <p className="dim small">Choose pieces that join into something.</p> : (
|
|
235
|
+
<>
|
|
236
|
+
<p className="voice">This run</p>
|
|
237
|
+
<p><strong>{count(product.length)} bp</strong> <span className="dim">{product.circular ? "circular" : "linear"}</span></p>
|
|
238
|
+
<SequenceMap name={run?.name ?? "product"} length={product.length} circular={product.circular} features={product.features}
|
|
239
|
+
marks={product.joins.map((join) => ({ at: join.at, label: join.kind === "blunt" ? "blunt" : join.bases }))} />
|
|
240
|
+
<p className="dim small">{product.features.length === 0 ? "Nothing was marked on the pieces, so nothing is marked on this." : "What was marked on each piece is marked where that piece now is."}</p>
|
|
241
|
+
<p className="voice">Checks</p>
|
|
242
|
+
{checks.length === 0 ? <p className="small good">Nothing about this ligation looks wrong.</p>
|
|
243
|
+
: <ul className="checks">{checks.map((check) => <li key={check.says} className={check.weight}>{check.says} <code className="because">{check.because}</code></li>)}</ul>}
|
|
244
|
+
<p className="voice">The working</p>
|
|
245
|
+
<ShowWorking working={ligationLengthWorking(product, pieces)} />
|
|
246
|
+
{product.pieces.length > 1 && (() => {
|
|
247
|
+
const longest = [...product.pieces].sort((a, b) => b.length - a.length)[0]!;
|
|
248
|
+
const other = product.pieces.find((piece) => piece.id !== longest.id)!;
|
|
249
|
+
return <ShowWorking working={ratioWorking({ name: longest.name, length: longest.length }, { name: other.name, length: other.length }, { ratio: whole(ratio) ?? 3 })}>
|
|
250
|
+
<label className="small">Molecules of insert to each of vector<input type="number" min={1} max={20} step={1} value={ratio} onChange={(event) => setRatio(event.target.value)} aria-label="Molar ratio" /></label>
|
|
251
|
+
</ShowWorking>;
|
|
252
|
+
})()}
|
|
253
|
+
<fieldset disabled={busy} className="stack">
|
|
254
|
+
<label>Call it<input value={name} onChange={(event) => setName(event.target.value)} placeholder={run?.name ?? ""} maxLength={200} /></label>
|
|
255
|
+
<label>Amount, in µL<input type="number" min={0} step={1} value={amount} onChange={(event) => setAmount(event.target.value)} /></label>
|
|
256
|
+
<label>Note<input value={note} onChange={(event) => setNote(event.target.value)} placeholder="Anything worth remembering" maxLength={2000} /></label>
|
|
257
|
+
<div className="row">
|
|
258
|
+
<button type="button" onClick={() => void record(run?.worked ?? null, "Recorded: the ligation is in the freezer.")}>It worked</button>
|
|
259
|
+
<button type="button" className="quiet" onClick={() => void record(run?.failed ?? null, "Recorded: it gave nothing.")}>It gave nothing</button>
|
|
260
|
+
</div>
|
|
261
|
+
</fieldset>
|
|
262
|
+
{said !== null && <p className="small" role="status">{said}</p>}
|
|
263
|
+
</>
|
|
264
|
+
)}
|
|
265
|
+
</section>
|
|
266
|
+
)}
|
|
267
|
+
</div>
|
|
268
|
+
);
|
|
269
|
+
return { stage, panel };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* A ligation on its own, for a lab that has not drawn its room.
|
|
274
|
+
*
|
|
275
|
+
* It is the same thing without the scene, so it carries its own way of moving between the views.
|
|
276
|
+
*
|
|
277
|
+
* @param props - `instrument` is the block it is set up at, if the lab has one; `onDone` adds a way to leave.
|
|
278
|
+
*/
|
|
279
|
+
export function LigationTool({ instrument = null, onDone }: { instrument?: { id: string; name: string } | null; onDone?: () => void }) {
|
|
280
|
+
const bench = useLigationBench({ instrument, ...(onDone === undefined ? {} : { onDone }) });
|
|
281
|
+
const names: [LigationView, string][] = [["machine", "The heat block"], ["block", "The wells"], ["screen", "The temperature"], ["tube", "In the tube"], ["result", "What it makes"]];
|
|
282
|
+
return (
|
|
283
|
+
<div className="pcr">
|
|
284
|
+
<div className="row tight pick" role="tablist" aria-label={`Views of ${bench.stage.name}`}>
|
|
285
|
+
{names.map(([one, said]) => (
|
|
286
|
+
<button key={one} type="button" role="tab" aria-selected={one === bench.stage.view} className={one === bench.stage.view ? "" : "quiet"}
|
|
287
|
+
onClick={() => bench.stage.onView(one)}>{said}</button>
|
|
288
|
+
))}
|
|
289
|
+
</div>
|
|
290
|
+
{bench.panel}
|
|
291
|
+
</div>
|
|
292
|
+
);
|
|
293
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A ligation's working: what each join is made of, where the product's length comes from, how much
|
|
3
|
+
* of each piece to put in, and what a careful person would ask before setting one up.
|
|
4
|
+
*
|
|
5
|
+
* Which ends fit is exact, and shown down to the bases. How much of each piece to use is arithmetic
|
|
6
|
+
* on a convention. Whether it will work at all is neither: it is what the checks are for.
|
|
7
|
+
*/
|
|
8
|
+
import type { LigationPiece, LigationPlan, LigationProduct, PieceEndBases } from "./ligate.js";
|
|
9
|
+
import { endBases, endsFit } from "./ligate.js";
|
|
10
|
+
import type { Working } from "./pcr-working.js";
|
|
11
|
+
|
|
12
|
+
const count = (value: number): string => value.toLocaleString("en-US");
|
|
13
|
+
const PAIR: Readonly<Record<string, string>> = { A: "T", T: "A", G: "C", C: "G", N: "N" };
|
|
14
|
+
|
|
15
|
+
/** Two ends written one over the other, to show that they pair. */
|
|
16
|
+
export interface JoinOverhangs {
|
|
17
|
+
/** The piece on the left of the join, and the one on the right. */
|
|
18
|
+
from: string;
|
|
19
|
+
to: string;
|
|
20
|
+
/** The overhang on the left-hand piece, 5′ to 3′ on the strand that carries it. */
|
|
21
|
+
left: string;
|
|
22
|
+
/** The right-hand piece's, written under it so each base sits beneath the one it pairs with. */
|
|
23
|
+
right: string;
|
|
24
|
+
/** Whether it is a 5′ overhang, a 3′ one, or two blunt ends. */
|
|
25
|
+
kind: "5′" | "3′" | "blunt";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* One join, said as steps that can be checked against the bases.
|
|
30
|
+
*
|
|
31
|
+
* @param from - The piece on the left of the join, and which of its ends this is.
|
|
32
|
+
* @param to - The piece on the right, and which of its ends.
|
|
33
|
+
* @returns The working, with the two overhangs written one over the other.
|
|
34
|
+
*/
|
|
35
|
+
export function joinWorking(from: { name: string; end: PieceEndBases }, to: { name: string; end: PieceEndBases }): Working & { bases: JoinOverhangs } {
|
|
36
|
+
const fit = endsFit(from.end, to.end);
|
|
37
|
+
const under = [...from.end.bases].map((base) => PAIR[base] ?? "N").join("");
|
|
38
|
+
const bases: JoinOverhangs = { from: from.name, to: to.name, left: from.end.bases, right: [...to.end.bases].reverse().join(""), kind: fit?.kind ?? from.end.kind };
|
|
39
|
+
if (fit === null) {
|
|
40
|
+
return {
|
|
41
|
+
of: `${from.name} to ${to.name}`, comes: "they do not fit", kind: "exact", bases,
|
|
42
|
+
steps: [
|
|
43
|
+
`${from.name}'s end is ${from.end.kind === "blunt" ? "blunt" : `a ${from.end.kind} overhang, ${from.end.bases}`}.`,
|
|
44
|
+
`${to.name}'s is ${to.end.kind === "blunt" ? "blunt" : `a ${to.end.kind} overhang, ${to.end.bases}`}.`,
|
|
45
|
+
from.end.kind !== to.end.kind ? "A sticky end and a blunt one have nothing to pair, so ligase cannot join them."
|
|
46
|
+
: from.end.bases.length !== to.end.bases.length ? `One overhang is ${from.end.bases.length} bases and the other ${to.end.bases.length}. They have to be the same length.`
|
|
47
|
+
: `${from.end.bases} would have to meet ${under} to pair, and it meets ${[...to.end.bases].reverse().join("")}.`,
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (fit.kind === "blunt") {
|
|
52
|
+
return {
|
|
53
|
+
of: `${from.name} to ${to.name}`, comes: "a blunt join", kind: "exact", bases,
|
|
54
|
+
steps: ["Both ends are blunt: every base is already paired with one opposite.",
|
|
55
|
+
"Ligase seals the backbone without anything having to find anything, so these two ends join, and so would any other two blunt ends in the tube."],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
of: `${from.name} to ${to.name}`, comes: `${fit.bases.length} bases, ${fit.bases}`, kind: "exact", bases,
|
|
60
|
+
steps: [
|
|
61
|
+
`${from.name} ends in a ${fit.kind} overhang of ${fit.bases.length} unpaired bases, ${fit.bases}.`,
|
|
62
|
+
`${to.name} begins with ${[...to.end.bases].reverse().join("")} read the other way, which is ${under}: each base is the partner of the one above it.`,
|
|
63
|
+
"So the two ends hold together while ligase seals the backbone on each strand.",
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Where a product's length comes from: the pieces, less the overhangs they share.
|
|
70
|
+
*
|
|
71
|
+
* @param product - The product.
|
|
72
|
+
* @param pieces - The pieces that went in, for their full lengths.
|
|
73
|
+
* @returns The working.
|
|
74
|
+
*/
|
|
75
|
+
export function ligationLengthWorking(product: LigationProduct, pieces: readonly LigationPiece[]): Working {
|
|
76
|
+
const lengthOf = (id: string): number => pieces.find((piece) => piece.id === id)?.sequence.replace(/\s+/g, "").length ?? 0;
|
|
77
|
+
const total = product.pieces.reduce((sum, piece) => sum + lengthOf(piece.id), 0);
|
|
78
|
+
const shared = product.joins.reduce((sum, join) => sum + join.bases.length, 0);
|
|
79
|
+
return {
|
|
80
|
+
of: "the product's length", comes: `${count(product.length)} bp`, kind: "exact",
|
|
81
|
+
steps: [
|
|
82
|
+
`The pieces are ${product.pieces.map((piece) => `${piece.name} ${count(lengthOf(piece.id))}`).join(", ")}: ${count(total)} bases in all.`,
|
|
83
|
+
shared === 0 ? "They are joined blunt, so nothing is shared between them."
|
|
84
|
+
: `Each join's overhang belongs to both pieces at once, so it is counted once: ${product.joins.map((join) => String(join.bases.length)).join(" + ")} = ${shared}.`,
|
|
85
|
+
`${count(total)} − ${count(shared)} = ${count(product.length)}${product.circular ? ", closed into a circle." : "."}`,
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* How much of each piece to put in the tube.
|
|
92
|
+
*
|
|
93
|
+
* @param vector - The piece being cloned into, by name and length.
|
|
94
|
+
* @param insert - The piece going in.
|
|
95
|
+
* @param options - `ratio` is how many times more insert than vector, by molecule, and `ng` how
|
|
96
|
+
* much of the vector is used.
|
|
97
|
+
* @returns The working.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { ratioWorking } from "@biolibs/bionet-tools";
|
|
102
|
+
*
|
|
103
|
+
* ratioWorking({ name: "vector", length: 3000 }, { name: "insert", length: 600 }).comes; // "30 ng of insert"
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export function ratioWorking(vector: { name: string; length: number }, insert: { name: string; length: number },
|
|
107
|
+
options: { ratio?: number; ng?: number } = {}): Working {
|
|
108
|
+
const ratio = options.ratio === undefined || options.ratio <= 0 ? 3 : options.ratio;
|
|
109
|
+
const ng = options.ng === undefined || options.ng <= 0 ? 50 : options.ng;
|
|
110
|
+
const wanted = ng * (insert.length / vector.length) * ratio;
|
|
111
|
+
const round = (value: number): string => String(Math.round(value * 100) / 100);
|
|
112
|
+
return {
|
|
113
|
+
of: `how much ${insert.name} to put in`, comes: `${round(wanted)} ng of insert`, kind: "estimate",
|
|
114
|
+
steps: [
|
|
115
|
+
`A molecule of ${insert.name} is ${count(insert.length)} bases and one of ${vector.name} is ${count(vector.length)}, so the same weight holds ${round(vector.length / insert.length)} times as many molecules of the insert.`,
|
|
116
|
+
`For ${ratio} molecules of insert to each of vector: ${ng} ng × ${count(insert.length)} ÷ ${count(vector.length)} × ${ratio} = ${round(wanted)} ng.`,
|
|
117
|
+
],
|
|
118
|
+
rests: "Three insert molecules to one of vector is the usual starting point, and the weight is worked out from length because a longer molecule weighs more. It assumes both preparations are what they say they are and that nothing has degraded, so it is where to start rather than a measurement.",
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Something a careful person would ask before setting a ligation up. */
|
|
123
|
+
export interface LigationCheck {
|
|
124
|
+
/** `stop` if what is hoped for is unlikely as set up, `look` if it is only worth a second glance. */
|
|
125
|
+
weight: "stop" | "look";
|
|
126
|
+
/** What to ask, said for a person. */
|
|
127
|
+
says: string;
|
|
128
|
+
/** What raised it, so it can be checked. */
|
|
129
|
+
because: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* What a careful person would ask of a ligation.
|
|
134
|
+
*
|
|
135
|
+
* These are the ways a ligation gives something other than what was wanted: a vector that closes on
|
|
136
|
+
* itself, an insert that can go in either way round, pieces that can join each other instead, a
|
|
137
|
+
* blunt join that will mostly not happen, and a PCR product whose ends ligase cannot seal.
|
|
138
|
+
*
|
|
139
|
+
* @param pieces - The pieces in the tube.
|
|
140
|
+
* @param plan - What they would make.
|
|
141
|
+
* @param options - `fromPcr` names pieces that came out of a PCR, which have no phosphate at their 5′ ends.
|
|
142
|
+
* @returns The checks that apply, the ones most likely to matter first.
|
|
143
|
+
*/
|
|
144
|
+
export function ligationChecks(pieces: readonly LigationPiece[], plan: LigationPlan,
|
|
145
|
+
options: { fromPcr?: readonly string[] } = {}): LigationCheck[] {
|
|
146
|
+
const checks: LigationCheck[] = [];
|
|
147
|
+
const wanted = plan.products.filter((product) => product.circular);
|
|
148
|
+
for (const piece of pieces) {
|
|
149
|
+
const ends = endBases(piece);
|
|
150
|
+
const fit = endsFit(ends.right, ends.left);
|
|
151
|
+
if (fit !== null && pieces.length > 1) {
|
|
152
|
+
checks.push({ weight: "stop", says: `${piece.name}'s two ends fit each other, so it can close on itself and give a colony with nothing in it. Cut with two different enzymes, or take the phosphate off its ends so only the insert can seal them.`,
|
|
153
|
+
because: fit.kind === "blunt" ? "both ends blunt" : `${ends.right.bases} meets ${ends.left.bases}` });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// The same pieces in the same order, differing only in which way round one went, is the thing a
|
|
157
|
+
// bench cannot tell apart without cutting the result.
|
|
158
|
+
const byShape = new Map<string, LigationProduct[]>();
|
|
159
|
+
for (const product of wanted) {
|
|
160
|
+
const shape = [...product.pieces].map((piece) => piece.id).sort().join("+");
|
|
161
|
+
byShape.set(shape, [...(byShape.get(shape) ?? []), product]);
|
|
162
|
+
}
|
|
163
|
+
for (const [, together] of byShape) {
|
|
164
|
+
if (together.length < 2) continue;
|
|
165
|
+
const turned = together.flatMap((product) => product.pieces.filter((piece) => piece.flipped).map((piece) => piece.name));
|
|
166
|
+
checks.push({ weight: "look", says: `These pieces make ${together.length} products that hold the same things${turned.length === 0 ? "" : `, with ${[...new Set(turned)].join(" and ")} the other way round`}. Both will be in the tube, and a check digest is what tells one from the other.`,
|
|
167
|
+
because: `${together.length} circles of ${together[0]!.pieces.length} pieces` });
|
|
168
|
+
}
|
|
169
|
+
if (wanted.some((product) => product.joins.some((join) => join.kind === "blunt"))) {
|
|
170
|
+
checks.push({ weight: "look", says: "A blunt join has nothing holding the two ends together while ligase works, so it happens far less often than a sticky one. Allow more ligase, more DNA and longer, and expect fewer colonies.", because: "a blunt join" });
|
|
171
|
+
}
|
|
172
|
+
const pcr = (options.fromPcr ?? []).filter((id) => pieces.some((piece) => piece.id === id));
|
|
173
|
+
if (pcr.length > 0) {
|
|
174
|
+
const named = pcr.map((id) => pieces.find((piece) => piece.id === id)!.name);
|
|
175
|
+
checks.push({ weight: "stop", says: `${named.join(" and ")} came out of a PCR, and a PCR product has no phosphate at its 5′ ends. Ligase seals a backbone by joining a phosphate to a hydroxyl, so there is nothing for it to join until the ends are phosphorylated.`,
|
|
176
|
+
because: "made by pcr" });
|
|
177
|
+
}
|
|
178
|
+
if (wanted.length === 0 && plan.products.length > 0) {
|
|
179
|
+
checks.push({ weight: "stop", says: "Nothing here closes into a circle. The pieces join end to end and stop, which is not something that can be grown.", because: "no circular product" });
|
|
180
|
+
}
|
|
181
|
+
return checks.sort((a, b) => Number(b.weight === "stop") - Number(a.weight === "stop"));
|
|
182
|
+
}
|