@biolibs/bionet-tools 0.1.5 → 0.1.7

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 (50) hide show
  1. package/README.md +50 -0
  2. package/dist/digest-bench.d.ts.map +1 -1
  3. package/dist/digest-bench.js +11 -2
  4. package/dist/digest-bench.js.map +1 -1
  5. package/dist/index.d.ts +8 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +8 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/ligate-bench.d.ts.map +1 -1
  10. package/dist/ligate-bench.js +10 -2
  11. package/dist/ligate-bench.js.map +1 -1
  12. package/dist/pcr-bench.d.ts.map +1 -1
  13. package/dist/pcr-bench.js +13 -2
  14. package/dist/pcr-bench.js.map +1 -1
  15. package/dist/plans.d.ts +66 -0
  16. package/dist/plans.d.ts.map +1 -0
  17. package/dist/plans.js +103 -0
  18. package/dist/plans.js.map +1 -0
  19. package/dist/primer-bench.d.ts +120 -0
  20. package/dist/primer-bench.d.ts.map +1 -0
  21. package/dist/primer-bench.js +285 -0
  22. package/dist/primer-bench.js.map +1 -0
  23. package/dist/primer-design.d.ts +273 -0
  24. package/dist/primer-design.d.ts.map +1 -0
  25. package/dist/primer-design.js +273 -0
  26. package/dist/primer-design.js.map +1 -0
  27. package/dist/primer-working.d.ts +154 -0
  28. package/dist/primer-working.d.ts.map +1 -0
  29. package/dist/primer-working.js +245 -0
  30. package/dist/primer-working.js.map +1 -0
  31. package/dist/tools.d.ts +8 -4
  32. package/dist/tools.d.ts.map +1 -1
  33. package/dist/tools.js +9 -4
  34. package/dist/tools.js.map +1 -1
  35. package/dist/working.d.ts +16 -0
  36. package/dist/working.d.ts.map +1 -1
  37. package/dist/working.js +21 -0
  38. package/dist/working.js.map +1 -1
  39. package/package.json +5 -4
  40. package/src/digest-bench.tsx +10 -1
  41. package/src/index.ts +8 -0
  42. package/src/ligate-bench.tsx +9 -1
  43. package/src/pcr-bench.tsx +11 -1
  44. package/src/plans.tsx +134 -0
  45. package/src/primer-bench.tsx +500 -0
  46. package/src/primer-design.ts +406 -0
  47. package/src/primer-working.ts +289 -0
  48. package/src/tools.tsx +14 -6
  49. package/src/working.tsx +29 -0
  50. package/tools.css +46 -0
package/package.json CHANGED
@@ -4,13 +4,14 @@
4
4
  },
5
5
  "dependencies": {
6
6
  "@biolibs/assembly2": "^1.0.0",
7
- "@biolibs/bionet": "^1.3.2",
8
- "@biolibs/bionet-panels": "^0.3.1",
7
+ "@biolibs/bionet": "^1.5.0",
8
+ "@biolibs/bionet-panels": "^0.3.3",
9
9
  "@biolibs/bionet-react": "^0.2.0",
10
10
  "@biolibs/dseq": "^1.0.0",
11
11
  "@biolibs/dseqrecord": "^1.1.1",
12
12
  "@biolibs/gel": "^1.0.0",
13
- "@biolibs/glossary-react": "^0.1.0",
13
+ "@biolibs/glossary-react": "^0.1.2",
14
+ "@biolibs/pcr": "^1.0.0",
14
15
  "@biolibs/restriction": "^1.0.0",
15
16
  "@biolibs/seq": "^1.0.0",
16
17
  "@biolibs/seqio": "^1.1.2",
@@ -62,5 +63,5 @@
62
63
  ],
63
64
  "type": "module",
64
65
  "types": "dist/index.d.ts",
65
- "version": "0.1.5"
66
+ "version": "0.1.7"
66
67
  }
@@ -17,6 +17,7 @@ import { cutters, enzymeNamed } from "./digest.js";
17
17
  import { Gel } from "./digest-tool.js";
18
18
  import { cutSites, digestChecks, digestPieces, migrationWorking, piecesWorking, siteWorking, type PieceEnd } from "./digest-working.js";
19
19
  import { SequenceMap } from "./map.js";
