@biolibs/bionet-tools 0.1.10 → 0.1.12
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 +211 -0
- package/dist/codons.d.ts +35 -0
- package/dist/codons.d.ts.map +1 -1
- package/dist/codons.js +55 -0
- package/dist/codons.js.map +1 -1
- package/dist/fusion-bench.d.ts +62 -0
- package/dist/fusion-bench.d.ts.map +1 -0
- package/dist/fusion-bench.js +114 -0
- package/dist/fusion-bench.js.map +1 -0
- package/dist/fusion.d.ts +120 -0
- package/dist/fusion.d.ts.map +1 -0
- package/dist/fusion.js +176 -0
- package/dist/fusion.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/modify.js +4 -4
- package/dist/modify.js.map +1 -1
- package/dist/ordering.d.ts +147 -0
- package/dist/ordering.d.ts.map +1 -0
- package/dist/ordering.js +203 -0
- package/dist/ordering.js.map +1 -0
- package/dist/protocol.d.ts +91 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +278 -0
- package/dist/protocol.js.map +1 -0
- package/dist/remedy.d.ts +137 -0
- package/dist/remedy.d.ts.map +1 -0
- package/dist/remedy.js +234 -0
- package/dist/remedy.js.map +1 -0
- package/dist/tools.d.ts +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +7 -3
- package/dist/tools.js.map +1 -1
- package/dist/work.d.ts +18 -0
- package/dist/work.d.ts.map +1 -0
- package/dist/work.js +155 -0
- package/dist/work.js.map +1 -0
- package/package.json +2 -2
- package/src/codons.ts +53 -0
- package/src/fusion-bench.tsx +209 -0
- package/src/fusion.ts +270 -0
- package/src/index.ts +12 -0
- package/src/modify.ts +4 -4
- package/src/ordering.ts +301 -0
- package/src/protocol.ts +332 -0
- package/src/remedy.ts +277 -0
- package/src/tools.tsx +8 -4
- package/src/work.tsx +319 -0
- package/tools.css +18 -0
package/src/codons.ts
CHANGED
|
@@ -180,6 +180,59 @@ function trouble(sequence: string, codon: string, avoid: readonly { name: string
|
|
|
180
180
|
return null;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Write a gene for a protein, in a host's own codons.
|
|
185
|
+
*
|
|
186
|
+
* This is how a lab gets something it can order. A protein is what somebody wants — read out of
|
|
187
|
+
* UniProt, or worked out, or decided on — and a synthesis company needs DNA. Going the other way
|
|
188
|
+
* round cannot be done exactly, because a protein does not say which of its synonymous codons was
|
|
189
|
+
* used and it does not matter; what matters is which the host reads best, and that is what this
|
|
190
|
+
* chooses.
|
|
191
|
+
*
|
|
192
|
+
* It is the optimiser underneath. A gene is written with any codon per residue and then rewritten
|
|
193
|
+
* into the host's own, so the host's preferences, the sites kept out and the runs of one base are
|
|
194
|
+
* handled by the same code that handles them for a gene somebody already had.
|
|
195
|
+
*
|
|
196
|
+
* @param protein - The amino acids, with or without a stop on the end.
|
|
197
|
+
* @param usage - How the host uses its codons, from `countCodonUsage`.
|
|
198
|
+
* @param options - `avoid` are sites to keep out; `longestRun` is the longest run of one base
|
|
199
|
+
* allowed; `stop` adds a stop codon on the end, which it does unless told not to.
|
|
200
|
+
* @returns The gene. `changes` is empty, because nothing was changed from anything.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* import { countCodonUsage, reverseTranslate } from "@biolibs/bionet-tools";
|
|
205
|
+
*
|
|
206
|
+
* const gene = reverseTranslate(casein, countCodonUsage(pichiaGenes), { avoid: [{ name: "EcoRI", site: "GAATTC" }] });
|
|
207
|
+
* gene.sequence; // what to send to be synthesised
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export function reverseTranslate(protein: string, usage: CodonUsage,
|
|
211
|
+
options: { avoid?: readonly { name: string; site: string }[]; longestRun?: number; stop?: boolean } = {}): CodonOptimised {
|
|
212
|
+
const chain = protein.replace(/\s+/g, "").toUpperCase().replace(/\*$/, "");
|
|
213
|
+
const nothing = (problem: string): CodonOptimised =>
|
|
214
|
+
({ sequence: "", protein: "", changes: [], codons: 0, gcBefore: 0, gcAfter: 0, avoided: [], warnings: [], problem });
|
|
215
|
+
if (chain === "") return nothing("There is no protein here to write a gene for.");
|
|
216
|
+
if (!/^[ACDEFGHIKLMNPQRSTVWY]+$/.test(chain)) return nothing("A protein to write a gene for is written in the twenty standard amino acids.");
|
|
217
|
+
if (usage.codons === 0) return nothing("The codon usage was counted over nothing, so there is nothing to prefer.");
|
|
218
|
+
|
|
219
|
+
// Any codon per residue, since what matters is only that the protein is right: `optimiseCodons`
|
|
220
|
+
// then rewrites it into the host's own, which is the whole of the work and is already tested.
|
|
221
|
+
const { byAminoAcid, stops } = synonyms(usage.table);
|
|
222
|
+
const first: string[] = [];
|
|
223
|
+
for (const residue of chain) {
|
|
224
|
+
const choices = byAminoAcid.get(residue);
|
|
225
|
+
if (choices === undefined || choices.length === 0) return nothing(`Nothing in genetic code ${usage.table} reads as ${residue}.`);
|
|
226
|
+
first.push([...choices].sort()[0]!);
|
|
227
|
+
}
|
|
228
|
+
if (options.stop !== false) first.push([...stops].sort()[0] ?? "TAA");
|
|
229
|
+
const made = optimiseCodons(first.join(""), usage, options);
|
|
230
|
+
if (made.problem !== null) return made;
|
|
231
|
+
// Nothing was rewritten from anything: every codon here was chosen, so a list of changes would be
|
|
232
|
+
// a list of what an arbitrary starting point happened to be, which says nothing about anything.
|
|
233
|
+
return { ...made, changes: [], warnings: [...made.warnings, `Written from the protein, not rewritten from a gene: every codon is the host's own choice, so there is nothing it was changed from.${options.stop === false ? "" : " A stop codon is on the end."}`] };
|
|
234
|
+
}
|
|
235
|
+
|
|
183
236
|
/**
|
|
184
237
|
* Rewrite a coding sequence in a host's codons, without changing the protein.
|
|
185
238
|
*
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Laying a construct out piece by piece, and watching the reading frame as you do it.
|
|
5
|
+
*
|
|
6
|
+
* The assembly desk is about the molecules: which pieces go round the ring and what primers make
|
|
7
|
+
* them fit. This is about the protein, and it is the other half of the same afternoon's work. A
|
|
8
|
+
* ring can be built perfectly, sequence exactly as designed, and give the wrong protein, because
|
|
9
|
+
* what was joined does not read as one chain — and nothing at the bench will say so.
|
|
10
|
+
*
|
|
11
|
+
* So the frame is the thing the panel is built around: every junction says whether it survived, and
|
|
12
|
+
* a piece that is not a whole number of codons is named along with what it does to everything after
|
|
13
|
+
* it. It is a desk, not a machine. What it hands a scene is the construct drawn over the tube of
|
|
14
|
+
* its first piece.
|
|
15
|
+
*/
|
|
16
|
+
import { useEffect, useMemo, useState, type ReactNode } from "react";
|
|
17
|
+
import { useAct, useLab } from "@biolibs/bionet-react";
|
|
18
|
+
import { Glossed } from "@biolibs/glossary-react";
|
|
19
|
+
import { ROLES, designFusion, fusionWorking, type Fusion, type Role } from "./fusion.js";
|
|
20
|
+
import { SequenceMap } from "./map.js";
|
|
21
|
+
import { moleculeOf, type DrawnMolecule } from "./sequence-file.js";
|
|
22
|
+
import { ShowWorking } from "./working.js";
|
|
23
|
+
|
|
24
|
+
/** What a host is handed to draw beside the panel. */
|
|
25
|
+
export interface FusionDesk {
|
|
26
|
+
/** The tube of the first piece, to look at, if the lab has one that has been put somewhere. */
|
|
27
|
+
focus: { place: string; item: string } | null;
|
|
28
|
+
/** The construct as a molecule, with each piece marked on it. `null` until there is one. */
|
|
29
|
+
molecule: DrawnMolecule | null;
|
|
30
|
+
/** The construct as it stands, or `null`. */
|
|
31
|
+
made: Fusion | null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** What each role is called, and a word on what it is for. */
|
|
35
|
+
const SAYS: Readonly<Record<Role, string>> = {
|
|
36
|
+
promoter: "turns the gene on; not part of the protein",
|
|
37
|
+
signal: "sends the protein out; cut off on the way, and only works at the very start",
|
|
38
|
+
coding: "the protein itself",
|
|
39
|
+
tag: "for pulling it out or spotting it; part of the protein",
|
|
40
|
+
linker: "a few residues between two pieces; part of the protein",
|
|
41
|
+
terminator: "stops the reading; not part of the protein",
|
|
42
|
+
other: "something else",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const count = (value: number): string => value.toLocaleString("en-US");
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Putting a construct together from the lab's own parts, with the frame checked as it is built.
|
|
49
|
+
*
|
|
50
|
+
* @param options - `start` says what to open on, for a tour or a link.
|
|
51
|
+
* @returns `panel`, the tool itself, and `desk`, what a scene beside it should look at.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* import { useFusionBench } from "@biolibs/bionet-tools";
|
|
56
|
+
*
|
|
57
|
+
* const bench = useFusionBench();
|
|
58
|
+
* <LabView lab={lab} wide beside={bench.panel} {...(bench.desk.focus === null ? {} : { focus: bench.desk.focus })} />
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function useFusionBench({ start }: {
|
|
62
|
+
/** What to show: the pieces in order, each with what it is for. Followed whenever it changes. */
|
|
63
|
+
start?: { pieces?: readonly { part: string; as: Role }[]; name?: string };
|
|
64
|
+
} = {}): { panel: ReactNode; desk: FusionDesk } {
|
|
65
|
+
const lab = useLab()?.lab;
|
|
66
|
+
const act = useAct();
|
|
67
|
+
const [pieces, setPieces] = useState<{ part: string; as: Role }[]>([...(start?.pieces ?? [])]);
|
|
68
|
+
const [name, setName] = useState(start?.name ?? "");
|
|
69
|
+
const [adding, setAdding] = useState("");
|
|
70
|
+
const [role, setRole] = useState<Role>("coding");
|
|
71
|
+
const [busy, setBusy] = useState(false);
|
|
72
|
+
const [said, setSaid] = useState<string | null>(null);
|
|
73
|
+
|
|
74
|
+
const asked = JSON.stringify(start ?? null);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (start === undefined) return;
|
|
77
|
+
if (start.pieces !== undefined) setPieces([...start.pieces]);
|
|
78
|
+
if (start.name !== undefined) setName(start.name);
|
|
79
|
+
}, [asked]);
|
|
80
|
+
|
|
81
|
+
// Only DNA: a fusion is built out of DNA, and a protein the lab holds is not a piece of one.
|
|
82
|
+
const offered = useMemo(() => (lab?.parts ?? []).filter((one) => one.kind !== "protein"), [lab?.parts]);
|
|
83
|
+
const made = useMemo(() => (lab === null || lab === undefined || pieces.length === 0 ? null
|
|
84
|
+
: designFusion(lab, { pieces, ...(name.trim() === "" ? {} : { name }) })), [lab, pieces, name]);
|
|
85
|
+
const good = made !== null && made.problem === null ? made : null;
|
|
86
|
+
const working = useMemo(() => (good === null ? [] : fusionWorking(good)), [good]);
|
|
87
|
+
|
|
88
|
+
const first = pieces[0] === undefined ? undefined : (lab?.items ?? []).find((one) => one.part === pieces[0]!.part && !one.retired && one.where !== null);
|
|
89
|
+
const desk: FusionDesk = {
|
|
90
|
+
focus: first?.where == null ? null : { place: first.where.place, item: first.item },
|
|
91
|
+
molecule: good === null ? null : { ...moleculeOf({ name: good.name, length: good.sequence.length, circular: false, features: good.features }), name: good.name },
|
|
92
|
+
made: good,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const partName = (checksum: string): string => lab?.parts.find((one) => one.checksum === checksum)?.name ?? "a part";
|
|
96
|
+
const move = (at: number, by: number): void => {
|
|
97
|
+
const to = at + by;
|
|
98
|
+
if (to < 0 || to >= pieces.length) return;
|
|
99
|
+
const next = [...pieces];
|
|
100
|
+
[next[at], next[to]] = [next[to]!, next[at]!];
|
|
101
|
+
setPieces(next);
|
|
102
|
+
setSaid(null);
|
|
103
|
+
};
|
|
104
|
+
const keep = async (): Promise<void> => {
|
|
105
|
+
if (good === null) return;
|
|
106
|
+
setBusy(true);
|
|
107
|
+
const answer = await act("addPart", { name: good.name, sequence: good.sequence, features: good.features });
|
|
108
|
+
setBusy(false);
|
|
109
|
+
setSaid(answer.ok ? `Kept as ${good.name}. There is no tube of it: it has to be built.` : answer.error);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const panel = lab === null || lab === undefined ? null : (
|
|
113
|
+
<div className="bionet fusion">
|
|
114
|
+
<section className="card">
|
|
115
|
+
<h2>Put a construct together</h2>
|
|
116
|
+
<p className="small"><Glossed text="A signal peptide is the first stretch of a protein the cell means to let out, and is cut off on the way." /></p>
|
|
117
|
+
<p className="dim small">
|
|
118
|
+
The pieces in the order they go along the construct. What matters here is not whether they join — that is the assembly desk —
|
|
119
|
+
but whether what they make reads as one protein. A piece that is not a whole number of codons shifts everything after it, and
|
|
120
|
+
a construct with the frame out by one base builds perfectly, sequences exactly as designed, and makes the wrong protein.
|
|
121
|
+
</p>
|
|
122
|
+
{offered.length === 0 ? <p className="empty">The lab has no DNA to build from.</p> : (
|
|
123
|
+
<fieldset disabled={busy} className="stack">
|
|
124
|
+
<ol className="pieces">
|
|
125
|
+
{pieces.map((piece, at) => (
|
|
126
|
+
<li key={`${piece.part} ${at}`}>
|
|
127
|
+
<span className="what"><strong>{partName(piece.part)}</strong> <span className="dim small">· {piece.as} — {SAYS[piece.as]}</span></span>
|
|
128
|
+
<span className="row tight">
|
|
129
|
+
<button type="button" className="plain" onClick={() => move(at, -1)} aria-label="Move it earlier" disabled={at === 0}>↑</button>
|
|
130
|
+
<button type="button" className="plain" onClick={() => move(at, 1)} aria-label="Move it later" disabled={at === pieces.length - 1}>↓</button>
|
|
131
|
+
<button type="button" className="plain" onClick={() => { setPieces(pieces.filter((_, each) => each !== at)); setSaid(null); }}>take out</button>
|
|
132
|
+
</span>
|
|
133
|
+
</li>
|
|
134
|
+
))}
|
|
135
|
+
</ol>
|
|
136
|
+
<form className="row tight" onSubmit={(event) => {
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
if (adding === "") return;
|
|
139
|
+
setPieces([...pieces, { part: adding, as: role }]);
|
|
140
|
+
setAdding(""); setSaid(null);
|
|
141
|
+
}}>
|
|
142
|
+
<select value={adding} onChange={(event) => setAdding(event.target.value)} aria-label="A piece to add">
|
|
143
|
+
<option value="">Add a piece…</option>
|
|
144
|
+
{offered.map((one) => <option key={one.checksum} value={one.checksum}>{one.name} · {count(one.length)} bp</option>)}
|
|
145
|
+
</select>
|
|
146
|
+
<select value={role} onChange={(event) => setRole(event.target.value as Role)} aria-label="What it is for">
|
|
147
|
+
{ROLES.map((one) => <option key={one} value={one}>{one}</option>)}
|
|
148
|
+
</select>
|
|
149
|
+
<button type="submit" disabled={adding === ""}>Add</button>
|
|
150
|
+
</form>
|
|
151
|
+
<label>Call it<input value={name} onChange={(event) => setName(event.target.value)} maxLength={200} placeholder={good?.name ?? "a name for the construct"} /></label>
|
|
152
|
+
</fieldset>
|
|
153
|
+
)}
|
|
154
|
+
{made !== null && made.problem !== null && <p className="trouble" role="status">{made.problem}</p>}
|
|
155
|
+
</section>
|
|
156
|
+
|
|
157
|
+
{good !== null && (
|
|
158
|
+
<>
|
|
159
|
+
<section className="card">
|
|
160
|
+
<h2>The frame</h2>
|
|
161
|
+
{good.junctions.length === 0 ? <p className="dim small">There is only one translated piece, so there is no junction inside the protein.</p> : (
|
|
162
|
+
<ul className="checks">
|
|
163
|
+
{good.junctions.map((one) => (
|
|
164
|
+
<li key={`${one.after} ${one.at}`} className={one.inFrame ? "look" : "stop"}>
|
|
165
|
+
{one.says} <code className="because">base {count(one.at)}</code>
|
|
166
|
+
</li>
|
|
167
|
+
))}
|
|
168
|
+
</ul>
|
|
169
|
+
)}
|
|
170
|
+
<p className="voice">Checks</p>
|
|
171
|
+
{good.checks.length === 0 ? <p className="small good">Nothing about this construct looks wrong.</p> : (
|
|
172
|
+
<ul className="checks">
|
|
173
|
+
{good.checks.map((one) => <li key={one.says} className={one.weight}>{one.says} <code className="because">{one.because}</code></li>)}
|
|
174
|
+
</ul>
|
|
175
|
+
)}
|
|
176
|
+
</section>
|
|
177
|
+
|
|
178
|
+
<section className="card">
|
|
179
|
+
<h2>What it makes</h2>
|
|
180
|
+
<SequenceMap name={good.name} length={good.sequence.length} circular={false} features={good.features}
|
|
181
|
+
{...(good.coding === null ? {} : { spans: [{ start: good.coding.from - 1, end: good.coding.to, label: "read", strand: 0 as const }] })} />
|
|
182
|
+
<p className="small"><strong>{count(good.protein.length)} amino acids</strong>{good.mature === null ? "" : <span className="dim"> · {count(good.mature.length)} once the signal peptide is cut off</span>}</p>
|
|
183
|
+
<p className="small"><code className="seq">{good.protein.slice(0, 120)}{good.protein.length > 120 ? "…" : ""}</code></p>
|
|
184
|
+
<fieldset disabled={busy} className="row">
|
|
185
|
+
<button type="button" onClick={() => void keep()}>Keep it as a part</button>
|
|
186
|
+
<span className="dim small">No tube: it still has to be built. The assembly desk designs the primers for that.</span>
|
|
187
|
+
</fieldset>
|
|
188
|
+
{said !== null && <p className="small" role="status">{said}</p>}
|
|
189
|
+
</section>
|
|
190
|
+
|
|
191
|
+
<section className="card">
|
|
192
|
+
<h2>The working</h2>
|
|
193
|
+
{working.map((one) => <ShowWorking key={one.of} working={one} />)}
|
|
194
|
+
</section>
|
|
195
|
+
</>
|
|
196
|
+
)}
|
|
197
|
+
</div>
|
|
198
|
+
);
|
|
199
|
+
return { panel, desk };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The construct desk on its own, for a lab that has not drawn its room.
|
|
204
|
+
*
|
|
205
|
+
* @param props - `start` says what to open on.
|
|
206
|
+
*/
|
|
207
|
+
export function FusionTool(props: Parameters<typeof useFusionBench>[0]) {
|
|
208
|
+
return <>{useFusionBench(props).panel}</>;
|
|
209
|
+
}
|
package/src/fusion.ts
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Putting a promoter, a signal, a gene and a tag together into one coding sequence, and checking
|
|
3
|
+
* that the frame survives it.
|
|
4
|
+
*
|
|
5
|
+
* `assembly-design.ts` is about the *molecules*: which pieces go round a ring and what primers make
|
|
6
|
+
* them fit. This is about the *protein*, and it is a different question with a different way of
|
|
7
|
+
* going wrong. A ring can be built perfectly and give nothing worth having, because what was joined
|
|
8
|
+
* does not read as one chain: a piece whose length is not a whole number of codons shifts
|
|
9
|
+
* everything after it, and the cell reads a different protein with no complaint from anybody. The
|
|
10
|
+
* gel shows a band, the sequencing matches the design, and the design was wrong.
|
|
11
|
+
*
|
|
12
|
+
* That failure is silent, common, and entirely computable, which is the case for doing it here.
|
|
13
|
+
*
|
|
14
|
+
* Three things are checked that nothing else here checks.
|
|
15
|
+
*
|
|
16
|
+
* **The frame at every junction.** Each translated piece is counted, and a junction is in frame
|
|
17
|
+
* only if everything before it comes to a whole number of codons. A piece that is 20 bases long
|
|
18
|
+
* rather than 21 is named, with what it does to everything after it.
|
|
19
|
+
*
|
|
20
|
+
* **A stop where no stop belongs.** The whole thing is translated and read: a stop codon anywhere
|
|
21
|
+
* but the end means the chain finishes early, and that is usually a frame that shifted a piece or
|
|
22
|
+
* two before it.
|
|
23
|
+
*
|
|
24
|
+
* **Where the signal peptide is.** A signal only works at the very beginning of the chain. Putting
|
|
25
|
+
* a tag in front of one is a mistake people make because the tag belongs at the N-terminus and so
|
|
26
|
+
* does the signal, and only one of them can be: the protein is made, and stays inside the cell.
|
|
27
|
+
*/
|
|
28
|
+
import type { PartFeature, PartState } from "@biolibs/bionet";
|
|
29
|
+
import { translate } from "@biolibs/seq";
|
|
30
|
+
import { CODON } from "./codons.js";
|
|
31
|
+
import type { Working } from "./pcr-working.js";
|
|
32
|
+
import type { ToolLab } from "./run.js";
|
|
33
|
+
|
|
34
|
+
/** What a piece of a fusion is there to do. */
|
|
35
|
+
export const ROLES = ["promoter", "signal", "coding", "tag", "linker", "terminator", "other"] as const;
|
|
36
|
+
|
|
37
|
+
/** One of them. */
|
|
38
|
+
export type Role = (typeof ROLES)[number];
|
|
39
|
+
|
|
40
|
+
/** Which roles are part of the protein, and so have to keep the frame. */
|
|
41
|
+
const TRANSLATED = new Set<Role>(["signal", "coding", "tag", "linker"]);
|
|
42
|
+
|
|
43
|
+
/** One piece to put in, in the order it goes. */
|
|
44
|
+
export interface FusionPiece {
|
|
45
|
+
/** The part, by checksum, where it is one the lab holds. */
|
|
46
|
+
part?: string;
|
|
47
|
+
/** Its bases, where they are given outright: a short linker nobody keeps a tube of. */
|
|
48
|
+
sequence?: string;
|
|
49
|
+
/** What to call it. */
|
|
50
|
+
name?: string;
|
|
51
|
+
/** What it is there to do. */
|
|
52
|
+
as: Role;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** One place two pieces meet. */
|
|
56
|
+
export interface Junction {
|
|
57
|
+
/** What is before it and what is after. */
|
|
58
|
+
after: string;
|
|
59
|
+
before: string;
|
|
60
|
+
/** Where it falls, counting bases from 1. */
|
|
61
|
+
at: number;
|
|
62
|
+
/** Whether everything translated before it comes to a whole number of codons. */
|
|
63
|
+
inFrame: boolean;
|
|
64
|
+
/** What it does, said for a person. */
|
|
65
|
+
says: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Something a careful person would stop and ask about a fusion before building it. */
|
|
69
|
+
export interface FusionCheck {
|
|
70
|
+
/** `stop` if it will not do what is wanted, `look` if it is only worth a second glance. */
|
|
71
|
+
weight: "stop" | "look";
|
|
72
|
+
/** What to say. */
|
|
73
|
+
says: string;
|
|
74
|
+
/** The short reason, to put beside it. */
|
|
75
|
+
because: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A fusion, designed. */
|
|
79
|
+
export interface Fusion {
|
|
80
|
+
/** What to call it. */
|
|
81
|
+
name: string;
|
|
82
|
+
/** The whole thing, promoter and terminator included. */
|
|
83
|
+
sequence: string;
|
|
84
|
+
/** What is marked on it: each piece, where it ended up. */
|
|
85
|
+
features: PartFeature[];
|
|
86
|
+
/** Where the translated stretch lies, counting from 1, or `null` if nothing is translated. */
|
|
87
|
+
coding: { from: number; to: number } | null;
|
|
88
|
+
/** What it would be read as, with no stop. */
|
|
89
|
+
protein: string;
|
|
90
|
+
/** What is left once a signal peptide at the start is cut off, which is what a lab collects. */
|
|
91
|
+
mature: string | null;
|
|
92
|
+
/** Every place two pieces meet. */
|
|
93
|
+
junctions: Junction[];
|
|
94
|
+
/** What a careful person would ask, the ones worth stopping for first. */
|
|
95
|
+
checks: FusionCheck[];
|
|
96
|
+
/** Why there is nothing to look at, or `null` if there is. */
|
|
97
|
+
problem: string | null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const clean = (bases: string): string => bases.replace(/\s+/g, "").toUpperCase();
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Put the pieces together and read what comes out.
|
|
104
|
+
*
|
|
105
|
+
* @param lab - The lab, for the parts it holds.
|
|
106
|
+
* @param choice - The pieces in order, and what to call the result.
|
|
107
|
+
* @returns The fusion, with its junctions and everything worth asking about it.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { designFusion } from "@biolibs/bionet-tools";
|
|
112
|
+
*
|
|
113
|
+
* const made = designFusion(lab, { pieces: [
|
|
114
|
+
* { part: aox1, as: "promoter" }, { part: alphaFactor, as: "signal" },
|
|
115
|
+
* { part: casein, as: "coding" }, { sequence: "CACCACCACCACCACCAC", name: "His6", as: "tag" },
|
|
116
|
+
* ] });
|
|
117
|
+
* made.checks.filter((one) => one.weight === "stop");
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export function designFusion(lab: Pick<ToolLab, "parts">, choice: { pieces: readonly FusionPiece[]; name?: string }): Fusion {
|
|
121
|
+
const nothing = (problem: string): Fusion =>
|
|
122
|
+
({ name: choice.name?.trim() || "a fusion", sequence: "", features: [], coding: null, protein: "", mature: null, junctions: [], checks: [], problem });
|
|
123
|
+
if (choice.pieces.length === 0) return nothing("A fusion is made of pieces, and none were given.");
|
|
124
|
+
|
|
125
|
+
/** Each piece with its bases, whatever it was named by. */
|
|
126
|
+
const pieces: { name: string; bases: string; as: Role }[] = [];
|
|
127
|
+
for (const piece of choice.pieces) {
|
|
128
|
+
const held: PartState | undefined = piece.part === undefined ? undefined : lab.parts.find((one) => one.checksum === piece.part);
|
|
129
|
+
if (piece.part !== undefined && held === undefined) return nothing("A piece names a part the lab does not have.");
|
|
130
|
+
if (held !== undefined && held.kind === "protein") return nothing(`${held.name} is a protein. A fusion is built out of DNA.`);
|
|
131
|
+
const bases = clean(piece.sequence ?? held?.sequence ?? "");
|
|
132
|
+
if (bases === "") return nothing("A piece has no bases: give a part the lab holds, or write the sequence out.");
|
|
133
|
+
if (!/^[ACGT]+$/.test(bases)) return nothing(`${piece.name ?? held?.name ?? "A piece"} is written in letters that are not A, C, G and T, and a reading frame cannot be counted through an uncertain base.`);
|
|
134
|
+
pieces.push({ name: piece.name?.trim() || held?.name || `a ${piece.as}`, bases, as: piece.as });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const sequence = pieces.map((one) => one.bases).join("");
|
|
138
|
+
// Where each piece ended up, which is what gets marked on the part.
|
|
139
|
+
const features: PartFeature[] = [];
|
|
140
|
+
const junctions: Junction[] = [];
|
|
141
|
+
const checks: FusionCheck[] = [];
|
|
142
|
+
let at = 0;
|
|
143
|
+
let translatedSoFar = 0;
|
|
144
|
+
let codingFrom: number | null = null;
|
|
145
|
+
let codingTo = 0;
|
|
146
|
+
for (const [index, piece] of pieces.entries()) {
|
|
147
|
+
features.push({ type: piece.as === "coding" ? "CDS" : piece.as === "signal" ? "sig_peptide" : piece.as,
|
|
148
|
+
label: piece.name, strand: 1, parts: [{ start: at, end: at + piece.bases.length }] });
|
|
149
|
+
if (TRANSLATED.has(piece.as)) {
|
|
150
|
+
if (codingFrom === null) codingFrom = at + 1;
|
|
151
|
+
codingTo = at + piece.bases.length;
|
|
152
|
+
// A junction is in frame only if everything translated before it is a whole number of codons.
|
|
153
|
+
if (index > 0 && TRANSLATED.has(pieces[index - 1]!.as)) {
|
|
154
|
+
const inFrame = translatedSoFar % CODON === 0;
|
|
155
|
+
junctions.push({
|
|
156
|
+
after: pieces[index - 1]!.name, before: piece.name, at: at + 1, inFrame,
|
|
157
|
+
says: inFrame
|
|
158
|
+
? `${pieces[index - 1]!.name} ends on a whole codon, so ${piece.name} is read in frame.`
|
|
159
|
+
: `${translatedSoFar} bases come before this, which is ${translatedSoFar % CODON} past a whole codon, so ${piece.name} and everything after it is read in the wrong frame.`,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (piece.bases.length % CODON !== 0) {
|
|
163
|
+
checks.push({
|
|
164
|
+
weight: "stop",
|
|
165
|
+
says: `${piece.name} is ${piece.bases.length} bases, which is not a whole number of codons. It shifts everything after it by ${piece.bases.length % CODON}, and the cell reads a different protein without complaining. Add or drop ${CODON - (piece.bases.length % CODON)} or ${piece.bases.length % CODON} bases.`,
|
|
166
|
+
because: `${piece.bases.length} ÷ 3 leaves ${piece.bases.length % CODON}`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
translatedSoFar += piece.bases.length;
|
|
170
|
+
}
|
|
171
|
+
at += piece.bases.length;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Where things are in the order matters for two of the roles, and the mistakes are classic ones.
|
|
175
|
+
const translatedPieces = pieces.filter((one) => TRANSLATED.has(one.as));
|
|
176
|
+
const signalAt = translatedPieces.findIndex((one) => one.as === "signal");
|
|
177
|
+
if (signalAt > 0) {
|
|
178
|
+
const before = translatedPieces.slice(0, signalAt).map((one) => one.name).join(" and ");
|
|
179
|
+
checks.push({
|
|
180
|
+
weight: "stop",
|
|
181
|
+
says: `${translatedPieces[signalAt]!.name} is a signal peptide, and one only works at the very start of the chain. ${before} comes before it, so nothing will recognise it: the protein will be made and will stay inside the cell. Put the signal first and the tag after it.`,
|
|
182
|
+
because: `${before} is before the signal`,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
const promoterAt = pieces.findIndex((one) => one.as === "promoter");
|
|
186
|
+
if (promoterAt > 0 && pieces.slice(0, promoterAt).some((one) => TRANSLATED.has(one.as))) {
|
|
187
|
+
checks.push({ weight: "stop", says: `${pieces[promoterAt]!.name} is a promoter and comes after something that is translated. A promoter goes before what it drives.`, because: "promoter after the coding" });
|
|
188
|
+
}
|
|
189
|
+
const terminatorAt = pieces.findIndex((one) => one.as === "terminator");
|
|
190
|
+
if (terminatorAt >= 0 && pieces.slice(terminatorAt + 1).some((one) => TRANSLATED.has(one.as))) {
|
|
191
|
+
checks.push({ weight: "stop", says: `${pieces[terminatorAt]!.name} is a terminator and comes before something that is translated. A terminator goes at the end.`, because: "terminator before the coding" });
|
|
192
|
+
}
|
|
193
|
+
if (translatedPieces.length === 0) {
|
|
194
|
+
return { ...nothing("None of these pieces is translated, so there is no protein to read."), sequence, features, name: choice.name?.trim() || "a fusion" };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Read it. The whole translated stretch is read as one, which is the point: a frame that shifted
|
|
198
|
+
// shows up here as a stop in the middle, not as a complaint from any one piece.
|
|
199
|
+
const stretch = sequence.slice((codingFrom ?? 1) - 1, codingTo);
|
|
200
|
+
const whole = stretch.slice(0, stretch.length - (stretch.length % CODON));
|
|
201
|
+
const read = String(translate(whole));
|
|
202
|
+
const stopped = read.endsWith("*");
|
|
203
|
+
const protein = stopped ? read.slice(0, -1) : read;
|
|
204
|
+
const inside = protein.indexOf("*");
|
|
205
|
+
if (inside >= 0) {
|
|
206
|
+
checks.push({
|
|
207
|
+
weight: "stop",
|
|
208
|
+
says: `There is a stop at amino acid ${inside + 1} of ${protein.length}, before the end, so the chain finishes early. If a piece above is not a whole number of codons, that is usually why.`,
|
|
209
|
+
because: `stop at ${inside + 1}`,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
if (!protein.startsWith("M")) {
|
|
213
|
+
checks.push({ weight: "look", says: "The translated stretch does not begin with methionine, which a coding sequence usually does. Check that the first translated piece really starts where the protein does.", because: `begins ${protein.slice(0, 1)}` });
|
|
214
|
+
}
|
|
215
|
+
if (!stopped) {
|
|
216
|
+
checks.push({ weight: "look", says: "There is no stop codon at the end of the translated stretch. Without one the cell reads on into whatever follows.", because: "no stop at the end" });
|
|
217
|
+
}
|
|
218
|
+
if (stretch.length % CODON !== 0) {
|
|
219
|
+
checks.push({ weight: "stop", says: `The translated stretch is ${stretch.length} bases, which is not a whole number of codons, so the last ${stretch.length % CODON} are read as part of nothing.`, because: `${stretch.length} ÷ 3 leaves ${stretch.length % CODON}` });
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// What is collected, for a protein that is let out: the chain with its signal peptide gone.
|
|
223
|
+
const signal = pieces.find((one) => one.as === "signal");
|
|
224
|
+
const mature = signal === undefined || signalAt !== 0 ? null : protein.slice(Math.floor(signal.bases.length / CODON));
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
name: choice.name?.trim() || `${pieces.map((one) => one.name).join(" + ")}`.slice(0, 200),
|
|
228
|
+
sequence, features,
|
|
229
|
+
coding: codingFrom === null ? null : { from: codingFrom, to: codingTo },
|
|
230
|
+
protein, mature, junctions,
|
|
231
|
+
checks: checks.sort((a, b) => Number(b.weight === "stop") - Number(a.weight === "stop")),
|
|
232
|
+
problem: null,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* The working behind a fusion: where the frame stands at each junction, and what was read.
|
|
238
|
+
*
|
|
239
|
+
* @param made - What `designFusion` gave.
|
|
240
|
+
* @returns The workings. Empty if there was nothing to design.
|
|
241
|
+
*/
|
|
242
|
+
export function fusionWorking(made: Fusion): Working[] {
|
|
243
|
+
if (made.problem !== null) return [];
|
|
244
|
+
const count = (value: number): string => value.toLocaleString("en-US");
|
|
245
|
+
const out: Working[] = [{
|
|
246
|
+
of: "the frame, through every junction",
|
|
247
|
+
comes: made.junctions.every((one) => one.inFrame) ? "whole the whole way" : "broken",
|
|
248
|
+
kind: "exact",
|
|
249
|
+
steps: [
|
|
250
|
+
"A junction is in frame when everything translated before it comes to a whole number of codons, because that is what decides which three bases the cell reads together.",
|
|
251
|
+
...made.junctions.map((one) => `${one.after} → ${one.before}, at base ${count(one.at)}: ${one.says}`),
|
|
252
|
+
...(made.junctions.length === 0 ? ["There is only one translated piece, so there is no junction inside the protein."] : []),
|
|
253
|
+
],
|
|
254
|
+
}];
|
|
255
|
+
if (made.coding !== null) {
|
|
256
|
+
out.push({
|
|
257
|
+
of: "what it reads as",
|
|
258
|
+
comes: `${count(made.protein.length)} amino acids`,
|
|
259
|
+
kind: "exact",
|
|
260
|
+
steps: [
|
|
261
|
+
`The translated stretch is bases ${count(made.coding.from)}–${count(made.coding.to)}, which is ${count(made.coding.to - made.coding.from + 1)} bases.`,
|
|
262
|
+
`${count(made.coding.to - made.coding.from + 1)} ÷ 3 is ${count(Math.floor((made.coding.to - made.coding.from + 1) / CODON))} codons.`,
|
|
263
|
+
`It begins ${made.protein.slice(0, 24)}${made.protein.length > 24 ? "…" : ""}`,
|
|
264
|
+
...(made.mature === null ? [] : [`With the signal peptide cut off, what is let out is ${count(made.mature.length)} amino acids, beginning ${made.mature.slice(0, 18)}…`]),
|
|
265
|
+
],
|
|
266
|
+
rests: "This is what the sequence says the cell would read. Whether the protein folds, is let out, or is any use is not something a sequence can be asked.",
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return out;
|
|
270
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -18,12 +18,15 @@
|
|
|
18
18
|
* - `protein.ts` — the protein a gene codes for, and what its sequence says about it
|
|
19
19
|
* - `induce.ts` — growing a strain to express what was put into it, and the mass its band should run at
|
|
20
20
|
* - `modify.ts` — which residues would be phosphorylated, and whether the host has the enzyme to do it
|
|
21
|
+
* - `remedy.ts` — the ways round a host that will not, and the one of them that can be computed
|
|
21
22
|
* - `induce-bench.tsx` — an induction at the shaking incubator, with the protein gel that answers it
|
|
22
23
|
* - `verify-bench.tsx` — checking a construct against the design at a desk, saying what was not covered
|
|
23
24
|
* - `verify.ts` — a sequencing read against the design it was meant to be, and what each difference costs
|
|
24
25
|
* - `codons.ts` — a gene rewritten in a host's codons, from usage counted over that host's own genes
|
|
25
26
|
* - `codon-bench.tsx` — writing a gene in a host's codons at a desk, with the counting on the screen
|
|
26
27
|
* - `assembly-design.ts` — a ring designed from a lab's own parts: the pieces in order, and the primers that make them fit
|
|
28
|
+
* - `fusion.ts` — a promoter, a signal, a gene and a tag put together, with the frame checked at every junction
|
|
29
|
+
* - `fusion-bench.tsx` — that at a desk: the pieces in order, and the frame watched as they are laid out
|
|
27
30
|
* - `assembly-bench.tsx` — building a ring at a desk: the pieces in order, and the primers that make them fit
|
|
28
31
|
* - `ligate.ts` — pieces that have already been cut, joined where their ends fit
|
|
29
32
|
* - `ligate-working.ts` — a ligation's working: each join in its bases, the length, how much to put in
|
|
@@ -38,6 +41,9 @@
|
|
|
38
41
|
* - `primer-working.ts` — the working behind a design: the melting temperature's sum, the GC count, the bases that pair
|
|
39
42
|
* - `primer-bench.tsx` — designing primers at a desk: the panel, and the template with the pair marked on it for a scene
|
|
40
43
|
* - `plans.tsx` — runs that have been proposed, at the tool that would carry them out
|
|
44
|
+
* - `ordering.ts` — those proposals read as one piece of work: what order, what can start, what is waiting
|
|
45
|
+
* - `work.tsx` — that work drawn: the chains, in order, with what has to be got first
|
|
46
|
+
* - `protocol.ts` — the work as a sheet to carry to a bench, with what the plan does not say named
|
|
41
47
|
* - `tools.tsx` — getting to one: from an instrument, or from a list of them all
|
|
42
48
|
*
|
|
43
49
|
* The tools are drawn with the styles of `@biolibs/bionet-panels` and belong inside its `LabWindow`.
|
|
@@ -55,12 +61,15 @@ export * from "./digest-working.js";
|
|
|
55
61
|
export * from "./protein.js";
|
|
56
62
|
export * from "./induce.js";
|
|
57
63
|
export * from "./modify.js";
|
|
64
|
+
export * from "./remedy.js";
|
|
58
65
|
export * from "./induce-bench.js";
|
|
59
66
|
export * from "./verify.js";
|
|
60
67
|
export * from "./verify-bench.js";
|
|
61
68
|
export * from "./codons.js";
|
|
62
69
|
export * from "./codon-bench.js";
|
|
63
70
|
export * from "./assembly-design.js";
|
|
71
|
+
export * from "./fusion.js";
|
|
72
|
+
export * from "./fusion-bench.js";
|
|
64
73
|
export * from "./assembly-bench.js";
|
|
65
74
|
export * from "./ligate.js";
|
|
66
75
|
export * from "./ligate-working.js";
|
|
@@ -71,6 +80,9 @@ export * from "./working.js";
|
|
|
71
80
|
export * from "./map.js";
|
|
72
81
|
export * from "./sequences-tool.js";
|
|
73
82
|
export * from "./plans.js";
|
|
83
|
+
export * from "./ordering.js";
|
|
84
|
+
export * from "./work.js";
|
|
85
|
+
export * from "./protocol.js";
|
|
74
86
|
export * from "./tools.js";
|
|
75
87
|
export * from "./pcr-bench.js";
|
|
76
88
|
export * from "./primer-design.js";
|
package/src/modify.ts
CHANGED
|
@@ -248,7 +248,7 @@ export interface HostKinases {
|
|
|
248
248
|
export const HOST_KINASES: readonly HostKinases[] = [
|
|
249
249
|
{
|
|
250
250
|
host: "Escherichia coli", secretoryKinase: "no", casein2: false, standing: "well established",
|
|
251
|
-
says: "A bacterium has no secretory pathway of this kind and no kinase in it
|
|
251
|
+
says: "A bacterium has no secretory pathway of this kind and no kinase in it, so casein made in plain E. coli is unphosphorylated. That is not the end of it: co-expressing a kinase on the same plasmid has worked, and worked well — Thurmond and colleagues got every phosphorylated form of human beta-casein that the native protein has, in E. coli, with human CK2 beside it. The same trick does much less for bovine beta-casein, because CK2 reads only some of its sites. E. coli also gives the highest yields of any host tried: up to 1.45 g/L.",
|
|
252
252
|
},
|
|
253
253
|
{
|
|
254
254
|
host: "Bacillus subtilis", secretoryKinase: "no", casein2: false, standing: "well established",
|
|
@@ -256,15 +256,15 @@ export const HOST_KINASES: readonly HostKinases[] = [
|
|
|
256
256
|
},
|
|
257
257
|
{
|
|
258
258
|
host: "Saccharomyces cerevisiae", secretoryKinase: "not known", casein2: true, standing: "reported",
|
|
259
|
-
says: "Budding yeast has casein kinase I and II homologues, but no homologue of the secretory-pathway kinase has been identified.
|
|
259
|
+
says: "Budding yeast has casein kinase I and II homologues, but no homologue of the secretory-pathway kinase has been identified. Yeast does appear to phosphorylate casein in vivo; how completely, and at which sites, is underexplored rather than measured — most studies went after secretion and yield instead. Some strains also put O-linked sugars on it, which native casein does not have.",
|
|
260
260
|
},
|
|
261
261
|
{
|
|
262
262
|
host: "Komagataella phaffii", secretoryKinase: "not known", casein2: true, standing: "reported",
|
|
263
|
-
says: "The yeast formerly called Pichia pastoris, and the usual choice for a secreted protein because it secretes a great deal of it
|
|
263
|
+
says: "The yeast formerly called Pichia pastoris, and the usual choice for a secreted protein because it secretes a great deal of it: 1 g/L of bovine beta-casein has been reported, the best of any yeast. The kinase of the secretory pathway has not been identified in it, as in budding yeast, and one report of a bovine beta-casein mutant made here found it both phosphorylated and glycosylated. How completely it phosphorylates, and where, nobody has measured.",
|
|
264
264
|
},
|
|
265
265
|
{
|
|
266
266
|
host: "Nicotiana benthamiana", secretoryKinase: "not known", casein2: true, standing: "reported",
|
|
267
|
-
says: "Plants have CK2 and a secretory pathway
|
|
267
|
+
says: "Plants have CK2 and a secretory pathway. What has actually been reported for casein in plants is poor: yields of a tenth of a per cent of total protein or less, and casein found unphosphorylated where anybody looked.",
|
|
268
268
|
},
|
|
269
269
|
{
|
|
270
270
|
host: "Cricetulus griseus", secretoryKinase: "yes", casein2: true, standing: "well established",
|