@biolibs/bionet-tools 0.1.5 → 0.1.6

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 CHANGED
@@ -184,6 +184,56 @@ close on itself, the same pieces making one product with an insert in and anothe
184
184
  way round, a blunt join that will mostly not happen, and a piece that came out of a PCR, which has
185
185
  no phosphate for ligase to seal. `ratioWorking` is the arithmetic for how much of each to put in.
186
186
 
187
+ ## Designing primers
188
+
189
+ Primers are designed at a desk and ordered, so this tool has no instrument. It takes a part from the
190
+ lab and a stretch of it — dragged out on a strip, typed as two bases, or chosen as a feature, which
191
+ is how people usually choose — and designs the pair that amplifies exactly that stretch.
192
+
193
+ ```ts
194
+ import { designPair, featureStretches, primerOrder } from "@biolibs/bionet-tools";
195
+
196
+ const [gene] = featureStretches(part); // what is marked on it, as stretches
197
+ const design = designPair(part, gene); // { targetTm: 60, minLength: 18, maxLength: 30 } unless said
198
+ design.forward.chosen.report.sequence; // 5′ to 3′
199
+ design.forward.candidates; // every length tried, each with its score, term by term
200
+ design.forward.why; // "24 bases scores lowest, at 0.72: 59.3 °C is 0.7 from the 60 °C aimed for, …"
201
+ design.warnings; // what a careful person would stop at
202
+ primerOrder(design, { base: "wrenA" }).lines; // "wrenA-F\tTTGAGT…", "wrenA-R\t…"
203
+ ```
204
+
205
+ The choosing is `@biolibs/pcr`'s and is not done again here. What is added is what a person wants
206
+ beside the answer. Every candidate is kept, with the score that ranked it, so the winner can be seen
207
+ to have won and any other length can be taken instead (`forwardLength`, `reverseLength`). A stretch
208
+ may run through a plasmid's origin. And the warnings cover the pair and the template as well as each
209
+ primer: melting temperatures too far apart, the two primers pairing with each other at a 3′ end, a
210
+ primer whose 3′ end is found in more than one place (`bindingPlaces` lists them, on both strands and
211
+ through the origin), and primers that overlap because the stretch is short.
212
+
213
+ Each figure has its working, as the other tools do: `primerTmWorking` is the nearest-neighbour sum
214
+ itself — every neighbouring pair with what the table gives for it, the ends, the salt and the one
215
+ formula they go into — and is only returned if the sum done here reaches the engine's figure;
216
+ `gcWorking` is the count over the length; `productWorking` the subtraction of the two ends, compared
217
+ with what the PCR engine makes from the pair; `selfWorking` and `crossWorking` the bases that pair
218
+ with each other, laid out for `PairedBases` to draw; `scoreWorking` the score of a candidate.
219
+
220
+ ```tsx
221
+ import { usePrimerBench } from "@biolibs/bionet-tools";
222
+
223
+ const primers = usePrimerBench({ onPcr: (tubes) => openPcr(tubes) });
224
+ <LabView lab={lab} wide beside={primers.panel} {...(primers.desk.focus === null ? {} : { focus: primers.desk.focus })}
225
+ molecule={(item) => (item === primers.desk.focus?.item ? primers.desk.molecule : null)} />
226
+ ```
227
+
228
+ `panel` is the tool. `desk` is what a scene beside it should show: the template's tube to look at,
229
+ and the template as a molecule with the stretch and a primer at each end marked on it, drawn over
230
+ that tube. `PrimerTool` is the panel alone.
231
+
232
+ Keeping a design adds the two primers to the lab as parts. A tube of each is added only when there
233
+ is one, with `addItem`, and no run is recorded: a tube of something ordered is not the output of a
234
+ run, so its record says only that it is in the lab. Once the lab has a tube of the template and of
235
+ each primer, `desk.ready` names them and the PCR tool can be opened on them.
236
+
187
237
  ## The working
188
238
 