20
+ import { Proposed, withPlan, type Plan } from "./plans.js";
20
21
  import { digestRun, digestTubes } from "./run.js";
21
22
  import { useRunning } from "./running.js";
22
23
  import { moleculeOf, type DrawnMolecule } from "./sequence-file.js";
@@ -132,11 +133,17 @@ export function useDigestBench({ instrument = null, onDone, start }: {
132
133
  ] } }),
133
134
  };
134
135
 
136
+ /** Set the bench up as a plan says: its tube, and the enzymes it names. */
137
+ const setUp = (plan: Plan): void => {
138
+ setTube(plan.inputs.find((one) => one.role === "cut")?.item ?? "");
139
+ setChosen(typeof plan.settings["enzymes"] === "string" ? plan.settings["enzymes"].split("+").filter((one) => one !== "") : []);
140
+ setSaid(null); setKeep([]); setView("result");
141
+ };
135
142
  const toggle = (name: string): void => { setChosen(chosen.includes(name) ? chosen.filter((one) => one !== name) : [...chosen, name]); setSaid(null); setKeep([]); };
136
143
  const record = async (what: Record<string, unknown> | null, done: string): Promise<void> => {
137
144
  if (what === null) return;
138
145
  setBusy(true);
139
- const answer = await act("recordRun", what);
146
+ const answer = await act("recordRun", withPlan(lab, what));
140
147
  setBusy(false);
141
148
  if (answer.ok) { setSaid(done); setNote(""); setKeep([]); }
142
149
  };
