@biolibs/bionet-tools 0.1.9 → 0.1.11
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 +139 -2
- 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/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -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/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/protein.d.ts.map +1 -1
- package/dist/protein.js +3 -1
- package/dist/protein.js.map +1 -1
- package/dist/run.d.ts +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +1 -1
- package/dist/run.js.map +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +9 -4
- 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 +145 -0
- package/dist/work.js.map +1 -0
- package/package.json +4 -4
- package/src/digest-tool.tsx +14 -5
- package/src/index.ts +10 -0
- package/src/induce-bench.tsx +406 -0
- package/src/induce.ts +448 -0
- package/src/modify.ts +350 -0
- package/src/ordering.ts +301 -0
- package/src/protein.ts +3 -1
- package/src/run.ts +2 -2
- package/src/tools.tsx +8 -3
- package/src/work.tsx +277 -0
- package/tools.css +11 -0
package/src/modify.ts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which residues of a protein would be phosphorylated, and whether the host would do it.
|
|
3
|
+
*
|
|
4
|
+
* This exists because of the gap between a band and a protein. The induction tool can tell a lab it
|
|
5
|
+
* will get a 24 kDa band; it cannot tell the lab that the band will be the right mass and the wrong
|
|
6
|
+
* thing. For casein that is the whole question. Casein builds a micelle — which is what makes it
|
|
7
|
+
* behave like cheese rather than like dissolved protein — by binding calcium through clusters of
|
|
8
|
+
* phosphorylated serines. A casein that was made but not phosphorylated weighs almost the same,
|
|
9
|
+
* runs almost in the same place, and will not do the job.
|
|
10
|
+
*
|
|
11
|
+
* So two separate things are worked out here, and they are kept separate because one is arithmetic
|
|
12
|
+
* and the other is not.
|
|
13
|
+
*
|
|
14
|
+
* - **Which residues carry the motif.** This is a rule over the sequence and nothing more. The
|
|
15
|
+
* secretory-pathway kinase that phosphorylates milk proteins recognises Ser-x-Glu, and once a
|
|
16
|
+
* serine is phosphorylated it acts like a glutamate for the one two residues before it, so the
|
|
17
|
+
* sites march backwards along a cluster. That hierarchy is why casein's serines come in runs.
|
|
18
|
+
* {@link phosphoSites} applies it, says which round each site was found in, and shows the working.
|
|
19
|
+
* - **Whether the host has the enzyme.** This is not arithmetic, and nothing here pretends it is.
|
|
20
|
+
* {@link hostPhosphorylation} says what is generally held about the usual expression hosts, how
|
|
21
|
+
* firmly, and says plainly that it is a claim to check — which the lab's own literature tools can
|
|
22
|
+
* now do.
|
|
23
|
+
*
|
|
24
|
+
* A motif is a prediction. Where a curated record exists, as it does for the caseins in UniProt,
|
|
25
|
+
* {@link comparedWithKnown} says which predictions it confirms and which it does not, and that
|
|
26
|
+
* comparison is worth far more than either on its own.
|
|
27
|
+
*/
|
|
28
|
+
import type { Working } from "./pcr-working.js";
|
|
29
|
+
|
|
30
|
+
/** One rule for recognising a site. */
|
|
31
|
+
export interface PhosphoMotif {
|
|
32
|
+
/** What to call it. */
|
|
33
|
+
name: string;
|
|
34
|
+
/** The kinase family that uses it. */
|
|
35
|
+
kinase: string;
|
|
36
|
+
/** The rule, written as people write it. */
|
|
37
|
+
pattern: string;
|
|
38
|
+
/** Which residues it can act on. */
|
|
39
|
+
acts: string;
|
|
40
|
+
/** What it is for, in a sentence. */
|
|
41
|
+
about: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The rules applied, in the order they are applied.
|
|
46
|
+
*
|
|
47
|
+
* Only two, and deliberately only two. These are the acidophilic motifs — the ones that read a
|
|
48
|
+
* negative charge two or three residues along — and they are the ones that matter for a secreted
|
|
49
|
+
* milk protein. A kinase whose rule is a structure rather than a few residues cannot be found by
|
|
50
|
+
* looking at a sequence, and nothing here claims otherwise.
|
|
51
|
+
*/
|
|
52
|
+
export const PHOSPHO_MOTIFS: readonly PhosphoMotif[] = [
|
|
53
|
+
{
|
|
54
|
+
name: "S-x-E", kinase: "secretory-pathway casein kinase (FAM20C family)", pattern: "S-x-[E/D]", acts: "S",
|
|
55
|
+
about: "The kinase that phosphorylates milk and other secreted proteins, inside the Golgi, as they are on their way out. It reads a negative charge two residues along.",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "S/T-x-x-E", kinase: "casein kinase II (CK2)", pattern: "[S/T]-x-x-[E/D]", acts: "ST",
|
|
59
|
+
about: "A kinase found in essentially every eukaryote, in the cytoplasm and the nucleus rather than the secretory pathway. Named after casein because casein is what it was first shown to work on, not because casein is what it does in a cell.",
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
/** One residue that would be phosphorylated, and why. */
|
|
64
|
+
export interface PhosphoSite {
|
|
65
|
+
/** Where it is, counting from 1. */
|
|
66
|
+
at: number;
|
|
67
|
+
/** The residue, as a letter. */
|
|
68
|
+
residue: string;
|
|
69
|
+
/** The rule that found it, by name. */
|
|
70
|
+
by: string;
|
|
71
|
+
/** The kinase family that rule belongs to. */
|
|
72
|
+
kinase: string;
|
|
73
|
+
/** The residues either side of it, as they are written. */
|
|
74
|
+
context: string;
|
|
75
|
+
/**
|
|
76
|
+
* Which round found it. Round 1 is the motif read off the sequence as it stands. A later round is
|
|
77
|
+
* a site that only became one because a site found in the round before gave it the charge it
|
|
78
|
+
* needed — which is how a cluster of phosphoserines builds backwards along a chain.
|
|
79
|
+
*/
|
|
80
|
+
round: number;
|
|
81
|
+
/** What made it a site, said for a person. */
|
|
82
|
+
because: string;
|
|
83
|
+
/**
|
|
84
|
+
* Any other rule that also matches this residue.
|
|
85
|
+
*
|
|
86
|
+
* A serine can carry more than one motif, and which one is reported first depends only on the
|
|
87
|
+
* order the rules are tried in. Saying "this is a CK2 site" when it is equally the secretory
|
|
88
|
+
* kinase's would be an accident of that order presented as a finding, so the others are listed.
|
|
89
|
+
*/
|
|
90
|
+
alsoBy: { name: string; kinase: string; because: string }[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** What was worked out about a protein. */
|
|
94
|
+
export interface Phosphorylation {
|
|
95
|
+
/** The sites, in order along the chain. */
|
|
96
|
+
sites: PhosphoSite[];
|
|
97
|
+
/** How many rounds found something. A further round, which found nothing, is what ended it. */
|
|
98
|
+
rounds: number;
|
|
99
|
+
/** Why there is nothing to say, or `null` if there is. */
|
|
100
|
+
problem: string | null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const ACID = new Set(["E", "D"]);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The residues of a protein that carry a phosphorylation motif.
|
|
107
|
+
*
|
|
108
|
+
* The rules are applied in rounds. In the first, each is read off the sequence as it stands. In
|
|
109
|
+
* each round after, a serine whose +2 residue is a site found already counts too, because a
|
|
110
|
+
* phosphoserine carries the negative charge the kinase was reading for. That is repeated until a
|
|
111
|
+
* round finds nothing, which is what builds the runs of phosphoserines a casein has.
|
|
112
|
+
*
|
|
113
|
+
* @param protein - The amino acids, in one letter each.
|
|
114
|
+
* @param options - `motifs` are the rules to apply, {@link PHOSPHO_MOTIFS} if not given; `prime`
|
|
115
|
+
* turns off the later rounds, leaving only what the bare sequence says.
|
|
116
|
+
* @returns The sites, and how many rounds it took.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { phosphoSites } from "@biolibs/bionet-tools";
|
|
121
|
+
*
|
|
122
|
+
* const found = phosphoSites(casein.sequence);
|
|
123
|
+
* found.sites.filter((one) => one.round > 1); // the ones a neighbour made possible
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export function phosphoSites(protein: string, options: { motifs?: readonly PhosphoMotif[]; prime?: boolean } = {}): Phosphorylation {
|
|
127
|
+
const chain = protein.replace(/\s+/g, "").toUpperCase();
|
|
128
|
+
if (chain === "") return { sites: [], rounds: 0, problem: "There is no protein here to look at." };
|
|
129
|
+
if (!/^[ACDEFGHIKLMNPQRSTVWY]+$/.test(chain)) return { sites: [], rounds: 0, problem: "That is written in letters that are not the twenty standard amino acids." };
|
|
130
|
+
const motifs = options.motifs ?? PHOSPHO_MOTIFS;
|
|
131
|
+
const found = new Map<number, PhosphoSite>();
|
|
132
|
+
const context = (at: number): string => chain.slice(Math.max(0, at - 4), at + 3);
|
|
133
|
+
|
|
134
|
+
let round = 0;
|
|
135
|
+
for (;;) {
|
|
136
|
+
round += 1;
|
|
137
|
+
const fresh: PhosphoSite[] = [];
|
|
138
|
+
for (let at = 1; at <= chain.length; at += 1) {
|
|
139
|
+
const residue = chain[at - 1]!;
|
|
140
|
+
/** Every rule that matches this residue as things stand, in the order the rules are given. */
|
|
141
|
+
const matching: { name: string; kinase: string; because: string }[] = [];
|
|
142
|
+
for (const motif of motifs) {
|
|
143
|
+
if (!motif.acts.includes(residue)) continue;
|
|
144
|
+
const reach = motif.name === "S-x-E" ? 2 : 3;
|
|
145
|
+
const charged = chain[at - 1 + reach];
|
|
146
|
+
if (charged === undefined) continue;
|
|
147
|
+
if (ACID.has(charged)) {
|
|
148
|
+
matching.push({ name: motif.name, kinase: motif.kinase, because: `${residue}${at} with ${charged} ${reach} residues along: ${motif.pattern}` });
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
// A serine that is already a site carries the charge the kinase was reading for, so the one
|
|
152
|
+
// before it becomes a site in the next round. That is what builds a run of them backwards.
|
|
153
|
+
if (options.prime !== false && charged === "S" && found.has(at + reach)) {
|
|
154
|
+
matching.push({ name: motif.name, kinase: motif.kinase,
|
|
155
|
+
because: `${residue}${at} with the phosphoserine at ${at + reach} ${reach} residues along, which carries the negative charge a glutamate would` });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (matching.length === 0) continue;
|
|
159
|
+
const already = found.get(at);
|
|
160
|
+
if (already !== undefined) {
|
|
161
|
+
// A rule that only matched once a neighbour was found is still a rule that matches, so it
|
|
162
|
+
// joins the site it belongs to rather than being lost or restarting the round count.
|
|
163
|
+
for (const one of matching) {
|
|
164
|
+
if (one.name !== already.by && !already.alsoBy.some((other) => other.name === one.name)) already.alsoBy.push(one);
|
|
165
|
+
}
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const [best, ...rest] = matching as [typeof matching[number], ...typeof matching];
|
|
169
|
+
fresh.push({ at, residue, by: best.name, kinase: best.kinase, context: context(at), round, because: best.because, alsoBy: rest });
|
|
170
|
+
}
|
|
171
|
+
for (const one of fresh) found.set(one.at, one);
|
|
172
|
+
// A round that adds nothing is the end, and is not counted: what is reported is how many
|
|
173
|
+
// rounds found something, which is what says how deep the hierarchy went.
|
|
174
|
+
if (fresh.length === 0) { round -= 1; break; }
|
|
175
|
+
if (options.prime === false) break;
|
|
176
|
+
if (round > chain.length) break;
|
|
177
|
+
}
|
|
178
|
+
return { sites: [...found.values()].sort((a, b) => a.at - b.at), rounds: Math.max(round, 1), problem: null };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** How a predicted set of sites stands against a curated one. */
|
|
182
|
+
export interface Compared {
|
|
183
|
+
/** Sites that were predicted and are recorded: the ones to trust. */
|
|
184
|
+
confirmed: number[];
|
|
185
|
+
/** Sites that are recorded and were not predicted: the rule missed them. */
|
|
186
|
+
missed: number[];
|
|
187
|
+
/** Sites that were predicted and are not recorded: they may be wrong, or merely unstudied. */
|
|
188
|
+
onlyPredicted: number[];
|
|
189
|
+
/** What fraction of the recorded sites the rule found. */
|
|
190
|
+
caught: number;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* How a prediction stands against what somebody has actually recorded.
|
|
195
|
+
*
|
|
196
|
+
* This is the honest way to use a motif. A rule over a sequence says what could be phosphorylated;
|
|
197
|
+
* a curated record says what somebody saw. Where both exist, how well they agree is the measure of
|
|
198
|
+
* whether to believe the rule anywhere else — on a variant, say, or on a gene that has been
|
|
199
|
+
* rewritten in another host's codons.
|
|
200
|
+
*
|
|
201
|
+
* @param predicted - Where the rule said, counting from 1.
|
|
202
|
+
* @param known - Where a record says, counting from 1 on the same sequence.
|
|
203
|
+
* @returns What agrees, what was missed, and what is predicted alone.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* import { comparedWithKnown, phosphoSites } from "@biolibs/bionet-tools";
|
|
208
|
+
*
|
|
209
|
+
* const found = phosphoSites(casein.sequence);
|
|
210
|
+
* comparedWithKnown(found.sites.map((one) => one.at), [30, 32, 33, 34, 50]).caught; // 1
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export function comparedWithKnown(predicted: readonly number[], known: readonly number[]): Compared {
|
|
214
|
+
const said = new Set(predicted);
|
|
215
|
+
const recorded = new Set(known);
|
|
216
|
+
const confirmed = [...recorded].filter((one) => said.has(one)).sort((a, b) => a - b);
|
|
217
|
+
return {
|
|
218
|
+
confirmed,
|
|
219
|
+
missed: [...recorded].filter((one) => !said.has(one)).sort((a, b) => a - b),
|
|
220
|
+
onlyPredicted: [...said].filter((one) => !recorded.has(one)).sort((a, b) => a - b),
|
|
221
|
+
caught: recorded.size === 0 ? 0 : confirmed.length / recorded.size,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** What is held about whether a host phosphorylates a secreted protein this way. */
|
|
226
|
+
export interface HostKinases {
|
|
227
|
+
/** The organism, as it would be written. */
|
|
228
|
+
host: string;
|
|
229
|
+
/** Whether it is held to have the secretory-pathway kinase, and whether it has CK2. */
|
|
230
|
+
secretoryKinase: "yes" | "no" | "not known";
|
|
231
|
+
casein2: boolean;
|
|
232
|
+
/** What is held, in a sentence or two. */
|
|
233
|
+
says: string;
|
|
234
|
+
/** How firmly: something long settled, something reported, or something to go and check. */
|
|
235
|
+
standing: "well established" | "reported" | "check";
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* What is generally held about the usual expression hosts.
|
|
240
|
+
*
|
|
241
|
+
* Everything here is a claim about biology and not something computed, which is why it carries a
|
|
242
|
+
* `standing` and why the answer tells a reader to check it. It rots: a homologue nobody had found
|
|
243
|
+
* when this was written may have been found since, and a host engineered to carry the kinase is now
|
|
244
|
+
* a thing people build. What it is for is to stop a lab discovering at the end of a month that the
|
|
245
|
+
* protein it made was never going to be phosphorylated — and then to point at the literature, which
|
|
246
|
+
* the lab's own tools can now read.
|
|
247
|
+
*/
|
|
248
|
+
export const HOST_KINASES: readonly HostKinases[] = [
|
|
249
|
+
{
|
|
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. Casein made in E. coli is reported unphosphorylated, and that is the usual reason a group that wanted micelles moved away from it.",
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
host: "Bacillus subtilis", secretoryKinase: "no", casein2: false, standing: "well established",
|
|
255
|
+
says: "As for E. coli: it secretes well, which is why people use it, but not through a compartment that phosphorylates what passes through.",
|
|
256
|
+
},
|
|
257
|
+
{
|
|
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. Phosphorylation of casein expressed in yeast is reported, and reported as partial and uneven between sites rather than as the full pattern.",
|
|
260
|
+
},
|
|
261
|
+
{
|
|
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. The same holds as for budding yeast: the kinase of the secretory pathway has not been identified in it.",
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
host: "Nicotiana benthamiana", secretoryKinase: "not known", casein2: true, standing: "reported",
|
|
267
|
+
says: "Plants have CK2 and a secretory pathway, and phosphorylated casein has been reported from plant expression. How complete the pattern is varies by report.",
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
host: "Cricetulus griseus", secretoryKinase: "yes", casein2: true, standing: "well established",
|
|
271
|
+
says: "CHO cells are mammalian and have the secretory-pathway kinase, so they phosphorylate a milk protein as a mammal does. They are slow and expensive, which is why nobody makes cheese protein in them.",
|
|
272
|
+
},
|
|
273
|
+
];
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* What is held about one host.
|
|
277
|
+
*
|
|
278
|
+
* @param host - What it is, as the lab writes it. Matched loosely, so `Pichia pastoris GS115` finds
|
|
279
|
+
* the entry for the species under its current name.
|
|
280
|
+
* @returns What is held, or `null` for a host nothing here knows about, which is not the same as a
|
|
281
|
+
* host that does not do it.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* import { hostPhosphorylation } from "@biolibs/bionet-tools";
|
|
286
|
+
*
|
|
287
|
+
* hostPhosphorylation("Saccharomyces cerevisiae W303")?.secretoryKinase; // "not known"
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
export function hostPhosphorylation(host: string): HostKinases | null {
|
|
291
|
+
const asked = host.trim().toLowerCase();
|
|
292
|
+
if (asked === "") return null;
|
|
293
|
+
// The old names are what a lab's own records are most likely to say.
|
|
294
|
+
const also: Readonly<Record<string, string>> = {
|
|
295
|
+
"pichia pastoris": "komagataella phaffii", "pichia": "komagataella phaffii",
|
|
296
|
+
"e. coli": "escherichia coli", "b. subtilis": "bacillus subtilis",
|
|
297
|
+
"s. cerevisiae": "saccharomyces cerevisiae", "cho": "cricetulus griseus", "tobacco": "nicotiana benthamiana",
|
|
298
|
+
};
|
|
299
|
+
for (const [old, now] of Object.entries(also)) {
|
|
300
|
+
if (asked.includes(old)) return HOST_KINASES.find((one) => one.host.toLowerCase() === now) ?? null;
|
|
301
|
+
}
|
|
302
|
+
return HOST_KINASES.find((one) => asked.includes(one.host.toLowerCase())
|
|
303
|
+
|| asked.includes(one.host.split(" ")[0]!.toLowerCase())) ?? null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* The working behind what was found: the rule, the rounds, and what it rests on.
|
|
308
|
+
*
|
|
309
|
+
* @param found - What {@link phosphoSites} gave.
|
|
310
|
+
* @param host - What is held about the host, if a host was named.
|
|
311
|
+
* @returns The workings, in the order to read them.
|
|
312
|
+
*/
|
|
313
|
+
export function phosphoWorking(found: Phosphorylation, host: HostKinases | null = null): Working[] {
|
|
314
|
+
if (found.problem !== null) return [];
|
|
315
|
+
const byRound = new Map<number, PhosphoSite[]>();
|
|
316
|
+
for (const one of found.sites) byRound.set(one.round, [...(byRound.get(one.round) ?? []), one]);
|
|
317
|
+
const out: Working[] = [{
|
|
318
|
+
of: "the sites the sequence carries",
|
|
319
|
+
comes: `${found.sites.length} ${found.sites.length === 1 ? "residue" : "residues"}`,
|
|
320
|
+
kind: "estimate",
|
|
321
|
+
steps: [
|
|
322
|
+
...PHOSPHO_MOTIFS.map((one) => `${one.name}: ${one.pattern}, which is ${one.kinase}.`),
|
|
323
|
+
...[...byRound.entries()].sort(([a], [b]) => a - b).map(([round, sites]) => {
|
|
324
|
+
const named = sites.map((one) => `${one.residue}${one.at}`).join(", ");
|
|
325
|
+
if (round === 1) return `Round 1 reads the sequence as it stands: ${named}.`;
|
|
326
|
+
return sites.length === 1
|
|
327
|
+
? `Round ${round} adds ${named}, which only became a site because the one two residues along was found in the round before.`
|
|
328
|
+
: `Round ${round} adds ${named}, each of which only became a site because the one two residues along was found in the round before.`;
|
|
329
|
+
}),
|
|
330
|
+
found.rounds === 1
|
|
331
|
+
? "One round found anything; the next found nothing more."
|
|
332
|
+
: `${found.rounds} rounds found something, and the next found nothing more, which is how far back along the chain the cluster builds.`,
|
|
333
|
+
],
|
|
334
|
+
rests: "A motif says a residue could be phosphorylated, not that it is. It is a rule over a few residues, and the kinases it stands for are not the only ones there are; a kinase that reads a shape rather than a sequence cannot be found this way at all. Where somebody has recorded the real sites, compare against those and believe the comparison rather than the rule.",
|
|
335
|
+
}];
|
|
336
|
+
if (host !== null) {
|
|
337
|
+
out.push({
|
|
338
|
+
of: `whether ${host.host} would do it`,
|
|
339
|
+
comes: host.secretoryKinase === "yes" ? "it has the kinase" : host.secretoryKinase === "no" ? "it has no such kinase" : "not known to have the kinase",
|
|
340
|
+
kind: "estimate",
|
|
341
|
+
steps: [
|
|
342
|
+
host.says,
|
|
343
|
+
host.casein2 ? "It does have CK2, so a site that is CK2's may still be phosphorylated." : "It has no CK2 either.",
|
|
344
|
+
"This is not worked out from anything. It is what is generally held, and it is what to check in the literature before spending a month on it.",
|
|
345
|
+
],
|
|
346
|
+
rests: `Held as ${host.standing}. A host engineered to carry the kinase is a thing people now build, and a homologue nobody had found when this was written may have been found since. Search the literature for this host and this protein rather than taking this for the answer.`,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
return out;
|
|
350
|
+
}
|
package/src/ordering.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The order a lab's open proposals have to be carried out in, worked out from what each one makes
|
|
3
|
+
* and what each one needs.
|
|
4
|
+
*
|
|
5
|
+
* A proposal is one run. Nothing in the log says that eleven of them are one piece of work, or which
|
|
6
|
+
* comes first, and until now nothing read them as anything but eleven unrelated cards. But the order
|
|
7
|
+
* is not missing from the data — it is simply never followed. A plan says what it `expects` to make,
|
|
8
|
+
* each thing with the checksum that would be its identity; another plan says what it needs, and may
|
|
9
|
+
* name a part there is no tube of yet by that same checksum. Where one plan expects what another
|
|
10
|
+
* needs, the first has to happen first. That is a fact about the molecules, not a declaration
|
|
11
|
+
* somebody made, and it is true whether or not anybody wrote it down.
|
|
12
|
+
*
|
|
13
|
+
* So this derives the order rather than adding a way to assert one. No new kind of entry, nothing an
|
|
14
|
+
* older device has to understand, and no way for the stated order and the real one to disagree.
|
|
15
|
+
*
|
|
16
|
+
* **Where the chain stops, and why.** It stops at a transformation. What a transformation makes is
|
|
17
|
+
* alive, so it has no checksum to point at: a strain is this lab's own, known by an ID, and the
|
|
18
|
+
* culture that would be an induction's input does not exist until somebody has grown it. A plan
|
|
19
|
+
* cannot name a tube that is not there. So the work up to and including putting a construct into a
|
|
20
|
+
* host can be proposed as one chain, and what follows it has to be proposed afresh once there is
|
|
21
|
+
* something growing. That is a real limit and it is said here rather than hidden: a plan that
|
|
22
|
+
* claimed to run past it would be claiming to name something nothing can name yet.
|
|
23
|
+
*/
|
|
24
|
+
import type { ItemState, PlanState } from "@biolibs/bionet";
|
|
25
|
+
|
|
26
|
+
/** As much of a lab as the ordering reads. */
|
|
27
|
+
export interface OrderingLab {
|
|
28
|
+
plans: readonly PlanState[];
|
|
29
|
+
items: readonly ItemState[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Why a step cannot be carried out yet, or `null` if it can. */
|
|
33
|
+
export type Holding =
|
|
34
|
+
| { why: "a step before it"; steps: string[] }
|
|
35
|
+
| { why: "something nobody is making"; parts: string[] }
|
|
36
|
+
| { why: "a tube that has run short"; tubes: string[] };
|
|
37
|
+
|
|
38
|
+
/** One step: a proposal, where it sits in the order, and what stands in its way. */
|
|
39
|
+
export interface Step {
|
|
40
|
+
/** The proposal itself. */
|
|
41
|
+
plan: PlanState;
|
|
42
|
+
/** The plans that have to be carried out before it, by ID. */
|
|
43
|
+
after: string[];
|
|
44
|
+
/** How deep it is: 0 for a step with nothing before it. */
|
|
45
|
+
depth: number;
|
|
46
|
+
/** What stands in its way, or `null` if it could be done now. */
|
|
47
|
+
held: Holding | null;
|
|
48
|
+
/** The checksums it would make. */
|
|
49
|
+
makes: string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The field a plan is filed under, unless a lab uses another word for it. */
|
|
53
|
+
export const FILED_UNDER = "project";
|
|
54
|
+
|
|
55
|
+
/** What a piece of work with no project is called. */
|
|
56
|
+
export const UNFILED = "Not filed";
|
|
57
|
+
|
|
58
|
+
/** One chain of steps that leads to one thing. */
|
|
59
|
+
export interface Thread {
|
|
60
|
+
/** What to call it: what it ends by making. */
|
|
61
|
+
name: string;
|
|
62
|
+
/** Its steps, in an order that can be carried out. */
|
|
63
|
+
steps: Step[];
|
|
64
|
+
/** What it ends with: what it makes that nothing else in it consumes. */
|
|
65
|
+
ends: { checksum: string; name: string }[];
|
|
66
|
+
/** Whether every step of it could be carried out as things stand. */
|
|
67
|
+
clear: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Everything on in one project. */
|
|
71
|
+
export interface Project {
|
|
72
|
+
/** What it is called, as somebody filed it. */
|
|
73
|
+
name: string;
|
|
74
|
+
/** Whether anybody actually filed it, or it is the heap of what nobody did. */
|
|
75
|
+
filed: boolean;
|
|
76
|
+
/** Its chains. */
|
|
77
|
+
threads: Thread[];
|
|
78
|
+
/** Its steps, in one order that works. */
|
|
79
|
+
order: Step[];
|
|
80
|
+
/** The ones that could be carried out now. */
|
|
81
|
+
ready: Step[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The open proposals, read as work to be done. */
|
|
85
|
+
export interface PlanOfWork {
|
|
86
|
+
/**
|
|
87
|
+
* What is on, by project.
|
|
88
|
+
*
|
|
89
|
+
* A chain is not a project and cannot be: four caseins are four chains in one project, and two
|
|
90
|
+
* unrelated projects are also chains. Which work belongs together is a thing people decide, so it
|
|
91
|
+
* is filed rather than derived, and a plan nobody filed is in `Not filed` rather than silently
|
|
92
|
+
* lumped in with somebody else's.
|
|
93
|
+
*/
|
|
94
|
+
projects: Project[];
|
|
95
|
+
/** The chains, each leading to one thing. A lab building four proteins has four. */
|
|
96
|
+
threads: Thread[];
|
|
97
|
+
/** Every open step, in one order that works. */
|
|
98
|
+
order: Step[];
|
|
99
|
+
/** The steps that could be carried out now. */
|
|
100
|
+
ready: Step[];
|
|
101
|
+
/** The steps that could not, and what each is waiting on. */
|
|
102
|
+
held: Step[];
|
|
103
|
+
/**
|
|
104
|
+
* Plans that need something nothing makes and no tube holds: what has to be ordered or
|
|
105
|
+
* synthesised before any of this can start, by checksum.
|
|
106
|
+
*/
|
|
107
|
+
toGet: { checksum: string; name: string; forSteps: string[] }[];
|
|
108
|
+
/** Plans that somehow depend on each other in a circle, by ID. Empty, unless something is wrong. */
|
|
109
|
+
tangled: string[];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Whether the lab holds a tube of a part that has anything in it. */
|
|
113
|
+
const holds = (lab: OrderingLab, checksum: string): boolean =>
|
|
114
|
+
lab.items.some((one) => one.part === checksum && !one.retired && one.amount > 0);
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The open proposals, read as work: what order they go in, what can start now, what is waiting.
|
|
118
|
+
*
|
|
119
|
+
* @param lab - The lab, with its plans and its tubes.
|
|
120
|
+
* @returns The work, in threads and in one order.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { planOfWork } from "@biolibs/bionet-tools";
|
|
125
|
+
*
|
|
126
|
+
* const work = planOfWork(lab);
|
|
127
|
+
* work.ready.map((one) => one.plan.kind); // what somebody could go and do now
|
|
128
|
+
* work.toGet; // what has to be ordered before any of it
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export function planOfWork(lab: OrderingLab): PlanOfWork {
|
|
132
|
+
const open = lab.plans.filter((one) => one.settled === null);
|
|
133
|
+
const byId = new Map(open.map((one) => [one.plan, one]));
|
|
134
|
+
|
|
135
|
+
// What each open plan would make, and who would make each thing.
|
|
136
|
+
const makers = new Map<string, string[]>();
|
|
137
|
+
for (const plan of open) {
|
|
138
|
+
for (const expected of plan.expects) makers.set(expected.checksum, [...(makers.get(expected.checksum) ?? []), plan.plan]);
|
|
139
|
+
}
|
|
140
|
+
const nameOf = (checksum: string): string =>
|
|
141
|
+
open.flatMap((one) => one.expects).find((one) => one.checksum === checksum)?.name ?? checksum.slice(0, 12);
|
|
142
|
+
|
|
143
|
+
/** What each plan waits on, and what it needs that nothing is making. */
|
|
144
|
+
const after = new Map<string, string[]>();
|
|
145
|
+
const missing = new Map<string, string[]>();
|
|
146
|
+
for (const plan of open) {
|
|
147
|
+
const waits: string[] = [];
|
|
148
|
+
const nowhere: string[] = [];
|
|
149
|
+
for (const input of plan.inputs) {
|
|
150
|
+
if (input.part === undefined) continue;
|
|
151
|
+
// A plan names a part rather than a tube when there was no tube of it when it was proposed.
|
|
152
|
+
// There may be one now, and that is a fact about the lab, not about the plan.
|
|
153
|
+
if (holds(lab, input.part)) continue;
|
|
154
|
+
const made = (makers.get(input.part) ?? []).filter((one) => one !== plan.plan);
|
|
155
|
+
if (made.length > 0) waits.push(...made);
|
|
156
|
+
else nowhere.push(input.part);
|
|
157
|
+
}
|
|
158
|
+
after.set(plan.plan, [...new Set(waits)]);
|
|
159
|
+
missing.set(plan.plan, [...new Set(nowhere)]);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// The order: a step comes after everything it waits on. Kahn's algorithm, which also finds a
|
|
163
|
+
// circle if the proposals somehow make one.
|
|
164
|
+
const left = new Set(open.map((one) => one.plan));
|
|
165
|
+
const depth = new Map<string, number>();
|
|
166
|
+
const order: string[] = [];
|
|
167
|
+
for (let guard = 0; left.size > 0 && guard <= open.length; guard += 1) {
|
|
168
|
+
const free = [...left].filter((id) => (after.get(id) ?? []).every((before) => !left.has(before)));
|
|
169
|
+
if (free.length === 0) break;
|
|
170
|
+
// In the order they were proposed, so that two steps that could both go now keep their order.
|
|
171
|
+
free.sort((a, b) => open.findIndex((one) => one.plan === a) - open.findIndex((one) => one.plan === b));
|
|
172
|
+
for (const id of free) {
|
|
173
|
+
depth.set(id, Math.max(0, ...(after.get(id) ?? []).map((before) => (depth.get(before) ?? 0) + 1)));
|
|
174
|
+
order.push(id);
|
|
175
|
+
left.delete(id);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const tangled = [...left];
|
|
179
|
+
|
|
180
|
+
const stepOf = (id: string): Step => {
|
|
181
|
+
const plan = byId.get(id)!;
|
|
182
|
+
const waits = (after.get(id) ?? []).filter((one) => byId.has(one));
|
|
183
|
+
const nowhere = missing.get(id) ?? [];
|
|
184
|
+
const held: Holding | null =
|
|
185
|
+
waits.length > 0 ? { why: "a step before it", steps: waits }
|
|
186
|
+
: nowhere.length > 0 ? { why: "something nobody is making", parts: nowhere }
|
|
187
|
+
: plan.wanting.length > 0 ? { why: "a tube that has run short", tubes: [...plan.wanting] }
|
|
188
|
+
: null;
|
|
189
|
+
return { plan, after: waits, depth: depth.get(id) ?? 0, held, makes: plan.expects.map((one) => one.checksum) };
|
|
190
|
+
};
|
|
191
|
+
const steps = order.map(stepOf);
|
|
192
|
+
const tangledSteps = tangled.map(stepOf);
|
|
193
|
+
|
|
194
|
+
// A thread is a set of steps joined by what they make and need: a lab building four proteins has
|
|
195
|
+
// four of them, and they are four separate pieces of work however they were proposed.
|
|
196
|
+
const where = new Map<string, number>();
|
|
197
|
+
const threads: Step[][] = [];
|
|
198
|
+
const join = (id: string, into: number): void => {
|
|
199
|
+
const was = where.get(id);
|
|
200
|
+
if (was === into) return;
|
|
201
|
+
if (was === undefined) { where.set(id, into); return; }
|
|
202
|
+
// Two threads met, so they were one thread: everything in the older joins the newer.
|
|
203
|
+
for (const [each, at] of where) if (at === was) where.set(each, into);
|
|
204
|
+
};
|
|
205
|
+
for (const step of steps) {
|
|
206
|
+
const joined = [step.plan.plan, ...step.after].map((id) => where.get(id)).find((at) => at !== undefined);
|
|
207
|
+
const at = joined ?? threads.push([]) - 1;
|
|
208
|
+
join(step.plan.plan, at);
|
|
209
|
+
for (const before of step.after) join(before, at);
|
|
210
|
+
}
|
|
211
|
+
for (const step of steps) threads[where.get(step.plan.plan)!]!.push(step);
|
|
212
|
+
|
|
213
|
+
const made = new Set(steps.flatMap((one) => one.makes));
|
|
214
|
+
const woven: Thread[] = threads.filter((one) => one.length > 0).map((one) => {
|
|
215
|
+
const inside = new Set(one.flatMap((step) => step.makes));
|
|
216
|
+
const needed = new Set(one.flatMap((step) => step.plan.inputs.flatMap((input) => (input.part === undefined ? [] : [input.part]))));
|
|
217
|
+
// What it ends with is what it makes that nothing in it then uses.
|
|
218
|
+
let ends = [...inside].filter((checksum) => !needed.has(checksum)).map((checksum) => ({ checksum, name: nameOf(checksum) }));
|
|
219
|
+
// Unless there is no such thing, which happens whenever a chain finishes with a transformation:
|
|
220
|
+
// every molecule it made went into the host, and what came out is alive and has no checksum to
|
|
221
|
+
// be named by. The last thing that can be named is then what the chain is known by.
|
|
222
|
+
if (ends.length === 0) {
|
|
223
|
+
const last = [...one].reverse().find((step) => step.makes.length > 0);
|
|
224
|
+
ends = (last?.makes ?? []).map((checksum) => ({ checksum, name: nameOf(checksum) }));
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
// A chain is known by what it is for, which is the last thing it makes.
|
|
228
|
+
name: ends.map((each) => each.name).join(" and ") || `${one.length} ${one.length === 1 ? "step" : "steps"}`,
|
|
229
|
+
steps: one, ends, clear: one.every((step) => step.held === null || step.held.why === "a step before it"),
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const toGet = new Map<string, string[]>();
|
|
234
|
+
for (const step of [...steps, ...tangledSteps]) {
|
|
235
|
+
for (const checksum of missing.get(step.plan.plan) ?? []) toGet.set(checksum, [...(toGet.get(checksum) ?? []), step.plan.plan]);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Filed, not derived: which chains belong to one project is somebody's decision.
|
|
239
|
+
const filedAs = (step: Step): string => {
|
|
240
|
+
const said = step.plan.fields[FILED_UNDER];
|
|
241
|
+
return typeof said === "string" && said.trim() !== "" ? said.trim() : UNFILED;
|
|
242
|
+
};
|
|
243
|
+
const byProject = new Map<string, Step[]>();
|
|
244
|
+
for (const step of steps) byProject.set(filedAs(step), [...(byProject.get(filedAs(step)) ?? []), step]);
|
|
245
|
+
const projects: Project[] = [...byProject].map(([name, own]) => ({
|
|
246
|
+
name, filed: name !== UNFILED,
|
|
247
|
+
// A chain belongs to a project if any of its steps was filed under it. A chain whose steps were
|
|
248
|
+
// filed differently is shown under each, since the steps really are in both and saying
|
|
249
|
+
// otherwise would hide work from one of them.
|
|
250
|
+
threads: woven.filter((thread) => thread.steps.some((step) => filedAs(step) === name)),
|
|
251
|
+
order: own, ready: own.filter((step) => step.held === null),
|
|
252
|
+
// What nobody filed goes last: it is a heap, not a project.
|
|
253
|
+
})).sort((a, b) => Number(a.name === UNFILED) - Number(b.name === UNFILED) || a.name.localeCompare(b.name));
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
projects, threads: woven, order: steps,
|
|
257
|
+
ready: steps.filter((one) => one.held === null),
|
|
258
|
+
held: steps.filter((one) => one.held !== null),
|
|
259
|
+
toGet: [...toGet].map(([checksum, forSteps]) => ({ checksum, name: made.has(checksum) ? nameOf(checksum) : checksum.slice(0, 12), forSteps })),
|
|
260
|
+
tangled,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The work said in a sentence or two, for somebody who wants to know where things stand.
|
|
266
|
+
*
|
|
267
|
+
* @param work - What `planOfWork` gave.
|
|
268
|
+
* @returns A line for each thing worth saying. Empty if nothing is proposed.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* import { planOfWork, saysWork } from "@biolibs/bionet-tools";
|
|
273
|
+
*
|
|
274
|
+
* saysWork(planOfWork(lab));
|
|
275
|
+
* // ["Eleven steps are proposed, in four pieces of work.", "Three could be done now.", …]
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
export function saysWork(work: PlanOfWork): string[] {
|
|
279
|
+
if (work.order.length === 0 && work.tangled.length === 0) return [];
|
|
280
|
+
const count = (many: number, one: string, more: string): string => `${many} ${many === 1 ? one : more}`;
|
|
281
|
+
const filed = work.projects.filter((one) => one.filed);
|
|
282
|
+
const said: string[] = [
|
|
283
|
+
`${count(work.order.length, "step is", "steps are")} proposed, in ${count(work.threads.length, "piece", "pieces")} of work`
|
|
284
|
+
+ (filed.length === 0 ? "." : `, across ${count(filed.length, "project", "projects")}: ${filed.map((one) => one.name).join(", ")}.`),
|
|
285
|
+
];
|
|
286
|
+
const loose = work.projects.find((one) => !one.filed);
|
|
287
|
+
if (loose !== undefined && filed.length > 0) {
|
|
288
|
+
said.push(`${count(loose.order.length, "step is", "steps are")} filed under no project.`);
|
|
289
|
+
}
|
|
290
|
+
if (work.ready.length > 0) said.push(`${count(work.ready.length, "step", "steps")} could be carried out now.`);
|
|
291
|
+
else if (work.order.length > 0) said.push("Nothing can be carried out yet.");
|
|
292
|
+
const waiting = work.held.filter((one) => one.held?.why === "a step before it").length;
|
|
293
|
+
if (waiting > 0) said.push(`${count(waiting, "step is", "steps are")} waiting on a step before it.`);
|
|
294
|
+
if (work.toGet.length > 0) {
|
|
295
|
+
said.push(`${count(work.toGet.length, "part has", "parts have")} to be ordered or made first: nothing proposed makes ${work.toGet.length === 1 ? "it" : "them"}, and there is no tube.`);
|
|
296
|
+
}
|
|
297
|
+
const short = work.held.filter((one) => one.held?.why === "a tube that has run short").length;
|
|
298
|
+
if (short > 0) said.push(`${count(short, "step counts", "steps count")} on a tube that has been retired or run short.`);
|
|
299
|
+
if (work.tangled.length > 0) said.push(`${count(work.tangled.length, "step", "steps")} depend on each other in a circle and cannot be ordered.`);
|
|
300
|
+
return said;
|
|
301
|
+
}
|
package/src/protein.ts
CHANGED
|
@@ -193,7 +193,9 @@ export function proteinWorking(made: Translated, facts: ProteinFacts | null): Wo
|
|
|
193
193
|
steps: [
|
|
194
194
|
`the weight is the amino acids added up, less a water for each bond: ${count(Math.round(facts.weight))} Da`,
|
|
195
195
|
`the isoelectric point is where its charges cancel: pH ${facts.isoelectric.toFixed(2)}`,
|
|
196
|
-
|
|
196
|
+
facts.extinction.reduced > 0
|
|
197
|
+
? `it absorbs at 280 nm with ${count(facts.extinction.reduced)} M⁻¹cm⁻¹, which is how a concentration is read off`
|
|
198
|
+
: "it has no tryptophan, tyrosine or cystine, so it does not absorb at 280 nm and a concentration cannot be read there",
|
|
197
199
|
`the instability index is ${facts.instability.toFixed(1)}; over 40 is reckoned unstable in a tube`,
|
|
198
200
|
`${Math.round(facts.structure.helix * 100)}% helix, ${Math.round(facts.structure.turn * 100)}% turn, ${Math.round(facts.structure.sheet * 100)}% sheet`,
|
|
199
201
|
],
|