@biolibs/bionet-tools 0.1.6 → 0.1.9

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.
Files changed (83) hide show
  1. package/dist/assembly-bench.d.ts +62 -0
  2. package/dist/assembly-bench.d.ts.map +1 -0
  3. package/dist/assembly-bench.js +114 -0
  4. package/dist/assembly-bench.js.map +1 -0
  5. package/dist/assembly-design.d.ts +119 -0
  6. package/dist/assembly-design.d.ts.map +1 -0
  7. package/dist/assembly-design.js +157 -0
  8. package/dist/assembly-design.js.map +1 -0
  9. package/dist/codon-bench.d.ts +51 -0
  10. package/dist/codon-bench.d.ts.map +1 -0
  11. package/dist/codon-bench.js +93 -0
  12. package/dist/codon-bench.js.map +1 -0
  13. package/dist/codons.d.ts +126 -0
  14. package/dist/codons.d.ts.map +1 -0
  15. package/dist/codons.js +287 -0
  16. package/dist/codons.js.map +1 -0
  17. package/dist/digest-bench.d.ts.map +1 -1
  18. package/dist/digest-bench.js +11 -2
  19. package/dist/digest-bench.js.map +1 -1
  20. package/dist/digest.d.ts +14 -0
  21. package/dist/digest.d.ts.map +1 -1
  22. package/dist/digest.js +18 -0
  23. package/dist/digest.js.map +1 -1
  24. package/dist/index.d.ts +16 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +16 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/ligate-bench.d.ts.map +1 -1
  29. package/dist/ligate-bench.js +10 -2
  30. package/dist/ligate-bench.js.map +1 -1
  31. package/dist/pcr-bench.d.ts.map +1 -1
  32. package/dist/pcr-bench.js +13 -2
  33. package/dist/pcr-bench.js.map +1 -1
  34. package/dist/pcr-tool.js +1 -1
  35. package/dist/pcr-tool.js.map +1 -1
  36. package/dist/plans.d.ts +66 -0
  37. package/dist/plans.d.ts.map +1 -0
  38. package/dist/plans.js +106 -0
  39. package/dist/plans.js.map +1 -0
  40. package/dist/primer-bench.js +1 -1
  41. package/dist/primer-bench.js.map +1 -1
  42. package/dist/protein.d.ts +106 -0
  43. package/dist/protein.d.ts.map +1 -0
  44. package/dist/protein.js +158 -0
  45. package/dist/protein.js.map +1 -0
  46. package/dist/run.d.ts +12 -0
  47. package/dist/run.d.ts.map +1 -1
  48. package/dist/run.js +19 -4
  49. package/dist/run.js.map +1 -1
  50. package/dist/sequences-tool.js +1 -1
  51. package/dist/sequences-tool.js.map +1 -1
  52. package/dist/tools.d.ts +1 -1
  53. package/dist/tools.d.ts.map +1 -1
  54. package/dist/tools.js +7 -3
  55. package/dist/tools.js.map +1 -1
  56. package/dist/verify-bench.d.ts +48 -0
  57. package/dist/verify-bench.d.ts.map +1 -0
  58. package/dist/verify-bench.js +77 -0
  59. package/dist/verify-bench.js.map +1 -0
  60. package/dist/verify.d.ts +138 -0
  61. package/dist/verify.d.ts.map +1 -0
  62. package/dist/verify.js +263 -0
  63. package/dist/verify.js.map +1 -0
  64. package/package.json +5 -3
  65. package/src/assembly-bench.tsx +232 -0
  66. package/src/assembly-design.ts +219 -0
  67. package/src/codon-bench.tsx +189 -0
  68. package/src/codons.ts +339 -0
  69. package/src/digest-bench.tsx +10 -1
  70. package/src/digest.ts +19 -0
  71. package/src/index.ts +16 -0
  72. package/src/ligate-bench.tsx +9 -1
  73. package/src/pcr-bench.tsx +11 -1
  74. package/src/pcr-tool.tsx +1 -1
  75. package/src/plans.tsx +137 -0
  76. package/src/primer-bench.tsx +1 -1
  77. package/src/protein.ts +204 -0
  78. package/src/run.ts +20 -4
  79. package/src/sequences-tool.tsx +1 -1
  80. package/src/tools.tsx +7 -3
  81. package/src/verify-bench.tsx +161 -0
  82. package/src/verify.ts +310 -0
  83. package/tools.css +18 -0
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Designing an assembly over a lab's own parts: which pieces, in which order, and the primers that
3
+ * make them fit.
4
+ *
5
+ * A ligation joins pieces that have already been cut and whose ends happen to match. This is the
6
+ * other way round: you say what you want the ring to be made of, in order, and the primers are
7
+ * designed to give each piece the overlap it needs. That is what a construct is built by — a
8
+ * promoter, a signal, a gene and a terminator in a vector — and it is the step between having a
9
+ * sequence and having something that can be put into a cell.
10
+ *
11
+ * The designing itself is `designGibson` in `@biolibs/cloning`. What is here is everything that
12
+ * makes it the lab's: the parts it holds, what it would call the product, and the working behind
13
+ * every figure, so that nothing has to be taken on trust.
14
+ */
15
+ import { designGibson, type DesignedJunction, type DesignedPrimer, type GibsonDesign } from "@biolibs/cloning";
16
+ import type { PartFeature, PartState } from "@biolibs/bionet";
17
+ import { carryFeatures } from "./sequence-file.js";
18
+ import type { ToolLab } from "./run.js";
19
+ import type { Working } from "./pcr-working.js";
20
+
21
+ /** The longest a designed ring may be, in bases. Past this it is not something to design in a window. */
22
+ export const LONGEST_RING = 200_000;
23
+
24
+ /** One piece of a planned assembly, as the lab holds it. */
25
+ export interface AssemblyPiece {
26
+ /** The part, by checksum. */
27
+ part: string;
28
+ /**
29
+ * Whether it is to be amplified by PCR, and so can be given primer tails. A piece used as it is —
30
+ * a vector opened with an enzyme — cannot be, so its neighbours carry the whole overlap.
31
+ */
32
+ amplify: boolean;
33
+ }
34
+
35
+ /** What is being designed. */
36
+ export interface AssemblyChoice {
37
+ /** The pieces, in the order they go round the ring. At least two. */
38
+ pieces: readonly AssemblyPiece[];
39
+ /** The overlap to design at each junction, in bases. 25 unless said. */
40
+ overlap?: number;
41
+ /** The melting temperature each primer's binding part aims at, in °C. 60 unless said. */
42
+ targetTm?: number;
43
+ /** What to call the product. */
44
+ name?: string;
45
+ }
46
+
47
+ /** A piece of an assembly, placed on the ring. */
48
+ export interface AssemblyPlaced {
49
+ /** The part it is. */
50
+ part: PartState;
51
+ /** Whether it is amplified. */
52
+ amplify: boolean;
53
+ /** How many bases come before it on the ring. */
54
+ start: number;
55
+ /** One past its last base. */
56
+ end: number;
57
+ }
58
+
59
+ /** A designed assembly over a lab's parts. */
60
+ export interface AssemblyDesign {
61
+ /** The pieces, in order, each placed on the ring. */
62
+ pieces: AssemblyPlaced[];
63
+ /** The primers to order. */
64
+ primers: DesignedPrimer[];
65
+ /** The junctions, in the order they go round. */
66
+ junctions: DesignedJunction[];
67
+ /** The ring's bases. */
68
+ sequence: string;
69
+ /** How long it is. */
70
+ length: number;
71
+ /** What is marked on it: what each piece carried, moved to where that piece now is. */
72
+ features: PartFeature[];
73
+ /** What it would be called. */
74
+ name: string;
75
+ /** Anything a careful person would look at, worst first. */
76
+ warnings: string[];
77
+ /** Why it cannot be designed, or `null`. */
78
+ problem: string | null;
79
+ }
80
+
81
+ const count = (value: number): string => value.toLocaleString("en-US");
82
+
83
+ /** Parts worth offering as a piece: anything long enough to carry an overlap and a primer. */
84
+ export function assemblyParts(lab: Pick<ToolLab, "parts">, overlap = 25, shortest = 18): PartState[] {
85
+ return lab.parts.filter((one) => one.kind !== "protein" && one.length >= overlap + shortest);
86
+ }
87
+
88
+ /**
89
+ * Design an assembly of a lab's parts.
90
+ *
91
+ * @param lab - The lab.
92
+ * @param choice - The pieces in order, and how to design them.
93
+ * @returns The design, with what it would make and what to watch for. `problem` says why if it
94
+ * could not be designed.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * import { designAssembly } from "@biolibs/bionet-tools";
99
+ *
100
+ * const design = designAssembly(lab, { pieces: [{ part: backbone, amplify: false }, { part: gene, amplify: true }] });
101
+ * design.length; // the ring, every piece end to end
102
+ * design.primers; // what to order
103
+ * ```
104
+ */
105
+ export function designAssembly(lab: Pick<ToolLab, "parts">, choice: AssemblyChoice): AssemblyDesign {
106
+ const nothing = (problem: string): AssemblyDesign =>
107
+ ({ pieces: [], primers: [], junctions: [], sequence: "", length: 0, features: [], name: "", warnings: [], problem });
108
+ const held = choice.pieces.map((one) => ({ piece: one, part: lab.parts.find((each) => each.checksum === one.part) }));
109
+ const missing = held.find((one) => one.part === undefined);
110
+ if (missing !== undefined) return nothing("One of the pieces is not a part the lab has.");
111
+ const protein = held.filter((one) => one.part!.kind === "protein");
112
+ if (protein.length > 0) return nothing(`${protein.map((one) => one.part!.name).join(" and ")} ${protein.length === 1 ? "is a protein" : "are proteins"}, which cannot be a piece of a ring of DNA.`);
113
+ if (held.length < 2) return nothing("An assembly is of at least two pieces, in the order they go round the ring.");
114
+ const circles = held.filter((one) => one.part!.circular && !one.piece.amplify);
115
+ if (circles.length > 0) {
116
+ return nothing(`${circles.map((one) => one.part!.name).join(" and ")} ${circles.length === 1 ? "is a circle" : "are circles"}, which has no ends to join. Cut it first, or amplify it.`);
117
+ }
118
+ const whole = held.reduce((sum, one) => sum + one.part!.length, 0);
119
+ if (whole > LONGEST_RING) return nothing(`That would be ${count(whole)} bases, which is more than this designs in one go.`);
120
+
121
+ const designed = designGibson(held.map((one) => ({ name: one.part!.name, residues: one.part!.sequence, amplify: one.piece.amplify })),
122
+ { ...(choice.overlap === undefined ? {} : { overlap: choice.overlap }), ...(choice.targetTm === undefined ? {} : { targetTm: choice.targetTm }) });
123
+ if (!designed.ok) return nothing(designed.error);
124
+ const design: GibsonDesign = designed.design;
125
+
126
+ // Each piece goes on the ring where the pieces before it end, and takes what was marked on it there.
127
+ const pieces: AssemblyPlaced[] = [];
128
+ const features: PartFeature[] = [];
129
+ let sequence = "";
130
+ for (const { piece, part } of held) {
131
+ const start = sequence.length;
132
+ pieces.push({ part: part!, amplify: piece.amplify, start, end: start + part!.length });
133
+ for (const feature of carryFeatures(part!.features, 0, part!.length, start)) features.push(feature);
134
+ sequence += part!.sequence;
135
+ }
136
+ const name = choice.name?.trim() !== undefined && choice.name.trim() !== "" ? choice.name.trim()
137
+ : held.map((one) => one.part!.name).join(" + ");
138
+ return {
139
+ pieces, primers: design.primers, junctions: design.junctions, sequence, length: sequence.length,
140
+ features, name, warnings: [...design.warnings], problem: null,
141
+ };
142
+ }
143
+
144
+ /**
145
+ * The working behind a designed assembly: where every figure comes from.
146
+ *
147
+ * @param design - The design.
148
+ * @returns One working for the ring's length, one for each junction, and one for each primer.
149
+ */
150
+ export function assemblyWorking(design: AssemblyDesign): Working[] {
151
+ if (design.problem !== null) return [];
152
+ const out: Working[] = [{
153
+ of: "the ring",
154
+ comes: `${count(design.length)} bases`,
155
+ kind: "exact",
156
+ steps: [
157
+ ...design.pieces.map((one) => `${one.part.name}: ${count(one.part.length)} bases, at ${count(one.start + 1)}–${count(one.end)}`),
158
+ `every piece end to end: ${design.pieces.map((one) => count(one.part.length)).join(" + ")} = ${count(design.length)}`,
159
+ "an overlap takes nothing away: it is the bases either side of a junction, which the primers' tails copy so the two products share them, and joining them puts each back once",
160
+ ],
161
+ }];
162
+ for (const junction of design.junctions) {
163
+ out.push({
164
+ of: `the join between ${junction.from} and ${junction.to}`,
165
+ comes: `${junction.length} bases, melting near ${Math.round(junction.tm)} °C`,
166
+ kind: "estimate",
167
+ steps: [
168
+ // A primer's tail reaches across the junction, so what each carries is its neighbour's
169
+ // bases: the forward primer of the second piece is what carries the end of the first.
170
+ `${junction.carried.toForward} bases from the end of ${junction.from}${junction.carried.toForward === 0 ? ", which contributes none here" : `, carried on ${junction.to}'s forward primer as a tail`}`,
171
+ `${junction.carried.fromReverse} bases from the start of ${junction.to}${junction.carried.fromReverse === 0 ? ", which contributes none here" : `, carried on ${junction.from}'s reverse primer as a tail`}`,
172
+ `the overlap the two products share: ${junction.overlap}`,
173
+ "its melting temperature: 2 °C for each A or T and 4 °C for each G or C, the rough figure written on a tube",
174
+ ],
175
+ rests: "The melting temperature is the Wallace rule, which is a guide and not a measurement.",
176
+ });
177
+ }
178
+ for (const primer of design.primers) {
179
+ out.push({
180
+ of: primer.name,
181
+ comes: `${primer.sequence.length} bases: a ${primer.tail.length}-base tail and a ${primer.binding.length}-base binding part`,
182
+ kind: "exact",
183
+ steps: [
184
+ `the tail: ${primer.tail === "" ? "none, since this end needs no overlap carried" : primer.tail}`,
185
+ `the part that binds: ${primer.binding}`,
186
+ `the annealing temperature comes from that part alone, which melts near ${Math.round(primer.binding_report.tm)} °C`,
187
+ `what is ordered: ${primer.sequence}`,
188
+ ],
189
+ });
190
+ }
191
+ return out;
192
+ }
193
+
194
+ /**
195
+ * A designed assembly, as a run the lab would record.
196
+ *
197
+ * It is one run: the pieces go in, the ring comes out. The primers are not inputs, because they are
198
+ * used in the PCRs that make the pieces, which are runs of their own.
199
+ *
200
+ * @param design - The design.
201
+ * @param choice - The tubes of each piece, how much of each, and where it was done.
202
+ * @returns What to hand to the lab's `recordRun`, or `null` if there is nothing to record.
203
+ */
204
+ export function assemblyRun(design: AssemblyDesign, choice: {
205
+ tubes: Readonly<Record<string, string>>; used?: Readonly<Record<string, number>>; instrument?: string | null; amount?: number; unit?: string | null; note?: string | null;
206
+ }): Record<string, unknown> | null {
207
+ if (design.problem !== null) return null;
208
+ const inputs = design.pieces.flatMap((one) => {
209
+ const tube = choice.tubes[one.part.checksum];
210
+ return tube === undefined ? [] : [{ item: tube, amount: Math.max(0, Math.round(choice.used?.[tube] ?? 1)), role: "piece" }];
211
+ });
212
+ if (inputs.length !== design.pieces.length) return null;
213
+ return {
214
+ kind: "assembly", instrument: choice.instrument ?? null, inputs,
215
+ outputs: [{ sequence: design.sequence, circular: true, name: design.name, amount: Math.max(0, Math.round(choice.amount ?? 20)), unit: choice.unit ?? "µL", features: design.features }],
216
+ settings: { pieces: design.pieces.length, joins: design.junctions.length, overlap: design.junctions[0]?.length ?? 0 },
217
+ outcome: "worked", note: choice.note ?? null,
218
+ };
219
+ }
@@ -0,0 +1,189 @@
1
+ "use client";
2
+
3
+ /**
4
+ * Writing a gene in a host's codons, at a desk.
5
+ *
6
+ * The whole of this tool turns on one thing being visible: where the host's preferences came from.
7
+ * There is no table built in and none is asserted. You choose which of the lab's own sequences are
8
+ * the host's genes, they are counted here, and the counts are on the screen beside the result. A
9
+ * table counted over three genes says so; a figure nobody can check is worse than no figure.
10
+ */
11
+ import { useEffect, useMemo, useState, type ReactNode } from "react";
12
+ import { useAct, useLab } from "@biolibs/bionet-react";
13
+ import { Glossed } from "@biolibs/glossary-react";
14
+ import { COMMON_ENZYMES, siteOf } from "./digest.js";
15
+ import { CODON, codonWorking, countCodonUsage, optimiseCodons } from "./codons.js";
16
+ import { ShowWorking } from "./working.js";
17
+
18
+ const count = (value: number): string => value.toLocaleString("en-US");
19
+ const share = (value: number): string => `${Math.round(value * 100)}%`;
20
+
21
+ /** What a host is handed to draw beside the panel. */
22
+ export interface CodonDesk {
23
+ /** The tube of the gene being rewritten, to look at, if the lab has one that has been put somewhere. */
24
+ focus: { place: string; item: string } | null;
25
+ /** The rewritten sequence, once there is one. */
26
+ sequence: string | null;
27
+ }
28
+
29
+ /**
30
+ * Rewriting one of the lab's genes in a host's codons.
31
+ *
32
+ * @param options - `start` says what to open on, for a tour or a link.
33
+ * @returns `panel`, the tool itself, and `desk`, what a scene beside it should look at.
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * import { useCodonBench } from "@biolibs/bionet-tools";
38
+ *
39
+ * const bench = useCodonBench();
40
+ * <LabView lab={lab} wide beside={bench.panel} />
41
+ * ```
42
+ */
43
+ export function useCodonBench({ start }: {
44
+ /** What to show: the gene, the host's genes, and sites to keep out. Followed whenever it changes. */
45
+ start?: { gene?: string; hostGenes?: readonly string[]; avoid?: readonly string[] };
46
+ } = {}): { panel: ReactNode; desk: CodonDesk } {
47
+ const lab = useLab()?.lab;
48
+ const act = useAct();
49
+ const [gene, setGene] = useState(start?.gene ?? "");
50
+ const [hostGenes, setHostGenes] = useState<string[]>([...(start?.hostGenes ?? [])]);
51
+ const [avoid, setAvoid] = useState<string[]>([...(start?.avoid ?? [])]);
52
+ const [busy, setBusy] = useState(false);
53
+ const [said, setSaid] = useState<string | null>(null);
54
+
55
+ const asked = JSON.stringify(start ?? null);
56
+ useEffect(() => {
57
+ if (start === undefined) return;
58
+ if (start.gene !== undefined) setGene(start.gene);
59
+ if (start.hostGenes !== undefined) setHostGenes([...start.hostGenes]);
60
+ if (start.avoid !== undefined) setAvoid([...start.avoid]);
61
+ }, [asked]);
62
+
63
+ // Anything that is a whole number of codons could be a coding sequence; nothing else can.
64
+ const coding = useMemo(() => (lab?.parts ?? []).filter((one) => one.kind !== "protein" && !one.circular && one.length >= CODON && one.length % CODON === 0), [lab?.parts]);
65
+ const usage = useMemo(() => {
66
+ const chosen = coding.filter((one) => hostGenes.includes(one.checksum));
67
+ return chosen.length === 0 ? null : countCodonUsage(chosen.map((one) => one.sequence), {
68
+ from: `${chosen.length} ${chosen.length === 1 ? "sequence" : "sequences"} this lab holds: ${chosen.map((one) => one.name).join(", ")}`,
69
+ });
70
+ }, [coding, hostGenes]);
71
+ const part = coding.find((one) => one.checksum === gene);
72
+ // Only the enzymes whose site is actually known can be kept out; the rest are not offered.
73
+ const sites = useMemo(() => avoid.flatMap((name) => { const site = siteOf(name); return site === null ? [] : [{ name, site }]; }), [avoid]);
74
+ const done = useMemo(() => {
75
+ if (part === undefined || usage === null) return null;
76
+ return optimiseCodons(part.sequence, usage, { avoid: sites });
77
+ }, [part, usage, sites]);
78
+ const working = useMemo(() => (done === null || done.problem !== null || usage === null ? [] : codonWorking(done, usage)), [done, usage]);
79
+
80
+ const tube = lab?.items.find((one) => one.part === gene && !one.retired && one.where !== null);
81
+ const desk: CodonDesk = {
82
+ focus: tube?.where == null ? null : { place: tube.where.place, item: tube.item },
83
+ sequence: done?.problem === null ? done.sequence : null,
84
+ };
85
+
86
+ const keep = async (): Promise<void> => {
87
+ if (done === null || done.problem !== null || part === undefined) return;
88
+ setBusy(true);
89
+ const answer = await act("addPart", { name: `${part.name} (codon optimised)`, sequence: done.sequence });
90
+ setBusy(false);
91
+ setSaid(answer.ok ? "Kept as a part. There is no tube of it: it has to be ordered or made." : answer.error);
92
+ };
93
+
94
+ const panel = lab === null || lab === undefined ? null : (
95
+ <div className="bionet codons">
96
+ <section className="card">
97
+ <h2>Write a gene for a host</h2>
98
+ <p className="small"><Glossed text="Most amino acids have more than one codon, and an organism uses them unevenly: a gene written in another organism's codons is read slowly." /></p>
99
+ <p className="dim small">There is no table of codon usage built into this. Choose which of the lab's sequences are the host's own genes and the preferences are counted from them, here, where you can check them. A handful of the host's genes, brought in on the Sequences tab, is what this wants.</p>
100
+ {coding.length === 0 ? <p className="empty">The lab has no sequence that is a whole number of codons. Bring a coding sequence in on the Sequences tab.</p> : (
101
+ <fieldset disabled={busy} className="stack">
102
+ <label>The gene to rewrite
103
+ <select value={gene} onChange={(event) => { setGene(event.target.value); setSaid(null); }} aria-label="The gene to rewrite">
104
+ <option value="">Choose a sequence…</option>
105
+ {coding.map((one) => <option key={one.checksum} value={one.checksum}>{one.name} · {count(one.length / CODON)} codons</option>)}
106
+ </select>
107
+ </label>
108
+ <label>The host&apos;s own genes
109
+ <select multiple size={Math.min(6, Math.max(3, coding.length))} value={hostGenes} aria-label="The host's own genes"
110
+ onChange={(event) => { setHostGenes(Array.from(event.target.selectedOptions, (one) => one.value)); setSaid(null); }}>
111
+ {coding.map((one) => <option key={one.checksum} value={one.checksum}>{one.name}</option>)}
112
+ </select>
113
+ </label>
114
+ <div className="row tight pick" role="group" aria-label="Sites to keep out">
115
+ <span className="dim small">Keep out</span>
116
+ {COMMON_ENZYMES.filter((one) => siteOf(one) !== null).slice(0, 6).map((one) => (
117
+ <button key={one} type="button" aria-pressed={avoid.includes(one)} className={avoid.includes(one) ? "" : "quiet"}
118
+ onClick={() => { setAvoid(avoid.includes(one) ? avoid.filter((each) => each !== one) : [...avoid, one]); setSaid(null); }}>{one}</button>
119
+ ))}
120
+ </div>
121
+ </fieldset>
122
+ )}
123
+ </section>
124
+
125
+ {usage !== null && (
126
+ <section className="card">
127
+ <h2>What this host prefers</h2>
128
+ <p className="voice">Counted here</p>
129
+ <p className="small">{count(usage.codons)} codons over {usage.genes} {usage.genes === 1 ? "gene" : "genes"}.</p>
130
+ {usage.warnings.length > 0 && <ul className="checks">{usage.warnings.map((one) => <li key={one} className="look">{one}</li>)}</ul>}
131
+ <p className="dim small">This is not a published table. It is what those genes do, and it is worth what they are worth as a sample of the host.</p>
132
+ </section>
133
+ )}
134
+
135
+ {done !== null && done.problem !== null && <p className="trouble" role="status">{done.problem}</p>}
136
+
137
+ {done !== null && done.problem === null && (
138
+ <>
139
+ <section className="card">
140
+ <h2>The rewrite</h2>
141
+ <p className="voice">This gene</p>
142
+ <p><strong>{count(done.changes.length)}</strong> of {count(done.codons)} codons changed · GC {share(done.gcBefore)} → {share(done.gcAfter)}</p>
143
+ <p className="small good">The protein is the same: it was translated before and after and compared.</p>
144
+ {done.avoided.length > 0 && <p className="small">Kept out: {done.avoided.join(", ")}.</p>}
145
+ {done.changes.length > 0 && (
146
+ <table>
147
+ <thead><tr><th>Codon</th><th>For</th><th>Was</th><th>Is</th><th>Why</th></tr></thead>
148
+ <tbody>
149
+ {done.changes.slice(0, 12).map((one) => (
150
+ <tr key={one.at}>
151
+ <td>{one.at}</td>
152
+ <td>{one.aminoAcid}</td>
153
+ <td><code>{one.from}</code> <span className="dim">{share(one.fromShare)}</span></td>
154
+ <td><code>{one.to}</code> <span className="dim">{share(one.toShare)}</span></td>
155
+ <td className="dim small">{one.instead ?? ""}</td>
156
+ </tr>
157
+ ))}
158
+ </tbody>
159
+ </table>
160
+ )}
161
+ {done.changes.length > 12 && <p className="dim small">and {count(done.changes.length - 12)} more.</p>}
162
+ {done.warnings.length > 0 && <ul className="checks">{done.warnings.map((one) => <li key={one} className="look">{one}</li>)}</ul>}
163
+ <code className="wrap">{done.sequence.length <= 240 ? done.sequence : `${done.sequence.slice(0, 120)} … ${done.sequence.slice(-120)}`}</code>
164
+ <fieldset disabled={busy} className="row">
165
+ <button type="button" onClick={() => void keep()}>Keep it as a part</button>
166
+ <span className="dim small">No tube: it has to be ordered or made.</span>
167
+ </fieldset>
168
+ {said !== null && <p className="small" role="status">{said}</p>}
169
+ </section>
170
+
171
+ <section className="card">
172
+ <h2>The working</h2>
173
+ {working.map((one) => <ShowWorking key={one.of} working={one} />)}
174
+ </section>
175
+ </>
176
+ )}
177
+ </div>
178
+ );
179
+ return { panel, desk };
180
+ }
181
+
182
+ /**
183
+ * The codon tool on its own, for a lab that has not drawn its room.
184
+ *
185
+ * @param props - `start` says what to open on.
186
+ */
187
+ export function CodonTool(props: Parameters<typeof useCodonBench>[0]) {
188
+ return <>{useCodonBench(props).panel}</>;
189
+ }