@biolibs/bionet-tools 0.1.7 → 0.1.10
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 +79 -2
- package/dist/assembly-bench.d.ts +62 -0
- package/dist/assembly-bench.d.ts.map +1 -0
- package/dist/assembly-bench.js +114 -0
- package/dist/assembly-bench.js.map +1 -0
- package/dist/assembly-design.d.ts +119 -0
- package/dist/assembly-design.d.ts.map +1 -0
- package/dist/assembly-design.js +157 -0
- package/dist/assembly-design.js.map +1 -0
- package/dist/codon-bench.d.ts +51 -0
- package/dist/codon-bench.d.ts.map +1 -0
- package/dist/codon-bench.js +93 -0
- package/dist/codon-bench.js.map +1 -0
- package/dist/codons.d.ts +126 -0
- package/dist/codons.d.ts.map +1 -0
- package/dist/codons.js +287 -0
- package/dist/codons.js.map +1 -0
- package/dist/digest-tool.d.ts +12 -3
- package/dist/digest-tool.d.ts.map +1 -1
- package/dist/digest-tool.js +10 -4
- package/dist/digest-tool.js.map +1 -1
- package/dist/digest.d.ts +14 -0
- package/dist/digest.d.ts.map +1 -1
- package/dist/digest.js +18 -0
- package/dist/digest.js.map +1 -1
- 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/induce-bench.d.ts +91 -0
- package/dist/induce-bench.d.ts.map +1 -0
- package/dist/induce-bench.js +201 -0
- package/dist/induce-bench.js.map +1 -0
- package/dist/induce.d.ts +280 -0
- package/dist/induce.d.ts.map +1 -0
- package/dist/induce.js +353 -0
- package/dist/induce.js.map +1 -0
- package/dist/modify.d.ts +197 -0
- package/dist/modify.d.ts.map +1 -0
- package/dist/modify.js +253 -0
- package/dist/modify.js.map +1 -0
- package/dist/pcr-tool.js +1 -1
- package/dist/pcr-tool.js.map +1 -1
- package/dist/plans.d.ts.map +1 -1
- package/dist/plans.js +4 -1
- package/dist/plans.js.map +1 -1
- package/dist/primer-bench.js +1 -1
- package/dist/primer-bench.js.map +1 -1
- package/dist/protein.d.ts +106 -0
- package/dist/protein.d.ts.map +1 -0
- package/dist/protein.js +160 -0
- package/dist/protein.js.map +1 -0
- package/dist/run.d.ts +13 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +20 -5
- package/dist/run.js.map +1 -1
- package/dist/sequences-tool.js +1 -1
- package/dist/sequences-tool.js.map +1 -1
- package/dist/tools.d.ts +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +12 -6
- package/dist/tools.js.map +1 -1
- package/dist/verify-bench.d.ts +48 -0
- package/dist/verify-bench.d.ts.map +1 -0
- package/dist/verify-bench.js +77 -0
- package/dist/verify-bench.js.map +1 -0
- package/dist/verify.d.ts +138 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +263 -0
- package/dist/verify.js.map +1 -0
- package/package.json +6 -4
- package/src/assembly-bench.tsx +232 -0
- package/src/assembly-design.ts +219 -0
- package/src/codon-bench.tsx +189 -0
- package/src/codons.ts +339 -0
- package/src/digest-tool.tsx +14 -5
- package/src/digest.ts +19 -0
- package/src/index.ts +20 -0
- package/src/induce-bench.tsx +406 -0
- package/src/induce.ts +448 -0
- package/src/modify.ts +350 -0
- package/src/pcr-tool.tsx +1 -1
- package/src/plans.tsx +4 -1
- package/src/primer-bench.tsx +1 -1
- package/src/protein.ts +206 -0
- package/src/run.ts +22 -6
- package/src/sequences-tool.tsx +1 -1
- package/src/tools.tsx +11 -5
- package/src/verify-bench.tsx +161 -0
- package/src/verify.ts +310 -0
- package/tools.css +13 -0
package/src/codons.ts
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codon optimisation: writing the same protein in the codons a host actually uses.
|
|
3
|
+
*
|
|
4
|
+
* Every amino acid but methionine and tryptophan has more than one codon, and an organism uses them
|
|
5
|
+
* unevenly. A bovine gene written in bovine codons is read slowly by yeast, which is why a casein
|
|
6
|
+
* expressed as it comes out of the cow gives poor yields. Optimising rewrites the gene in the
|
|
7
|
+
* host's own preferences without changing one amino acid of what it makes.
|
|
8
|
+
*
|
|
9
|
+
* **Where the preferences come from matters more than the optimising.** There is no table of codon
|
|
10
|
+
* usage built into this package, and none is asserted from memory: a table is counted here, from
|
|
11
|
+
* coding sequences the lab supplies — the host's own genes, fetched and kept like anything else.
|
|
12
|
+
* That makes it checkable. The counts are shown, the number of genes they came from is shown, and
|
|
13
|
+
* a table counted over too few genes says so. A table is only as good as what went into it, and
|
|
14
|
+
* nothing here pretends otherwise.
|
|
15
|
+
*
|
|
16
|
+
* The genetic code itself is not counted but read, from the NCBI tables in `@biolibs/seq`.
|
|
17
|
+
*/
|
|
18
|
+
import { CodonTable, translate } from "@biolibs/seq";
|
|
19
|
+
import type { Working } from "./pcr-working.js";
|
|
20
|
+
|
|
21
|
+
/** How many bases a codon is. */
|
|
22
|
+
export const CODON = 3;
|
|
23
|
+
|
|
24
|
+
/** Fewer coding sequences than this, and a table is too thin to lean on. */
|
|
25
|
+
export const FEW_GENES = 5;
|
|
26
|
+
|
|
27
|
+
/** Fewer codons than this for one amino acid, and its preference is not worth much. */
|
|
28
|
+
export const FEW_CODONS = 20;
|
|
29
|
+
|
|
30
|
+
/** The longest run of one base an optimised sequence is allowed to make. */
|
|
31
|
+
export const LONGEST_RUN = 6;
|
|
32
|
+
|
|
33
|
+
/** What one codon was counted as. */
|
|
34
|
+
export interface CodonCount {
|
|
35
|
+
/** The amino acid it codes for. */
|
|
36
|
+
aminoAcid: string;
|
|
37
|
+
/** How many times it appeared. */
|
|
38
|
+
count: number;
|
|
39
|
+
/** Its share of the codons for that amino acid, from 0 to 1. */
|
|
40
|
+
share: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** How a host uses its codons, counted from its own genes. */
|
|
44
|
+
export interface CodonUsage {
|
|
45
|
+
/** Which NCBI genetic code it was read with. */
|
|
46
|
+
table: number;
|
|
47
|
+
/** What the sequences were said to be of, for saying where this came from. Never asserted here. */
|
|
48
|
+
from: string;
|
|
49
|
+
/** How many coding sequences were counted. */
|
|
50
|
+
genes: number;
|
|
51
|
+
/** How many codons in all. */
|
|
52
|
+
codons: number;
|
|
53
|
+
/** Each sense codon, with its count and its share of its amino acid. */
|
|
54
|
+
counts: Record<string, CodonCount>;
|
|
55
|
+
/** Anything about the counting worth knowing before leaning on it. */
|
|
56
|
+
warnings: string[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** One codon that was changed. */
|
|
60
|
+
export interface CodonChange {
|
|
61
|
+
/** Which codon of the gene it is, counting from 1. */
|
|
62
|
+
at: number;
|
|
63
|
+
/** The amino acid, unchanged. */
|
|
64
|
+
aminoAcid: string;
|
|
65
|
+
/** What it was, and that codon's share in the host. */
|
|
66
|
+
from: string;
|
|
67
|
+
fromShare: number;
|
|
68
|
+
/** What it became, and that codon's share. */
|
|
69
|
+
to: string;
|
|
70
|
+
toShare: number;
|
|
71
|
+
/** Why, if the host's favourite was not taken. */
|
|
72
|
+
instead: string | null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** A gene rewritten in a host's codons. */
|
|
76
|
+
export interface CodonOptimised {
|
|
77
|
+
/** The rewritten sequence. */
|
|
78
|
+
sequence: string;
|
|
79
|
+
/** The protein, which is the same before and after. This is checked, not assumed. */
|
|
80
|
+
protein: string;
|
|
81
|
+
/** Every codon that changed. */
|
|
82
|
+
changes: CodonChange[];
|
|
83
|
+
/** How many codons there are in all. */
|
|
84
|
+
codons: number;
|
|
85
|
+
/** The GC content before and after, from 0 to 1. */
|
|
86
|
+
gcBefore: number;
|
|
87
|
+
gcAfter: number;
|
|
88
|
+
/** Sites that were kept out of the sequence, by name. */
|
|
89
|
+
avoided: string[];
|
|
90
|
+
/** Anything a careful person would look at. */
|
|
91
|
+
warnings: string[];
|
|
92
|
+
/** Why it could not be done, or `null`. */
|
|
93
|
+
problem: string | null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const clean = (bases: string): string => bases.replace(/\s+/g, "").toUpperCase();
|
|
97
|
+
const gc = (bases: string): number => (bases.length === 0 ? 0 : [...bases].filter((one) => one === "G" || one === "C").length / bases.length);
|
|
98
|
+
const share = (value: number): string => `${Math.round(value * 100)}%`;
|
|
99
|
+
|
|
100
|
+
/** The genetic code, as the codons for each amino acid. */
|
|
101
|
+
function synonyms(table: number): { forward: Map<string, string>; byAminoAcid: Map<string, string[]>; stops: string[] } {
|
|
102
|
+
const code = CodonTable.unambiguousDnaById.get(table);
|
|
103
|
+
if (code === undefined) throw new Error(`There is no NCBI genetic code numbered ${table}.`);
|
|
104
|
+
const forward = new Map<string, string>();
|
|
105
|
+
const byAminoAcid = new Map<string, string[]>();
|
|
106
|
+
for (const [codon, aminoAcid] of code.forwardTable as unknown as Iterable<[string, string]>) {
|
|
107
|
+
forward.set(codon, aminoAcid);
|
|
108
|
+
byAminoAcid.set(aminoAcid, [...(byAminoAcid.get(aminoAcid) ?? []), codon]);
|
|
109
|
+
}
|
|
110
|
+
return { forward, byAminoAcid, stops: [...code.stopCodons] };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Count how a host uses its codons, from its own coding sequences.
|
|
115
|
+
*
|
|
116
|
+
* @param genes - The coding sequences, each a whole number of codons. Anything else is left out and said so.
|
|
117
|
+
* @param options - `from` says where the genes came from, which is kept with the table; `table` is
|
|
118
|
+
* the NCBI genetic code, 1 unless said.
|
|
119
|
+
* @returns The table, with the counts it was made of.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { countCodonUsage } from "@biolibs/bionet-tools";
|
|
124
|
+
*
|
|
125
|
+
* const usage = countCodonUsage([geneOne, geneTwo], { from: "12 Pichia pastoris genes" });
|
|
126
|
+
* usage.counts["CTG"]?.share; // how much of this host's leucine is CTG
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export function countCodonUsage(genes: readonly string[], options: { from?: string; table?: number } = {}): CodonUsage {
|
|
130
|
+
const table = options.table ?? 1;
|
|
131
|
+
const { forward, byAminoAcid } = synonyms(table);
|
|
132
|
+
const counts: Record<string, CodonCount> = {};
|
|
133
|
+
for (const [codon, aminoAcid] of forward) counts[codon] = { aminoAcid, count: 0, share: 0 };
|
|
134
|
+
const warnings: string[] = [];
|
|
135
|
+
let used = 0;
|
|
136
|
+
let codons = 0;
|
|
137
|
+
for (const [at, gene] of genes.entries()) {
|
|
138
|
+
const bases = clean(gene);
|
|
139
|
+
if (bases.length < CODON || bases.length % CODON !== 0) {
|
|
140
|
+
warnings.push(`Sequence ${at + 1} is ${bases.length} bases, which is not a whole number of codons, so it was left out.`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (!/^[ACGT]+$/.test(bases)) {
|
|
144
|
+
warnings.push(`Sequence ${at + 1} has bases that are not A, C, G or T, so it was left out.`);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
used += 1;
|
|
148
|
+
for (let start = 0; start + CODON <= bases.length; start += CODON) {
|
|
149
|
+
const held = counts[bases.slice(start, start + CODON)];
|
|
150
|
+
// A stop codon is not counted: nothing chooses between stops when optimising.
|
|
151
|
+
if (held !== undefined) { held.count += 1; codons += 1; }
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
for (const family of byAminoAcid.values()) {
|
|
155
|
+
const total = family.reduce((sum, codon) => sum + counts[codon]!.count, 0);
|
|
156
|
+
for (const codon of family) counts[codon]!.share = total === 0 ? 0 : counts[codon]!.count / total;
|
|
157
|
+
if (total > 0 && total < FEW_CODONS) {
|
|
158
|
+
warnings.push(`${counts[family[0]!]!.aminoAcid} appears only ${total} times, so which of ${family.join(", ")} this host prefers is not well counted.`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (used < FEW_GENES) warnings.push(`Counted over ${used} ${used === 1 ? "gene" : "genes"}, which is few. A table counted over more genes is worth more.`);
|
|
162
|
+
return { table, from: options.from ?? "sequences the lab supplied", genes: used, codons, counts, warnings };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Why putting `codon` after `sequence` would not do, or `null` if it would.
|
|
167
|
+
*
|
|
168
|
+
* Only the join is looked at, far enough back to catch a run or a site that straddles it: what came
|
|
169
|
+
* before was already allowed when it was put there.
|
|
170
|
+
*/
|
|
171
|
+
function trouble(sequence: string, codon: string, avoid: readonly { name: string; site: string }[], longestRun: number): string | null {
|
|
172
|
+
const whole = sequence + codon;
|
|
173
|
+
const longest = Math.max(longestRun + CODON, ...avoid.map((one) => one.site.length + CODON));
|
|
174
|
+
const tail = whole.slice(Math.max(0, whole.length - longest));
|
|
175
|
+
const run = new RegExp(`(.)\\1{${longestRun}}`).exec(tail);
|
|
176
|
+
if (run !== null) return `a run of ${run[0]!.length} ${run[1]!}s`;
|
|
177
|
+
for (const one of avoid) {
|
|
178
|
+
if (tail.includes(one.site)) return `a ${one.name} site`;
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Rewrite a coding sequence in a host's codons, without changing the protein.
|
|
185
|
+
*
|
|
186
|
+
* Each codon becomes the one the host uses most for that amino acid, unless that would make a long
|
|
187
|
+
* run of one base or a site that was to be kept out; then the next most used is taken, and the
|
|
188
|
+
* reason is kept with the change.
|
|
189
|
+
*
|
|
190
|
+
* @param cds - The coding sequence: a whole number of codons, starting at the first one.
|
|
191
|
+
* @param usage - How the host uses its codons, from `countCodonUsage`.
|
|
192
|
+
* @param options - `avoid` are sites to keep out, by name and sequence; `longestRun` is the longest
|
|
193
|
+
* run of one base allowed, 6 unless said.
|
|
194
|
+
* @returns The rewritten gene, every change, and what it did to the GC content. `problem` says why
|
|
195
|
+
* if it could not be done.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* import { countCodonUsage, optimiseCodons } from "@biolibs/bionet-tools";
|
|
200
|
+
*
|
|
201
|
+
* const done = optimiseCodons(gene, countCodonUsage(hostGenes), { avoid: [{ name: "EcoRI", site: "GAATTC" }] });
|
|
202
|
+
* done.protein === translate(gene); // the same protein, which is checked
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export function optimiseCodons(cds: string, usage: CodonUsage, options: { avoid?: readonly { name: string; site: string }[]; longestRun?: number } = {}): CodonOptimised {
|
|
206
|
+
const nothing = (problem: string): CodonOptimised =>
|
|
207
|
+
({ sequence: "", protein: "", changes: [], codons: 0, gcBefore: 0, gcAfter: 0, avoided: [], warnings: [], problem });
|
|
208
|
+
const bases = clean(cds);
|
|
209
|
+
if (bases.length < CODON || bases.length % CODON !== 0) return nothing(`That is ${bases.length} bases, which is not a whole number of codons.`);
|
|
210
|
+
if (!/^[ACGT]+$/.test(bases)) return nothing("A coding sequence to optimise is written in A, C, G and T, with no uncertain bases.");
|
|
211
|
+
if (usage.codons === 0) return nothing("The codon usage was counted over nothing, so there is nothing to prefer.");
|
|
212
|
+
|
|
213
|
+
const { forward, byAminoAcid, stops } = synonyms(usage.table);
|
|
214
|
+
const avoid = (options.avoid ?? []).map((one) => ({ name: one.name, site: clean(one.site) }));
|
|
215
|
+
const longestRun = options.longestRun ?? LONGEST_RUN;
|
|
216
|
+
const warnings: string[] = [];
|
|
217
|
+
const changes: CodonChange[] = [];
|
|
218
|
+
let out = "";
|
|
219
|
+
/** The codons for an amino acid, the host's favourite first, with ties broken the same way always. */
|
|
220
|
+
const liked = (aminoAcid: string): string[] =>
|
|
221
|
+
[...(byAminoAcid.get(aminoAcid) ?? [])].sort((a, b) => usage.counts[b]!.share - usage.counts[a]!.share || (a < b ? -1 : 1));
|
|
222
|
+
|
|
223
|
+
for (let start = 0; start + CODON <= bases.length; start += CODON) {
|
|
224
|
+
const was = bases.slice(start, start + CODON);
|
|
225
|
+
const at = start / CODON + 1;
|
|
226
|
+
// A stop stays exactly as it is: it is not an amino acid and nothing is gained by moving it.
|
|
227
|
+
if (stops.includes(was)) { out += was; continue; }
|
|
228
|
+
const aminoAcid = forward.get(was);
|
|
229
|
+
if (aminoAcid === undefined) return nothing(`Codon ${at} is ${was}, which is not a codon of NCBI table ${usage.table}.`);
|
|
230
|
+
const family = liked(aminoAcid);
|
|
231
|
+
let chosen: string | undefined;
|
|
232
|
+
let instead: string | null = null;
|
|
233
|
+
for (const candidate of family) {
|
|
234
|
+
const why = trouble(out, candidate, avoid, longestRun);
|
|
235
|
+
if (why === null) { chosen = candidate; break; }
|
|
236
|
+
if (instead === null) instead = `the host's ${share(usage.counts[candidate]!.share)} codon ${candidate} would have made ${why}`;
|
|
237
|
+
}
|
|
238
|
+
if (chosen === undefined && changes.length > 0 && out.length >= CODON) {
|
|
239
|
+
// Nothing fits after what was chosen last time, which means last time's choice was the
|
|
240
|
+
// mistake: taking the host's favourite there left this amino acid nowhere to go. A run of one
|
|
241
|
+
// amino acid does this every time. So the one before is tried again, and the pair taken
|
|
242
|
+
// together, which is enough for a run and costs one step of looking back.
|
|
243
|
+
const back = out.slice(0, out.length - CODON);
|
|
244
|
+
const previous = out.slice(out.length - CODON);
|
|
245
|
+
const earlier = forward.get(previous);
|
|
246
|
+
outer: for (const other of earlier === undefined ? [] : liked(earlier)) {
|
|
247
|
+
if (other === previous || trouble(back, other, avoid, longestRun) !== null) continue;
|
|
248
|
+
for (const candidate of family) {
|
|
249
|
+
if (trouble(back + other, candidate, avoid, longestRun) !== null) continue;
|
|
250
|
+
out = back + other;
|
|
251
|
+
const last = changes.at(-1);
|
|
252
|
+
if (last !== undefined && last.at === at - 1) {
|
|
253
|
+
last.to = other;
|
|
254
|
+
last.toShare = usage.counts[other]!.share;
|
|
255
|
+
last.instead = `the host's favourite left codon ${at} nowhere to go`;
|
|
256
|
+
}
|
|
257
|
+
chosen = candidate;
|
|
258
|
+
break outer;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (chosen === undefined) {
|
|
263
|
+
// Still nothing. The sequence has to say something, so it keeps what it had and says so.
|
|
264
|
+
chosen = was;
|
|
265
|
+
warnings.push(`At codon ${at}, no codon for ${aminoAcid} would avoid a run or a site, so it was left as ${was}.`);
|
|
266
|
+
instead = null;
|
|
267
|
+
}
|
|
268
|
+
if (chosen !== was) {
|
|
269
|
+
changes.push({ at, aminoAcid, from: was, fromShare: usage.counts[was]?.share ?? 0, to: chosen, toShare: usage.counts[chosen]!.share, instead });
|
|
270
|
+
}
|
|
271
|
+
out += chosen;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// The one thing that must be true. If it is not, nothing is handed back.
|
|
275
|
+
const before = String(translate(bases));
|
|
276
|
+
const after = String(translate(out));
|
|
277
|
+
if (before !== after) return nothing("The rewrite would have changed the protein, so nothing was changed. This is a fault in the tool, not in what was asked.");
|
|
278
|
+
if (usage.genes < FEW_GENES) warnings.push(`The codon usage was counted over ${usage.genes} ${usage.genes === 1 ? "gene" : "genes"}, which is few to lean on.`);
|
|
279
|
+
const after_gc = gc(out);
|
|
280
|
+
if (after_gc > 0.65 || after_gc < 0.3) warnings.push(`The rewritten gene is ${share(after_gc)} GC, which is far from the middle and may be hard to make.`);
|
|
281
|
+
return {
|
|
282
|
+
sequence: out, protein: after, changes, codons: bases.length / CODON,
|
|
283
|
+
gcBefore: gc(bases), gcAfter: after_gc, avoided: avoid.map((one) => one.name),
|
|
284
|
+
warnings: [...new Set(warnings)], problem: null,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* The working behind a rewrite: what was counted, what changed, and what it did to the gene.
|
|
290
|
+
*
|
|
291
|
+
* @param done - The rewrite.
|
|
292
|
+
* @param usage - The table it used.
|
|
293
|
+
* @returns One working for the table, one for the rewrite, and one for the protein being unchanged.
|
|
294
|
+
*/
|
|
295
|
+
export function codonWorking(done: CodonOptimised, usage: CodonUsage): Working[] {
|
|
296
|
+
if (done.problem !== null) return [];
|
|
297
|
+
const count = (value: number): string => value.toLocaleString("en-US");
|
|
298
|
+
const favourite = (aminoAcid: string): string => {
|
|
299
|
+
const family = Object.entries(usage.counts).filter(([, one]) => one.aminoAcid === aminoAcid).sort((a, b) => b[1].share - a[1].share);
|
|
300
|
+
return family.map(([codon, one]) => `${codon} ${share(one.share)}`).join(", ");
|
|
301
|
+
};
|
|
302
|
+
const touched = [...new Set(done.changes.map((one) => one.aminoAcid))].sort();
|
|
303
|
+
return [
|
|
304
|
+
{
|
|
305
|
+
of: "the host's preferences",
|
|
306
|
+
comes: `${count(usage.codons)} codons counted over ${usage.genes} ${usage.genes === 1 ? "gene" : "genes"}`,
|
|
307
|
+
kind: "estimate",
|
|
308
|
+
steps: [
|
|
309
|
+
`counted from: ${usage.from}`,
|
|
310
|
+
`read with NCBI genetic code ${usage.table}`,
|
|
311
|
+
...touched.slice(0, 8).map((aminoAcid) => `${aminoAcid}: ${favourite(aminoAcid)}`),
|
|
312
|
+
...(touched.length > 8 ? [`and ${touched.length - 8} more amino acids`] : []),
|
|
313
|
+
],
|
|
314
|
+
rests: "Nothing here is a published table. It is counted from the sequences it was given, and it is worth exactly what those genes are worth as a sample of the host.",
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
of: "the rewrite",
|
|
318
|
+
comes: `${count(done.changes.length)} of ${count(done.codons)} codons changed`,
|
|
319
|
+
kind: "exact",
|
|
320
|
+
steps: [
|
|
321
|
+
`${count(done.codons - done.changes.length)} codons were already the host's choice`,
|
|
322
|
+
...done.changes.slice(0, 6).map((one) => `codon ${one.at}: ${one.from} → ${one.to} for ${one.aminoAcid}, ${share(one.fromShare)} → ${share(one.toShare)}${one.instead === null ? "" : ` (${one.instead})`}`),
|
|
323
|
+
...(done.changes.length > 6 ? [`and ${count(done.changes.length - 6)} more`] : []),
|
|
324
|
+
...(done.avoided.length === 0 ? [] : [`kept out of the sequence: ${done.avoided.join(", ")}`]),
|
|
325
|
+
`GC went from ${share(done.gcBefore)} to ${share(done.gcAfter)}`,
|
|
326
|
+
],
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
of: "the protein",
|
|
330
|
+
comes: `${count(done.protein.length)} amino acids, unchanged`,
|
|
331
|
+
kind: "exact",
|
|
332
|
+
steps: [
|
|
333
|
+
"every codon was replaced only by another for the same amino acid",
|
|
334
|
+
"the gene was translated before and after, and the two were compared",
|
|
335
|
+
`it begins ${done.protein.slice(0, 24)}${done.protein.length > 24 ? "…" : ""}`,
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
];
|
|
339
|
+
}
|
package/src/digest-tool.tsx
CHANGED
|
@@ -15,11 +15,19 @@ import { cutters, enzymeNamed } from "./digest.js";
|
|
|
15
15
|
import { digestRun, digestTubes } from "./run.js";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* A gel, drawn: a
|
|
18
|
+
* A gel, drawn: a marker in one lane and the sample in the next.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* The same picture serves agarose and acrylamide, because reading one is reading the other: bands
|
|
21
|
+
* down a lane, read against a lane of known sizes. What differs is what the numbers are, and that
|
|
22
|
+
* has to be said rather than assumed, or a screen reader is told base pairs about a protein.
|
|
23
|
+
*
|
|
24
|
+
* @param props - `ladder` and `bands` are what a plan gave; `name` is what the sample is called;
|
|
25
|
+
* `unit` is what the sizes are in, base pairs unless it says otherwise; `marker` names the first
|
|
26
|
+
* lane, and `says` describes what the lane shows, for anybody who cannot see it.
|
|
21
27
|
*/
|
|
22
|
-
export function Gel({ ladder, bands, name
|
|
28
|
+
export function Gel({ ladder, bands, name, unit = "base pairs", marker = "ladder", says }: {
|
|
29
|
+
ladder: readonly Band[]; bands: readonly Band[]; name: string; unit?: string; marker?: string; says?: string;
|
|
30
|
+
}) {
|
|
23
31
|
const [top, height] = [26, 250];
|
|
24
32
|
const lane = (x: number, drawn: readonly Band[], tone: string, labelled: "left" | "right"): React.ReactNode => drawn.map((band, at) => {
|
|
25
33
|
const y = top + 10 + band.position * (height - 24);
|
|
@@ -33,9 +41,10 @@ export function Gel({ ladder, bands, name }: { ladder: readonly Band[]; bands: r
|
|
|
33
41
|
);
|
|
34
42
|
});
|
|
35
43
|
return (
|
|
36
|
-
<svg className="gel" viewBox="0 0 330 290" role="img"
|
|
44
|
+
<svg className="gel" viewBox="0 0 330 290" role="img"
|
|
45
|
+
aria-label={says ?? `A gel: a ${marker} beside ${name}, showing bands at ${bands.flatMap((band) => band.sizes).join(", ")} ${unit}`}>
|
|
37
46
|
<rect x={52} y={top} width={176} height={height} rx={6} className="slab" />
|
|
38
|
-
<text x={89} y={16} textAnchor="middle" className="lane">
|
|
47
|
+
<text x={89} y={16} textAnchor="middle" className="lane">{marker}</text>
|
|
39
48
|
<text x={177} y={16} textAnchor="middle" className="lane">{name.length > 16 ? `${name.slice(0, 15)}…` : name}</text>
|
|
40
49
|
<rect x={62} y={top + 4} width={54} height={4} className="well" />
|
|
41
50
|
<rect x={150} y={top + 4} width={54} height={4} className="well" />
|
package/src/digest.ts
CHANGED
|
@@ -64,6 +64,25 @@ export function enzymeNamed(name: string): string | null {
|
|
|
64
64
|
return Object.keys(enzymes).find((one) => one.toLowerCase() === lower) ?? null;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* One enzyme's recognition sequence.
|
|
69
|
+
*
|
|
70
|
+
* @param name - The enzyme, by name, in any case.
|
|
71
|
+
* @returns The bases it recognises, in IUPAC letters, or `null` if there is no such enzyme.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { siteOf } from "@biolibs/bionet-tools";
|
|
76
|
+
*
|
|
77
|
+
* siteOf("EcoRI"); // "GAATTC"
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export function siteOf(name: string): string | null {
|
|
81
|
+
const found = enzymeNamed(name);
|
|
82
|
+
const enzyme = found === null || !Object.hasOwn(enzymes, found) ? undefined : enzymes[found];
|
|
83
|
+
return enzyme === undefined ? null : String(enzyme.site).toUpperCase();
|
|
84
|
+
}
|
|
85
|
+
|
|
67
86
|
/**
|
|
68
87
|
* Where one enzyme cuts a molecule.
|
|
69
88
|
*
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,16 @@
|
|
|
15
15
|
* - `pcr-tool.tsx`, `digest-tool.tsx` — the tools
|
|
16
16
|
* - `pcr-bench.tsx` — a PCR at the machine: what is beside the scene, and what the scene is told to show
|
|
17
17
|
* - `pcr-working.ts` — the working behind what the PCR tool says: each figure with the steps that give it
|
|
18
|
+
* - `protein.ts` — the protein a gene codes for, and what its sequence says about it
|
|
19
|
+
* - `induce.ts` — growing a strain to express what was put into it, and the mass its band should run at
|
|
20
|
+
* - `modify.ts` — which residues would be phosphorylated, and whether the host has the enzyme to do it
|
|
21
|
+
* - `induce-bench.tsx` — an induction at the shaking incubator, with the protein gel that answers it
|
|
22
|
+
* - `verify-bench.tsx` — checking a construct against the design at a desk, saying what was not covered
|
|
23
|
+
* - `verify.ts` — a sequencing read against the design it was meant to be, and what each difference costs
|
|
24
|
+
* - `codons.ts` — a gene rewritten in a host's codons, from usage counted over that host's own genes
|
|
25
|
+
* - `codon-bench.tsx` — writing a gene in a host's codons at a desk, with the counting on the screen
|
|
26
|
+
* - `assembly-design.ts` — a ring designed from a lab's own parts: the pieces in order, and the primers that make them fit
|
|
27
|
+
* - `assembly-bench.tsx` — building a ring at a desk: the pieces in order, and the primers that make them fit
|
|
18
28
|
* - `ligate.ts` — pieces that have already been cut, joined where their ends fit
|
|
19
29
|
* - `ligate-working.ts` — a ligation's working: each join in its bases, the length, how much to put in
|
|
20
30
|
* - `ligate-bench.tsx` — a ligation at the heat block: what is shown beside it, and what the scene draws
|
|
@@ -42,6 +52,16 @@ export * from "./pcr-tool.js";
|
|
|
42
52
|
export * from "./digest-tool.js";
|
|
43
53
|
export * from "./pcr-working.js";
|
|
44
54
|
export * from "./digest-working.js";
|
|
55
|
+
export * from "./protein.js";
|
|
56
|
+
export * from "./induce.js";
|
|
57
|
+
export * from "./modify.js";
|
|
58
|
+
export * from "./induce-bench.js";
|
|
59
|
+
export * from "./verify.js";
|
|
60
|
+
export * from "./verify-bench.js";
|
|
61
|
+
export * from "./codons.js";
|
|
62
|
+
export * from "./codon-bench.js";
|
|
63
|
+
export * from "./assembly-design.js";
|
|
64
|
+
export * from "./assembly-bench.js";
|
|
45
65
|
export * from "./ligate.js";
|
|
46
66
|
export * from "./ligate-working.js";
|
|
47
67
|
export * from "./ligate-bench.js";
|