@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/run.ts
CHANGED
|
@@ -5,10 +5,14 @@
|
|
|
5
5
|
* primers, and what to ask the lab to record once somebody has chosen. It is plain data in and plain
|
|
6
6
|
* data out, so the window that uses it decides nothing.
|
|
7
7
|
*/
|
|
8
|
-
import type { ItemState, PartState, PlaceState } from "@biolibs/bionet";
|
|
8
|
+
import type { ItemState, PartFeature, PartState, PlaceState } from "@biolibs/bionet";
|
|
9
9
|
import { amountOf, whereWords } from "@biolibs/bionet-panels";
|
|
10
10
|
import { planDigest, type DigestPlan } from "./digest.js";
|
|
11
|
+
import { cutSites, digestPieces, type DigestPiece } from "./digest-working.js";
|
|
12
|
+
import { endBases, planLigation, type LigationPiece, type LigationPlan, type LigationProduct } from "./ligate.js";
|
|
11
13
|
import { ANNEAL_AT_LEAST, looksLikePrimer, planPcr, type PcrPlan } from "./pcr.js";
|
|
14
|
+
import { primerBinding, type PcrProgramme } from "./pcr-scene.js";
|
|
15
|
+
import { carryFeatures } from "./sequence-file.js";
|
|
12
16
|
|
|
13
17
|
/** As much of a lab as a tool reads. */
|
|
14
18
|
export interface ToolLab {
|
|
@@ -67,12 +71,16 @@ export interface PcrChoice {
|
|
|
67
71
|
unit?: string | null;
|
|
68
72
|
/** Anything worth saying about the run. */
|
|
69
73
|
note?: string | null;
|
|
74
|
+
/** The programme the machine was set to, to be kept with the run. */
|
|
75
|
+
programme?: PcrProgramme;
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
/** A PCR as chosen: what it would make, and what to ask the lab to record. */
|
|
73
79
|
export interface PcrRun {
|
|
74
80
|
/** What the PCR would make, or `null` if a tube that was chosen is not one the lab has. */
|
|
75
81
|
plan: PcrPlan | null;
|
|
82
|
+
/** What is marked on the product: what the template had on the stretch copied, and the primers at its ends. */
|
|
83
|
+
features: PartFeature[];
|
|
76
84
|
/** What the product would be called. */
|
|
77
85
|
name: string;
|
|
78
86
|
/** What to hand to the lab's `recordRun` if it worked. `null` while there is not exactly one product. */
|
|
@@ -81,6 +89,37 @@ export interface PcrRun {
|
|
|
81
89
|
failed: Record<string, unknown> | null;
|
|
82
90
|
}
|
|
83
91
|
|
|
92
|
+
/**
|
|
93
|
+
* What is marked on a PCR's product.
|
|
94
|
+
*
|
|
95
|
+
* A feature of the template that lies on the stretch copied is carried over, moved to where it now
|
|
96
|
+
* is; one that is only partly copied is carried as the part that was, and named as a part. Each
|
|
97
|
+
* primer is marked at the end it became. If the template is a circle and the stretch copied runs
|
|
98
|
+
* through its origin, only the primers are marked.
|
|
99
|
+
*
|
|
100
|
+
* @param template - The template, with what is marked on it.
|
|
101
|
+
* @param forward - One primer, by name and bases.
|
|
102
|
+
* @param reverse - The other.
|
|
103
|
+
* @param least - How many bases at each primer's 3′ end must bind.
|
|
104
|
+
* @returns The features, placed on the product. Empty if either primer does not bind in one place.
|
|
105
|
+
*/
|
|
106
|
+
export function pcrFeatures(template: Pick<PartState, "sequence" | "features">, forward: { name: string; sequence: string },
|
|
107
|
+
reverse: { name: string; sequence: string }, least = ANNEAL_AT_LEAST): PartFeature[] {
|
|
108
|
+
const found = [forward, reverse].map((primer) => ({ primer, binding: primerBinding(template.sequence, primer.sequence, least) }));
|
|
109
|
+
const top = found.find((one) => one.binding?.reads === "top");
|
|
110
|
+
const bottom = found.find((one) => one.binding?.reads === "bottom");
|
|
111
|
+
if (top?.binding == null || bottom?.binding == null) return [];
|
|
112
|
+
const [from, to] = [top.binding.start, bottom.binding.end];
|
|
113
|
+
const straight = to > from;
|
|
114
|
+
const copied = straight ? to - from : template.sequence.replace(/\s+/g, "").length - from + to;
|
|
115
|
+
const length = top.binding.tail + copied + bottom.binding.tail;
|
|
116
|
+
const primers: PartFeature[] = [
|
|
117
|
+
{ type: "primer_bind", label: top.primer.name, strand: 1, parts: [{ start: 0, end: Math.min(length, top.primer.sequence.length) }] },
|
|
118
|
+
{ type: "primer_bind", label: bottom.primer.name, strand: -1, parts: [{ start: Math.max(0, length - bottom.primer.sequence.length), end: length }] },
|
|
119
|
+
];
|
|
120
|
+
return [...(straight ? carryFeatures(template.features, from, to, top.binding.tail) : []), ...primers];
|
|
121
|
+
}
|
|
122
|
+
|
|
84
123
|
/**
|
|
85
124
|
* Work a choice of tubes out into a run.
|
|
86
125
|
*
|
|
@@ -104,7 +143,7 @@ export function pcrRun(lab: ToolLab, choice: PcrChoice): PcrRun {
|
|
|
104
143
|
};
|
|
105
144
|
const [template, forward, reverse] = [partOf(choice.template), partOf(choice.forward), partOf(choice.reverse)];
|
|
106
145
|
const typed = choice.name?.trim() ?? "";
|
|
107
|
-
if (template === undefined || forward === undefined || reverse === undefined) return { plan: null, name: typed, worked: null, failed: null };
|
|
146
|
+
if (template === undefined || forward === undefined || reverse === undefined) return { plan: null, name: typed, features: [], worked: null, failed: null };
|
|
108
147
|
const least = choice.annealAtLeast ?? ANNEAL_AT_LEAST;
|
|
109
148
|
const plan = planPcr(template, forward.sequence, reverse.sequence, { annealAtLeast: least });
|
|
110
149
|
const name = typed !== "" ? typed : `${template.name} × ${forward.name} + ${reverse.name}`.slice(0, 200);
|
|
@@ -116,15 +155,22 @@ export function pcrRun(lab: ToolLab, choice: PcrChoice): PcrRun {
|
|
|
116
155
|
{ item: choice.forward, amount: whole(choice.used?.forward, 1), role: "forward primer" },
|
|
117
156
|
{ item: choice.reverse, amount: whole(choice.used?.reverse, 1), role: "reverse primer" },
|
|
118
157
|
],
|
|
119
|
-
|
|
158
|
+
// What the operator set is part of what was done, and is what somebody repeating the run needs.
|
|
159
|
+
settings: { anneal_at_least: least, ...(choice.programme === undefined ? {} : {
|
|
160
|
+
denature_c: choice.programme.steps[0].celsius, anneal_c: choice.programme.steps[1].celsius, anneal_s: choice.programme.steps[1].seconds,
|
|
161
|
+
extend_c: choice.programme.steps[2].celsius, extend_s: choice.programme.steps[2].seconds, cycles: choice.programme.cycles,
|
|
162
|
+
}) },
|
|
120
163
|
note: choice.note ?? null,
|
|
121
164
|
};
|
|
122
165
|
const product = plan.problem === null ? plan.products[0]! : null;
|
|
166
|
+
// Only marked if they land on the product the engine made: the two are worked out separately.
|
|
167
|
+
const marked = product === null ? [] : pcrFeatures(template, forward, reverse, least);
|
|
168
|
+
const features = marked.every((one) => one.parts.every((piece) => piece.end <= product!.length)) ? marked : [];
|
|
123
169
|
return {
|
|
124
|
-
plan, name,
|
|
170
|
+
plan, name, features,
|
|
125
171
|
worked: product === null ? null : {
|
|
126
172
|
...record, outcome: "worked",
|
|
127
|
-
outputs: [{ sequence: product.sequence, circular: false, name, amount: whole(choice.amount, 50), unit: choice.unit === undefined ? "µL" : choice.unit }],
|
|
173
|
+
outputs: [{ sequence: product.sequence, circular: false, name, features, amount: whole(choice.amount, 50), unit: choice.unit === undefined ? "µL" : choice.unit }],
|
|
128
174
|
},
|
|
129
175
|
failed: { ...record, outcome: "failed", outputs: [] },
|
|
130
176
|
};
|
|
@@ -152,6 +198,14 @@ export interface DigestChoice {
|
|
|
152
198
|
/** The gel's agarose concentration and the ladder beside it, by their IDs in `@biolibs/gel`. */
|
|
153
199
|
gel?: string;
|
|
154
200
|
ladder?: string;
|
|
201
|
+
/**
|
|
202
|
+
* The pieces to keep as tubes, each by where it starts on the molecule. Cutting a band out of a
|
|
203
|
+
* gel and cleaning it up gives a tube of that piece, with the ends the enzymes left.
|
|
204
|
+
*/
|
|
205
|
+
keep?: readonly { from: number; name?: string; amount?: number; unit?: string | null }[];
|
|
206
|
+
/** What the power supply was set to: volts, and minutes run. Whole numbers. */
|
|
207
|
+
volts?: number;
|
|
208
|
+
minutes?: number;
|
|
155
209
|
/** The gel station it was run at, if the lab has one. */
|
|
156
210
|
instrument?: string | null;
|
|
157
211
|
/** Anything worth saying about it. */
|
|
@@ -162,6 +216,8 @@ export interface DigestChoice {
|
|
|
162
216
|
export interface DigestRun {
|
|
163
217
|
/** What the digest would give, or `null` if the tube is not one the lab has. */
|
|
164
218
|
plan: DigestPlan | null;
|
|
219
|
+
/** The pieces, each with its ends and what it carries. */
|
|
220
|
+
pieces: DigestPiece[];
|
|
165
221
|
/** What to hand to the lab's `recordRun` if the gel matched. `null` while there is nothing to match. */
|
|
166
222
|
matched: Record<string, unknown> | null;
|
|
167
223
|
/** What to hand to it if the gel was run and did not match. `null` likewise. */
|
|
@@ -171,9 +227,9 @@ export interface DigestRun {
|
|
|
171
227
|
/**
|
|
172
228
|
* Work a choice of tube and enzymes out into a run.
|
|
173
229
|
*
|
|
174
|
-
* A digest
|
|
175
|
-
*
|
|
176
|
-
*
|
|
230
|
+
* A digest is first a check: it uses some of a tube, and what is recorded is which enzymes, what
|
|
231
|
+
* pieces were expected, and whether the gel showed them. Pieces may also be kept. Each kept piece
|
|
232
|
+
* becomes a tube of a part with the ends the enzymes left, since a cut piece is defined by its ends.
|
|
177
233
|
*
|
|
178
234
|
* @param lab - The lab.
|
|
179
235
|
* @param choice - The tube, the enzymes, and how much was used.
|
|
@@ -182,26 +238,142 @@ export interface DigestRun {
|
|
|
182
238
|
export function digestRun(lab: ToolLab, choice: DigestChoice): DigestRun {
|
|
183
239
|
const item = lab.items.find((one) => one.item === choice.tube);
|
|
184
240
|
const part = item === undefined ? undefined : lab.parts.find((one) => one.checksum === item.part);
|
|
185
|
-
if (part === undefined) return { plan: null, matched: null, differed: null };
|
|
241
|
+
if (part === undefined) return { plan: null, pieces: [], matched: null, differed: null };
|
|
186
242
|
const plan = planDigest(part, choice.enzymes, { ...(choice.gel === undefined ? {} : { gel: choice.gel }), ...(choice.ladder === undefined ? {} : { ladder: choice.ladder }) });
|
|
187
|
-
if (plan.problem !== null) return { plan, matched: null, differed: null };
|
|
243
|
+
if (plan.problem !== null) return { plan, pieces: [], matched: null, differed: null };
|
|
244
|
+
const pieces = digestPieces(part, plan.cutters.flatMap((one) => cutSites(part, one)));
|
|
245
|
+
const enzymesUsed = plan.cutters.filter((one) => one.positions.length > 0).map((one) => one.name).join("+");
|
|
246
|
+
const kept = (choice.keep ?? []).flatMap((wanted) => {
|
|
247
|
+
const piece = pieces.find((one) => one.from === wanted.from);
|
|
248
|
+
if (piece === undefined) return [];
|
|
249
|
+
const amount = wanted.amount === undefined || !Number.isSafeInteger(wanted.amount) || wanted.amount < 0 ? 20 : wanted.amount;
|
|
250
|
+
const typed = wanted.name?.trim() ?? "";
|
|
251
|
+
return [{ sequence: piece.sequence, circular: false, ends: piece.ends, features: piece.features, amount, unit: wanted.unit === undefined ? "µL" : wanted.unit,
|
|
252
|
+
name: (typed !== "" ? typed : `${part.name} ${enzymesUsed} ${piece.length} bp`).slice(0, 200) }];
|
|
253
|
+
});
|
|
188
254
|
const used = choice.used === undefined || !Number.isSafeInteger(choice.used) || choice.used < 0 ? 1 : choice.used;
|
|
189
255
|
const record = {
|
|
190
256
|
kind: "digest", instrument: choice.instrument ?? null,
|
|
191
257
|
inputs: [{ item: choice.tube, amount: used, role: "cut" }],
|
|
192
258
|
outputs: [],
|
|
193
259
|
// Settings are short text, so a digest into very many pieces records as many as fit.
|
|
194
|
-
settings: { enzymes: plan.cutters.map((one) => one.name).join("+").slice(0, 200), expected: plan.fragments.join(",").slice(0, 200), gel: plan.gel
|
|
260
|
+
settings: { enzymes: plan.cutters.map((one) => one.name).join("+").slice(0, 200), expected: plan.fragments.join(",").slice(0, 200), gel: plan.gel,
|
|
261
|
+
...(Number.isSafeInteger(choice.volts) ? { volts: choice.volts } : {}), ...(Number.isSafeInteger(choice.minutes) ? { minutes: choice.minutes } : {}) },
|
|
262
|
+
note: choice.note ?? null,
|
|
263
|
+
};
|
|
264
|
+
// Pieces can only be kept from a gel that showed them.
|
|
265
|
+
return { plan, pieces, matched: { ...record, outputs: kept, outcome: "worked", ...(kept.length === 0 ? {} : { settings: { ...record.settings, kept: kept.length } }) },
|
|
266
|
+
differed: { ...record, outcome: "failed" } };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The tubes a ligation could be set up from: every tube of a linear molecule with something in it.
|
|
271
|
+
*
|
|
272
|
+
* A circle has no ends to join, so it is left out until somebody cuts it.
|
|
273
|
+
*
|
|
274
|
+
* @param lab - The lab.
|
|
275
|
+
* @returns The tubes to offer, the ones with sticky ends first, since those are the ones that were cut.
|
|
276
|
+
*/
|
|
277
|
+
export function ligationTubes(lab: ToolLab): TubeChoice[] {
|
|
278
|
+
return pcrTubes(lab).templates.filter((one) => !one.part.circular)
|
|
279
|
+
.sort((a, b) => Number(sticky(b.part)) - Number(sticky(a.part)) || b.part.length - a.part.length);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Whether a part has an end with unpaired bases. */
|
|
283
|
+
const sticky = (part: PartState): boolean => (part.ends?.left ?? 0) !== 0 || (part.ends?.right ?? 0) !== 0;
|
|
284
|
+
|
|
285
|
+
/** What somebody has chosen for a ligation. */
|
|
286
|
+
export interface LigationChoice {
|
|
287
|
+
/** The tubes to join, by item ID. */
|
|
288
|
+
tubes: readonly string[];
|
|
289
|
+
/** How much of each was used, in its own unit. Whole numbers, by item ID. */
|
|
290
|
+
used?: Readonly<Record<string, number>>;
|
|
291
|
+
/** Whether two blunt ends may be joined, and whether to keep the products that do not close. */
|
|
292
|
+
blunt?: boolean;
|
|
293
|
+
linear?: boolean;
|
|
294
|
+
/** Which product is being made, by its place in the plan. The first by default. */
|
|
295
|
+
chosen?: number;
|
|
296
|
+
/** The heat block or water bath it was set up at, if the lab has one. */
|
|
297
|
+
instrument?: string | null;
|
|
298
|
+
/** What to call the product, how much of it there is, and in what unit. */
|
|
299
|
+
name?: string;
|
|
300
|
+
amount?: number;
|
|
301
|
+
unit?: string | null;
|
|
302
|
+
/** Anything worth saying about it. */
|
|
303
|
+
note?: string | null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** A ligation as chosen: what it would make, and what to ask the lab to record. */
|
|
307
|
+
export interface LigationRun {
|
|
308
|
+
/** What it would make, or `null` if a tube that was chosen is not one the lab has. */
|
|
309
|
+
plan: LigationPlan | null;
|
|
310
|
+
/** The pieces, as the sequence layer needs them. */
|
|
311
|
+
pieces: LigationPiece[];
|
|
312
|
+
/** The product being made, or `null` if there is nothing to make. */
|
|
313
|
+
product: LigationProduct | null;
|
|
314
|
+
/** What it would be called. */
|
|
315
|
+
name: string;
|
|
316
|
+
/** What to hand to the lab's `recordRun` if it worked. `null` while there is nothing to make. */
|
|
317
|
+
worked: Record<string, unknown> | null;
|
|
318
|
+
/** What to hand to it if it was set up and gave nothing. `null` if a tube is missing. */
|
|
319
|
+
failed: Record<string, unknown> | null;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Work a choice of tubes out into a ligation.
|
|
324
|
+
*
|
|
325
|
+
* What comes out is one molecule, and it is a part like any other: a circle if the pieces closed,
|
|
326
|
+
* and otherwise a line with the outer ends the pieces brought. It carries what the pieces carried.
|
|
327
|
+
*
|
|
328
|
+
* @param lab - The lab.
|
|
329
|
+
* @param choice - The tubes, how much of each, and what to call what comes out.
|
|
330
|
+
* @returns What it would make, and what to record either way.
|
|
331
|
+
*/
|
|
332
|
+
export function ligationRun(lab: ToolLab, choice: LigationChoice): LigationRun {
|
|
333
|
+
const pieces: LigationPiece[] = [];
|
|
334
|
+
for (const item of choice.tubes) {
|
|
335
|
+
const held = lab.items.find((one) => one.item === item);
|
|
336
|
+
const part = held === undefined ? undefined : lab.parts.find((one) => one.checksum === held.part);
|
|
337
|
+
if (part === undefined || part.circular) return { plan: null, pieces: [], product: null, name: "", worked: null, failed: null };
|
|
338
|
+
pieces.push({ id: item, name: part.name, sequence: part.sequence, ends: part.ends ?? { left: 0, right: 0 }, features: part.features });
|
|
339
|
+
}
|
|
340
|
+
const plan = planLigation(pieces, { blunt: choice.blunt === true, linear: choice.linear === true });
|
|
341
|
+
const product = plan.products[Math.max(0, Math.min(choice.chosen ?? 0, plan.products.length - 1))] ?? null;
|
|
342
|
+
const typed = choice.name?.trim() ?? "";
|
|
343
|
+
const name = (typed !== "" ? typed : pieces.map((piece) => piece.name).join(" + ")).slice(0, 200);
|
|
344
|
+
const whole = (value: number | undefined, usual: number): number => (value === undefined || !Number.isSafeInteger(value) || value < 0 ? usual : value);
|
|
345
|
+
const record = {
|
|
346
|
+
kind: "ligation", instrument: choice.instrument ?? null,
|
|
347
|
+
inputs: pieces.map((piece) => ({ item: piece.id, amount: whole(choice.used?.[piece.id], 1), role: "piece" })),
|
|
348
|
+
settings: { pieces: pieces.length, ...(product === null ? {} : { joins: product.joins.length, made: product.circular ? "circle" : "line" }),
|
|
349
|
+
...(choice.blunt === true ? { blunt: "allowed" } : {}) },
|
|
195
350
|
note: choice.note ?? null,
|
|
196
351
|
};
|
|
197
|
-
return { plan,
|
|
352
|
+
if (product === null) return { plan, pieces, product, name, worked: null, failed: { ...record, outcome: "failed", outputs: [] } };
|
|
353
|
+
// A circle has no ends. A line keeps the outer ends of the pieces at each of its own ends.
|
|
354
|
+
const first = product.pieces[0]!;
|
|
355
|
+
const last = product.pieces.at(-1)!;
|
|
356
|
+
const endsOf = (placed: typeof first, which: "left" | "right"): number => {
|
|
357
|
+
const piece = pieces.find((one) => one.id === placed.id)!;
|
|
358
|
+
const own = placed.flipped ? { left: -piece.ends.right, right: -piece.ends.left } : piece.ends;
|
|
359
|
+
return own[which];
|
|
360
|
+
};
|
|
361
|
+
const ends = product.circular ? undefined : { left: endsOf(first, "left"), right: endsOf(last, "right") };
|
|
362
|
+
return {
|
|
363
|
+
plan, pieces, product, name,
|
|
364
|
+
worked: { ...record, outcome: "worked",
|
|
365
|
+
outputs: [{ sequence: product.sequence, circular: product.circular, name, features: product.features,
|
|
366
|
+
amount: whole(choice.amount, 20), unit: choice.unit === undefined ? "µL" : choice.unit,
|
|
367
|
+
...(ends === undefined || (ends.left === 0 && ends.right === 0) ? {} : { ends }) }] },
|
|
368
|
+
failed: { ...record, outcome: "failed", outputs: [] },
|
|
369
|
+
};
|
|
198
370
|
}
|
|
199
371
|
|
|
200
372
|
/** The tools there are. */
|
|
201
|
-
export type ToolName = "pcr" | "digest";
|
|
373
|
+
export type ToolName = "pcr" | "digest" | "ligation";
|
|
202
374
|
|
|
203
375
|
/** The model of instrument each tool is used at. */
|
|
204
|
-
export const TOOL_AT: Readonly<Record<ToolName, string>> = { pcr: "thermocycler", digest: "gel-station" };
|
|
376
|
+
export const TOOL_AT: Readonly<Record<ToolName, string>> = { pcr: "thermocycler", digest: "gel-station", ligation: "heat-block" };
|
|
205
377
|
|
|
206
378
|
/**
|
|
207
379
|
* Which tool an instrument opens.
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bringing a sequence in from the file a lab already has.
|
|
3
|
+
*
|
|
4
|
+
* Most labs keep their sequences as SnapGene or GenBank files, with the genes, promoters and origins
|
|
5
|
+
* already marked. This reads one into what a lab's freezer keeps of a part: a name, the bases,
|
|
6
|
+
* whether it is a circle, and what is marked on it. SnapGene's own format, GenBank, EMBL and FASTA
|
|
7
|
+
* are read, by `@biolibs/seqio`.
|
|
8
|
+
*/
|
|
9
|
+
import type { PartFeature } from "@biolibs/bionet";
|
|
10
|
+
import { parse } from "@biolibs/seqio";
|
|
11
|
+
|
|
12
|
+
/** A sequence read from a file. */
|
|
13
|
+
export interface SequenceFile {
|
|
14
|
+
/** The file it came from. */
|
|
15
|
+
fileName: string;
|
|
16
|
+
/** What kind of file it was read as: `snapgene`, `genbank`, `embl` or `fasta`. */
|
|
17
|
+
format: string;
|
|
18
|
+
/** What the file calls the sequence. */
|
|
19
|
+
name: string;
|
|
20
|
+
/** What the file says about it. */
|
|
21
|
+
description: string;
|
|
22
|
+
/** The bases, in capitals. */
|
|
23
|
+
sequence: string;
|
|
24
|
+
/** Whether it is a circle. */
|
|
25
|
+
circular: boolean;
|
|
26
|
+
/** What is marked on it. */
|
|
27
|
+
features: PartFeature[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const TEXT_FORMATS: Readonly<Record<string, string>> = { gb: "genbank", gbk: "genbank", gbff: "genbank", genbank: "genbank", embl: "embl", fa: "fasta", fasta: "fasta", fna: "fasta" };
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* What kind of sequence file something is, from its name or failing that from how it begins.
|
|
34
|
+
*
|
|
35
|
+
* @param name - The file's name.
|
|
36
|
+
* @param bytes - What is in it.
|
|
37
|
+
* @returns The format's name, or `null` if it is none this reads.
|
|
38
|
+
*/
|
|
39
|
+
export function sequenceFormat(name: string, bytes: Uint8Array): string | null {
|
|
40
|
+
const extension = name.split(".").pop()?.toLowerCase() ?? "";
|
|
41
|
+
if (extension === "dna") return "snapgene";
|
|
42
|
+
if (Object.hasOwn(TEXT_FORMATS, extension)) return TEXT_FORMATS[extension]!;
|
|
43
|
+
if (bytes[0] === 0x09) return "snapgene"; // every SnapGene file opens with a packet of type 9
|
|
44
|
+
const start = new TextDecoder().decode(bytes.slice(0, 16));
|
|
45
|
+
if (start.startsWith("LOCUS")) return "genbank";
|
|
46
|
+
if (start.startsWith(">")) return "fasta";
|
|
47
|
+
if (start.startsWith("ID ")) return "embl";
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Read the first sequence in a file.
|
|
53
|
+
*
|
|
54
|
+
* @param name - The file's name.
|
|
55
|
+
* @param bytes - What is in it.
|
|
56
|
+
* @returns The sequence and what is marked on it.
|
|
57
|
+
* @throws If it is not a kind of file this reads, or holds no sequence.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { readSequenceFile } from "@biolibs/bionet-tools";
|
|
62
|
+
*
|
|
63
|
+
* const read = readSequenceFile("pUC19.fa", new TextEncoder().encode(">pUC19\nGGATCACAGTCTACACTG\n"));
|
|
64
|
+
* read.name; // "pUC19"
|
|
65
|
+
* read.sequence; // "GGATCACAGTCTACACTG"
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function readSequenceFile(name: string, bytes: Uint8Array): SequenceFile {
|
|
69
|
+
const format = sequenceFormat(name, bytes);
|
|
70
|
+
if (format === null) throw new Error("Could not tell what kind of file that is. SnapGene (.dna), GenBank (.gb), EMBL and FASTA are read.");
|
|
71
|
+
let record;
|
|
72
|
+
try {
|
|
73
|
+
// Binary formats take bytes and text formats take a string.
|
|
74
|
+
record = parse(format === "snapgene" ? bytes : new TextDecoder().decode(bytes), format)[Symbol.iterator]().next().value;
|
|
75
|
+
} catch (cause) {
|
|
76
|
+
throw new Error(`That ${format} file could not be read: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
77
|
+
}
|
|
78
|
+
if (record === undefined || record === null || !record.seq) throw new Error("That file holds no sequence.");
|
|
79
|
+
const sequence = String(record.seq).toUpperCase();
|
|
80
|
+
const whole = (position: unknown): number => Number((position as { position?: number }).position ?? position);
|
|
81
|
+
const first = (values: unknown): string | undefined => (Array.isArray(values) && values.length > 0 ? String(values[0]) : undefined);
|
|
82
|
+
const features: PartFeature[] = [];
|
|
83
|
+
for (const feature of record.features) {
|
|
84
|
+
if (!feature.location || feature.type === "source") continue;
|
|
85
|
+
const said = (key: string): string | undefined => first(feature.qualifiers.get(key));
|
|
86
|
+
const parts = (feature.location.parts as { start: unknown; end: unknown }[]).map((part) => ({ start: whole(part.start), end: whole(part.end) }))
|
|
87
|
+
.filter((part) => Number.isSafeInteger(part.start) && Number.isSafeInteger(part.end) && part.start >= 0 && part.end > part.start && part.end <= sequence.length);
|
|
88
|
+
if (parts.length === 0) continue;
|
|
89
|
+
const strand = feature.location.strand === 1 ? 1 : feature.location.strand === -1 ? -1 : 0;
|
|
90
|
+
features.push({ type: String(feature.type).slice(0, 40), label: (said("label") ?? said("gene") ?? said("product") ?? said("note") ?? String(feature.type)).slice(0, 200), strand, parts });
|
|
91
|
+
}
|
|
92
|
+
const stem = name.replace(/\.[^.]+$/, "");
|
|
93
|
+
const called = record.name && record.name !== "<unknown name>" ? record.name : record.id && record.id !== "<unknown id>" ? record.id : stem;
|
|
94
|
+
return {
|
|
95
|
+
fileName: name, format, name: String(called || stem).slice(0, 200),
|
|
96
|
+
description: record.description === "<unknown description>" ? "" : String(record.description ?? ""),
|
|
97
|
+
sequence, circular: record.annotations.get("topology") === "circular", features,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* What is marked on a stretch of a sequence, as it would be marked on that stretch alone.
|
|
103
|
+
*
|
|
104
|
+
* A PCR's product is a stretch of its template, so whatever was marked there is marked on the
|
|
105
|
+
* product, moved to where it now is. Something only partly inside is kept as far as it is inside,
|
|
106
|
+
* and its name says so, since half a gene is not the gene.
|
|
107
|
+
*
|
|
108
|
+
* @param features - What is marked on the whole sequence.
|
|
109
|
+
* @param from - Where the stretch starts.
|
|
110
|
+
* @param to - Where it stops.
|
|
111
|
+
* @param shift - How many bases the stretch is preceded by where it is going, such as a primer's tail.
|
|
112
|
+
* @returns What is marked on the stretch.
|
|
113
|
+
*/
|
|
114
|
+
export function carryFeatures(features: readonly PartFeature[], from: number, to: number, shift = 0): PartFeature[] {
|
|
115
|
+
const carried: PartFeature[] = [];
|
|
116
|
+
for (const feature of features) {
|
|
117
|
+
const inside = feature.parts.map((part) => ({ start: Math.max(part.start, from), end: Math.min(part.end, to) })).filter((part) => part.end > part.start);
|
|
118
|
+
if (inside.length === 0) continue;
|
|
119
|
+
const whole = inside.length === feature.parts.length && inside.every((part, at) => part.start === feature.parts[at]!.start && part.end === feature.parts[at]!.end);
|
|
120
|
+
carried.push({ type: feature.type, strand: feature.strand, label: whole ? feature.label : `${feature.label} (part)`.slice(0, 200),
|
|
121
|
+
parts: inside.map((part) => ({ start: part.start - from + shift, end: part.end - from + shift })) });
|
|
122
|
+
}
|
|
123
|
+
return carried;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* What a kind of feature's colour means, in the theme's terms.
|
|
128
|
+
*
|
|
129
|
+
* @param type - The feature's type, as sequence files say it.
|
|
130
|
+
* @returns One of the theme's meanings.
|
|
131
|
+
*/
|
|
132
|
+
export function featureTone(type: string): "yours" | "theirs" | "held" | "found" | "good" | "attention" | "dim" {
|
|
133
|
+
switch (type) {
|
|
134
|
+
case "CDS": case "gene": return "yours";
|
|
135
|
+
case "promoter": return "held";
|
|
136
|
+
case "terminator": return "attention";
|
|
137
|
+
case "rep_origin": return "theirs";
|
|
138
|
+
case "primer_bind": return "found";
|
|
139
|
+
case "misc_feature": case "regulatory": return "good";
|
|
140
|
+
default: return "dim";
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** A molecule as a scene draws one. It is the shape `@biolibs/bionet-scene` takes, so it can be handed straight over. */
|
|
145
|
+
export interface DrawnMolecule {
|
|
146
|
+
name: string;
|
|
147
|
+
length: number;
|
|
148
|
+
circular: boolean;
|
|
149
|
+
/** Each piece of each feature, with the theme's meaning for its colour. */
|
|
150
|
+
features: { start: number; end: number; strand: -1 | 0 | 1; tone: ReturnType<typeof featureTone>; label: string }[];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* A part as a molecule to draw in a scene.
|
|
155
|
+
*
|
|
156
|
+
* @param part - Its name, length, shape and what is marked on it.
|
|
157
|
+
* @returns The molecule, with each feature's pieces as stretches and its colour as a meaning.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* import { moleculeOf } from "@biolibs/bionet-tools";
|
|
162
|
+
*
|
|
163
|
+
* const drawn = moleculeOf({ name: "pUC19", length: 2686, circular: true, features: [{ type: "CDS", label: "bla", strand: -1, parts: [{ start: 1626, end: 2487 }] }] });
|
|
164
|
+
* drawn.features[0].tone; // "yours"
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export function moleculeOf(part: { name: string; length: number; circular: boolean; features: readonly PartFeature[] }): DrawnMolecule {
|
|
168
|
+
return {
|
|
169
|
+
name: part.name, length: part.length, circular: part.circular,
|
|
170
|
+
features: part.features.flatMap((feature) => feature.parts.map((piece) => ({ start: piece.start, end: piece.end, strand: feature.strand, tone: featureTone(feature.type), label: feature.label }))),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A lab's sequences: bringing them in from the files it already has, and reading one as a map.
|
|
5
|
+
*
|
|
6
|
+
* This is the part of a sequence editor most people use most: open a construct, see what is on it,
|
|
7
|
+
* see where the enzymes cut. Here the construct is a part in the lab's freezer, so what is being
|
|
8
|
+
* looked at is something the lab holds, and what is brought in is added to what it holds.
|
|
9
|
+
*/
|
|
10
|
+
import { useMemo, useState } from "react";
|
|
11
|
+
import { useAct, useLab } from "@biolibs/bionet-react";
|
|
12
|
+
import { endsWords } from "@biolibs/bionet-panels";
|
|
13
|
+
import { cutters } from "./digest.js";
|
|
14
|
+
import { SequenceMap } from "./map.js";
|
|
15
|
+
import { featureTone, readSequenceFile } from "./sequence-file.js";
|
|
16
|
+
|
|
17
|
+
const count = (value: number): string => value.toLocaleString("en-US");
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Bring sequences in from files, and look at any part the lab has as a map.
|
|
21
|
+
*
|
|
22
|
+
* Choosing files adds each as a part, with the name, the shape and the features the file gives it.
|
|
23
|
+
* SnapGene's own files, GenBank, EMBL and FASTA are read. A part is known by its sequence, so
|
|
24
|
+
* bringing in one the lab already has adds nothing but what is marked on it.
|
|
25
|
+
*
|
|
26
|
+
* @param props - `part` is the checksum of the part to open on.
|
|
27
|
+
*/
|
|
28
|
+
export function SequencesTool({ part: first }: { part?: string }) {
|
|
29
|
+
const lab = useLab()?.lab;
|
|
30
|
+
const act = useAct();
|
|
31
|
+
const [chosen, setChosen] = useState<string | null>(first ?? null);
|
|
32
|
+
const [said, setSaid] = useState<string[]>([]);
|
|
33
|
+
const [busy, setBusy] = useState(false);
|
|
34
|
+
const [once, setOnce] = useState(true);
|
|
35
|
+
const part = lab?.parts.find((one) => one.checksum === chosen) ?? lab?.parts[0];
|
|
36
|
+
const cuts = useMemo(() => (part === undefined ? [] : cutters(part)), [part]);
|
|
37
|
+
if (lab === null || lab === undefined) return null;
|
|
38
|
+
// On a map, the enzymes worth naming are the ones that cut once or twice: those are the ones to cut with.
|
|
39
|
+
const shown = cuts.filter((one) => one.positions.length <= (once ? 1 : 2));
|
|
40
|
+
const tubes = part === undefined ? 0 : lab.items.filter((item) => item.part === part.checksum && !item.retired).length;
|
|
41
|
+
|
|
42
|
+
const bring = async (files: FileList | null): Promise<void> => {
|
|
43
|
+
if (files === null || files.length === 0) return;
|
|
44
|
+
setBusy(true);
|
|
45
|
+
const lines: string[] = [];
|
|
46
|
+
for (const file of Array.from(files)) {
|
|
47
|
+
try {
|
|
48
|
+
const read = readSequenceFile(file.name, new Uint8Array(await file.arrayBuffer()));
|
|
49
|
+
const answer = await act("addPart", { name: read.name, sequence: read.sequence, circular: read.circular, features: read.features });
|
|
50
|
+
lines.push(answer.ok ? `${read.name}: ${count(read.sequence.length)} bp, ${read.circular ? "circular" : "linear"}, ${read.features.length} ${read.features.length === 1 ? "feature" : "features"}, from ${read.format}`
|
|
51
|
+
: `${file.name}: ${answer.error}`);
|
|
52
|
+
} catch (cause) {
|
|
53
|
+
lines.push(`${file.name}: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
setSaid(lines);
|
|
57
|
+
setBusy(false);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div className="pcr sequences">
|
|
62
|
+
<section className="card">
|
|
63
|
+
<h2>Bring sequences in</h2>
|
|
64
|
+
<p className="dim small">Choose SnapGene (.dna), GenBank (.gb), EMBL or FASTA files. Each becomes a part in the freezer, with what the file marks on it. Add a tube of it on the Freezer tab when there is one.</p>
|
|
65
|
+
<input type="file" multiple disabled={busy} accept=".dna,.gb,.gbk,.gbff,.genbank,.embl,.fa,.fasta,.fna" aria-label="Sequence files" onChange={(event) => { void bring(event.target.files); event.target.value = ""; }} />
|
|
66
|
+
{said.length > 0 && <ul className="plainlist small" role="status">{said.map((line) => <li key={line}>{line}</li>)}</ul>}
|
|
67
|
+
</section>
|
|
68
|
+
|
|
69
|
+
{part === undefined ? <p className="empty">The lab has no parts yet.</p> : (
|
|
70
|
+
<section className="card">
|
|
71
|
+
<div className="toolhead">
|
|
72
|
+
<label>Part
|
|
73
|
+
<select value={part.checksum} onChange={(event) => setChosen(event.target.value)} aria-label="Part">
|
|
74
|
+
{lab.parts.map((one) => <option key={one.checksum} value={one.checksum}>{one.name} · {count(one.length)} bp{one.circular ? " · circular" : ""}</option>)}
|
|
75
|
+
</select>
|
|
76
|
+
</label>
|
|
77
|
+
{endsWords(part) !== null && <span className="small">ends <code>{endsWords(part)}</code></span>}
|
|
78
|
+
<span className="dim small">{tubes === 0 ? "no tubes of it" : `${tubes} ${tubes === 1 ? "tube" : "tubes"} of it`}</span>
|
|
79
|
+
</div>
|
|
80
|
+
<div className="mapped">
|
|
81
|
+
<SequenceMap name={part.name} length={part.length} circular={part.circular} features={part.features}
|
|
82
|
+
marks={shown.flatMap((one) => one.positions.map((at) => ({ at, label: one.name })))} />
|
|
83
|
+
<div>
|
|
84
|
+
<table>
|
|
85
|
+
<thead><tr><th>Feature</th><th>Type</th><th>Where</th><th>Strand</th></tr></thead>
|
|
86
|
+
<tbody>
|
|
87
|
+
{part.features.map((feature, at) => (
|
|
88
|
+
<tr key={at}>
|
|
89
|
+
<td><span className={`swatch tone-${featureTone(feature.type)}`} />{feature.label}</td>
|
|
90
|
+
<td className="dim">{feature.type}</td>
|
|
91
|
+
<td><code>{feature.parts.map((piece) => `${count(piece.start + 1)}..${count(piece.end)}`).join(", ")}</code></td>
|
|
92
|
+
<td className="dim">{feature.strand === 1 ? "forward" : feature.strand === -1 ? "reverse" : "—"}</td>
|
|
93
|
+
</tr>
|
|
94
|
+
))}
|
|
95
|
+
{part.features.length === 0 && <tr><td colSpan={4} className="dim">Nothing is marked on this part. A part brought in from a SnapGene or GenBank file keeps what the file marks.</td></tr>}
|
|
96
|
+
</tbody>
|
|
97
|
+
</table>
|
|
98
|
+
<p className="small">
|
|
99
|
+
<strong>Cuts once:</strong> {cuts.filter((one) => one.positions.length === 1).map((one) => one.name).join(", ") || "none of the usual enzymes"}
|
|
100
|
+
{cuts.some((one) => one.positions.length === 2) && <> · <strong>twice:</strong> {cuts.filter((one) => one.positions.length === 2).map((one) => one.name).join(", ")}</>}
|
|
101
|
+
</p>
|
|
102
|
+
<label className="check small"><input type="checkbox" checked={!once} onChange={(event) => setOnce(!event.target.checked)} /> Mark the ones that cut twice as well</label>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</section>
|
|
106
|
+
)}
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
package/src/tools.tsx
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
/** Getting to a tool: from the instrument it is used at, or from a list of them all. */
|
|
4
|
-
import { useState } from "react";
|
|
4
|
+
import { useState, type ReactNode } from "react";
|
|
5
5
|
import { useLab } from "@biolibs/bionet-react";
|
|
6
6
|
import { DigestTool } from "./digest-tool.js";
|
|
7
7
|
import { PcrTool } from "./pcr-tool.js";
|
|
8
8
|
import { instrumentFor, toolFor, type ToolName } from "./run.js";
|
|
9
|
+
import { LigationTool } from "./ligate-bench.js";
|
|
10
|
+
import { SequencesTool } from "./sequences-tool.js";
|
|
9
11
|
|
|
10
12
|
/** What each tool is called. */
|
|
11
|
-
export const TOOL_NAMES: Readonly<Record<ToolName, string>> = { pcr: "PCR", digest: "Digest and gel" };
|
|
13
|
+
export const TOOL_NAMES: Readonly<Record<ToolName, string>> = { pcr: "PCR", digest: "Digest and gel", ligation: "Ligation" };
|
|
12
14
|
|
|
13
15
|
function Tool({ tool, instrument, onDone }: { tool: ToolName; instrument: { id: string; name: string } | null; onDone?: (() => void) | undefined }) {
|
|
14
16
|
const more = onDone === undefined ? {} : { onDone };
|
|
15
|
-
return tool === "pcr" ? <PcrTool instrument={instrument} {...more} />
|
|
17
|
+
return tool === "pcr" ? <PcrTool instrument={instrument} {...more} />
|
|
18
|
+
: tool === "ligation" ? <LigationTool instrument={instrument} {...more} />
|
|
19
|
+
: <DigestTool instrument={instrument} {...more} />;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
/**
|
|
@@ -44,20 +48,22 @@ export function InstrumentTool({ place, onDone }: { place: string; onDone?: () =
|
|
|
44
48
|
*
|
|
45
49
|
* A run is still recorded as done at the instrument for that tool, if the lab has placed one.
|
|
46
50
|
*
|
|
47
|
-
* @param props - `tool` is which to open on
|
|
51
|
+
* @param props - `tool` is which to open on, `sequences` being the lab's sequences and their maps; `views` lets a host show a tool its own way, such as
|
|
52
|
+
* at its instrument in a scene, in place of the plain form.
|
|
48
53
|
*/
|
|
49
|
-
export function Tools({ tool: first = "pcr" }: { tool?: ToolName }) {
|
|
54
|
+
export function Tools({ tool: first = "pcr", views = {} }: { tool?: ToolName | "sequences"; views?: Partial<Record<ToolName, ReactNode>> }) {
|
|
50
55
|
const lab = useLab()?.lab;
|
|
51
|
-
const [tool, setTool] = useState<ToolName>(first);
|
|
56
|
+
const [tool, setTool] = useState<ToolName | "sequences">(first);
|
|
52
57
|
if (lab === null || lab === undefined) return null;
|
|
58
|
+
const names: [ToolName | "sequences", string][] = [["sequences", "Sequences"], ...(Object.keys(TOOL_NAMES) as ToolName[]).map((one): [ToolName, string] => [one, TOOL_NAMES[one]])];
|
|
53
59
|
return (
|
|
54
60
|
<div className="tools">
|
|
55
61
|
<div className="row tight pick" role="tablist" aria-label="Tools">
|
|
56
|
-
{
|
|
57
|
-
<button key={one} type="button" role="tab" aria-selected={one === tool} className={one === tool ? "" : "quiet"} onClick={() => setTool(one)}>{
|
|
62
|
+
{names.map(([one, name]) => (
|
|
63
|
+
<button key={one} type="button" role="tab" aria-selected={one === tool} className={one === tool ? "" : "quiet"} onClick={() => setTool(one)}>{name}</button>
|
|
58
64
|
))}
|
|
59
65
|
</div>
|
|
60
|
-
<Tool key={tool} tool={tool} instrument={instrumentFor(lab, tool)} />
|
|
66
|
+
{tool === "sequences" ? <SequencesTool /> : views[tool] ?? <Tool key={tool} tool={tool} instrument={instrumentFor(lab, tool)} />}
|
|
61
67
|
</div>
|
|
62
68
|
);
|
|
63
69
|
}
|