@@ -191,6 +198,8 @@ export function useDigestBench({ instrument = null, onDone, start }: {
191
198
  {plan !== null && chosen.length > 0 && plan.problem !== null && <p className="trouble" role="status">{plan.problem}</p>}
192
199
  </section>
193
200
 
201
+ <Proposed kind="digest" now={run?.matched ?? null} onSetUp={setUp} />
202
+
194
203
  {view === "machine" && (
195
204
  <section className="card">
196
205
  <h2>At the gel box</h2>
package/src/index.ts CHANGED
@@ -24,6 +24,10 @@
24
24
  * - `working.tsx` — the working drawn: a figure that opens to show its steps
25
25
  * - `map.tsx` — a sequence's map: a circle or a line, with what is marked on it
26
26
  * - `sequences-tool.tsx` — bringing sequences in from files, and reading a part as a map
27
+ * - `primer-design.ts` — a pair of primers designed for a stretch of a part, with every candidate that was weighed and what to warn of
28
+ * - `primer-working.ts` — the working behind a design: the melting temperature's sum, the GC count, the bases that pair
29
+ * - `primer-bench.tsx` — designing primers at a desk: the panel, and the template with the pair marked on it for a scene
30
+ * - `plans.tsx` — runs that have been proposed, at the tool that would carry them out
27
31
  * - `tools.tsx` — getting to one: from an instrument, or from a list of them all
28
32
  *
29
33
  * The tools are drawn with the styles of `@biolibs/bionet-panels` and belong inside its `LabWindow`.
@@ -46,5 +50,9 @@ export * from "./digest-bench.js";
46
50
  export * from "./working.js";
47
51
  export * from "./map.js";
48
52
  export * from "./sequences-tool.js";
53
+ export * from "./plans.js";
49
54
  export * from "./tools.js";
50
55
  export * from "./pcr-bench.js";
56
+ export * from "./primer-design.js";
57
+ export * from "./primer-working.js";
58
+ export * from "./primer-bench.js";
@@ -14,6 +14,7 @@ import { Glossed } from "@biolibs/glossary-react";
14
14
  import { endBases, type LigationPiece, type LigationProduct } from "./ligate.js";
15
15
  import { joinWorking, ligationChecks, ligationLengthWorking, ratioWorking } from "./ligate-working.js";
16
16
  import { SequenceMap } from "./map.js";
17
+ import { Proposed, withPlan, type Plan } from "./plans.js";
17
18
  import { ligationRun, ligationTubes } from "./run.js";
18
19
  import { useRunning } from "./running.js";
19
20
  import { moleculeOf, type DrawnMolecule } from "./sequence-file.js";
@@ -125,6 +126,11 @@ export function useLigationBench({ instrument = null, onDone, start }: {
125
126
  } }),
126
127
  };
127
128
 
129
+ /** Set the bench up as a plan says: the pieces it names, in the tube. */
130
+ const setUp = (plan: Plan): void => {
131
+ setTubes(plan.inputs.flatMap((one) => (one.item === undefined ? [] : [one.item])));
132
+ setChosen(0); setSaid(null); setView("result");
133
+ };
128
134
  const pick = (item: string): void => {
129
135
  setTubes(tubes.includes(item) ? tubes.filter((one) => one !== item) : [...tubes, item]);
130
136
  setChosen(0);
@@ -133,7 +139,7 @@ export function useLigationBench({ instrument = null, onDone, start }: {
133
139
  const record = async (what: Record<string, unknown> | null, done: string): Promise<void> => {
134
140
  if (what === null) return;
135
141
  setBusy(true);
136
- const answer = await act("recordRun", what);
142
+ const answer = await act("recordRun", withPlan(lab, what));
137
143
  setBusy(false);
138
144
  if (answer.ok) { setSaid(done); setNote(""); setName(""); setTubes([]); }
139
145
  };
@@ -175,6 +181,8 @@ export function useLigationBench({ instrument = null, onDone, start }: {
175
181
  )}
176
182
  </section>
177
183
 
184
+ <Proposed kind="ligation" now={run?.worked ?? null} onSetUp={setUp} />
185
+
178
186
  {view === "machine" && (
179
187
  <section className="card">
180
188
  <h2>At the block</h2>
package/src/pcr-bench.tsx CHANGED
@@ -22,6 +22,7 @@ import { moleculeOf, type DrawnMolecule } from "./sequence-file.js";
22
22
  import { primerTm } from "./pcr.js";
23
23
  import { primerBinding, programmeChecks, screenOf, strandCounts, suggestProgramme, tubeLens, tubeView,
24
24
  type PcrProgramme, type PcrStepName, type TubeLens, type TubeStrand } from "./pcr-scene.js";
25
+ import { Proposed, withPlan, type Plan } from "./plans.js";
25
26
  import { pcrRun, pcrTubes, type TubeChoice } from "./run.js";
26
27
 
27
28
  /** The views of the machine, in the order a person meets them. */
@@ -237,11 +238,18 @@ export function usePcrBench({ instrument = null, onDone, start }: {
237
238
  const record = async (what: Record<string, unknown> | null, done: string): Promise<void> => {
238
239
  if (what === null) return;
239
240
  setBusy(true);
240
- const answer = await act("recordRun", what);
241
+ const answer = await act("recordRun", withPlan(lab, what));
241
242
  setBusy(false);
242
243
  if (answer.ok) { setSaid(done); setName(""); setNote(""); }
243
244
  };
244
245
  const chosen = templatePart !== undefined && forwardPart !== undefined && reversePart !== undefined;
246
+ /** Set the bench up as a plan says: each tube in the place the plan gives it. */
247
+ const setUp = (plan: Plan): void => {
248
+ const as = (role: string): string => plan.inputs.find((one) => one.role === role)?.item ?? "";
249
+ setTemplate(as("template")); setForward(as("forward primer")); setReverse(as("reverse primer"));
250
+ if (typeof plan.settings["anneal_at_least"] === "number") setLeast(String(plan.settings["anneal_at_least"]));
251
+ setView("result");
252
+ };
245
253
 
246
254
  const panel = lab === null || lab === undefined ? null : (
247
255
  <div className="bionet benchpanel">
@@ -271,6 +279,8 @@ export function usePcrBench({ instrument = null, onDone, start }: {
271
279
  )}
272
280
  </section>
273
281
 
282
+ <Proposed kind="pcr" now={run?.worked ?? null} onSetUp={setUp} />
283
+
274
284
  {view === "machine" && (
275
285
  <section className="card">
276
286
  <h2>At the machine</h2>
package/src/plans.tsx ADDED
@@ -0,0 +1,134 @@
1
+ "use client";
2
+
3
+ /**
4
+ * Runs that have been proposed, at the tool that would carry them out.
5
+ *
6
+ * A plan is a run nobody has done: somebody, or something with no hands, saying what they would do
7
+ * and what they expect of it. It is shown where it would be done, with who proposed it and why, and
8
+ * a person there can set the bench up as it says, look at the working their own tools give for it,
9
+ * and then do it or not. Nothing is taken on trust: the plan says what it expects, and the tool says
10
+ * what it would make.
11
+ *
12
+ * A run is said to carry a plan out when it is of the same kind and uses exactly the tubes the plan
13
+ * names. That is decided from what is set up, not from a button pressed earlier, so a bench that is
14
+ * changed after being set up from a plan stops claiming to be that plan.
15
+ */
16
+ import { useState, type ReactNode } from "react";
17
+ import { useAct, useLab } from "@biolibs/bionet-react";
18
+
19
+ /** One proposed run, as the lab holds it. */
20
+ export type Plan = NonNullable<NonNullable<ReturnType<typeof useLab>>["lab"]>["plans"][number];
21
+
22
+ /** As much of a lab as it takes to say which plan a run carries out. */
23
+ export interface PlanLab { plans: readonly Plan[] }
24
+
25
+ /**
26
+ * A run as a tool would record it, turned into the same run proposed.
27
+ *
28
+ * @param run - What would be handed to `recordRun`.
29
+ * @param note - Why it is proposed.
30
+ * @returns What to hand to `planRun`: the same tubes and settings, and what came out as what is expected.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { pcrRun, toPlan } from "@biolibs/bionet-tools";
35
+ *
36
+ * const run = pcrRun(lab, { template, forward, reverse });
37
+ * if (run.worked !== null) await act("planRun", toPlan(run.worked, "to check the insert is there"));
38
+ * ```
39
+ */
40
+ export function toPlan(run: Record<string, unknown>, note?: string): Record<string, unknown> {
41
+ const outputs = (Array.isArray(run["outputs"]) ? run["outputs"] : []) as { sequence: string; circular?: boolean; name: string; ends?: { left: number; right: number } }[];
42
+ const said = note?.trim() ?? "";
43
+ return {
44
+ kind: run["kind"], instrument: run["instrument"] ?? null, inputs: run["inputs"], settings: run["settings"] ?? {},
45
+ expects: outputs.map((one) => ({ sequence: one.sequence, name: one.name, ...(one.circular === true ? { circular: true } : {}), ...(one.ends === undefined ? {} : { ends: one.ends }) })),
46
+ note: said === "" ? (typeof run["note"] === "string" ? run["note"] : null) : said,
47
+ };
48
+ }
49
+
50
+ /**
51
+ * The open plan that a run, as it is set up, would carry out.
52
+ *
53
+ * @param lab - The lab.
54
+ * @param run - What would be handed to `recordRun`, or `null` if nothing is set up.
55
+ * @returns The plan of the same kind that names exactly the tubes the run uses and, where the plan
56
+ * names enzymes, the same ones; `undefined` if there is none.
57
+ */
58
+ export function planCarried(lab: PlanLab, run: Record<string, unknown> | null): Plan | undefined {
59
+ if (run === null) return undefined;
60
+ const used = ((Array.isArray(run["inputs"]) ? run["inputs"] : []) as { item?: string }[]).map((one) => one.item).sort().join(" ");
61
+ const enzymes = (run["settings"] as Record<string, unknown> | undefined)?.["enzymes"];
62
+ return lab.plans.find((plan) => plan.settled === null && plan.kind === run["kind"] && plan.inputs.every((one) => one.item !== undefined)
63
+ && plan.inputs.map((one) => one.item).sort().join(" ") === used && (plan.settings["enzymes"] === undefined || plan.settings["enzymes"] === enzymes));
64
+ }
65
+
66
+ /**
67
+ * A run to record, saying which plan it carries out if it does.
68
+ *
69
+ * @param lab - The lab.
70
+ * @param run - What would be handed to `recordRun`.
71
+ * @returns The same, with the plan it carries out named, so that recording it settles the plan.
72
+ */
73
+ export function withPlan(lab: PlanLab | null | undefined, run: Record<string, unknown>): Record<string, unknown> {
74
+ const plan = lab === null || lab === undefined ? undefined : planCarried(lab, run);
75
+ return plan === undefined ? run : { ...run, plan: plan.plan };
76
+ }
77
+
78
+ /**
79
+ * The runs proposed for one kind of tool, and a way to propose the one that is set up.
80
+ *
81
+ * @param props - `kind` is the kind of run; `now` is the run as the tool is set up, the way it would
82
+ * be recorded, or `null`; `onSetUp` is told a plan to set the tool up as.
83
+ */
84
+ export function Proposed({ kind, now, onSetUp }: { kind: string; now: Record<string, unknown> | null; onSetUp: (plan: Plan) => void }): ReactNode {
85
+ const lab = useLab()?.lab;
86
+ const act = useAct();
87
+ const [why, setWhy] = useState("");
88
+ const [busy, setBusy] = useState(false);
89
+ const [trouble, setTrouble] = useState<string | null>(null);
90
+ if (lab === null || lab === undefined) return null;
91
+ const open = lab.plans.filter((one) => one.settled === null && one.kind === kind);
92
+ const carried = planCarried(lab, now);
93
+ const person = (key: string): string => lab.roster.find((one) => one.key === key)?.person ?? "A device";
94
+ const partName = (checksum: string | undefined): string => lab.parts.find((one) => one.checksum === checksum)?.name ?? "a part";
95
+ const tubeName = (item: string | undefined): string => partName(lab.items.find((one) => one.item === item)?.part);
96
+ const ask = async (action: "planRun" | "settlePlan", payload: unknown): Promise<void> => {
97
+ setBusy(true);
98
+ const answer = await act(action, payload);
99
+ setBusy(false);
100
+ setTrouble(answer.ok ? null : answer.error);
101
+ if (answer.ok && action === "planRun") setWhy("");
102
+ };
103
+ if (open.length === 0 && now === null) return null;
104
+ return (
105
+ <section className="card proposed">
106
+ <h2>Proposed</h2>
107
+ {open.length === 0 && <p className="dim small">Nothing is proposed here. What is set up now can be proposed, for somebody to carry out: nothing is used and nothing is recorded as done.</p>}
108
+ {open.map((plan) => {
109
+ const missing = plan.inputs.filter((one) => one.item === undefined);
110
+ return (
111
+ <article key={plan.plan} className={plan === carried ? "plan now" : "plan"}>
112
+ <p className="small"><strong>{person(plan.by)}</strong> proposes using {plan.inputs.map((one) => `${one.item === undefined ? partName(one.part) : tubeName(one.item)} as ${one.role}`).join(", ")}
113
+ {plan.expects.length > 0 && <>, expecting {plan.expects.map((one) => `${one.name} (${one.length.toLocaleString("en-US")} bp${one.circular ? ", circular" : ""})`).join(" and ")}</>}.</p>
114
+ {plan.note !== null && <p className="small why">{plan.note}</p>}
115
+ {missing.length > 0 && <p className="small attention">There is no tube yet of {missing.map((one) => partName(one.part)).join(" or ")}. It has to be ordered or made before this can be done.</p>}
116
+ {plan.wanting.length > 0 && <p className="small attention">Since this was proposed, {plan.wanting.map(tubeName).join(" and ")} {plan.wanting.length === 1 ? "has" : "have"} been retired or run short of what it would use.</p>}
117
+ {plan === carried && <p className="small good">This is what is set up now. Recording the run will say this proposal was carried out.</p>}
118
+ <div className="row tight">
119
+ {plan !== carried && <button type="button" disabled={busy || missing.length > 0} onClick={() => onSetUp(plan)}>Set it up</button>}
120
+ <button type="button" className="quiet" disabled={busy} onClick={() => void ask("settlePlan", { plan: plan.plan })}>Set it aside</button>
121
+ </div>
122
+ </article>
123
+ );
124
+ })}
125
+ {now !== null && carried === undefined && (
126
+ <fieldset disabled={busy} className="stack">
127
+ <label>Why<input value={why} onChange={(event) => setWhy(event.target.value)} maxLength={2000} placeholder="What it is for, for whoever carries it out" aria-label="Why this run is proposed" /></label>
128
+ <div className="row"><button type="button" className="quiet" onClick={() => void ask("planRun", toPlan(now, why))}>Propose what is set up</button></div>
129
+ </fieldset>
130
+ )}
131
+ {trouble !== null && <p className="trouble small" role="alert">{trouble}</p>}
132
+ </section>
133
+ );
134
+ }