@biolibs/bionet-tools 0.1.6 → 0.1.9

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.
Files changed (83) hide show
  1. package/dist/assembly-bench.d.ts +62 -0
  2. package/dist/assembly-bench.d.ts.map +1 -0
  3. package/dist/assembly-bench.js +114 -0
  4. package/dist/assembly-bench.js.map +1 -0
  5. package/dist/assembly-design.d.ts +119 -0
  6. package/dist/assembly-design.d.ts.map +1 -0
  7. package/dist/assembly-design.js +157 -0
  8. package/dist/assembly-design.js.map +1 -0
  9. package/dist/codon-bench.d.ts +51 -0
  10. package/dist/codon-bench.d.ts.map +1 -0
  11. package/dist/codon-bench.js +93 -0
  12. package/dist/codon-bench.js.map +1 -0
  13. package/dist/codons.d.ts +126 -0
  14. package/dist/codons.d.ts.map +1 -0
  15. package/dist/codons.js +287 -0
  16. package/dist/codons.js.map +1 -0
  17. package/dist/digest-bench.d.ts.map +1 -1
  18. package/dist/digest-bench.js +11 -2
  19. package/dist/digest-bench.js.map +1 -1
  20. package/dist/digest.d.ts +14 -0
  21. package/dist/digest.d.ts.map +1 -1
  22. package/dist/digest.js +18 -0
  23. package/dist/digest.js.map +1 -1
  24. package/dist/index.d.ts +16 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +16 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/ligate-bench.d.ts.map +1 -1
  29. package/dist/ligate-bench.js +10 -2
  30. package/dist/ligate-bench.js.map +1 -1
  31. package/dist/pcr-bench.d.ts.map +1 -1
  32. package/dist/pcr-bench.js +13 -2
  33. package/dist/pcr-bench.js.map +1 -1
  34. package/dist/pcr-tool.js +1 -1
  35. package/dist/pcr-tool.js.map +1 -1
  36. package/dist/plans.d.ts +66 -0
  37. package/dist/plans.d.ts.map +1 -0
  38. package/dist/plans.js +106 -0
  39. package/dist/plans.js.map +1 -0
  40. package/dist/primer-bench.js +1 -1
  41. package/dist/primer-bench.js.map +1 -1
  42. package/dist/protein.d.ts +106 -0
  43. package/dist/protein.d.ts.map +1 -0
  44. package/dist/protein.js +158 -0
  45. package/dist/protein.js.map +1 -0
  46. package/dist/run.d.ts +12 -0
  47. package/dist/run.d.ts.map +1 -1
  48. package/dist/run.js +19 -4
  49. package/dist/run.js.map +1 -1
  50. package/dist/sequences-tool.js +1 -1
  51. package/dist/sequences-tool.js.map +1 -1
  52. package/dist/tools.d.ts +1 -1
  53. package/dist/tools.d.ts.map +1 -1
  54. package/dist/tools.js +7 -3
  55. package/dist/tools.js.map +1 -1
  56. package/dist/verify-bench.d.ts +48 -0
  57. package/dist/verify-bench.d.ts.map +1 -0
  58. package/dist/verify-bench.js +77 -0
  59. package/dist/verify-bench.js.map +1 -0
  60. package/dist/verify.d.ts +138 -0
  61. package/dist/verify.d.ts.map +1 -0
  62. package/dist/verify.js +263 -0
  63. package/dist/verify.js.map +1 -0
  64. package/package.json +5 -3
  65. package/src/assembly-bench.tsx +232 -0
  66. package/src/assembly-design.ts +219 -0
  67. package/src/codon-bench.tsx +189 -0
  68. package/src/codons.ts +339 -0
  69. package/src/digest-bench.tsx +10 -1
  70. package/src/digest.ts +19 -0
  71. package/src/index.ts +16 -0
  72. package/src/ligate-bench.tsx +9 -1
  73. package/src/pcr-bench.tsx +11 -1
  74. package/src/pcr-tool.tsx +1 -1
  75. package/src/plans.tsx +137 -0
  76. package/src/primer-bench.tsx +1 -1
  77. package/src/protein.ts +204 -0
  78. package/src/run.ts +20 -4
  79. package/src/sequences-tool.tsx +1 -1
  80. package/src/tools.tsx +7 -3
  81. package/src/verify-bench.tsx +161 -0
  82. package/src/verify.ts +310 -0
  83. package/tools.css +18 -0
