@biolibs/bionet-tools 0.1.1 → 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 +146 -4
- 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-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 +20 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -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 +9 -0
- package/dist/pcr-bench.d.ts.map +1 -1
- package/dist/pcr-bench.js +26 -2
- package/dist/pcr-bench.js.map +1 -1
- package/dist/pcr-scene.d.ts +2 -0
- package/dist/pcr-scene.d.ts.map +1 -1
- package/dist/pcr-scene.js +8 -8
- package/dist/pcr-scene.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 +101 -6
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +127 -11
- 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 +2 -2
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +9 -4
- 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 +5 -2
- package/src/digest-bench.tsx +307 -0
- package/src/digest-working.ts +288 -0
- package/src/index.ts +20 -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 +54 -1
- package/src/pcr-scene.ts +10 -8
- package/src/pcr-working.ts +228 -0
- package/src/run.ts +179 -14
- package/src/sequence-file.ts +172 -0
- package/src/sequences-tool.tsx +109 -0
- package/src/tools.tsx +13 -8
- package/src/working.tsx +96 -0
- package/tools.css +54 -0
package/src/pcr-bench.tsx
CHANGED
|
@@ -15,6 +15,10 @@ import { bandsOf, gelById, ladderBands, ladderById } from "@biolibs/gel";
|
|
|
15
15
|
import { useAct, useLab } from "@biolibs/bionet-react";
|
|
16
16
|
import { Glossed } from "@biolibs/glossary-react";
|
|
17
17
|
import { Gel } from "./digest-tool.js";
|
|
18
|
+
import { SequenceMap } from "./map.js";
|
|
19
|
+
import { bindingWorking, carriedWorking, countsWorking, lengthWorking, programmeWorking, tmWorking } from "./pcr-working.js";
|
|
20
|
+
import { FacedBases, ShowWorking } from "./working.js";
|
|
21
|
+
import { moleculeOf, type DrawnMolecule } from "./sequence-file.js";
|
|
18
22
|
import { primerTm } from "./pcr.js";
|
|
19
23
|
import { primerBinding, programmeChecks, screenOf, strandCounts, suggestProgramme, tubeLens, tubeView,
|
|
20
24
|
type PcrProgramme, type PcrStepName, type TubeLens, type TubeStrand } from "./pcr-scene.js";
|
|
@@ -32,6 +36,10 @@ export interface BenchStage {
|
|
|
32
36
|
screen: { text: string; lit?: boolean }[];
|
|
33
37
|
well?: { row: number; column: number };
|
|
34
38
|
tube?: { length: number; strands: TubeStrand[] };
|
|
39
|
+
/** Lengths marked off under the strands, each with the subtraction that gives it. */
|
|
40
|
+
measures?: { from: number; to: number; label: string }[];
|
|
41
|
+
/** What the run makes, to be drawn above the machine in the result view. */
|
|
42
|
+
molecule?: DrawnMolecule;
|
|
35
43
|
/** The real bases at the primer being looked at, for any moment of the step showing. */
|
|
36
44
|
lens?: (through: number) => (TubeLens & { rows: [number, number] }) | null;
|
|
37
45
|
legend: Partial<Record<TubeStrand["kind"], string>>;
|
|
@@ -172,6 +180,13 @@ export function usePcrBench({ instrument = null, onDone }: { instrument?: { id:
|
|
|
172
180
|
const rows: [number, number] = step === "denature" ? [0, 3] : site === "top" ? [2, 3] : [0, 1];
|
|
173
181
|
return (through: number) => ({ ...tubeLens(templatePart.sequence, primer.sequence, binding, step, through, { primer: primer.name, template: templatePart.name }), rows });
|
|
174
182
|
}, [bindings, templatePart, forwardPart, reversePart, annealAtLeast, site, step]);
|
|
183
|
+
// The working for the primer being looked at, and for the counts.
|
|
184
|
+
const bound = useMemo(() => {
|
|
185
|
+
if (bindings === null || templatePart === undefined) return null;
|
|
186
|
+
const primer = [forwardPart, reversePart].find((part) => part !== undefined && primerBinding(templatePart.sequence, part.sequence, annealAtLeast)?.reads === site);
|
|
187
|
+
return primer === undefined ? null : { ...bindingWorking(templatePart.sequence, primer, bindings[site], annealAtLeast), name: primer.name };
|
|
188
|
+
}, [bindings, templatePart, forwardPart, reversePart, annealAtLeast, site]);
|
|
189
|
+
const counted = useMemo(() => countsWorking(programme.cycles), [programme.cycles]);
|
|
175
190
|
const inTube = bindings === null || templatePart === undefined ? undefined : tubeView(templatePart.length, bindings.top, bindings.bottom, step, cycle);
|
|
176
191
|
// Running the programme: each step plays into the next, and each cycle into the next, as the
|
|
177
192
|
// machine would. The first three cycles are played at the pace chosen, since each shows something
|
|
@@ -194,6 +209,10 @@ export function usePcrBench({ instrument = null, onDone }: { instrument?: { id:
|
|
|
194
209
|
...(templatePart === undefined ? {} : { well: { row: 0, column: 0 } }),
|
|
195
210
|
...(inTube === undefined || templatePart === undefined ? {} : { tube: { length: templatePart.length, strands: inTube.strands } }),
|
|
196
211
|
...(lens === undefined || cycle > 3 ? {} : { lens }),
|
|
212
|
+
// The product's length, shown as what it is: the distance between where the two primers reach.
|
|
213
|
+
...(bindings === null || bindings.bottom.end <= bindings.top.start ? {} : { measures: [{ from: bindings.top.start, to: bindings.bottom.end,
|
|
214
|
+
label: `${bindings.bottom.end.toLocaleString("en-US")} − ${(bindings.top.start + 1).toLocaleString("en-US")} + 1 = ${(bindings.bottom.end - bindings.top.start).toLocaleString("en-US")} bases copied` }] }),
|
|
215
|
+
...(product === null || run === null || view !== "result" ? {} : { molecule: moleculeOf({ name: run.name, length: product.length, circular: false, features: run.features }) }),
|
|
197
216
|
legend: { template: "the template's two strands", primer: "a primer", long: "a copy that runs on too far", product: "the product, at its exact length" },
|
|
198
217
|
};
|
|
199
218
|
|
|
@@ -222,6 +241,17 @@ export function usePcrBench({ instrument = null, onDone }: { instrument?: { id:
|
|
|
222
241
|
</fieldset>
|
|
223
242
|
)}
|
|
224
243
|
{chosen && drafted?.plan?.problem !== null && drafted?.plan !== null && <p className="trouble" role="status">{drafted?.plan?.problem}</p>}
|
|
244
|
+
{templatePart !== undefined && (
|
|
245
|
+
<SequenceMap name={templatePart.name} length={templatePart.length} circular={templatePart.circular} features={templatePart.features}
|
|
246
|
+
spans={bindings === null ? [] : [
|
|
247
|
+
// What is copied: from one primer's far end to the other's.
|
|
248
|
+
...(product !== null && bindings.bottom.end > bindings.top.start ? [{ start: bindings.top.start, end: bindings.bottom.end, label: `${product.length.toLocaleString("en-US")} bp`, strand: 0 as const }] : []),
|
|
249
|
+
...[forwardPart, reversePart].flatMap((part) => {
|
|
250
|
+
const binding = part === undefined ? null : primerBinding(templatePart.sequence, part.sequence, annealAtLeast);
|
|
251
|
+
return binding === null || part === undefined ? [] : [{ start: binding.start, end: binding.end, label: part.name, strand: binding.reads === "top" ? (1 as const) : (-1 as const) }];
|
|
252
|
+
}),
|
|
253
|
+
]} />
|
|
254
|
+
)}
|
|
225
255
|
</section>
|
|
226
256
|
|
|
227
257
|
{view === "machine" && (
|
|
@@ -260,8 +290,11 @@ export function usePcrBench({ instrument = null, onDone }: { instrument?: { id:
|
|
|
260
290
|
</p>
|
|
261
291
|
<p className="voice">Checks</p>
|
|
262
292
|
{checks.length === 0 ? <p className="small good">Nothing in this programme looks wrong for this reaction.</p> : (
|
|
263
|
-
<ul className="checks">{checks.map((check) => <li key={check.says} className={check.weight}>{check.says}</li>)}</ul>
|
|
293
|
+
<ul className="checks">{checks.map((check) => <li key={check.says} className={check.weight}>{check.says} <code className="because">{check.because}</code></li>)}</ul>
|
|
264
294
|
)}
|
|
295
|
+
<p className="voice">The working</p>
|
|
296
|
+
{[forwardPart, reversePart].map((part) => { const working = part === undefined ? null : tmWorking(part.name, part.sequence); return working === null ? null : <ShowWorking key={part!.checksum} working={working} />; })}
|
|
297
|
+
{programmeWorking(reaction, suggested).map((working) => <ShowWorking key={working.of} working={working} />)}
|
|
265
298
|
</>
|
|
266
299
|
)}
|
|
267
300
|
</section>
|
|
@@ -309,6 +342,14 @@ export function usePcrBench({ instrument = null, onDone }: { instrument?: { id:
|
|
|
309
342
|
Strands in the tube now, from one double-stranded template. Each step along a bar is twice as many. The copies that run on too far
|
|
310
343
|
grow by two a cycle; the product doubles, and after {programme.cycles} cycles there are {strandCounts(programme.cycles).product.toLocaleString("en-US")}.
|
|
311
344
|
</p>
|
|
345
|
+
<p className="voice">The working</p>
|
|
346
|
+
{bound !== null && <ShowWorking working={bound}><FacedBases working={bound} name={bound.name} /></ShowWorking>}
|
|
347
|
+
<ShowWorking working={counted}>
|
|
348
|
+
<table className="counts">
|
|
349
|
+
<thead><tr><th>After cycle</th><th>Template</th><th>Too long</th><th>Product</th><th>In all</th></tr></thead>
|
|
350
|
+
<tbody>{counted.rows.map((row) => <tr key={row.cycle}><td>{row.cycle}</td><td>{row.template}</td><td>{row.long}</td><td>{row.product.toLocaleString("en-US")}</td><td>{row.total.toLocaleString("en-US")}</td></tr>)}</tbody>
|
|
351
|
+
</table>
|
|
352
|
+
</ShowWorking>
|
|
312
353
|
</>
|
|
313
354
|
)}
|
|
314
355
|
</section>
|
|
@@ -321,6 +362,18 @@ export function usePcrBench({ instrument = null, onDone }: { instrument?: { id:
|
|
|
321
362
|
<>
|
|
322
363
|
<p className="voice">This run</p>
|
|
323
364
|
<p><strong>{product.length.toLocaleString("en-US")} bp</strong> <span className="dim">linear</span></p>
|
|
365
|
+
<SequenceMap name={run?.name ?? "product"} length={product.length} circular={false} features={run?.features ?? []} />
|
|
366
|
+
{bindings !== null && templatePart !== undefined && (
|
|
367
|
+
<>
|
|
368
|
+
<p className="voice">The working</p>
|
|
369
|
+
<ShowWorking working={lengthWorking(bindings.top, bindings.bottom, templatePart, product.length)} />
|
|
370
|
+
{bindings.bottom.end > bindings.top.start && carriedWorking(templatePart.features, bindings.top.start, bindings.bottom.end, bindings.top.tail).length > 0 && (
|
|
371
|
+
<ShowWorking working={{ of: "what is marked on the product", comes: `${carriedWorking(templatePart.features, bindings.top.start, bindings.bottom.end, bindings.top.tail).length} carried from the template`, kind: "exact",
|
|
372
|
+
steps: carriedWorking(templatePart.features, bindings.top.start, bindings.bottom.end, bindings.top.tail) }} />
|
|
373
|
+
)}
|
|
374
|
+
</>
|
|
375
|
+
)}
|
|
376
|
+
<p className="dim small">{(run?.features.length ?? 0) > 2 ? "What the template had marked on this stretch is marked on the product, and is kept with it when the run is recorded." : "The primers are marked at the ends they became."}</p>
|
|
324
377
|
<code className="wrap">{product.length <= 96 ? product.sequence : `${product.sequence.slice(0, 44)} … ${product.sequence.slice(-44)}`}</code>
|
|
325
378
|
<Gel ladder={ladderBands(ladderById(product.length < 1500 ? "100bp" : "1kb").sizes, gelById(product.length < 1500 ? "1.5" : "1.0"))}
|
|
326
379
|
bands={bandsOf([product.length], gelById(product.length < 1500 ? "1.5" : "1.0"))} name={run?.name ?? "product"} />
|
package/src/pcr-scene.ts
CHANGED
|
@@ -129,6 +129,8 @@ export interface PcrCheck {
|
|
|
129
129
|
weight: "stop" | "look";
|
|
130
130
|
/** What to ask, said for a person. */
|
|
131
131
|
says: string;
|
|
132
|
+
/** The comparison that raised it, so it can be checked. */
|
|
133
|
+
because: string;
|
|
132
134
|
}
|
|
133
135
|
|
|
134
136
|
/**
|
|
@@ -148,22 +150,22 @@ export function programmeChecks(programme: PcrProgramme, reaction: PcrReaction):
|
|
|
148
150
|
const coolest = sorted[0];
|
|
149
151
|
const warmest = sorted.at(-1);
|
|
150
152
|
if (coolest !== undefined && anneal.celsius > coolest.tm) {
|
|
151
|
-
checks.push({ about: "anneal", weight: "stop", says: `Annealing at ${anneal.celsius} °C is above ${coolest.name}'s melting temperature, about ${Math.round(coolest.tm)} °C. It may not bind
|
|
153
|
+
checks.push({ about: "anneal", weight: "stop", says: `Annealing at ${anneal.celsius} °C is above ${coolest.name}'s melting temperature, about ${Math.round(coolest.tm)} °C. It may not bind.`, because: `${anneal.celsius} °C > ${Math.round(coolest.tm)} °C` });
|
|
152
154
|
} else if (coolest !== undefined && anneal.celsius < coolest.tm - 10) {
|
|
153
|
-
checks.push({ about: "anneal", weight: "look", says: `Annealing at ${anneal.celsius} °C is more than ten degrees under the primers' melting temperatures. They may bind in places they should not
|
|
155
|
+
checks.push({ about: "anneal", weight: "look", says: `Annealing at ${anneal.celsius} °C is more than ten degrees under the primers' melting temperatures. They may bind in places they should not.`, because: `${anneal.celsius} °C < ${Math.round(coolest.tm)} − 10 = ${Math.round(coolest.tm) - 10} °C` });
|
|
154
156
|
}
|
|
155
157
|
if (coolest !== undefined && warmest !== undefined && warmest.tm - coolest.tm > 5) {
|
|
156
|
-
checks.push({ about: "anneal", weight: "look", says: `${warmest.name} melts about ${Math.round(warmest.tm - coolest.tm)} degrees above ${coolest.name}. No one annealing temperature suits both well
|
|
158
|
+
checks.push({ about: "anneal", weight: "look", says: `${warmest.name} melts about ${Math.round(warmest.tm - coolest.tm)} degrees above ${coolest.name}. No one annealing temperature suits both well.`, because: `${Math.round(warmest.tm)} − ${Math.round(coolest.tm)} = ${Math.round(warmest.tm - coolest.tm)} > 5` });
|
|
157
159
|
}
|
|
158
160
|
const wanted = (reaction.length / 1000) * SECONDS_PER_KB;
|
|
159
161
|
if (extend.seconds < wanted / 2) {
|
|
160
|
-
checks.push({ about: "extend", weight: "stop", says: `${extend.seconds} seconds is short for a ${reaction.length.toLocaleString("en-US")} base product. Allow about a minute for every thousand bases unless the polymerase is a fast one
|
|
162
|
+
checks.push({ about: "extend", weight: "stop", says: `${extend.seconds} seconds is short for a ${reaction.length.toLocaleString("en-US")} base product. Allow about a minute for every thousand bases unless the polymerase is a fast one.`, because: `${extend.seconds} s < half of ${reaction.length.toLocaleString("en-US")} ÷ 1,000 × ${SECONDS_PER_KB} = ${Math.round(wanted)} s` });
|
|
161
163
|
} else if (extend.seconds < wanted) {
|
|
162
|
-
checks.push({ about: "extend", weight: "look", says: `${extend.seconds} seconds is under a minute per thousand bases for a ${reaction.length.toLocaleString("en-US")} base product. Fine for a fast polymerase
|
|
164
|
+
checks.push({ about: "extend", weight: "look", says: `${extend.seconds} seconds is under a minute per thousand bases for a ${reaction.length.toLocaleString("en-US")} base product. Fine for a fast polymerase.`, because: `${extend.seconds} s < ${reaction.length.toLocaleString("en-US")} ÷ 1,000 × ${SECONDS_PER_KB} = ${Math.round(wanted)} s` });
|
|
163
165
|
}
|
|
164
|
-
if (denature.celsius < 90) checks.push({ about: "denature", weight: "stop", says: `${denature.celsius} °C may not separate the strands. It is usually 94 to 98 °C
|
|
165
|
-
if (programme.cycles > 40) checks.push({ about: "cycles", weight: "look", says: `${programme.cycles} cycles is a lot. Past about 35, wrong products build up faster than the right one
|
|
166
|
-
if (programme.cycles < 15) checks.push({ about: "cycles", weight: "look", says: `${programme.cycles} cycles may not make enough to see on a gel
|
|
166
|
+
if (denature.celsius < 90) checks.push({ about: "denature", weight: "stop", says: `${denature.celsius} °C may not separate the strands. It is usually 94 to 98 °C.`, because: `${denature.celsius} °C < 90 °C` });
|
|
167
|
+
if (programme.cycles > 40) checks.push({ about: "cycles", weight: "look", says: `${programme.cycles} cycles is a lot. Past about 35, wrong products build up faster than the right one.`, because: `${programme.cycles} > 40` });
|
|
168
|
+
if (programme.cycles < 15) checks.push({ about: "cycles", weight: "look", says: `${programme.cycles} cycles may not make enough to see on a gel.`, because: `${programme.cycles} < 15` });
|
|
167
169
|
return checks.sort((a, b) => Number(b.weight === "stop") - Number(a.weight === "stop"));
|
|
168
170
|
}
|
|
169
171
|
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The working behind what a PCR tool says: each figure, with the steps that give it.
|
|
3
|
+
*
|
|
4
|
+
* Everything the tool says is worked out in the window, from the lab's own sequences. Nothing is
|
|
5
|
+
* looked up and nothing comes back from a server. So it can all be shown: which bases a primer
|
|
6
|
+
* matched, the count behind a melting temperature, the subtraction behind a length. Somebody who
|
|
7
|
+
* doubts a figure can follow it, and somebody learning can see where it comes from.
|
|
8
|
+
*
|
|
9
|
+
* Some of this is exact and some is a rule of thumb, and each piece says which. That a primer's
|
|
10
|
+
* bases match the template's is a fact about two sequences. That it melts at 58 °C is an estimate
|
|
11
|
+
* from a simple rule, and a different rule would give a different figure.
|
|
12
|
+
*/
|
|
13
|
+
import type { PartFeature } from "@biolibs/bionet";
|
|
14
|
+
import { primerTm } from "./pcr.js";
|
|
15
|
+
import { SECONDS_PER_KB, strandCounts, type Binding, type PcrProgramme, type PcrReaction } from "./pcr-scene.js";
|
|
16
|
+
|
|
17
|
+
/** One figure, and how it was reached. */
|
|
18
|
+
export interface Working {
|
|
19
|
+
/** What was worked out, in a few words. */
|
|
20
|
+
of: string;
|
|
21
|
+
/** What it came to. */
|
|
22
|
+
comes: string;
|
|
23
|
+
/** `exact` if it follows from the sequences alone; `estimate` if it rests on a rule that could have been another. */
|
|
24
|
+
kind: "exact" | "estimate";
|
|
25
|
+
/** The steps, in order. Each can be checked by hand. */
|
|
26
|
+
steps: string[];
|
|
27
|
+
/** For an estimate, what it rests on and how far to trust it. */
|
|
28
|
+
rests?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const count = (value: number): string => value.toLocaleString("en-US");
|
|
32
|
+
const clean = (bases: string): string => bases.replace(/\s+/g, "").toUpperCase();
|
|
33
|
+
const PAIR: Readonly<Record<string, string>> = { A: "T", T: "A", G: "C", C: "G", N: "N" };
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A primer's melting temperature, with the count behind it.
|
|
37
|
+
*
|
|
38
|
+
* @param name - What the primer is called.
|
|
39
|
+
* @param sequence - Its bases.
|
|
40
|
+
* @returns The working, or `null` if that is not a sequence the rule can be applied to.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { tmWorking } from "@biolibs/bionet-tools";
|
|
45
|
+
*
|
|
46
|
+
* tmWorking("fwd", "GGATCACAGTCTACACTG")?.steps;
|
|
47
|
+
* // ["9 of its 18 bases are A or T, and 9 are G or C.", "2 × 9 + 4 × 9 = 54 °C."]
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function tmWorking(name: string, sequence: string): Working | null {
|
|
51
|
+
const bases = clean(sequence);
|
|
52
|
+
const tm = primerTm(bases);
|
|
53
|
+
if (tm === null) return null;
|
|
54
|
+
const weak = [...bases].filter((base) => base === "A" || base === "T" || base === "W").length;
|
|
55
|
+
const strong = [...bases].filter((base) => base === "G" || base === "C" || base === "S").length;
|
|
56
|
+
return {
|
|
57
|
+
of: `${name}'s melting temperature`, comes: `about ${Math.round(tm)} °C`, kind: "estimate",
|
|
58
|
+
steps: [
|
|
59
|
+
`${count(weak)} of its ${count(bases.length)} bases are A or T, and ${count(strong)} are G or C.`,
|
|
60
|
+
`2 × ${weak} + 4 × ${strong} = ${2 * weak + 4 * strong} °C.`,
|
|
61
|
+
],
|
|
62
|
+
rests: "The Wallace rule: an A·T pair holds with two bonds and a G·C pair with three, so each is given 2 °C or 4 °C. It ignores salt, how much primer there is and which bases are neighbours, and is rough past about 20 bases. It is good for seeing that two primers are near each other.",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** One place along a primer laid against the template: the primer's base, the base it faces, and whether they pair. */
|
|
67
|
+
export interface FacedBase {
|
|
68
|
+
/** The primer's base here. */
|
|
69
|
+
primer: string;
|
|
70
|
+
/** The base of the strand it binds that faces it, or `""` where the template has run out. */
|
|
71
|
+
faces: string;
|
|
72
|
+
/** Whether the two pair: A with T, G with C. */
|
|
73
|
+
pairs: boolean;
|
|
74
|
+
/** Whether this base is one of those at the 3′ end that must pair for the primer to bind. */
|
|
75
|
+
needed: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A primer laid against the strand it binds, base by base. */
|
|
79
|
+
export interface BindingWorking extends Working {
|
|
80
|
+
/** The primer 5′ to 3′, each base with the one it faces. */
|
|
81
|
+
faced: FacedBase[];
|
|
82
|
+
/** Which strand it binds. */
|
|
83
|
+
strand: "top" | "bottom";
|
|
84
|
+
/** Where on the template it sits, counting bases from 1 as a sequence file does. */
|
|
85
|
+
from: number;
|
|
86
|
+
to: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A primer laid against the strand it binds, to show that it does.
|
|
91
|
+
*
|
|
92
|
+
* @param template - The template's top strand.
|
|
93
|
+
* @param primer - What the primer is called, and its bases 5′ to 3′.
|
|
94
|
+
* @param binding - Where it binds, from `primerBinding`.
|
|
95
|
+
* @param least - How many bases at its 3′ end must pair.
|
|
96
|
+
* @returns Each of the primer's bases with the base it faces, and what that shows.
|
|
97
|
+
*/
|
|
98
|
+
export function bindingWorking(template: string, primer: { name: string; sequence: string }, binding: Binding, least: number): BindingWorking {
|
|
99
|
+
const top = clean(template);
|
|
100
|
+
const bases = clean(primer.sequence);
|
|
101
|
+
const bound = bases.length - binding.tail;
|
|
102
|
+
// A primer that reads as the top strand binds the bottom one, and the other way about. Walking the
|
|
103
|
+
// primer 5′ to 3′ walks the template rightwards for the first and leftwards for the second.
|
|
104
|
+
const faced = [...bases].map((base, at): FacedBase => {
|
|
105
|
+
const along = at - binding.tail;
|
|
106
|
+
const place = binding.reads === "top" ? binding.start + along : binding.end - 1 - along;
|
|
107
|
+
const there = along < 0 || place < 0 || place >= top.length ? "" : top[place]!;
|
|
108
|
+
const faces = there === "" ? "" : binding.reads === "top" ? PAIR[there] ?? "N" : there;
|
|
109
|
+
return { primer: base, faces, pairs: faces !== "" && PAIR[base] === faces, needed: at >= bases.length - least };
|
|
110
|
+
});
|
|
111
|
+
const paired = faced.filter((one) => one.pairs).length;
|
|
112
|
+
const end = faced.slice(-least);
|
|
113
|
+
// Every place the 3′ end could sit, on either strand: binding in one place only is part of what is claimed.
|
|
114
|
+
const flipped = [...bases].reverse().map((base) => PAIR[base] ?? "N").join("");
|
|
115
|
+
const sites = (needle: string): number => { let found = 0; for (let at = top.indexOf(needle); at !== -1; at = top.indexOf(needle, at + 1)) found++; return found; };
|
|
116
|
+
const places = sites(bases.slice(-least)) + sites(flipped.slice(0, least));
|
|
117
|
+
return {
|
|
118
|
+
of: `where ${primer.name} binds`, kind: "exact", faced, strand: binding.reads === "top" ? "bottom" : "top",
|
|
119
|
+
from: binding.start + 1, to: binding.end,
|
|
120
|
+
comes: `bases ${count(binding.start + 1)} to ${count(binding.end)}, on the ${binding.reads === "top" ? "bottom" : "top"} strand`,
|
|
121
|
+
steps: [
|
|
122
|
+
`The last ${least} bases at its 3′ end ${end.every((one) => one.pairs) ? "each pair with the base they face" : "do not all pair"}. That is what the polymerase needs to start from.`,
|
|
123
|
+
`${count(paired)} of its ${count(bases.length)} bases pair in all${binding.tail === 0 ? "." : `. The first ${binding.tail} at its 5′ end do not: they are a tail, and are carried onto the product.`}`,
|
|
124
|
+
`Those ${least} bases are found in ${places === 1 ? "one place only" : `${places} places`} on the template, counting both strands.`,
|
|
125
|
+
`It has the ${binding.reads} strand's sequence, so it binds the ${binding.reads === "top" ? "bottom" : "top"} strand and is copied ${binding.reads === "top" ? "rightwards" : "leftwards"}.`,
|
|
126
|
+
],
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* How long the product is, as arithmetic on where the primers bind.
|
|
132
|
+
*
|
|
133
|
+
* This is worked out separately from the engine that makes the product, so the two can be compared.
|
|
134
|
+
*
|
|
135
|
+
* @param top - Where the primer that reads as the top strand binds.
|
|
136
|
+
* @param bottom - Where the other binds.
|
|
137
|
+
* @param template - How long the template is, and whether it is a circle.
|
|
138
|
+
* @param made - How long the engine's product is, to compare with.
|
|
139
|
+
* @returns The working.
|
|
140
|
+
*/
|
|
141
|
+
export function lengthWorking(top: Binding, bottom: Binding, template: { length: number; circular: boolean }, made?: number): Working {
|
|
142
|
+
const straight = bottom.end > top.start;
|
|
143
|
+
const copied = straight ? bottom.end - top.start : template.length - top.start + bottom.end;
|
|
144
|
+
const total = top.tail + copied + bottom.tail;
|
|
145
|
+
const steps = [
|
|
146
|
+
straight
|
|
147
|
+
? `The copy runs from base ${count(top.start + 1)}, where one primer starts, to base ${count(bottom.end)}, where the other ends: ${count(bottom.end)} − ${count(top.start + 1)} + 1 = ${count(copied)}.`
|
|
148
|
+
: `The template is a circle and the copy runs through its origin: from base ${count(top.start + 1)} to the end is ${count(template.length - top.start)}, and from the start to base ${count(bottom.end)} is ${count(bottom.end)}, so ${count(copied)}.`,
|
|
149
|
+
...(top.tail + bottom.tail === 0 ? [] : [`The primers' tails are added at the ends: ${count(copied)} + ${top.tail} + ${bottom.tail} = ${count(total)}.`]),
|
|
150
|
+
...(made === undefined ? [] : [made === total ? `The engine that builds the product, working it out its own way, also gives ${count(made)}.` : `The engine that builds the product gives ${count(made)}, which does not agree. Trust neither until that is understood.`]),
|
|
151
|
+
];
|
|
152
|
+
return { of: "the product's length", comes: `${count(total)} bp`, kind: "exact", steps };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Where the suggested programme's two figures come from.
|
|
157
|
+
*
|
|
158
|
+
* @param reaction - The product's length and the primers' melting temperatures.
|
|
159
|
+
* @param programme - The programme suggested for it.
|
|
160
|
+
* @returns The working for the annealing temperature and for the extension time.
|
|
161
|
+
*/
|
|
162
|
+
export function programmeWorking(reaction: PcrReaction, programme: PcrProgramme): Working[] {
|
|
163
|
+
const sorted = [...reaction.primers].sort((a, b) => a.tm - b.tm);
|
|
164
|
+
const coolest = sorted[0];
|
|
165
|
+
const [, anneal, extend] = programme.steps;
|
|
166
|
+
const wanted = (reaction.length / 1000) * SECONDS_PER_KB;
|
|
167
|
+
const under = coolest === undefined ? null : Math.round(coolest.tm) - 5;
|
|
168
|
+
return [
|
|
169
|
+
...(coolest === undefined || under === null ? [] : [{
|
|
170
|
+
of: "the annealing temperature suggested", comes: `${anneal.celsius} °C`, kind: "estimate" as const,
|
|
171
|
+
steps: [
|
|
172
|
+
`The cooler primer is ${coolest.name}, at about ${Math.round(coolest.tm)} °C.`,
|
|
173
|
+
`Five degrees under it: ${Math.round(coolest.tm)} − 5 = ${under} °C${under === anneal.celsius ? "." : `, kept between 45 and 72, so ${anneal.celsius} °C.`}`,
|
|
174
|
+
],
|
|
175
|
+
rests: "Five under the cooler primer is a convention. It rests on the melting temperatures, which are estimates themselves, so it is where to start and not where to stop.",
|
|
176
|
+
}]),
|
|
177
|
+
{
|
|
178
|
+
of: "the extension time suggested", comes: `${extend.seconds} s`, kind: "estimate" as const,
|
|
179
|
+
steps: [
|
|
180
|
+
`${count(reaction.length)} bases at a minute for every thousand: ${count(reaction.length)} ÷ 1,000 × ${SECONDS_PER_KB} = ${Math.round(wanted * 10) / 10} s.`,
|
|
181
|
+
`Rounded up to the next 5 s, and never under 15: ${extend.seconds} s.`,
|
|
182
|
+
],
|
|
183
|
+
rests: "A minute for every thousand bases suits an ordinary polymerase. A fast one needs a quarter of that, and its maker says so.",
|
|
184
|
+
},
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* How many strands a tube holds after each cycle, as a table that can be followed down.
|
|
190
|
+
*
|
|
191
|
+
* @param cycles - How many cycles the programme runs.
|
|
192
|
+
* @returns The working, and a row for each of the first cycles and for the last.
|
|
193
|
+
*/
|
|
194
|
+
export function countsWorking(cycles: number): Working & { rows: { cycle: number; template: number; long: number; product: number; total: number }[] } {
|
|
195
|
+
const last = Math.max(0, Math.floor(cycles));
|
|
196
|
+
const shown = [...new Set([0, 1, 2, 3, 4, 5, last].filter((one) => one <= last))];
|
|
197
|
+
const rows = shown.map((cycle) => { const at = strandCounts(cycle); return { cycle, ...at, total: at.template + at.long + at.product }; });
|
|
198
|
+
const end = strandCounts(last);
|
|
199
|
+
return {
|
|
200
|
+
of: `how many strands there are after ${last} cycles`, comes: `${count(end.product)} of the product`, kind: "estimate", rows,
|
|
201
|
+
steps: [
|
|
202
|
+
"Every cycle copies every strand once, so the number of strands doubles: 2, 4, 8, and after n cycles 2 × 2ⁿ.",
|
|
203
|
+
"The template's two strands are only ever copied, never made: 2.",
|
|
204
|
+
"Each cycle copies those two into two strands that start at a primer and run on too far: 2 × n.",
|
|
205
|
+
`Everything else is the product: 2 × 2ⁿ − 2n − 2. After ${last} cycles, ${count(2 * 2 ** last)} − ${count(2 * last)} − 2 = ${count(end.product)}.`,
|
|
206
|
+
],
|
|
207
|
+
rests: "The counting is exact for a tube in which every strand is copied every cycle. A real one falls behind as primers and nucleotides run low, usually after 25 to 30 cycles, so the real figure is lower.",
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* How each feature on the product was carried from the template, one line for each.
|
|
213
|
+
*
|
|
214
|
+
* @param features - What is marked on the template.
|
|
215
|
+
* @param from - Where the stretch copied starts.
|
|
216
|
+
* @param to - Where it stops.
|
|
217
|
+
* @param shift - How many bases precede it on the product: the forward primer's tail.
|
|
218
|
+
* @returns A line for each feature that touches the stretch, with the subtraction that moved it.
|
|
219
|
+
*/
|
|
220
|
+
export function carriedWorking(features: readonly PartFeature[], from: number, to: number, shift = 0): string[] {
|
|
221
|
+
return features.flatMap((feature) => feature.parts.flatMap((piece) => {
|
|
222
|
+
const [start, end] = [Math.max(piece.start, from), Math.min(piece.end, to)];
|
|
223
|
+
if (end <= start) return [];
|
|
224
|
+
const cut = start !== piece.start || end !== piece.end;
|
|
225
|
+
return [`${feature.label}: ${count(piece.start + 1)}..${count(piece.end)} on the template${cut ? `, of which ${count(start + 1)}..${count(end)} is copied` : ""}. `
|
|
226
|
+
+ `Less the ${count(from)} bases before the copy${shift === 0 ? "" : ` and plus the tail's ${shift}`}: ${count(start - from + shift + 1)}..${count(end - from + shift)} on the product.`];
|
|
227
|
+
}));
|
|
228
|
+
}
|