@biolibs/bionet-tools 0.1.9 → 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/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 +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -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/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 +5 -3
- package/dist/tools.js.map +1 -1
- package/package.json +4 -4
- package/src/digest-tool.tsx +14 -5
- package/src/index.ts +6 -0
- package/src/induce-bench.tsx +406 -0
- package/src/induce.ts +448 -0
- package/src/modify.ts +350 -0
- package/src/protein.ts +3 -1
- package/src/run.ts +2 -2
- package/src/tools.tsx +4 -2
package/src/induce.ts
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Growing a strain and making it express what was put into it, and the gel that shows whether it did.
|
|
3
|
+
*
|
|
4
|
+
* This is the step the rest of the lab's tools lead up to. A gene is found, copied, cut, joined into
|
|
5
|
+
* a construct, checked and put into a host, and all of that is still only DNA: a promise about a
|
|
6
|
+
* protein that nobody has yet seen. An induction is where the promise is kept or is not. The flask
|
|
7
|
+
* is fed something that turns the promoter on, it shakes for a few hours, and then a lane of a
|
|
8
|
+
* polyacrylamide gel either has a band at the right mass or it does not.
|
|
9
|
+
*
|
|
10
|
+
* Two things about this are worth being plain about, because they are what makes an induction
|
|
11
|
+
* different from every other tool here.
|
|
12
|
+
*
|
|
13
|
+
* - **Nothing that comes out is worked out from what went in.** A PCR's product is the stretch
|
|
14
|
+
* between the primers, and arithmetic gives it. A culture's product is whatever the cells chose to
|
|
15
|
+
* make, and no sequence predicts the yield, the solubility, or whether the thing folded. So what
|
|
16
|
+
* is computed here is only the protein the gene *codes for* and the mass its band *should* run at.
|
|
17
|
+
* Whether that band is there is read off a gel by a person, and is the one thing recorded.
|
|
18
|
+
* - **The protein is not an output of the run.** A run's outputs are DNA, every device that reads
|
|
19
|
+
* the log agrees on that, and an entry that said otherwise would be refused by the ones that are
|
|
20
|
+
* older. So an induction is recorded as a run with no outputs that used some of a culture — the
|
|
21
|
+
* same shape a transformation has — and the protein is added afterwards as a part in its own
|
|
22
|
+
* right. The run says in its settings which protein it was expected to make, by the checksum that
|
|
23
|
+
* protein will have, which is how the two are tied together without a new kind of entry.
|
|
24
|
+
*/
|
|
25
|
+
import { partChecksum, type PartState, type StrainState } from "@biolibs/bionet";
|
|
26
|
+
import { amountOf, whereWords } from "@biolibs/bionet-panels";
|
|
27
|
+
import { PROTEIN_LADDERS, proteinBands, proteinGelById, proteinLadderById, type Band, type ProteinGel, type ProteinLadder } from "@biolibs/gel";
|
|
28
|
+
import { proteinFacts, proteinWorking, translateGene, type ProteinFacts, type Translated } from "./protein.js";
|
|
29
|
+
import type { Working } from "./pcr-working.js";
|
|
30
|
+
import type { ToolLab } from "./run.js";
|
|
31
|
+
|
|
32
|
+
/** What a run that grew a culture and made it express something is called, for the lab's record. */
|
|
33
|
+
export const INDUCTION = "induction";
|
|
34
|
+
|
|
35
|
+
/** The gel an induction is checked on unless somebody says otherwise: 12% acrylamide. */
|
|
36
|
+
export const USUAL_PROTEIN_GEL = "12";
|
|
37
|
+
|
|
38
|
+
/** The marker run beside it unless the operator picks one: `markerFor` chooses to suit the gel. */
|
|
39
|
+
export const USUAL_PROTEIN_LADDER = "";
|
|
40
|
+
|
|
41
|
+
/** A dalton is a gram per mole; a gel is read in thousands of them. */
|
|
42
|
+
export const DA_PER_KDA = 1_000;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The marker to run beside a gel, unless somebody says otherwise: the one with most of its bands
|
|
46
|
+
* inside what that gel separates.
|
|
47
|
+
*
|
|
48
|
+
* A marker is chosen to suit the gel, the way a person does it. A broad-range marker on a 12% gel
|
|
49
|
+
* puts its 250, 150 and 100 kDa bands all in the well, where they are one smudge and no use for
|
|
50
|
+
* reading anything off.
|
|
51
|
+
*
|
|
52
|
+
* @param gel - The gel.
|
|
53
|
+
* @returns The marker.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { markerFor, proteinGelById } from "@biolibs/bionet-tools";
|
|
58
|
+
*
|
|
59
|
+
* markerFor(proteinGelById("12")).id; // "low" — a broad-range marker's top three sit in the well
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export function markerFor(gel: ProteinGel): ProteinLadder {
|
|
63
|
+
const inside = (marker: ProteinLadder): number => marker.sizes.filter((one) => one <= gel.largest && one >= gel.smallest).length;
|
|
64
|
+
return [...PROTEIN_LADDERS].sort((a, b) => inside(b) - inside(a) || (a.sizes.length - inside(a)) - (b.sizes.length - inside(b)))[0]!;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** As much of a lab as an induction reads: an induction needs the strains, which no other tool does. */
|
|
68
|
+
export interface InductionLab extends ToolLab {
|
|
69
|
+
strains: readonly StrainState[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** One culture that could be grown and induced. */
|
|
73
|
+
export interface CultureChoice {
|
|
74
|
+
/** The culture's tube. */
|
|
75
|
+
item: string;
|
|
76
|
+
/** The strain it is a culture of. */
|
|
77
|
+
strain: StrainState;
|
|
78
|
+
/** How to say it in a list: what it is, how much there is, where it is. */
|
|
79
|
+
label: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** One thing a strain carries that codes for a protein, and could be expressed. */
|
|
83
|
+
export interface GeneChoice {
|
|
84
|
+
/** The part. */
|
|
85
|
+
part: PartState;
|
|
86
|
+
/** The coding sequences marked on it, by label, longest first. An empty list means the whole part is the only choice. */
|
|
87
|
+
coding: string[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** What somebody has chosen for an induction. */
|
|
91
|
+
export interface InductionChoice {
|
|
92
|
+
/** The culture to grow, by its tube ID. */
|
|
93
|
+
culture: string;
|
|
94
|
+
/** The gene to express, by its part's checksum. One of the ones the strain carries. */
|
|
95
|
+
gene: string;
|
|
96
|
+
/** The label of a coding sequence marked on it, to read in place of the whole part. */
|
|
97
|
+
cds?: string;
|
|
98
|
+
/** Whether to take off a signal peptide marked at the start of it: for a secreted protein, that is what is collected. */
|
|
99
|
+
cutSignal?: boolean;
|
|
100
|
+
/** What the promoter was turned on with, and how much, as the operator writes it: `IPTG`, `0.5 mM`. */
|
|
101
|
+
inducer?: string;
|
|
102
|
+
concentration?: string;
|
|
103
|
+
/** What the incubator was set to: degrees, revolutions a minute, and how long it ran. Whole numbers. */
|
|
104
|
+
celsius?: number;
|
|
105
|
+
rpm?: number;
|
|
106
|
+
hours?: number;
|
|
107
|
+
/** How much of the culture was used, in its own unit. A whole number. */
|
|
108
|
+
used?: number;
|
|
109
|
+
/** The acrylamide gel and the marker beside it, by their IDs in `@biolibs/gel`. */
|
|
110
|
+
gel?: string;
|
|
111
|
+
ladder?: string;
|
|
112
|
+
/** The shaking incubator it was grown in, if the lab has one. */
|
|
113
|
+
instrument?: string | null;
|
|
114
|
+
/** What to call the protein, how much of it there is, and in what unit. */
|
|
115
|
+
name?: string;
|
|
116
|
+
amount?: number;
|
|
117
|
+
unit?: string | null;
|
|
118
|
+
/** Anything worth saying about it. */
|
|
119
|
+
note?: string | null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** What an induction would be expected to give. */
|
|
123
|
+
export interface InductionPlan {
|
|
124
|
+
/** The strain being grown, and the gene being expressed. */
|
|
125
|
+
strain: StrainState | null;
|
|
126
|
+
gene: PartState | null;
|
|
127
|
+
/** The protein the gene codes for, or `null` if it could not be read as one. */
|
|
128
|
+
made: Translated | null;
|
|
129
|
+
/** What is known of that protein from its sequence alone. */
|
|
130
|
+
facts: ProteinFacts | null;
|
|
131
|
+
/** The checksum the protein will have in the lab, which is its identity. `null` if there is none to have. */
|
|
132
|
+
checksum: string | null;
|
|
133
|
+
/** What it weighs, in kilodaltons, as a gel is read: `null` unless the weight could be worked out. */
|
|
134
|
+
kilodaltons: number | null;
|
|
135
|
+
/** The band it should show, and the marker's bands beside it. */
|
|
136
|
+
bands: Band[];
|
|
137
|
+
ladder: Band[];
|
|
138
|
+
/** The gel and marker it was worked out for. */
|
|
139
|
+
gel: ProteinGel;
|
|
140
|
+
ladderName: string;
|
|
141
|
+
/** Why there is nothing to expect, said for a person, or `null` if there is. */
|
|
142
|
+
problem: string | null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** An induction as chosen: what it would give, what to record, and the protein to keep if it worked. */
|
|
146
|
+
export interface InductionRun {
|
|
147
|
+
/** What it would be expected to give. */
|
|
148
|
+
plan: InductionPlan;
|
|
149
|
+
/** The protein to add as a part, and the tube of it to add, if the band is there. `null` while there is no protein to expect. */
|
|
150
|
+
keep: { name: string; sequence: string; kind: "protein"; amount: number; unit: string | null; checksum: string } | null;
|
|
151
|
+
/** What to hand to the lab's `recordRun` if the band was there. `null` likewise. */
|
|
152
|
+
showed: Record<string, unknown> | null;
|
|
153
|
+
/** What to hand to it if it was grown and nothing was at that mass. `null` if the culture is missing. */
|
|
154
|
+
nothing: Record<string, unknown> | null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const whole = (value: number | undefined, usual: number): number =>
|
|
158
|
+
value === undefined || !Number.isSafeInteger(value) || value < 0 ? usual : value;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The cultures a lab could grow and induce: every culture with something in it.
|
|
162
|
+
*
|
|
163
|
+
* A tube of DNA is not offered, however much of it there is. Expression is something cells do.
|
|
164
|
+
*
|
|
165
|
+
* @param lab - The lab.
|
|
166
|
+
* @returns The cultures to offer, the ones of a strain that carries something first, since those
|
|
167
|
+
* are the ones there is anything to express in.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* import { inductionCultures } from "@biolibs/bionet-tools";
|
|
172
|
+
*
|
|
173
|
+
* const cultures = inductionCultures(lab);
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export function inductionCultures(lab: InductionLab): CultureChoice[] {
|
|
177
|
+
const found: CultureChoice[] = [];
|
|
178
|
+
for (const item of lab.items) {
|
|
179
|
+
if (item.part !== null || item.retired || item.amount <= 0) continue;
|
|
180
|
+
const strain = lab.strains.find((one) => one.strain === item.strain);
|
|
181
|
+
if (strain === undefined) continue;
|
|
182
|
+
found.push({ item: item.item, strain, label: `${strain.name} · ${amountOf(item)} · ${whereWords(item, lab.places)}` });
|
|
183
|
+
}
|
|
184
|
+
return found.sort((a, b) => b.strain.carries.length - a.strain.carries.length);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* What a culture's strain carries that there is any point inducing.
|
|
189
|
+
*
|
|
190
|
+
* A strain carries parts, and a part is DNA; a protein the lab happens to hold is not something to
|
|
191
|
+
* express. What is marked on each is read for coding sequences, since a construct usually carries
|
|
192
|
+
* more than a gene — a promoter, a marker, an origin — and it is the gene that is being asked for.
|
|
193
|
+
*
|
|
194
|
+
* @param lab - The lab.
|
|
195
|
+
* @param culture - The culture's tube ID.
|
|
196
|
+
* @returns What could be expressed, and the coding sequences marked on each.
|
|
197
|
+
*/
|
|
198
|
+
export function inductionGenes(lab: InductionLab, culture: string): GeneChoice[] {
|
|
199
|
+
const item = lab.items.find((one) => one.item === culture);
|
|
200
|
+
const strain = item === undefined ? undefined : lab.strains.find((one) => one.strain === item.strain);
|
|
201
|
+
if (strain === undefined) return [];
|
|
202
|
+
return strain.carries.flatMap((checksum) => {
|
|
203
|
+
const part = lab.parts.find((one) => one.checksum === checksum);
|
|
204
|
+
if (part === undefined || part.kind === "protein") return [];
|
|
205
|
+
const coding = part.features.filter((one) => /^cds$/i.test(one.type) && one.parts.length === 1)
|
|
206
|
+
.sort((a, b) => (b.parts[0]!.end - b.parts[0]!.start) - (a.parts[0]!.end - a.parts[0]!.start))
|
|
207
|
+
.map((one) => one.label);
|
|
208
|
+
return [{ part, coding }];
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* What an induction would be expected to give: the protein, and where its band should run.
|
|
214
|
+
*
|
|
215
|
+
* @param lab - The lab.
|
|
216
|
+
* @param choice - The culture, the gene, and the gel to read it on.
|
|
217
|
+
* @returns The protein, its mass, and the gel it should show.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* import { planInduction } from "@biolibs/bionet-tools";
|
|
222
|
+
*
|
|
223
|
+
* const plan = planInduction(lab, { culture, gene, cds: "casein", cutSignal: true });
|
|
224
|
+
* plan.kilodaltons; // what the band should run at
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
export function planInduction(lab: InductionLab, choice: InductionChoice): InductionPlan {
|
|
228
|
+
let gel: ProteinGel;
|
|
229
|
+
try { gel = proteinGelById(choice.gel ?? USUAL_PROTEIN_GEL); } catch { gel = proteinGelById(USUAL_PROTEIN_GEL); }
|
|
230
|
+
// Chosen to suit the gel unless the operator has named one, since a marker whose bands all sit in
|
|
231
|
+
// the well is a marker nothing can be read against.
|
|
232
|
+
let marker = markerFor(gel);
|
|
233
|
+
if (choice.ladder !== undefined) { try { marker = proteinLadderById(choice.ladder); } catch { /* the one that suits the gel */ } }
|
|
234
|
+
const ladder = proteinBands(marker.sizes, gel).map((one) => ({ ...one, intensity: 1 }));
|
|
235
|
+
const empty = (problem: string | null, strain: StrainState | null = null, gene: PartState | null = null): InductionPlan =>
|
|
236
|
+
({ strain, gene, made: null, facts: null, checksum: null, kilodaltons: null, bands: [], ladder, gel, ladderName: marker.name, problem });
|
|
237
|
+
|
|
238
|
+
const item = lab.items.find((one) => one.item === choice.culture);
|
|
239
|
+
if (item === undefined || item.part !== null) return empty("An induction grows a culture of a strain. Choose one of the lab's cultures.");
|
|
240
|
+
const strain = lab.strains.find((one) => one.strain === item.strain);
|
|
241
|
+
if (strain === undefined) return empty("The lab no longer lists the strain this is a culture of.");
|
|
242
|
+
if (choice.gene === "") return empty(strain.carries.length === 0
|
|
243
|
+
? `Nothing has been put into ${strain.name}, so there is nothing in it to express.`
|
|
244
|
+
: "Choose which of the things the strain carries to express.", strain);
|
|
245
|
+
if (!strain.carries.includes(choice.gene)) return empty(`${strain.name} does not carry that part, so inducing it would not make that protein.`, strain);
|
|
246
|
+
const gene = lab.parts.find((one) => one.checksum === choice.gene);
|
|
247
|
+
if (gene === undefined) return empty("The lab no longer lists that part.", strain);
|
|
248
|
+
if (gene.kind === "protein") return empty(`${gene.name} is a protein. What is expressed is a gene.`, strain, gene);
|
|
249
|
+
|
|
250
|
+
const made = translateGene(gene, { ...(choice.cds === undefined || choice.cds === "" ? {} : { cds: choice.cds }), ...(choice.cutSignal === true ? { cutSignal: true } : {}) });
|
|
251
|
+
if (made.problem !== null) return empty(made.problem, strain, gene);
|
|
252
|
+
const facts = proteinFacts(made.protein);
|
|
253
|
+
const kilodaltons = facts === null ? null : facts.weight / DA_PER_KDA;
|
|
254
|
+
// A gene read in the wrong frame, or a broken one, gives a chain with a stop in the middle. That
|
|
255
|
+
// is not something there can be a tube of, so it has no checksum and nothing offers to keep it —
|
|
256
|
+
// but it is still shown, with the warnings that say what is wrong, because that is the finding.
|
|
257
|
+
const keepable = /^[ACDEFGHIKLMNPQRSTVWYBXZJUO]+$/i.test(made.protein);
|
|
258
|
+
return {
|
|
259
|
+
strain, gene, made, facts,
|
|
260
|
+
checksum: keepable ? partChecksum({ sequence: made.protein, kind: "protein" }) : null,
|
|
261
|
+
kilodaltons,
|
|
262
|
+
bands: kilodaltons === null ? [] : proteinBands([kilodaltons], gel),
|
|
263
|
+
ladder, gel, ladderName: marker.name, problem: null,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Work a choice out into an induction: what to record, and the protein to keep.
|
|
269
|
+
*
|
|
270
|
+
* What is recorded is a run that used some of a culture and made no molecule, because a run's
|
|
271
|
+
* outputs are DNA and what this makes is not. The protein it was expected to make is named in the
|
|
272
|
+
* run's settings by the checksum it will have, so that the run and the part can be put back together
|
|
273
|
+
* afterwards by anybody reading the log, including a device that was not here.
|
|
274
|
+
*
|
|
275
|
+
* @param lab - The lab.
|
|
276
|
+
* @param choice - The culture, the gene, how it was set up, and what to call what comes out.
|
|
277
|
+
* @returns What it would give, what to record either way, and the protein to add if it worked.
|
|
278
|
+
*/
|
|
279
|
+
export function inductionRun(lab: InductionLab, choice: InductionChoice): InductionRun {
|
|
280
|
+
const plan = planInduction(lab, choice);
|
|
281
|
+
const item = lab.items.find((one) => one.item === choice.culture);
|
|
282
|
+
if (item === undefined || item.part !== null) return { plan, keep: null, showed: null, nothing: null };
|
|
283
|
+
const typed = choice.name?.trim() ?? "";
|
|
284
|
+
const name = (typed !== "" ? typed
|
|
285
|
+
: plan.made === null || plan.gene === null ? "a protein"
|
|
286
|
+
: `${plan.made.signal === null ? "" : "mature "}${choice.cds !== undefined && choice.cds !== "" ? choice.cds : plan.gene.name}`).slice(0, 200);
|
|
287
|
+
const inducer = choice.inducer?.trim() ?? "";
|
|
288
|
+
const concentration = choice.concentration?.trim() ?? "";
|
|
289
|
+
const record = {
|
|
290
|
+
kind: INDUCTION, instrument: choice.instrument ?? null,
|
|
291
|
+
inputs: [{ item: choice.culture, amount: whole(choice.used, 1), role: "culture" }],
|
|
292
|
+
outputs: [],
|
|
293
|
+
settings: {
|
|
294
|
+
...(inducer === "" ? {} : { inducer: inducer.slice(0, 200) }),
|
|
295
|
+
...(concentration === "" ? {} : { at: concentration.slice(0, 200) }),
|
|
296
|
+
...(Number.isSafeInteger(choice.celsius) ? { celsius: choice.celsius! } : {}),
|
|
297
|
+
...(Number.isSafeInteger(choice.rpm) ? { rpm: choice.rpm! } : {}),
|
|
298
|
+
...(Number.isSafeInteger(choice.hours) ? { hours: choice.hours! } : {}),
|
|
299
|
+
...(plan.gene === null ? {} : { gene: plan.gene.name.slice(0, 200), gene_part: plan.gene.checksum }),
|
|
300
|
+
// Which stretch was read, and whether the signal peptide came off, because the protein's mass
|
|
301
|
+
// depends on both and a name does not say either.
|
|
302
|
+
...(choice.cds === undefined || choice.cds === "" ? {} : { cds: choice.cds.slice(0, 200) }),
|
|
303
|
+
...(choice.cutSignal === true ? { signal_cut: plan.made?.signal === null ? "none marked" : "yes" } : {}),
|
|
304
|
+
// Written as text, not as a number: an entry carries only whole numbers, and a mass to one
|
|
305
|
+
// decimal place is what a gel is read to. Rounding it to a whole kDa would lose a small protein.
|
|
306
|
+
...(plan.kilodaltons === null ? {} : { expected_kda: (Math.round(plan.kilodaltons * 10) / 10).toFixed(1) }),
|
|
307
|
+
// The protein is added as a part of its own, so this is what ties the two together.
|
|
308
|
+
...(plan.checksum === null ? {} : { made: plan.checksum }),
|
|
309
|
+
gel: `${plan.gel.percent}%`,
|
|
310
|
+
},
|
|
311
|
+
note: choice.note ?? null,
|
|
312
|
+
};
|
|
313
|
+
const keep = plan.made === null || plan.checksum === null || plan.made.protein === "" ? null : {
|
|
314
|
+
name, sequence: plan.made.protein, kind: "protein" as const,
|
|
315
|
+
amount: whole(choice.amount, 1), unit: choice.unit === undefined ? "mL" : choice.unit, checksum: plan.checksum,
|
|
316
|
+
};
|
|
317
|
+
return {
|
|
318
|
+
plan, keep,
|
|
319
|
+
showed: keep === null ? null : { ...record, outcome: "worked" },
|
|
320
|
+
nothing: { ...record, outcome: "failed" },
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Something a careful operator would stop and ask about an induction before setting it up. */
|
|
325
|
+
export interface InductionCheck {
|
|
326
|
+
/** `stop` if the gel is unlikely to show what is hoped, `look` if it is only worth a second glance. */
|
|
327
|
+
weight: "stop" | "look";
|
|
328
|
+
/** What to say. */
|
|
329
|
+
says: string;
|
|
330
|
+
/** The short reason, to put beside it. */
|
|
331
|
+
because: string;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* What a careful operator would ask of an induction before running it.
|
|
336
|
+
*
|
|
337
|
+
* None of this is about the protein being wrong. It is about the gel being unable to answer the
|
|
338
|
+
* question: a band smaller than the gel separates runs off the front, one larger stays in the well,
|
|
339
|
+
* and one that lands on a marker band cannot be told from it. A protein that the sequence says is
|
|
340
|
+
* unstable is worth knowing about before a day is spent on it.
|
|
341
|
+
*
|
|
342
|
+
* @param plan - The induction as worked out.
|
|
343
|
+
* @returns What to say, the ones worth stopping for first.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```ts
|
|
347
|
+
* import { inductionChecks, planInduction } from "@biolibs/bionet-tools";
|
|
348
|
+
*
|
|
349
|
+
* inductionChecks(planInduction(lab, choice)).filter((one) => one.weight === "stop");
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
export function inductionChecks(plan: InductionPlan): InductionCheck[] {
|
|
353
|
+
const checks: InductionCheck[] = [];
|
|
354
|
+
const kda = plan.kilodaltons;
|
|
355
|
+
const round = (value: number): string => `${Math.round(value * 10) / 10} kDa`;
|
|
356
|
+
if (kda !== null) {
|
|
357
|
+
if (kda < plan.gel.smallest) {
|
|
358
|
+
checks.push({ weight: "stop", says: `${round(kda)} is smaller than ${plan.gel.percent}% acrylamide separates, so the band would run off the front or be too faint to see. A higher percentage would hold it.`, because: `${round(kda)} < ${plan.gel.smallest} kDa` });
|
|
359
|
+
} else if (kda > plan.gel.largest) {
|
|
360
|
+
checks.push({ weight: "stop", says: `${round(kda)} is larger than ${plan.gel.percent}% acrylamide separates, so the band would stay at the well. A lower percentage would spread it.`, because: `${round(kda)} > ${plan.gel.largest} kDa` });
|
|
361
|
+
} else {
|
|
362
|
+
// A band within a few per cent of a marker band is a band nobody can report having seen.
|
|
363
|
+
const near = plan.ladder.find((one) => Math.abs(one.size - kda) <= kda * 0.06);
|
|
364
|
+
if (near !== undefined) {
|
|
365
|
+
checks.push({ weight: "look", says: `${round(kda)} is close to the marker's ${near.size} kDa band, so the two would be hard to tell apart. A marker whose bands fall elsewhere, or a lane of uninduced cells to compare against, would settle it.`, because: `${round(kda)} ≈ ${near.size} kDa` });
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (plan.made !== null) {
|
|
370
|
+
for (const warning of plan.made.warnings) checks.push({ weight: "look", says: warning, because: "read from the gene" });
|
|
371
|
+
if (plan.made.signal !== null) {
|
|
372
|
+
checks.push({ weight: "look", says: `${plan.made.signal.label} was taken off, so this is the mass of what the cells let out. What is still inside them is ${plan.made.signal.peptide.length} amino acids longer and runs higher.`, because: "signal peptide cut" });
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (plan.facts !== null && plan.facts.instability > 40) {
|
|
376
|
+
checks.push({ weight: "look", says: `The sequence puts the instability index at ${plan.facts.instability.toFixed(1)}, and over 40 is reckoned unstable in a tube. Keep it cold and run the gel the same day.`, because: `instability ${plan.facts.instability.toFixed(1)} > 40` });
|
|
377
|
+
}
|
|
378
|
+
return checks.sort((a, b) => Number(b.weight === "stop") - Number(a.weight === "stop"));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* The working behind an induction: the protein, and where its band should run.
|
|
383
|
+
*
|
|
384
|
+
* The first of these is the translation and what the sequence says about the protein, which is
|
|
385
|
+
* `proteinWorking`'s. The last is the one thing added here, and it is the one that has to be read
|
|
386
|
+
* carefully: a position on a gel is an estimate from a straight-line rule, and a mass is read
|
|
387
|
+
* against the marker beside it and never off a distance.
|
|
388
|
+
*
|
|
389
|
+
* @param plan - The induction as worked out.
|
|
390
|
+
* @returns The workings, in the order to read them. Empty if there is nothing to expect.
|
|
391
|
+
*/
|
|
392
|
+
export function inductionWorking(plan: InductionPlan): Working[] {
|
|
393
|
+
if (plan.made === null) return [];
|
|
394
|
+
const out = [...proteinWorking(plan.made, plan.facts)];
|
|
395
|
+
const kda = plan.kilodaltons;
|
|
396
|
+
if (kda !== null) {
|
|
397
|
+
const [high, low, own] = [Math.log10(plan.gel.largest), Math.log10(plan.gel.smallest), Math.log10(kda)];
|
|
398
|
+
const round = (value: number): string => value.toFixed(2);
|
|
399
|
+
const position = plan.bands[0]?.position ?? 0;
|
|
400
|
+
const inside = kda <= plan.gel.largest && kda >= plan.gel.smallest;
|
|
401
|
+
out.push({
|
|
402
|
+
of: `where ${Math.round(kda * 10) / 10} kDa runs on ${plan.gel.percent}% acrylamide`,
|
|
403
|
+
comes: `${Math.round(position * 100)}% of the way down`, kind: "estimate",
|
|
404
|
+
steps: [
|
|
405
|
+
`${Math.round(plan.facts!.weight)} Da is ${Math.round(kda * 10) / 10} kDa, which is what a protein gel is read in.`,
|
|
406
|
+
`This gel separates ${plan.gel.largest} kDa, which barely leaves the well, down to ${plan.gel.smallest} kDa, which reaches the front.`,
|
|
407
|
+
`Distance goes with the logarithm of mass: log₁₀ ${plan.gel.largest} = ${round(high)}, log₁₀ ${plan.gel.smallest} = ${round(low)}, log₁₀ ${Math.round(kda * 10) / 10} = ${round(own)}.`,
|
|
408
|
+
inside ? `So it is (${round(high)} − ${round(own)}) ÷ (${round(high)} − ${round(low)}) = ${round(position)} of the way down, beside the marker's ${plan.ladder.filter((one) => one.size >= kda).at(-1)?.size ?? plan.gel.largest} kDa band.`
|
|
409
|
+
: `${Math.round(kda * 10) / 10} kDa is ${kda > plan.gel.largest ? "larger" : "smaller"} than this gel separates, so it is drawn at the ${kda > plan.gel.largest ? "well" : "front"}.`,
|
|
410
|
+
],
|
|
411
|
+
rests: "SDS coats a protein with much the same charge for every unit of mass and undoes its shape, so what is left to sort chains by is size, and over a gel's working range the distance is close to a straight line against the logarithm of mass. It is an approximation. A marker's bands are themselves calibrated and run a little off their printed weights, and a protein that is glycosylated or not fully reduced runs at a size that is not the mass its sequence comes to. Read a band against the marker in the lane beside it, never off a distance.",
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
return out;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Which of a lab's parts came out of an induction, as the runs themselves say.
|
|
419
|
+
*
|
|
420
|
+
* A protein part is added apart from the run that made it, so the tie between them is the checksum
|
|
421
|
+
* the run recorded in its settings. Reading it back this way means a device that was not there when
|
|
422
|
+
* it happened arrives at the same answer from the log alone.
|
|
423
|
+
*
|
|
424
|
+
* @param lab - The lab, with its runs.
|
|
425
|
+
* @param checksum - The protein's checksum.
|
|
426
|
+
* @returns The IDs of the runs that said they would make it, in the order they were recorded.
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```ts
|
|
430
|
+
* import { inducedBy } from "@biolibs/bionet-tools";
|
|
431
|
+
*
|
|
432
|
+
* inducedBy(lab, protein.checksum); // ["…"], or [] for a protein nobody grew here
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
export function inducedBy(lab: { runs: readonly { run: string; kind: string; outcome: string; settings: Readonly<Record<string, string | number>> }[] },
|
|
436
|
+
checksum: string): string[] {
|
|
437
|
+
return lab.runs.filter((one) => one.kind === INDUCTION && one.outcome === "worked" && one.settings["made"] === checksum).map((one) => one.run);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Whether a part looks like one an induction made: a protein, with a run that says it made it.
|
|
442
|
+
*
|
|
443
|
+
* @param lab - The lab, with its runs.
|
|
444
|
+
* @param part - The part.
|
|
445
|
+
* @returns Whether some induction in the lab's record was expected to make it.
|
|
446
|
+
*/
|
|
447
|
+
export const wasInduced = (lab: Parameters<typeof inducedBy>[0], part: Pick<PartState, "checksum" | "kind">): boolean =>
|
|
448
|
+
part.kind === "protein" && inducedBy(lab, part.checksum).length > 0;
|