189
239
  ```tsx
package/dist/index.d.ts CHANGED
@@ -24,6 +24,9 @@
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
27
30
  * - `tools.tsx` — getting to one: from an instrument, or from a list of them all
28
31
  *
29
32
  * The tools are drawn with the styles of `@biolibs/bionet-panels` and belong inside its `LabWindow`.
@@ -48,4 +51,7 @@ export * from "./map.js";
48
51
  export * from "./sequences-tool.js";
49
52
  export * from "./tools.js";
50
53
  export * from "./pcr-bench.js";
54
+ export * from "./primer-design.js";
55
+ export * from "./primer-working.js";
56
+ export * from "./primer-bench.js";
51
57
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -24,6 +24,9 @@
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
27
30
  * - `tools.tsx` — getting to one: from an instrument, or from a list of them all
28
31
  *
29
32
  * The tools are drawn with the styles of `@biolibs/bionet-panels` and belong inside its `LabWindow`.
@@ -48,4 +51,7 @@ export * from "./map.js";
48
51
  export * from "./sequences-tool.js";
49
52
  export * from "./tools.js";
50
53
  export * from "./pcr-bench.js";
54
+ export * from "./primer-design.js";
55
+ export * from "./primer-working.js";
56
+ export * from "./primer-bench.js";
51
57
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Designing primers, at a desk.
3
+ *
4
+ * Primers are not made at a machine. They are chosen by somebody looking at a sequence, sent off to
5
+ * be made, and arrive as tubes. So this tool has no instrument: it has a part from the lab, a
6
+ * stretch of it to amplify, and the pair that would amplify it — with every candidate that was
7
+ * weighed, what a careful person would stop at, and the working for each figure.
8
+ *
9
+ * Like the tools that do stand at a machine, it knows nothing of three dimensions. It hands a host
10
+ * the tube of the template to look at and the template as a molecule with the stretch and the pair
11
+ * marked on it, and a scene that is showing that tube draws them over it.
12
+ */
13
+ import { type ReactNode } from "react";
14
+ import type { PartState } from "@biolibs/bionet";
15
+ import { type PrimerDesign, type Stretch } from "./primer-design.js";
16
+ import { type DrawnMolecule } from "./sequence-file.js";
17
+ /** The parts of the panel, in the order they are read, for a host that wants one of them in view. */
18
+ export type PrimerSection = "choose" | "pair" | "considered" | "working" | "order";
19
+ /** What a host is handed to draw beside the panel: where to look, and what to picture there. */
20
+ export interface PrimerDesk {
21
+ /** The tube of the template to look at, and the place it is in, if the lab has one that has been put somewhere. */
22
+ focus: {
23
+ place: string;
24
+ item: string;
25
+ } | null;
26
+ /** The template as a molecule, with the stretch and the two primers marked on it. `null` until a part is chosen. */
27
+ molecule: DrawnMolecule | null;
28
+ /** The tubes a PCR of this design would be run from, once the lab has a tube of each: the template and the two primers. */
29
+ ready: {
30
+ template: string;
31
+ forward: string;
32
+ reverse: string;
33
+ } | null;
34
+ }
35
+ /**
36
+ * The template with a design drawn on it: its own features, the stretch, and a primer at each end.
37
+ *
38
+ * @param part - The template.
39
+ * @param design - The design, if there is one.
40
+ * @param names - What the two primers are called.
41
+ * @returns The molecule, as a scene draws one.
42
+ */
43
+ export declare function designedMolecule(part: Pick<PartState, "name" | "length" | "circular" | "features">, design: PrimerDesign | null, names: {
44
+ forward: string;
45
+ reverse: string;
46
+ }): DrawnMolecule;
47
+ /**
48
+ * A part laid out as a strip, to drag a stretch out on.
49
+ *
50
+ * What is marked on the part is drawn above the line, so that a stretch can be dragged to fit a
51
+ * feature by eye. The stretch chosen is shaded. Typing the numbers does the same thing, and is the
52
+ * only way to say a stretch that runs through a circle's origin.
53
+ *
54
+ * @param props - `part` is the part; `stretch` is what is chosen; `onStretch` is told a new one.
55
+ */
56
+ export declare function StretchStrip({ part, stretch, onStretch }: {
57
+ part: Pick<PartState, "name" | "length" | "features">;
58
+ stretch: Stretch | null;
59
+ onStretch: (stretch: Stretch) => void;
60
+ }): import("react").JSX.Element;
61
+ /**
62
+ * The one picture that makes a pair of primers plain: the template's two strands, and a primer on
63
+ * each, at the two ends of the stretch, pointing at each other.
64
+ *
65
+ * The forward primer has the top strand's sequence, so it lies on the bottom strand and is extended
66
+ * rightwards; the reverse primer the other way about. It is not to scale along its length: the ends
67
+ * are drawn large enough to read and the middle is cut short.
68
+ *
69
+ * @param props - `design` is the design; `names` is what the primers are called.
70
+ */
71
+ export declare function PairPicture({ design, names }: {
72
+ design: PrimerDesign;
73
+ names: {
74
+ forward: string;
75
+ reverse: string;
76
+ };
77
+ }): import("react").JSX.Element;
78
+ /**
79
+ * Designing primers.
80
+ *
81
+ * @param options - `start` says what to open on, for a tour or a link: the part by its checksum, a
82
+ * stretch or a feature of it by name, what to call the pair, and which part of the panel to have in view. `onPcr`, if given, adds a way to
83
+ * go on to a PCR once the lab has a tube of the template and of each primer, and is told which.
84
+ * @returns `panel`, the tool itself, and `desk`, what a scene beside it should look at and picture.
85
+ *
86
+ * @example
87
+ * ```tsx
88
+ * import { usePrimerBench } from "@biolibs/bionet-tools";
89
+ *
90
+ * const primers = usePrimerBench();
91
+ * // LabView is the scene package's. The room stays, with the template's tube in view and the pair drawn on its molecule.
92
+ * <LabView lab={lab} wide beside={primers.panel} {...(primers.desk.focus === null ? {} : { focus: primers.desk.focus })}
93
+ * molecule={(item) => (item === primers.desk.focus?.item ? primers.desk.molecule : null)} />
94
+ * ```
95
+ */
96
+ export declare function usePrimerBench({ start, onPcr }?: {
97
+ /** What to show. Followed whenever it changes. */
98
+ start?: {
99
+ part?: string;
100
+ stretch?: Stretch;
101
+ feature?: string;
102
+ name?: string;
103
+ section?: PrimerSection;
104
+ };
105
+ onPcr?: (tubes: {
106
+ template: string;
107
+ forward: string;
108
+ reverse: string;
109
+ }) => void;
110
+ }): {
111
+ panel: ReactNode;
112
+ desk: PrimerDesk;
113
+ };
114
+ /**
115
+ * The primer design tool on its own, for a lab that has not drawn its room.
116
+ *
117
+ * @param props - `start` says what to open on; `onPcr` adds a way to go on to the PCR.
118
+ */
119
+ export declare function PrimerTool(props: Parameters<typeof usePrimerBench>[0]): import("react").JSX.Element;
120
+ //# sourceMappingURL=primer-bench.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primer-bench.d.ts","sourceRoot":"","sources":["../src/primer-bench.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,OAAO,EAA2D,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAChG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAMjD,OAAO,EAAiF,KAAK,YAAY,EAAE,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEpJ,OAAO,EAA2B,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMjF,qGAAqG;AACrG,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,MAAM,GAAG,YAAY,GAAG,SAAS,GAAG,OAAO,CAAC;AAEnF,gGAAgG;AAChG,MAAM,WAAW,UAAU;IACzB,mHAAmH;IACnH,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC9C,oHAAoH;IACpH,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IAC/B,2HAA2H;IAC3H,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACtE;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,EAC/F,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,CAiB3F;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC,CAAC;IAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAAC,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;CAAE,+BAuCnL;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,+BAsBnH;AAsCD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,GAAE;IAC/C,kDAAkD;IAClD,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,aAAa,CAAA;KAAE,CAAC;IACvG,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAC5E,GAAG;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAsR9C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,+BAErE"}
@@ -0,0 +1,285 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ /**
4
+ * Designing primers, at a desk.
5
+ *
6
+ * Primers are not made at a machine. They are chosen by somebody looking at a sequence, sent off to
7
+ * be made, and arrive as tubes. So this tool has no instrument: it has a part from the lab, a
8
+ * stretch of it to amplify, and the pair that would amplify it — with every candidate that was
9
+ * weighed, what a careful person would stop at, and the working for each figure.
10
+ *
11
+ * Like the tools that do stand at a machine, it knows nothing of three dimensions. It hands a host
12
+ * the tube of the template to look at and the template as a molecule with the stretch and the pair
13
+ * marked on it, and a scene that is showing that tube draws them over it.
14
+ */
15
+ import { useEffect, useMemo, useRef, useState } from "react";
16
+ import { useAct, useLab } from "@biolibs/bionet-react";
17
+ import { Glossed } from "@biolibs/glossary-react";
18
+ import { DEFAULT_DESIGN } from "@biolibs/pcr";
19
+ import { SequenceMap } from "./map.js";
20
+ import { planPcr } from "./pcr.js";
21
+ import { designPair, featureStretches, primerOrder, stretchLength } from "./primer-design.js";
22
+ import { crossWorking, gcWorking, primerTmWorking, productWorking, scoreWorking, selfWorking, tmApartWorking } from "./primer-working.js";
23
+ import { featureTone, moleculeOf } from "./sequence-file.js";
24
+ import { PairedBases, ShowWorking } from "./working.js";
25
+ const count = (value) => value.toLocaleString("en-US");
26
+ const whole = (text) => (text.trim() === "" || !Number.isFinite(Number(text)) ? undefined : Math.round(Number(text)));
27
+ /**
28
+ * The template with a design drawn on it: its own features, the stretch, and a primer at each end.
29
+ *
30
+ * @param part - The template.
31
+ * @param design - The design, if there is one.
32
+ * @param names - What the two primers are called.
33
+ * @returns The molecule, as a scene draws one.
34
+ */
35
+ export function designedMolecule(part, design, names) {
36
+ const drawn = moleculeOf(part);
37
+ if (design === null)
38
+ return drawn;
39
+ // A stretch through the origin is drawn as the two pieces either side of it.
40
+ const pieces = (start, end) => (end <= part.length ? [[start, end]] : [[start, part.length], [0, end - part.length]]);
41
+ const mark = (start, end, strand, tone, label) => pieces(start, end).filter(([from, to]) => to > from).map(([from, to], at) => ({ start: from, end: to, strand, tone, label: at === 0 ? label : "" }));
42
+ return {
43
+ ...drawn,
44
+ features: [
45
+ ...drawn.features,
46
+ ...mark(design.stretch.start, design.stretch.start + design.length, 0, "good", `${count(design.length)} bp`),
47
+ ...mark(design.forward.start, design.forward.end, 1, featureTone("primer_bind"), names.forward),
48
+ ...mark(design.reverse.start, design.reverse.end, -1, featureTone("primer_bind"), names.reverse),
49
+ ],
50
+ };
51
+ }
52
+ /**
53
+ * A part laid out as a strip, to drag a stretch out on.
54
+ *
55
+ * What is marked on the part is drawn above the line, so that a stretch can be dragged to fit a
56
+ * feature by eye. The stretch chosen is shaded. Typing the numbers does the same thing, and is the
57
+ * only way to say a stretch that runs through a circle's origin.
58
+ *
59
+ * @param props - `part` is the part; `stretch` is what is chosen; `onStretch` is told a new one.
60
+ */
61
+ export function StretchStrip({ part, stretch, onStretch }) {
62
+ const [width, left, axis] = [640, 12, 34];
63
+ const across = width - 2 * left;
64
+ const x = (position) => left + (position / part.length) * across;
65
+ const dragging = useRef(null);
66
+ const [drag, setDrag] = useState(null);
67
+ const at = (event) => {
68
+ const box = event.currentTarget.getBoundingClientRect();
69
+ const along = ((event.clientX - box.left) / box.width) * width;
70
+ return Math.round(Math.min(Math.max((along - left) / across, 0), 1) * part.length);
71
+ };
72
+ const shown = drag !== null ? [[Math.min(...drag), Math.max(...drag)]]
73
+ : stretch === null ? [] : stretch.end > stretch.start ? [[stretch.start, stretch.end]] : [[stretch.start, part.length], [0, stretch.end]];
74
+ return (_jsxs("svg", { className: "strip", viewBox: `0 0 ${width} 52`, role: "img", style: { touchAction: "none" }, "aria-label": `${part.name} as a strip of ${count(part.length)} bases. ${stretch === null ? "No stretch is chosen." : `The stretch chosen is ${count(stretch.start + 1)} to ${count(stretch.end)}.`} Drag across it to choose another.`, onPointerDown: (event) => { event.currentTarget.setPointerCapture(event.pointerId); dragging.current = at(event); setDrag([dragging.current, dragging.current]); }, onPointerMove: (event) => { if (dragging.current !== null)
75
+ setDrag([dragging.current, at(event)]); }, onPointerUp: (event) => {
76
+ const from = dragging.current;
77
+ dragging.current = null;
78
+ setDrag(null);
79
+ if (from === null)
80
+ return;
81
+ const [start, end] = [Math.min(from, at(event)), Math.max(from, at(event))];
82
+ // A press without a drag chooses nothing.
83
+ if (end - start >= 2)
84
+ onStretch({ start, end });
85
+ }, children: [shown.map(([from, to], index) => _jsx("rect", { x: x(from), y: 4, width: Math.max(1, x(to) - x(from)), height: 44, className: "chosen" }, index)), part.features.flatMap((feature, index) => feature.parts.filter((piece) => piece.end > piece.start).map((piece, nth) => (_jsx("rect", { x: x(piece.start), y: axis - 16, width: Math.max(1.5, x(piece.end) - x(piece.start)), height: 9, rx: 2, className: `feature tone-${featureTone(feature.type)}`, children: _jsx("title", { children: `${feature.label}, ${count(piece.start + 1)}..${count(piece.end)}` }) }, `${index} ${nth}`)))), _jsx("line", { x1: left, x2: left + across, y1: axis, y2: axis, className: "backbone" }), _jsx("text", { x: left, y: axis + 13, className: "length", children: "1" }), _jsx("text", { x: left + across, y: axis + 13, textAnchor: "end", className: "length", children: count(part.length) }), shown.length > 0 && _jsxs("text", { x: (x(shown[0][0]) + x(shown[0][1])) / 2, y: axis + 13, textAnchor: "middle", className: "spanned", children: [count(shown[0][0] + 1), "\u2013", count(shown[0][1])] })] }));
86
+ }
87
+ /**
88
+ * The one picture that makes a pair of primers plain: the template's two strands, and a primer on
89
+ * each, at the two ends of the stretch, pointing at each other.
90
+ *
91
+ * The forward primer has the top strand's sequence, so it lies on the bottom strand and is extended
92
+ * rightwards; the reverse primer the other way about. It is not to scale along its length: the ends
93
+ * are drawn large enough to read and the middle is cut short.
94
+ *
95
+ * @param props - `design` is the design; `names` is what the primers are called.
96
+ */
97
+ export function PairPicture({ design, names }) {
98
+ const [f, r] = [design.forward.chosen.report, design.reverse.chosen.report];
99
+ const says = `The template's two strands, with ${count(design.length)} bases between the ends of the stretch. ${names.forward}, ${f.length} bases, lies on the bottom strand at the left end, from base ${count(design.forward.start + 1)}, and points right. `
100
+ + `${names.reverse}, ${r.length} bases, lies on the top strand at the right end, up to base ${count(design.stretch.end)}, and points left. What lies between their far ends is copied.`;
101
+ const [from, to, top, bottom] = [90, 550, 34, 92];
102
+ const arrow = (x1, x2, y) => { const back = x2 > x1 ? -8 : 8; return `M${x1},${y} L${x2},${y} M${x2 + back},${y - 5} L${x2},${y} L${x2 + back},${y + 5}`; };
103
+ return (_jsxs("svg", { className: "pairpicture", viewBox: "0 0 640 128", role: "img", "aria-label": says, children: [_jsx("rect", { x: from, y: top - 12, width: to - from, height: bottom - top + 24, className: "chosen" }), _jsx("line", { x1: 20, x2: 620, y1: top, y2: top, className: "strand" }), _jsx("line", { x1: 20, x2: 620, y1: bottom, y2: bottom, className: "strand" }), _jsx("text", { x: 14, y: top + 4, textAnchor: "end", className: "ends", children: "5\u2032" }), _jsx("text", { x: 626, y: top + 4, className: "ends", children: "3\u2032" }), _jsx("text", { x: 14, y: bottom + 4, textAnchor: "end", className: "ends", children: "3\u2032" }), _jsx("text", { x: 626, y: bottom + 4, className: "ends", children: "5\u2032" }), _jsx("text", { x: 320, y: top - 16, textAnchor: "middle", className: "ends", children: "top strand" }), _jsx("text", { x: 320, y: bottom + 28, textAnchor: "middle", className: "ends", children: "bottom strand" }), _jsx("path", { d: arrow(from, from + 120, bottom - 12), className: "primer" }), _jsxs("text", { x: from, y: bottom - 22, className: "named", children: [names.forward, " \u00B7 5\u2032\u21923\u2032 \u00B7 ", f.length, " bases"] }), _jsx("path", { d: arrow(to, to - 120, top + 12), className: "primer" }), _jsxs("text", { x: to, y: top + 32, textAnchor: "end", className: "named", children: [names.reverse, " \u00B7 5\u2032\u21923\u2032 \u00B7 ", r.length, " bases"] }), _jsxs("text", { x: 320, y: (top + bottom) / 2 + 4, textAnchor: "middle", className: "between", children: [count(design.length), " bp copied"] }), _jsx("text", { x: from, y: bottom + 28, textAnchor: "middle", className: "ends", children: count(design.stretch.start + 1) }), _jsx("text", { x: to, y: top - 16, textAnchor: "middle", className: "ends", children: count(design.stretch.end) })] }));
104
+ }
105
+ /** The candidates for one primer, as a comparison. */
106
+ function Candidates({ end, name, targetTm, onUse }) {
107
+ return (_jsxs("div", { className: "candidates", children: [_jsxs("h3", { children: [name, " ", _jsxs("span", { className: "dim", children: ["\u00B7 ", end.which] })] }), _jsxs("table", { children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Bases" }), _jsx("th", { children: "Tm" }), _jsxs("th", { children: ["from ", targetTm, "\u00B0"] }), _jsx("th", { children: "GC" }), _jsx("th", { children: "3\u2032 end" }), _jsx("th", { children: "Self" }), _jsx("th", { children: "Score" }), _jsx("th", {})] }) }), _jsx("tbody", { children: end.candidates.map((one) => {
108
+ const { report } = one;
109
+ const [chosen, best] = [one === end.chosen, one === end.best];
110
+ return (_jsxs("tr", { className: chosen ? "chosen" : undefined, "aria-current": chosen ? "true" : undefined, children: [_jsx("td", { children: report.length }), _jsx("td", { children: report.tm.toFixed(1) }), _jsx("td", { children: one.offTarget.toFixed(1) }), _jsxs("td", { children: [(report.gc * 100).toFixed(0), "%"] }), _jsxs("td", { className: report.gcClamp ? undefined : "look", title: report.gcClamp ? "It ends in G or C." : "It does not end in G or C, which adds 2 to its score.", children: [report.sequence.at(-1), report.gcClamp ? "" : " +2"] }), _jsxs("td", { title: `${report.selfComplement} bases in a row pair with itself; ${report.endSelfComplement} at its 3′ end. Longest run of one base: ${report.longestRun}.`, children: [report.selfComplement, "/", report.endSelfComplement] }), _jsx("td", { children: _jsx("strong", { children: one.score.toFixed(2) }) }), _jsxs("td", { className: "small", children: [best && _jsx("span", { className: "good", children: "scored best" }), chosen && !best && _jsx("span", { children: "in use" }), !chosen && _jsx("button", { type: "button", className: "plain", onClick: () => onUse(best ? undefined : report.length), "aria-label": `Use ${report.length} bases for the ${end.which} primer`, children: "use" }), report.warnings.length > 0 && _jsxs("span", { className: "look", title: report.warnings.join("\n"), children: [" \u00B7 ", report.warnings.length, " ", report.warnings.length === 1 ? "warning" : "warnings"] })] })] }, report.length));
111
+ }) })] }), _jsxs("p", { className: "small", children: [end.why, end.chosen !== end.best && _jsxs(_Fragment, { children: [" ", _jsxs("strong", { children: [end.chosen.report.length, " bases is in use instead, by your choice."] })] })] })] }));
112
+ }
113
+ /**
114
+ * Designing primers.
115
+ *
116
+ * @param options - `start` says what to open on, for a tour or a link: the part by its checksum, a
117
+ * stretch or a feature of it by name, what to call the pair, and which part of the panel to have in view. `onPcr`, if given, adds a way to
118
+ * go on to a PCR once the lab has a tube of the template and of each primer, and is told which.
119
+ * @returns `panel`, the tool itself, and `desk`, what a scene beside it should look at and picture.
120
+ *
121
+ * @example
122
+ * ```tsx
123
+ * import { usePrimerBench } from "@biolibs/bionet-tools";
124
+ *
125
+ * const primers = usePrimerBench();
126
+ * // LabView is the scene package's. The room stays, with the template's tube in view and the pair drawn on its molecule.
127
+ * <LabView lab={lab} wide beside={primers.panel} {...(primers.desk.focus === null ? {} : { focus: primers.desk.focus })}
128
+ * molecule={(item) => (item === primers.desk.focus?.item ? primers.desk.molecule : null)} />
129
+ * ```
130
+ */
131
+ export function usePrimerBench({ start, onPcr } = {}) {
132
+ const lab = useLab()?.lab;
133
+ const act = useAct();
134
+ const [chosen, setChosen] = useState(start?.part ?? null);
135
+ const [from, setFrom] = useState(start?.stretch === undefined ? "" : String(start.stretch.start + 1));
136
+ const [to, setTo] = useState(start?.stretch === undefined ? "" : String(start.stretch.end));
137
+ const [target, setTarget] = useState(String(DEFAULT_DESIGN.targetTm));
138
+ const [shortest, setShortest] = useState(String(DEFAULT_DESIGN.minLength));
139
+ const [longest, setLongest] = useState(String(DEFAULT_DESIGN.maxLength));
140
+ const [lengths, setLengths] = useState({});
141
+ const [base, setBase] = useState(start?.name ?? "");
142
+ const [amount, setAmount] = useState("100");
143
+ const [busy, setBusy] = useState(false);
144
+ const [said, setSaid] = useState(null);
145
+ // The lab as it stands now, for reading straight after asking it to change.
146
+ const latest = useRef(lab);
147
+ latest.current = lab;
148
+ // Templates worth designing on: anything long enough to hold a pair with something between them.
149
+ const parts = useMemo(() => (lab?.parts ?? []).filter((one) => one.length >= 2 * DEFAULT_DESIGN.minLength + 1), [lab?.parts]);
150
+ const part = parts.find((one) => one.checksum === chosen) ?? parts.find((one) => one.features.length > 0) ?? parts[0];
151
+ const offered = useMemo(() => (part === undefined ? [] : featureStretches(part)), [part]);
152
+ const choose = (stretch) => { setFrom(String(stretch.start + 1)); setTo(String(stretch.end)); setLengths({}); setSaid(null); };
153
+ // A host driving the tool — a tour, or a link — says what to show by changing `start`.
154
+ const asked = JSON.stringify(start ?? null);
155
+ useEffect(() => {
156
+ if (start === undefined)
157
+ return;
158
+ if (start.part !== undefined)
159
+ setChosen(start.part);
160
+ if (start.name !== undefined)
161
+ setBase(start.name);
162
+ const held = latest.current?.parts.find((one) => one.checksum === start.part);
163
+ const named = start.feature === undefined || held === undefined ? undefined : featureStretches(held).find((one) => one.label === start.feature);
164
+ const stretch = start.stretch ?? named;
165
+ if (stretch !== undefined)
166
+ choose(stretch);
167
+ }, [asked]);
168
+ // The panel is long, so a host that is talking about one part of it can ask for that part to be in view.
169
+ const shown = useRef(null);
170
+ useEffect(() => {
171
+ if (start?.section === undefined)
172
+ return;
173
+ const held = setTimeout(() => shown.current?.querySelector(`[data-section="${start.section}"]`)?.scrollIntoView({ block: "start" }), 60);
174
+ return () => clearTimeout(held);
175
+ }, [asked]);
176
+ // Typed as a sequence file numbers bases: from 1, and the last one counted.
177
+ const stretch = useMemo(() => {
178
+ const [first, last] = [whole(from), whole(to)];
179
+ if (part === undefined || first === undefined || last === undefined)
180
+ return null;
181
+ const typed = { start: first - 1, end: last };
182
+ return stretchLength(typed, part) === 0 ? null : typed;
183
+ }, [part, from, to]);
184
+ const ask = useMemo(() => ({
185
+ targetTm: whole(target) ?? DEFAULT_DESIGN.targetTm, minLength: whole(shortest) ?? DEFAULT_DESIGN.minLength, maxLength: whole(longest) ?? DEFAULT_DESIGN.maxLength,
186
+ ...(lengths.forward === undefined ? {} : { forwardLength: lengths.forward }), ...(lengths.reverse === undefined ? {} : { reverseLength: lengths.reverse }),
187
+ }), [target, shortest, longest, lengths]);
188
+ const design = useMemo(() => {
189
+ if (part === undefined || stretch === null)
190
+ return null;
191
+ try {
192
+ return designPair(part, stretch, ask);
193
+ }
194
+ catch {
195
+ return null;
196
+ }
197
+ }, [part, stretch, ask]);
198
+ const feature = stretch === null ? undefined : offered.find((one) => one.start === stretch.start && one.end === stretch.end);
199
+ const usual = (base.trim() || feature?.label || part?.name || "primer").slice(0, 190);
200
+ const order = design === null ? null : primerOrder(design, { base: usual });
201
+ const names = { forward: order?.parts[0].name ?? "forward", reverse: order?.parts[1].name ?? "reverse" };
202
+ // The same engine the PCR tool uses, given the pair: what a PCR with them would in fact make.
203
+ const made = useMemo(() => (part === undefined || design === null ? null
204
+ : planPcr(part, design.forward.chosen.report.sequence, design.reverse.chosen.report.sequence, { annealAtLeast: Math.min(18, design.forward.chosen.report.length, design.reverse.chosen.report.length) })), [part, design]);
205
+ const tubeOf = (sequence, circular) => {
206
+ const held = lab?.parts.find((one) => one.circular === circular && one.sequence.toUpperCase() === sequence?.toUpperCase());
207
+ return held === undefined ? undefined : lab?.items.find((item) => item.part === held.checksum && !item.retired && item.amount > 0)?.item;
208
+ };
209
+ const templateTube = part === undefined ? undefined : lab?.items.filter((item) => item.part === part.checksum && !item.retired).sort((a, b) => Number(b.where !== null) - Number(a.where !== null))[0];
210
+ const [forwardTube, reverseTube] = [tubeOf(order?.parts[0].sequence, false), tubeOf(order?.parts[1].sequence, false)];
211
+ const held = order === null ? [false, false] : order.parts.map((one) => lab?.parts.some((each) => !each.circular && each.sequence.toUpperCase() === one.sequence) === true);
212
+ const ready = templateTube === undefined || templateTube.amount <= 0 || forwardTube === undefined || reverseTube === undefined ? null
213
+ : { template: templateTube.item, forward: forwardTube, reverse: reverseTube };
214
+ const desk = {
215
+ focus: templateTube === undefined || templateTube.where === null ? null : { place: templateTube.where.place, item: templateTube.item },
216
+ molecule: part === undefined ? null : designedMolecule(part, design, names),
217
+ ready,
218
+ };
219
+ /** Add the two primers as parts, and a tube of each if they have arrived. */
220
+ const add = async (arrived) => {
221
+ if (order === null)
222
+ return;
223
+ setBusy(true);
224
+ const tubes = whole(amount);
225
+ let trouble = null;
226
+ for (const primer of order.parts) {
227
+ const answer = await act("addPart", primer);
228
+ if (!answer.ok) {
229
+ trouble = answer.error;
230
+ break;
231
+ }
232
+ if (!arrived)
233
+ continue;
234
+ // The part is known by its sequence, so the one just added is the one with these bases. The
235
+ // window hears of it a moment after the lab has it.
236
+ let found;
237
+ for (let tries = 0; tries < 40 && found === undefined; tries++) {
238
+ found = latest.current?.parts.find((one) => !one.circular && one.sequence.toUpperCase() === primer.sequence);
239
+ if (found === undefined)
240
+ await new Promise((resolve) => setTimeout(resolve, 25));
241
+ }
242
+ if (found === undefined) {
243
+ trouble = `${primer.name} was added, but the lab has not shown it yet, so no tube of it was added.`;
244
+ break;
245
+ }
246
+ const tube = await act("addItem", { part: found.checksum, amount: tubes === undefined || tubes < 0 ? 100 : tubes, unit: "µL" });
247
+ if (!tube.ok) {
248
+ trouble = tube.error;
249
+ break;
250
+ }
251
+ }
252
+ setBusy(false);
253
+ setSaid(trouble ?? (arrived
254
+ ? `${names.forward} and ${names.reverse} are parts in the freezer now, with a tube of each, not yet put anywhere. No run was recorded, because nothing was made here: the tubes say only that they are in the lab.`
255
+ : `${names.forward} and ${names.reverse} are parts in the freezer now, with no tubes. Add a tube of each when they arrive.`));
256
+ };
257
+ // One set for the panel, so that a term is explained where it is first met and not at every mention.
258
+ const seen = new Set();
259
+ const spans = part === undefined || design === null ? [] : designedMolecule({ ...part, features: [] }, design, names).features
260
+ .map((one) => ({ start: one.start, end: one.end, label: one.label, strand: one.strand }));
261
+ const stops = design?.warnings.filter((one) => one.weight === "stop").length ?? 0;
262
+ const panel = lab === null || lab === undefined ? null : (_jsxs("div", { className: "bionet benchpanel primers", ref: shown, children: [_jsxs("section", { className: "card", "data-section": "choose", children: [_jsx("div", { className: "toolhead", children: _jsx("h2", { children: "Design primers" }) }), _jsx("p", { className: "small", children: _jsx(Glossed, { seen: seen, text: "A pair of primers marks the two ends of the stretch a PCR copies. Choose a part and the stretch of it to amplify, and the pair is designed here, in this window, from the lab's own sequence." }) }), part === undefined ? _jsx("p", { className: "empty", children: "The lab has no part long enough to design primers on. Bring one in on the Sequences tool." }) : (_jsxs(_Fragment, { children: [_jsxs("fieldset", { disabled: busy, className: "choosing", children: [_jsxs("label", { children: ["Template", _jsx("select", { value: part.checksum, "aria-label": "Template", onChange: (event) => { setChosen(event.target.value); setFrom(""); setTo(""); setLengths({}); setSaid(null); }, children: parts.map((one) => _jsxs("option", { value: one.checksum, children: [one.name, " \u00B7 ", count(one.length), " bp", one.circular ? " · circular" : ""] }, one.checksum)) })] }), _jsxs("label", { children: ["Amplify a feature", _jsxs("select", { value: feature === undefined ? "" : String(offered.indexOf(feature)), "aria-label": "Amplify a feature", disabled: offered.length === 0, onChange: (event) => { const picked = offered[Number(event.target.value)]; if (event.target.value !== "" && picked !== undefined)
263
+ choose(picked); }, children: [_jsx("option", { value: "", children: offered.length === 0 ? "Nothing is marked on this part" : "Choose a feature…" }), offered.map((one, index) => _jsxs("option", { value: index, children: [one.label, " \u00B7 ", one.type, " \u00B7 ", count(one.start + 1), "..", count(one.end), " \u00B7 ", count(one.length), " bp"] }, index))] })] }), _jsxs("label", { children: ["From base", _jsx("input", { type: "number", min: 1, max: part.length, step: 1, value: from, onChange: (event) => { setFrom(event.target.value); setLengths({}); }, "aria-label": "From base" })] }), _jsxs("label", { children: ["To base", _jsx("input", { type: "number", min: 1, max: part.length, step: 1, value: to, onChange: (event) => { setTo(event.target.value); setLengths({}); }, "aria-label": "To base" })] })] }), _jsx(StretchStrip, { part: part, stretch: stretch, onStretch: choose }), _jsxs("p", { className: "dim small", children: ["Drag across the strip, type the two bases, or choose a feature.", part.circular && " On a circle, a From after the To runs the stretch through the origin.", stretch === null && from !== "" && to !== "" && _jsx("strong", { className: "trouble", children: " That is not a stretch of this part." })] }), _jsxs("div", { className: "mapped", children: [_jsx(SequenceMap, { name: part.name, length: part.length, circular: part.circular, features: part.features, spans: spans }), _jsxs("fieldset", { disabled: busy, className: "aims", children: [_jsxs("label", { children: ["Aim for", _jsx("input", { type: "number", min: 40, max: 80, step: 1, value: target, onChange: (event) => { setTarget(event.target.value); setLengths({}); }, "aria-label": "Melting temperature aimed for" }), " \u00B0C"] }), _jsxs("label", { children: ["Shortest", _jsx("input", { type: "number", min: 8, max: 60, step: 1, value: shortest, onChange: (event) => { setShortest(event.target.value); setLengths({}); }, "aria-label": "Shortest primer" }), " bases"] }), _jsxs("label", { children: ["Longest", _jsx("input", { type: "number", min: 8, max: 60, step: 1, value: longest, onChange: (event) => { setLongest(event.target.value); setLengths({}); }, "aria-label": "Longest primer" }), " bases"] }), _jsx("p", { className: "dim small", children: _jsx(Glossed, { seen: seen, text: "The melting temperature both primers are aimed at, and the lengths tried for each. Every length in the range is measured; nothing is thrown away unseen." }) })] })] })] }))] }), part !== undefined && stretch !== null && design === null && (_jsx("section", { className: "card", children: _jsx("p", { className: "trouble", role: "status", children: "No primer can be designed at one end of this stretch: it is shorter than the shortest primer asked for, or its end holds a base that is not known for certain." }) })), part !== undefined && design !== null && order !== null && (_jsxs(_Fragment, { children: [_jsxs("section", { className: "card", "data-section": "pair", children: [_jsx("h2", { children: "The pair" }), _jsx("p", { className: "voice", children: "This design" }), _jsx(PairPicture, { design: design, names: names }), _jsxs("table", { className: "pair", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Primer" }), _jsx("th", { children: "5\u2032 \u2192 3\u2032" }), _jsx("th", { children: "Bases" }), _jsx("th", { children: "Tm" }), _jsx("th", { children: "GC" }), _jsx("th", { children: "3\u2032 end" })] }) }), _jsx("tbody", { children: [design.forward, design.reverse].map((end, index) => (_jsxs("tr", { children: [_jsx("td", { children: order.parts[index].name }), _jsx("td", { children: _jsx("code", { className: "oligo", children: end.chosen.report.sequence }) }), _jsx("td", { children: end.chosen.report.length }), _jsxs("td", { children: [end.chosen.report.tm.toFixed(1), " \u00B0C"] }), _jsxs("td", { children: [(end.chosen.report.gc * 100).toFixed(0), "%"] }), _jsx("td", { children: end.chosen.report.sequence.at(-1) })] }, end.which))) })] }), _jsxs("p", { className: "small", children: [_jsxs("strong", { children: [count(design.length), " bp"] }), " product", design.wraps ? ", through the origin" : "", " \u00B7 melting temperatures ", design.tmApart.toFixed(1), " \u00B0C apart", made !== null && (made.problem === null && made.products[0].length === design.length
264
+ ? _jsxs("span", { className: "good", children: [" \u00B7 the PCR engine makes one product of ", count(design.length), " bp from this pair"] })
265
+ : _jsxs("span", { className: "trouble", children: [" \u00B7 the PCR engine does not make one product of this length from this pair", made.problem === null ? "" : `: ${made.problem}`] }))] }), _jsx("p", { className: "voice", children: "Checks" }), design.warnings.length === 0 ? _jsx("p", { className: "small good", children: _jsx(Glossed, { seen: seen, text: "Nothing about this pair looks wrong: the melting temperatures are close, neither primer folds into a hairpin or pairs with the other as a primer dimer, and each binds this template in one place." }) }) : (_jsxs(_Fragment, { children: [_jsx("ul", { className: "checks", children: design.warnings.map((one) => _jsx("li", { className: one.weight, children: _jsx(Glossed, { seen: seen, text: one.says }) }, one.says)) }), _jsx("p", { className: "dim small", children: stops > 0 ? "The ones in red are likely to spoil the PCR. Try another length for that primer below, or move the stretch a few bases." : "None of these need stop you. They are what to think of first if the PCR gives trouble." })] }))] }), _jsxs("section", { className: "card", "data-section": "considered", children: [_jsx("h2", { children: "What was considered" }), _jsx("p", { className: "small", children: _jsx(Glossed, { seen: seen, text: "A primer has to start at its end of the stretch, so the only choice is how long it is. Here is every length tried, with what was measured of it. The score is how far its melting temperature is from the one aimed for, plus 2 if it lacks a GC clamp, plus a little for a GC content off the middle. The lowest wins." }) }), _jsxs("div", { className: "considered", children: [_jsx(Candidates, { end: design.forward, name: names.forward, targetTm: design.targetTm, onUse: (length) => setLengths(({ forward: _, ...rest }) => (length === undefined ? rest : { ...rest, forward: length })) }), _jsx(Candidates, { end: design.reverse, name: names.reverse, targetTm: design.targetTm, onUse: (length) => setLengths(({ reverse: _, ...rest }) => (length === undefined ? rest : { ...rest, reverse: length })) })] }), _jsxs("p", { className: "dim small", children: ["Self is how many bases in a row pair with the primer itself, anywhere and at its 3\u2032 end. Press ", _jsx("em", { children: "use" }), " to take a different length; the checks and the working follow."] })] }), _jsxs("section", { className: "card", "data-section": "working", children: [_jsx("h2", { children: "The working" }), _jsx("p", { className: "dim small", children: "Every figure above, opened out. Each was worked out here from the bases and can be followed by hand." }), [design.forward, design.reverse].map((end, index) => {
266
+ const name = order.parts[index].name;
267
+ const { sequence } = end.chosen.report;
268
+ const tm = primerTmWorking(name, sequence);
269
+ const self = selfWorking(name, sequence);
270
+ return (_jsxs("div", { className: "workings", children: [_jsx("p", { className: "voice", children: name }), tm !== null && (_jsx(ShowWorking, { working: tm, children: _jsxs("table", { className: "counts", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Pair" }), _jsx("th", { children: "Times" }), _jsx("th", { children: "\u0394H each" }), _jsx("th", { children: "\u0394S each" }), _jsx("th", { children: "\u0394H" }), _jsx("th", { children: "\u0394S" })] }) }), _jsxs("tbody", { children: [tm.terms.pairs.map((one) => _jsxs("tr", { children: [_jsx("td", { children: one.pair }), _jsx("td", { children: one.times }), _jsx("td", { children: one.dH.toFixed(1) }), _jsx("td", { children: one.dS.toFixed(1) }), _jsx("td", { children: (one.times * one.dH).toFixed(1) }), _jsx("td", { children: (one.times * one.dS).toFixed(1) })] }, one.pair)), _jsxs("tr", { children: [_jsx("td", { children: "ends" }), _jsx("td", { children: "2" }), _jsx("td", {}), _jsx("td", {}), _jsx("td", { children: tm.terms.ends.dH.toFixed(1) }), _jsx("td", { children: tm.terms.ends.dS.toFixed(1) })] }), _jsxs("tr", { children: [_jsx("td", { children: "salt" }), _jsx("td", {}), _jsx("td", {}), _jsx("td", {}), _jsx("td", {}), _jsx("td", { children: tm.terms.salt.toFixed(2) })] }), _jsxs("tr", { children: [_jsx("th", { children: "sum" }), _jsx("td", {}), _jsx("td", {}), _jsx("td", {}), _jsx("th", { children: tm.terms.dH.toFixed(1) }), _jsx("th", { children: tm.terms.dS.toFixed(2) })] })] })] }) })), _jsx(ShowWorking, { working: gcWorking(name, sequence) }), _jsxs(ShowWorking, { working: self, children: [self.longest > 0 && _jsx(PairedBases, { paired: self.paired, upper: name, lower: `${name} again` }), self.atEnd > 0 && (self.paired.endShift !== self.paired.shift || self.paired.endFrom !== self.paired.from) && _jsx(PairedBases, { paired: self.paired, upper: name, lower: `${name} again`, run: "end" })] }), _jsx(ShowWorking, { working: scoreWorking(end, end.chosen, design.targetTm) })] }, end.which));
271
+ }), _jsx("p", { className: "voice", children: "The pair" }), _jsx(ShowWorking, { working: productWorking(design, part, made?.problem === null ? made.products[0].length : undefined) }), _jsx(ShowWorking, { working: tmApartWorking(design, names) }), (() => {
272
+ const cross = crossWorking(design, names);
273
+ return (_jsxs(ShowWorking, { working: cross, children: [cross.longest > 0 && _jsx(PairedBases, { paired: cross.paired, upper: names.forward, lower: names.reverse }), cross.atEnd > 0 && (cross.paired.endShift !== cross.paired.shift || cross.paired.endFrom !== cross.paired.from) && _jsx(PairedBases, { paired: cross.paired, upper: names.forward, lower: names.reverse, run: "end" })] }));
274
+ })()] }), _jsxs("section", { className: "card", "data-section": "order", children: [_jsx("h2", { children: "Order them, and keep them" }), _jsx("p", { className: "small", children: "Primers are ordered, not made at the bench. These two lines are what is sent to whoever makes them: a name, and the bases 5\u2032 to 3\u2032." }), _jsx("code", { className: "wrap order", children: order.lines.map((line) => _jsx("span", { children: line.replace("\t", " ") }, line)) }), _jsxs("fieldset", { disabled: busy, className: "stack", children: [_jsxs("label", { children: ["Call them", _jsx("input", { value: base, onChange: (event) => setBase(event.target.value), placeholder: usual, maxLength: 190, "aria-label": "What to call the pair" })] }), _jsxs("label", { children: ["When they arrive, each tube holds, in \u00B5L", _jsx("input", { type: "number", min: 0, step: 1, value: amount, onChange: (event) => setAmount(event.target.value), "aria-label": "Amount in each tube, in \u00B5L" })] }), _jsxs("div", { className: "row", children: [_jsx("button", { type: "button", disabled: held.every(Boolean), onClick: () => void add(false), title: "Adds the two primers to the lab as parts, known by their sequences. No tubes: there is nothing in the freezer yet.", children: held.every(Boolean) ? "The design is kept" : "Keep the design" }), _jsx("button", { type: "button", className: "quiet", onClick: () => void add(true), title: "Adds the two primers as parts, and a tube of each. No run is recorded, since nothing was made here.", children: "They have arrived: add a tube of each" })] })] }), _jsx("p", { className: "dim small", children: "Keeping the design adds two parts. A tube is added only when there is one, and it is recorded as a tube that came into the lab, not as something a run made." }), said !== null && _jsx("p", { className: "small", role: "status", children: said }), ready !== null && (_jsxs("p", { className: "small good", children: ["The lab has a tube of ", part.name, " and of each primer, so this PCR can be run.", onPcr !== undefined && _jsxs(_Fragment, { children: [" ", _jsx("button", { type: "button", onClick: () => onPcr(ready), children: "Run the PCR" })] })] })), ready === null && held.every(Boolean) && _jsxs("p", { className: "dim small", children: ["A PCR needs a tube of ", part.name, " and of each primer. ", templateTube === undefined || templateTube.amount <= 0 ? `There is no tube of ${part.name} with anything in it. ` : "", forwardTube === undefined || reverseTube === undefined ? "There is no tube of the primers yet." : ""] })] })] }))] }));
275
+ return { panel, desk };
276
+ }
277
+ /**
278
+ * The primer design tool on its own, for a lab that has not drawn its room.
279
+ *
280
+ * @param props - `start` says what to open on; `onPcr` adds a way to go on to the PCR.
281
+ */
282
+ export function PrimerTool(props) {
283
+ return _jsx(_Fragment, { children: usePrimerBench(props).panel });
284
+ }
285
+ //# sourceMappingURL=primer-bench.js.map