@@ -0,0 +1,93 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ /**
4
+ * Writing a gene in a host's codons, at a desk.
5
+ *
6
+ * The whole of this tool turns on one thing being visible: where the host's preferences came from.
7
+ * There is no table built in and none is asserted. You choose which of the lab's own sequences are
8
+ * the host's genes, they are counted here, and the counts are on the screen beside the result. A
9
+ * table counted over three genes says so; a figure nobody can check is worse than no figure.
10
+ */
11
+ import { useEffect, useMemo, useState } from "react";
12
+ import { useAct, useLab } from "@biolibs/bionet-react";
13
+ import { Glossed } from "@biolibs/glossary-react";
14
+ import { COMMON_ENZYMES, siteOf } from "./digest.js";
15
+ import { CODON, codonWorking, countCodonUsage, optimiseCodons } from "./codons.js";
16
+ import { ShowWorking } from "./working.js";
17
+ const count = (value) => value.toLocaleString("en-US");
18
+ const share = (value) => `${Math.round(value * 100)}%`;
19
+ /**
20
+ * Rewriting one of the lab's genes in a host's codons.
21
+ *
22
+ * @param options - `start` says what to open on, for a tour or a link.
23
+ * @returns `panel`, the tool itself, and `desk`, what a scene beside it should look at.
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * import { useCodonBench } from "@biolibs/bionet-tools";
28
+ *
29
+ * const bench = useCodonBench();
30
+ * <LabView lab={lab} wide beside={bench.panel} />
31
+ * ```
32
+ */
33
+ export function useCodonBench({ start } = {}) {
34
+ const lab = useLab()?.lab;
35
+ const act = useAct();
36
+ const [gene, setGene] = useState(start?.gene ?? "");
37
+ const [hostGenes, setHostGenes] = useState([...(start?.hostGenes ?? [])]);
38
+ const [avoid, setAvoid] = useState([...(start?.avoid ?? [])]);
39
+ const [busy, setBusy] = useState(false);
40
+ const [said, setSaid] = useState(null);
41
+ const asked = JSON.stringify(start ?? null);
42
+ useEffect(() => {
43
+ if (start === undefined)
44
+ return;
45
+ if (start.gene !== undefined)
46
+ setGene(start.gene);
47
+ if (start.hostGenes !== undefined)
48
+ setHostGenes([...start.hostGenes]);
49
+ if (start.avoid !== undefined)
50
+ setAvoid([...start.avoid]);
51
+ }, [asked]);
52
+ // Anything that is a whole number of codons could be a coding sequence; nothing else can.
53
+ const coding = useMemo(() => (lab?.parts ?? []).filter((one) => one.kind !== "protein" && !one.circular && one.length >= CODON && one.length % CODON === 0), [lab?.parts]);
54
+ const usage = useMemo(() => {
55
+ const chosen = coding.filter((one) => hostGenes.includes(one.checksum));
56
+ return chosen.length === 0 ? null : countCodonUsage(chosen.map((one) => one.sequence), {
57
+ from: `${chosen.length} ${chosen.length === 1 ? "sequence" : "sequences"} this lab holds: ${chosen.map((one) => one.name).join(", ")}`,
58
+ });
59
+ }, [coding, hostGenes]);
60
+ const part = coding.find((one) => one.checksum === gene);
61
+ // Only the enzymes whose site is actually known can be kept out; the rest are not offered.
62
+ const sites = useMemo(() => avoid.flatMap((name) => { const site = siteOf(name); return site === null ? [] : [{ name, site }]; }), [avoid]);
63
+ const done = useMemo(() => {
64
+ if (part === undefined || usage === null)
65
+ return null;
66
+ return optimiseCodons(part.sequence, usage, { avoid: sites });
67
+ }, [part, usage, sites]);
68
+ const working = useMemo(() => (done === null || done.problem !== null || usage === null ? [] : codonWorking(done, usage)), [done, usage]);
69
+ const tube = lab?.items.find((one) => one.part === gene && !one.retired && one.where !== null);
70
+ const desk = {
71
+ focus: tube?.where == null ? null : { place: tube.where.place, item: tube.item },
72
+ sequence: done?.problem === null ? done.sequence : null,
73
+ };
74
+ const keep = async () => {
75
+ if (done === null || done.problem !== null || part === undefined)
76
+ return;
77
+ setBusy(true);
78
+ const answer = await act("addPart", { name: `${part.name} (codon optimised)`, sequence: done.sequence });
79
+ setBusy(false);
80
+ setSaid(answer.ok ? "Kept as a part. There is no tube of it: it has to be ordered or made." : answer.error);
81
+ };
82
+ const panel = lab === null || lab === undefined ? null : (_jsxs("div", { className: "bionet codons", children: [_jsxs("section", { className: "card", children: [_jsx("h2", { children: "Write a gene for a host" }), _jsx("p", { className: "small", children: _jsx(Glossed, { text: "Most amino acids have more than one codon, and an organism uses them unevenly: a gene written in another organism's codons is read slowly." }) }), _jsx("p", { className: "dim small", children: "There is no table of codon usage built into this. Choose which of the lab's sequences are the host's own genes and the preferences are counted from them, here, where you can check them. A handful of the host's genes, brought in on the Sequences tab, is what this wants." }), coding.length === 0 ? _jsx("p", { className: "empty", children: "The lab has no sequence that is a whole number of codons. Bring a coding sequence in on the Sequences tab." }) : (_jsxs("fieldset", { disabled: busy, className: "stack", children: [_jsxs("label", { children: ["The gene to rewrite", _jsxs("select", { value: gene, onChange: (event) => { setGene(event.target.value); setSaid(null); }, "aria-label": "The gene to rewrite", children: [_jsx("option", { value: "", children: "Choose a sequence\u2026" }), coding.map((one) => _jsxs("option", { value: one.checksum, children: [one.name, " \u00B7 ", count(one.length / CODON), " codons"] }, one.checksum))] })] }), _jsxs("label", { children: ["The host's own genes", _jsx("select", { multiple: true, size: Math.min(6, Math.max(3, coding.length)), value: hostGenes, "aria-label": "The host's own genes", onChange: (event) => { setHostGenes(Array.from(event.target.selectedOptions, (one) => one.value)); setSaid(null); }, children: coding.map((one) => _jsx("option", { value: one.checksum, children: one.name }, one.checksum)) })] }), _jsxs("div", { className: "row tight pick", role: "group", "aria-label": "Sites to keep out", children: [_jsx("span", { className: "dim small", children: "Keep out" }), COMMON_ENZYMES.filter((one) => siteOf(one) !== null).slice(0, 6).map((one) => (_jsx("button", { type: "button", "aria-pressed": avoid.includes(one), className: avoid.includes(one) ? "" : "quiet", onClick: () => { setAvoid(avoid.includes(one) ? avoid.filter((each) => each !== one) : [...avoid, one]); setSaid(null); }, children: one }, one)))] })] }))] }), usage !== null && (_jsxs("section", { className: "card", children: [_jsx("h2", { children: "What this host prefers" }), _jsx("p", { className: "voice", children: "Counted here" }), _jsxs("p", { className: "small", children: [count(usage.codons), " codons over ", usage.genes, " ", usage.genes === 1 ? "gene" : "genes", "."] }), usage.warnings.length > 0 && _jsx("ul", { className: "checks", children: usage.warnings.map((one) => _jsx("li", { className: "look", children: one }, one)) }), _jsx("p", { className: "dim small", children: "This is not a published table. It is what those genes do, and it is worth what they are worth as a sample of the host." })] })), done !== null && done.problem !== null && _jsx("p", { className: "trouble", role: "status", children: done.problem }), done !== null && done.problem === null && (_jsxs(_Fragment, { children: [_jsxs("section", { className: "card", children: [_jsx("h2", { children: "The rewrite" }), _jsx("p", { className: "voice", children: "This gene" }), _jsxs("p", { children: [_jsx("strong", { children: count(done.changes.length) }), " of ", count(done.codons), " codons changed \u00B7 GC ", share(done.gcBefore), " \u2192 ", share(done.gcAfter)] }), _jsx("p", { className: "small good", children: "The protein is the same: it was translated before and after and compared." }), done.avoided.length > 0 && _jsxs("p", { className: "small", children: ["Kept out: ", done.avoided.join(", "), "."] }), done.changes.length > 0 && (_jsxs("table", { children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Codon" }), _jsx("th", { children: "For" }), _jsx("th", { children: "Was" }), _jsx("th", { children: "Is" }), _jsx("th", { children: "Why" })] }) }), _jsx("tbody", { children: done.changes.slice(0, 12).map((one) => (_jsxs("tr", { children: [_jsx("td", { children: one.at }), _jsx("td", { children: one.aminoAcid }), _jsxs("td", { children: [_jsx("code", { children: one.from }), " ", _jsx("span", { className: "dim", children: share(one.fromShare) })] }), _jsxs("td", { children: [_jsx("code", { children: one.to }), " ", _jsx("span", { className: "dim", children: share(one.toShare) })] }), _jsx("td", { className: "dim small", children: one.instead ?? "" })] }, one.at))) })] })), done.changes.length > 12 && _jsxs("p", { className: "dim small", children: ["and ", count(done.changes.length - 12), " more."] }), done.warnings.length > 0 && _jsx("ul", { className: "checks", children: done.warnings.map((one) => _jsx("li", { className: "look", children: one }, one)) }), _jsx("code", { className: "wrap", children: done.sequence.length <= 240 ? done.sequence : `${done.sequence.slice(0, 120)} … ${done.sequence.slice(-120)}` }), _jsxs("fieldset", { disabled: busy, className: "row", children: [_jsx("button", { type: "button", onClick: () => void keep(), children: "Keep it as a part" }), _jsx("span", { className: "dim small", children: "No tube: it has to be ordered or made." })] }), said !== null && _jsx("p", { className: "small", role: "status", children: said })] }), _jsxs("section", { className: "card", children: [_jsx("h2", { children: "The working" }), working.map((one) => _jsx(ShowWorking, { working: one }, one.of))] })] }))] }));
83
+ return { panel, desk };
84
+ }
85
+ /**
86
+ * The codon tool on its own, for a lab that has not drawn its room.
87
+ *
88
+ * @param props - `start` says what to open on.
89
+ */
90
+ export function CodonTool(props) {
91
+ return _jsx(_Fragment, { children: useCodonBench(props).panel });
92
+ }
93
+ //# sourceMappingURL=codon-bench.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codon-bench.js","sourceRoot":"","sources":["../src/codon-bench.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;;;;;;;GAOG;AACH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,KAAK,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AACvE,MAAM,KAAK,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;AAUvE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,EAAE,KAAK,KAGjC,EAAE;IACJ,MAAM,GAAG,GAAG,MAAM,EAAE,EAAE,GAAG,CAAC;IAC1B,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;IACpD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAW,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,IAAI,EAA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C,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,aAAc,SAAS,EAAC,MAAM,YAAE,GAAG,IAA1B,GAAG,CAA6B,CAAC,GAAM,EAChI,eAAM,SAAS,EAAC,MAAM,YAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,GAAQ,EAC7I,oBAAU,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAC,KAAK,aACvC,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,IAAI,EAAE,kCAA4B,EAC5E,eAAM,SAAS,EAAC,WAAW,uDAA8C,IAChE,EACV,IAAI,KAAK,IAAI,IAAI,YAAG,SAAS,EAAC,OAAO,EAAC,IAAI,EAAC,QAAQ,YAAE,IAAI,GAAK,IACvD,EAEV,mBAAS,SAAS,EAAC,MAAM,aACvB,uCAAoB,EACnB,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAC,WAAW,IAAc,OAAO,EAAE,GAAG,IAApB,GAAG,CAAC,EAAE,CAAkB,CAAC,IACzD,IACT,CACJ,IACG,CACP,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAA0C;IAClE,OAAO,4BAAG,aAAa,CAAC,KAAK,CAAC,CAAC,KAAK,GAAI,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,126 @@
1
+ import type { Working } from "./pcr-working.js";
2
+ /** How many bases a codon is. */
3
+ export declare const CODON = 3;
4
+ /** Fewer coding sequences than this, and a table is too thin to lean on. */
5
+ export declare const FEW_GENES = 5;
6
+ /** Fewer codons than this for one amino acid, and its preference is not worth much. */
7
+ export declare const FEW_CODONS = 20;
8
+ /** The longest run of one base an optimised sequence is allowed to make. */
9
+ export declare const LONGEST_RUN = 6;
10
+ /** What one codon was counted as. */
11
+ export interface CodonCount {
12
+ /** The amino acid it codes for. */
13
+ aminoAcid: string;
14
+ /** How many times it appeared. */
15
+ count: number;
16
+ /** Its share of the codons for that amino acid, from 0 to 1. */
17
+ share: number;
18
+ }
19
+ /** How a host uses its codons, counted from its own genes. */
20
+ export interface CodonUsage {
21
+ /** Which NCBI genetic code it was read with. */
22
+ table: number;
23
+ /** What the sequences were said to be of, for saying where this came from. Never asserted here. */
24
+ from: string;
25
+ /** How many coding sequences were counted. */
26
+ genes: number;
27
+ /** How many codons in all. */
28
+ codons: number;
29
+ /** Each sense codon, with its count and its share of its amino acid. */
30
+ counts: Record<string, CodonCount>;
31
+ /** Anything about the counting worth knowing before leaning on it. */
32
+ warnings: string[];
33
+ }
34
+ /** One codon that was changed. */
35
+ export interface CodonChange {
36
+ /** Which codon of the gene it is, counting from 1. */
37
+ at: number;
38
+ /** The amino acid, unchanged. */
39
+ aminoAcid: string;
40
+ /** What it was, and that codon's share in the host. */
41
+ from: string;
42
+ fromShare: number;
43
+ /** What it became, and that codon's share. */
44
+ to: string;
45
+ toShare: number;
46
+ /** Why, if the host's favourite was not taken. */
47
+ instead: string | null;
48
+ }
49
+ /** A gene rewritten in a host's codons. */
50
+ export interface CodonOptimised {
51
+ /** The rewritten sequence. */
52
+ sequence: string;
53
+ /** The protein, which is the same before and after. This is checked, not assumed. */
54
+ protein: string;
55
+ /** Every codon that changed. */
56
+ changes: CodonChange[];
57
+ /** How many codons there are in all. */
58
+ codons: number;
59
+ /** The GC content before and after, from 0 to 1. */
60
+ gcBefore: number;
61
+ gcAfter: number;
62
+ /** Sites that were kept out of the sequence, by name. */
63
+ avoided: string[];
64
+ /** Anything a careful person would look at. */
65
+ warnings: string[];
66
+ /** Why it could not be done, or `null`. */
67
+ problem: string | null;
68
+ }
69
+ /**
70
+ * Count how a host uses its codons, from its own coding sequences.
71
+ *
72
+ * @param genes - The coding sequences, each a whole number of codons. Anything else is left out and said so.
73
+ * @param options - `from` says where the genes came from, which is kept with the table; `table` is
74
+ * the NCBI genetic code, 1 unless said.
75
+ * @returns The table, with the counts it was made of.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import { countCodonUsage } from "@biolibs/bionet-tools";
80
+ *
81
+ * const usage = countCodonUsage([geneOne, geneTwo], { from: "12 Pichia pastoris genes" });
82
+ * usage.counts["CTG"]?.share; // how much of this host's leucine is CTG
83
+ * ```
84
+ */
85
+ export declare function countCodonUsage(genes: readonly string[], options?: {
86
+ from?: string;
87
+ table?: number;
88
+ }): CodonUsage;
89
+ /**
90
+ * Rewrite a coding sequence in a host's codons, without changing the protein.
91
+ *
92
+ * Each codon becomes the one the host uses most for that amino acid, unless that would make a long
93
+ * run of one base or a site that was to be kept out; then the next most used is taken, and the
94
+ * reason is kept with the change.
95
+ *
96
+ * @param cds - The coding sequence: a whole number of codons, starting at the first one.
97
+ * @param usage - How the host uses its codons, from `countCodonUsage`.
98
+ * @param options - `avoid` are sites to keep out, by name and sequence; `longestRun` is the longest
99
+ * run of one base allowed, 6 unless said.
100
+ * @returns The rewritten gene, every change, and what it did to the GC content. `problem` says why
101
+ * if it could not be done.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * import { countCodonUsage, optimiseCodons } from "@biolibs/bionet-tools";
106
+ *
107
+ * const done = optimiseCodons(gene, countCodonUsage(hostGenes), { avoid: [{ name: "EcoRI", site: "GAATTC" }] });
108
+ * done.protein === translate(gene); // the same protein, which is checked
109
+ * ```
110
+ */
111
+ export declare function optimiseCodons(cds: string, usage: CodonUsage, options?: {
112
+ avoid?: readonly {
113
+ name: string;
114
+ site: string;
115
+ }[];
116
+ longestRun?: number;
117
+ }): CodonOptimised;
118
+ /**
119
+ * The working behind a rewrite: what was counted, what changed, and what it did to the gene.
120
+ *
121
+ * @param done - The rewrite.
122
+ * @param usage - The table it used.
123
+ * @returns One working for the table, one for the rewrite, and one for the protein being unchanged.
124
+ */
125
+ export declare function codonWorking(done: CodonOptimised, usage: CodonUsage): Working[];
126
+ //# sourceMappingURL=codons.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codons.d.ts","sourceRoot":"","sources":["../src/codons.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,iCAAiC;AACjC,eAAO,MAAM,KAAK,IAAI,CAAC;AAEvB,4EAA4E;AAC5E,eAAO,MAAM,SAAS,IAAI,CAAC;AAE3B,uFAAuF;AACvF,eAAO,MAAM,UAAU,KAAK,CAAC;AAE7B,4EAA4E;AAC5E,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B,qCAAqC;AACrC,MAAM,WAAW,UAAU;IACzB,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;CACf;AAED,8DAA8D;AAC9D,MAAM,WAAW,UAAU;IACzB,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,mGAAmG;IACnG,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACnC,sEAAsE;IACtE,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,kCAAkC;AAClC,MAAM,WAAW,WAAW;IAC1B,sDAAsD;IACtD,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;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,CA4C/E"}
package/dist/codons.js ADDED
@@ -0,0 +1,287 @@
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
+ /** How many bases a codon is. */
20
+ export const CODON = 3;
21
+ /** Fewer coding sequences than this, and a table is too thin to lean on. */
22
+ export const FEW_GENES = 5;
23
+ /** Fewer codons than this for one amino acid, and its preference is not worth much. */
24
+ export const FEW_CODONS = 20;
25
+ /** The longest run of one base an optimised sequence is allowed to make. */
26
+ export const LONGEST_RUN = 6;
27
+ const clean = (bases) => bases.replace(/\s+/g, "").toUpperCase();
28
+ const gc = (bases) => (bases.length === 0 ? 0 : [...bases].filter((one) => one === "G" || one === "C").length / bases.length);
29
+ const share = (value) => `${Math.round(value * 100)}%`;
30
+ /** The genetic code, as the codons for each amino acid. */
31
+ function synonyms(table) {
32
+ const code = CodonTable.unambiguousDnaById.get(table);
33
+ if (code === undefined)
34
+ throw new Error(`There is no NCBI genetic code numbered ${table}.`);
35
+ const forward = new Map();
36
+ const byAminoAcid = new Map();
37
+ for (const [codon, aminoAcid] of code.forwardTable) {
38
+ forward.set(codon, aminoAcid);
39
+ byAminoAcid.set(aminoAcid, [...(byAminoAcid.get(aminoAcid) ?? []), codon]);
40
+ }
41
+ return { forward, byAminoAcid, stops: [...code.stopCodons] };
42
+ }
43
+ /**
44
+ * Count how a host uses its codons, from its own coding sequences.
45
+ *
46
+ * @param genes - The coding sequences, each a whole number of codons. Anything else is left out and said so.
47
+ * @param options - `from` says where the genes came from, which is kept with the table; `table` is
48
+ * the NCBI genetic code, 1 unless said.
49
+ * @returns The table, with the counts it was made of.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { countCodonUsage } from "@biolibs/bionet-tools";
54
+ *
55
+ * const usage = countCodonUsage([geneOne, geneTwo], { from: "12 Pichia pastoris genes" });
56
+ * usage.counts["CTG"]?.share; // how much of this host's leucine is CTG
57
+ * ```
58
+ */
59
+ export function countCodonUsage(genes, options = {}) {
60
+ const table = options.table ?? 1;
61
+ const { forward, byAminoAcid } = synonyms(table);
62
+ const counts = {};
63
+ for (const [codon, aminoAcid] of forward)
64
+ counts[codon] = { aminoAcid, count: 0, share: 0 };
65
+ const warnings = [];
66
+ let used = 0;
67
+ let codons = 0;
68
+ for (const [at, gene] of genes.entries()) {
69
+ const bases = clean(gene);
70
+ if (bases.length < CODON || bases.length % CODON !== 0) {
71
+ warnings.push(`Sequence ${at + 1} is ${bases.length} bases, which is not a whole number of codons, so it was left out.`);
72
+ continue;
73
+ }
74
+ if (!/^[ACGT]+$/.test(bases)) {
75
+ warnings.push(`Sequence ${at + 1} has bases that are not A, C, G or T, so it was left out.`);
76
+ continue;
77
+ }
78
+ used += 1;
79
+ for (let start = 0; start + CODON <= bases.length; start += CODON) {
80
+ const held = counts[bases.slice(start, start + CODON)];
81
+ // A stop codon is not counted: nothing chooses between stops when optimising.
82
+ if (held !== undefined) {
83
+ held.count += 1;
84
+ codons += 1;
85
+ }
86
+ }
87
+ }
88
+ for (const family of byAminoAcid.values()) {
89
+ const total = family.reduce((sum, codon) => sum + counts[codon].count, 0);
90
+ for (const codon of family)
91
+ counts[codon].share = total === 0 ? 0 : counts[codon].count / total;
92
+ if (total > 0 && total < FEW_CODONS) {
93
+ warnings.push(`${counts[family[0]].aminoAcid} appears only ${total} times, so which of ${family.join(", ")} this host prefers is not well counted.`);
94
+ }
95
+ }
96
+ if (used < FEW_GENES)
97
+ warnings.push(`Counted over ${used} ${used === 1 ? "gene" : "genes"}, which is few. A table counted over more genes is worth more.`);
98
+ return { table, from: options.from ?? "sequences the lab supplied", genes: used, codons, counts, warnings };
99
+ }
100
+ /**
101
+ * Why putting `codon` after `sequence` would not do, or `null` if it would.
102
+ *
103
+ * Only the join is looked at, far enough back to catch a run or a site that straddles it: what came
104
+ * before was already allowed when it was put there.
105
+ */
106
+ function trouble(sequence, codon, avoid, longestRun) {
107
+ const whole = sequence + codon;
108
+ const longest = Math.max(longestRun + CODON, ...avoid.map((one) => one.site.length + CODON));
109
+ const tail = whole.slice(Math.max(0, whole.length - longest));
110
+ const run = new RegExp(`(.)\\1{${longestRun}}`).exec(tail);
111
+ if (run !== null)
112
+ return `a run of ${run[0].length} ${run[1]}s`;
113
+ for (const one of avoid) {
114
+ if (tail.includes(one.site))
115
+ return `a ${one.name} site`;
116
+ }
117
+ return null;
118
+ }
119
+ /**
120
+ * Rewrite a coding sequence in a host's codons, without changing the protein.
121
+ *
122
+ * Each codon becomes the one the host uses most for that amino acid, unless that would make a long
123
+ * run of one base or a site that was to be kept out; then the next most used is taken, and the
124
+ * reason is kept with the change.
125
+ *
126
+ * @param cds - The coding sequence: a whole number of codons, starting at the first one.
127
+ * @param usage - How the host uses its codons, from `countCodonUsage`.
128
+ * @param options - `avoid` are sites to keep out, by name and sequence; `longestRun` is the longest
129
+ * run of one base allowed, 6 unless said.
130
+ * @returns The rewritten gene, every change, and what it did to the GC content. `problem` says why
131
+ * if it could not be done.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * import { countCodonUsage, optimiseCodons } from "@biolibs/bionet-tools";
136
+ *
137
+ * const done = optimiseCodons(gene, countCodonUsage(hostGenes), { avoid: [{ name: "EcoRI", site: "GAATTC" }] });
138
+ * done.protein === translate(gene); // the same protein, which is checked
139
+ * ```
140
+ */
141
+ export function optimiseCodons(cds, usage, options = {}) {
142
+ const nothing = (problem) => ({ sequence: "", protein: "", changes: [], codons: 0, gcBefore: 0, gcAfter: 0, avoided: [], warnings: [], problem });
143
+ const bases = clean(cds);
144
+ if (bases.length < CODON || bases.length % CODON !== 0)
145
+ return nothing(`That is ${bases.length} bases, which is not a whole number of codons.`);
146
+ if (!/^[ACGT]+$/.test(bases))
147
+ return nothing("A coding sequence to optimise is written in A, C, G and T, with no uncertain bases.");
148
+ if (usage.codons === 0)
149
+ return nothing("The codon usage was counted over nothing, so there is nothing to prefer.");
150
+ const { forward, byAminoAcid, stops } = synonyms(usage.table);
151
+ const avoid = (options.avoid ?? []).map((one) => ({ name: one.name, site: clean(one.site) }));
152
+ const longestRun = options.longestRun ?? LONGEST_RUN;
153
+ const warnings = [];
154
+ const changes = [];
155
+ let out = "";
156
+ /** The codons for an amino acid, the host's favourite first, with ties broken the same way always. */
157
+ const liked = (aminoAcid) => [...(byAminoAcid.get(aminoAcid) ?? [])].sort((a, b) => usage.counts[b].share - usage.counts[a].share || (a < b ? -1 : 1));
158
+ for (let start = 0; start + CODON <= bases.length; start += CODON) {
159
+ const was = bases.slice(start, start + CODON);
160
+ const at = start / CODON + 1;
161
+ // A stop stays exactly as it is: it is not an amino acid and nothing is gained by moving it.
162
+ if (stops.includes(was)) {
163
+ out += was;
164
+ continue;
165
+ }
166
+ const aminoAcid = forward.get(was);
167
+ if (aminoAcid === undefined)
168
+ return nothing(`Codon ${at} is ${was}, which is not a codon of NCBI table ${usage.table}.`);
169
+ const family = liked(aminoAcid);
170
+ let chosen;
171
+ let instead = null;
172
+ for (const candidate of family) {
173
+ const why = trouble(out, candidate, avoid, longestRun);
174
+ if (why === null) {
175
+ chosen = candidate;
176
+ break;
177
+ }
178
+ if (instead === null)
179
+ instead = `the host's ${share(usage.counts[candidate].share)} codon ${candidate} would have made ${why}`;
180
+ }
181
+ if (chosen === undefined && changes.length > 0 && out.length >= CODON) {
182
+ // Nothing fits after what was chosen last time, which means last time's choice was the
183
+ // mistake: taking the host's favourite there left this amino acid nowhere to go. A run of one
184
+ // amino acid does this every time. So the one before is tried again, and the pair taken
185
+ // together, which is enough for a run and costs one step of looking back.
186
+ const back = out.slice(0, out.length - CODON);
187
+ const previous = out.slice(out.length - CODON);
188
+ const earlier = forward.get(previous);
189
+ outer: for (const other of earlier === undefined ? [] : liked(earlier)) {
190
+ if (other === previous || trouble(back, other, avoid, longestRun) !== null)
191
+ continue;
192
+ for (const candidate of family) {
193
+ if (trouble(back + other, candidate, avoid, longestRun) !== null)
194
+ continue;
195
+ out = back + other;
196
+ const last = changes.at(-1);
197
+ if (last !== undefined && last.at === at - 1) {
198
+ last.to = other;
199
+ last.toShare = usage.counts[other].share;
200
+ last.instead = `the host's favourite left codon ${at} nowhere to go`;
201
+ }
202
+ chosen = candidate;
203
+ break outer;
204
+ }
205
+ }
206
+ }
207
+ if (chosen === undefined) {
208
+ // Still nothing. The sequence has to say something, so it keeps what it had and says so.
209
+ chosen = was;
210
+ warnings.push(`At codon ${at}, no codon for ${aminoAcid} would avoid a run or a site, so it was left as ${was}.`);
211
+ instead = null;
212
+ }
213
+ if (chosen !== was) {
214
+ changes.push({ at, aminoAcid, from: was, fromShare: usage.counts[was]?.share ?? 0, to: chosen, toShare: usage.counts[chosen].share, instead });
215
+ }
216
+ out += chosen;
217
+ }
218
+ // The one thing that must be true. If it is not, nothing is handed back.
219
+ const before = String(translate(bases));
220
+ const after = String(translate(out));
221
+ if (before !== after)
222
+ 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.");
223
+ if (usage.genes < FEW_GENES)
224
+ warnings.push(`The codon usage was counted over ${usage.genes} ${usage.genes === 1 ? "gene" : "genes"}, which is few to lean on.`);
225
+ const after_gc = gc(out);
226
+ if (after_gc > 0.65 || after_gc < 0.3)
227
+ warnings.push(`The rewritten gene is ${share(after_gc)} GC, which is far from the middle and may be hard to make.`);
228
+ return {
229
+ sequence: out, protein: after, changes, codons: bases.length / CODON,
230
+ gcBefore: gc(bases), gcAfter: after_gc, avoided: avoid.map((one) => one.name),
231
+ warnings: [...new Set(warnings)], problem: null,
232
+ };
233
+ }
234
+ /**
235
+ * The working behind a rewrite: what was counted, what changed, and what it did to the gene.
236
+ *
237
+ * @param done - The rewrite.
238
+ * @param usage - The table it used.
239
+ * @returns One working for the table, one for the rewrite, and one for the protein being unchanged.
240
+ */
241
+ export function codonWorking(done, usage) {
242
+ if (done.problem !== null)
243
+ return [];
244
+ const count = (value) => value.toLocaleString("en-US");
245
+ const favourite = (aminoAcid) => {
246
+ const family = Object.entries(usage.counts).filter(([, one]) => one.aminoAcid === aminoAcid).sort((a, b) => b[1].share - a[1].share);
247
+ return family.map(([codon, one]) => `${codon} ${share(one.share)}`).join(", ");
248
+ };
249
+ const touched = [...new Set(done.changes.map((one) => one.aminoAcid))].sort();
250
+ return [
251
+ {
252
+ of: "the host's preferences",
253
+ comes: `${count(usage.codons)} codons counted over ${usage.genes} ${usage.genes === 1 ? "gene" : "genes"}`,
254
+ kind: "estimate",
255
+ steps: [
256
+ `counted from: ${usage.from}`,
257
+ `read with NCBI genetic code ${usage.table}`,
258
+ ...touched.slice(0, 8).map((aminoAcid) => `${aminoAcid}: ${favourite(aminoAcid)}`),
259
+ ...(touched.length > 8 ? [`and ${touched.length - 8} more amino acids`] : []),
260
+ ],
261
+ 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.",
262
+ },
263
+ {
264
+ of: "the rewrite",
265
+ comes: `${count(done.changes.length)} of ${count(done.codons)} codons changed`,
266
+ kind: "exact",
267
+ steps: [
268
+ `${count(done.codons - done.changes.length)} codons were already the host's choice`,
269
+ ...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})`}`),
270
+ ...(done.changes.length > 6 ? [`and ${count(done.changes.length - 6)} more`] : []),
271
+ ...(done.avoided.length === 0 ? [] : [`kept out of the sequence: ${done.avoided.join(", ")}`]),
272
+ `GC went from ${share(done.gcBefore)} to ${share(done.gcAfter)}`,
273
+ ],
274
+ },
275
+ {
276
+ of: "the protein",
277
+ comes: `${count(done.protein.length)} amino acids, unchanged`,
278
+ kind: "exact",
279
+ steps: [
280
+ "every codon was replaced only by another for the same amino acid",
281
+ "the gene was translated before and after, and the two were compared",
282
+ `it begins ${done.protein.slice(0, 24)}${done.protein.length > 24 ? "…" : ""}`,
283
+ ],
284
+ },
285
+ ];
286
+ }
287
+ //# sourceMappingURL=codons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codons.js","sourceRoot":"","sources":["../src/codons.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGrD,iCAAiC;AACjC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC;AAEvB,4EAA4E;AAC5E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAE3B,uFAAuF;AACvF,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC;AAE7B,4EAA4E;AAC5E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAiE7B,MAAM,KAAK,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AACjF,MAAM,EAAE,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,GA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