@biolibs/glossary 0.0.0-stage → 0.1.0

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/src/terms.ts ADDED
@@ -0,0 +1,926 @@
1
+ /**
2
+ * The terms: general molecular-biology and bioinformatics words, each said in one sentence, then a
3
+ * paragraph, then why anybody needs to know it.
4
+ *
5
+ * Every term has a picture, drawn by `@biolibs/glossary-react`. A term is not added here without
6
+ * one being added there; a test in that package fails if any term has no picture.
7
+ */
8
+
9
+ /** The groups the terms are sorted into. */
10
+ export type Category = "basics" | "molecules" | "genes" | "records" | "lab" | "comparison" | "structure";
11
+
12
+ /** Each group, with what to call it and a line about it, in the order they are read. */
13
+ export const CATEGORIES: { id: Category; title: string; blurb: string }[] = [
14
+ { id: "basics", title: "The basics", blurb: "Cells, DNA, RNA, proteins and how big things are." },
15
+ { id: "molecules", title: "DNA as a molecule", blurb: "Bases, strands and how they pair." },
16
+ { id: "genes", title: "From gene to protein", blurb: "How a sequence is read and what changes do to it." },
17
+ { id: "records", title: "Records and files", blurb: "How sequences are labelled, numbered and stored." },
18
+ { id: "lab", title: "At the bench", blurb: "Cutting, joining, copying and checking DNA." },
19
+ { id: "comparison", title: "Comparing sequences", blurb: "Alignments, patterns and trees." },
20
+ { id: "structure", title: "Three-dimensional structure", blurb: "What molecules look like." },
21
+ ];
22
+
23
+ /** One term. */
24
+ export interface GlossaryEntry {
25
+ /** How it is named in an address and in code. It never changes. */
26
+ slug: string;
27
+ /** The term, as it is written. */
28
+ term: string;
29
+ /** The group it is in. */
30
+ category: Category;
31
+ /** One sentence. Shown on cards and in hover definitions. */
32
+ definition: string;
33
+ /** A short paragraph of further explanation. */
34
+ detail: string;
35
+ /** Why anyone needs to know this. */
36
+ why: string;
37
+ /** Phrases in lesson text that should link here, longest first where they overlap. */
38
+ match: string[];
39
+ /** The slugs of terms worth reading next. */
40
+ related: string[];
41
+ /** The lessons on the biolibs site that teach it, by slug. */
42
+ lessons: string[];
43
+ /** biolibs packages that work with this concept. */
44
+ packages: string[];
45
+ }
46
+
47
+ /** Every term, in the order they are taught. */
48
+ export const GLOSSARY: GlossaryEntry[] = [
49
+ // --- The basics -------------------------------------------------------------------------------
50
+ {
51
+ slug: "cell",
52
+ term: "Cell",
53
+ category: "basics",
54
+ definition: "The smallest unit of life: a membrane-wrapped compartment that can feed, maintain and copy itself.",
55
+ detail:
56
+ "Bacteria are single small cells with no internal compartments. The cells of animals, plants and fungi are larger and keep their DNA in a compartment called the nucleus. Every cell carries a full copy of the organism's DNA and the machinery to read it.",
57
+ why: "Everything in molecular biology happens inside cells, and most laboratory methods borrow machinery from them.",
58
+ match: ["cells", "cell"],
59
+ related: ["dna", "protein", "plasmid", "genome"],
60
+ lessons: [],
61
+ packages: [],
62
+ },
63
+ {
64
+ slug: "dna",
65
+ term: "DNA",
66
+ category: "basics",
67
+ definition: "The molecule that stores a living thing's instructions, as a long sequence of four bases: A, C, G and T.",
68
+ detail:
69
+ "DNA is two strands wound round each other in a double helix, with the bases of one strand paired to the bases of the other. Because each strand determines its partner, a cell copies DNA by separating the strands and rebuilding the missing half of each.",
70
+ why: "Its sequence can be written as text, which is what makes biology something software can work on.",
71
+ match: ["DNA"],
72
+ related: ["base", "base-pair", "rna", "gene", "nucleotide"],
73
+ lessons: ["sequences"],
74
+ packages: ["seq", "dseq"],
75
+ },
76
+ {
77
+ slug: "rna",
78
+ term: "RNA",
79
+ category: "basics",
80
+ definition: "A close relative of DNA, usually a single strand, that cells use as a working copy of a gene.",
81
+ detail:
82
+ "RNA uses the base U where DNA uses T, and a slightly different sugar. Messenger RNA carries a gene's instructions to the ribosome. Other kinds of RNA do jobs of their own, and some viruses use RNA instead of DNA as their genome.",
83
+ why: "It is the step between a gene and its protein, and a sequence type software must handle differently from DNA.",
84
+ match: ["RNA"],
85
+ related: ["dna", "transcription", "translation"],
86
+ lessons: ["sequences"],
87
+ packages: ["seq"],
88
+ },
89
+ {
90
+ slug: "nucleotide",
91
+ term: "Nucleotide",
92
+ category: "basics",
93
+ definition: "One building block of DNA or RNA: a sugar, a phosphate and a base.",
94
+ detail:
95
+ "Nucleotides join sugar to phosphate to sugar, forming the backbone of a strand, with the bases sticking out to the side. The backbone has a direction: one end finishes with a phosphate, called the 5′ end, and the other with a sugar, the 3′ end.",
96
+ why: "It explains why strands have a direction, and the abbreviation nt, for nucleotides, is how single-stranded lengths are counted.",
97
+ match: ["nucleotides", "nucleotide"],
98
+ related: ["base", "strand-direction", "dna"],
99
+ lessons: ["sequences"],
100
+ packages: ["seq"],
101
+ },
102
+ {
103
+ slug: "amino-acid",
104
+ term: "Amino acid",
105
+ category: "basics",
106
+ definition: "One building block of a protein. There are 20 kinds.",
107
+ detail:
108
+ "Every amino acid has the same backbone, which links to the next one in the chain, and a side chain that differs. Side chains may be large or small, charged or neutral, water-loving or water-avoiding, and that variety is what gives each protein its shape. Each amino acid has a three-letter and a one-letter abbreviation, so glycine is Gly or G.",
109
+ why: "Protein sequences are written in the one-letter code, and a codon's meaning is an amino acid.",
110
+ match: ["amino acids", "amino acid"],
111
+ related: ["protein", "residue", "codon", "genetic-code"],
112
+ lessons: ["sequences", "structures"],
113
+ packages: ["seq", "seqtools"],
114
+ },
115
+ {
116
+ slug: "enzyme",
117
+ term: "Enzyme",
118
+ category: "basics",
119
+ definition: "A protein that speeds up one specific chemical reaction without being used up.",
120
+ detail:
121
+ "An enzyme has a pocket, the active site, shaped to fit the molecules it acts on. It holds them in a way that makes the reaction easy, releases the products and is ready to go again. Enzyme names usually end in -ase: a polymerase copies DNA, a ligase joins it, a nuclease cuts it.",
122
+ why: "The tools of genetic engineering are enzymes, so predicting an experiment means predicting what its enzymes will do.",
123
+ match: ["enzymes", "enzyme"],
124
+ related: ["protein", "restriction-enzyme", "ligation", "pcr"],
125
+ lessons: ["cloning"],
126
+ packages: ["restriction"],
127
+ },
128
+ {
129
+ slug: "chromosome",
130
+ term: "Chromosome",
131
+ category: "basics",
132
+ definition: "One very long DNA molecule, carrying many genes.",
133
+ detail:
134
+ "A bacterium usually has a single circular chromosome. Human cells have 46 linear ones, 23 inherited from each parent. A chromosome is far too long to read in one piece, so it is sequenced in fragments that software fits back together.",
135
+ why: "Positions in a genome are given as a chromosome and a coordinate along it.",
136
+ match: ["chromosomes", "chromosome"],
137
+ related: ["genome", "gene", "dna", "plasmid"],
138
+ lessons: [],
139
+ packages: ["seqio"],
140
+ },
141
+ {
142
+ slug: "genome",
143
+ term: "Genome",
144
+ category: "basics",
145
+ definition: "All of the DNA of an organism.",
146
+ detail:
147
+ "Genomes vary enormously in size, from tens of thousands of bases in a virus to billions in an animal or plant. Size is not a measure of complexity: genes make up most of a bacterial genome but only a few percent of a human one.",
148
+ why: "Its size is why nobody reads a genome by eye, and why searching and comparing need software.",
149
+ match: ["genomes", "genome"],
150
+ related: ["chromosome", "gene", "units"],
151
+ lessons: [],
152
+ packages: ["seqio"],
153
+ },
154
+ {
155
+ slug: "units",
156
+ term: "Units of size",
157
+ category: "basics",
158
+ definition: "The abbreviations used for lengths, masses and distances: bp, kb, Mb, Da and Å.",
159
+ detail:
160
+ "DNA length is counted in base pairs (bp), thousands of them (kb, kilobases) or millions (Mb, megabases). The mass of a molecule is given in daltons (Da), one dalton being about the mass of a hydrogen atom. Distances inside a molecule are given in ångströms (Å), ten-billionths of a metre.",
161
+ why: "These turn up in every result: fragment sizes on a gel, molecular weights, distances between atoms.",
162
+ match: ["kilobases", "kilobase", "daltons", "dalton", "ångströms"],
163
+ related: ["base-pair", "genome", "gel-electrophoresis"],
164
+ lessons: ["cloning", "structures"],
165
+ packages: ["seqtools", "gel", "pdb"],
166
+ },
167
+
168
+ // --- DNA as a molecule ------------------------------------------------------------------------
169
+ {
170
+ slug: "base",
171
+ term: "Base",
172
+ category: "molecules",
173
+ definition: "One of the four chemical letters of DNA (A, C, G and T) or of RNA (A, C, G and U).",
174
+ detail:
175
+ "Each base is attached to a sugar and a phosphate. That unit is a nucleotide, and nucleotides joined end to end make a strand. When a base is not known for certain, extra letters stand for a set of possibilities: N means any base, R means A or G, and so on.",
176
+ why: "Every sequence file, search and alignment is built from these letters.",
177
+ match: ["bases", "base"],
178
+ related: ["base-pair", "strand-direction", "gc-content"],
179
+ lessons: ["sequences"],
180
+ packages: ["seq"],
181
+ },
182
+ {
183
+ slug: "base-pair",
184
+ term: "Base pair",
185
+ category: "molecules",
186
+ definition: "Two bases, one on each strand, held together by hydrogen bonds: A with T, and G with C.",
187
+ detail:
188
+ "A G–C pair is held by three hydrogen bonds and an A–T pair by two, so G–C pairs are harder to pull apart. The length of double-stranded DNA is counted in base pairs, written bp; a thousand base pairs is a kilobase, kb.",
189
+ why: "Pairing is what lets one strand be rebuilt from the other, and it is the unit every fragment size is measured in.",
190
+ match: ["base pairs", "base pair"],
191
+ related: ["base", "complement", "gc-content"],
192
+ lessons: ["sequences", "cloning"],
193
+ packages: ["seq", "dseq"],
194
+ },
195
+ {
196
+ slug: "strand-direction",
197
+ term: "5′ and 3′ ends",
198
+ category: "molecules",
199
+ definition: "The two ends of a DNA strand are chemically different, and are called 5′ (five prime) and 3′ (three prime).",
200
+ detail:
201
+ "The names come from the numbered carbon atoms of the sugar in each nucleotide. Enzymes that copy DNA can only add to a 3′ end, so by convention a sequence is always written from 5′ to 3′. The two strands of a double helix run in opposite directions, which is called antiparallel.",
202
+ why: "Direction decides which way a gene is read and which way a primer is extended.",
203
+ match: ["opposite directions", "antiparallel"],
204
+ related: ["complement", "reverse-complement", "primer"],
205
+ lessons: ["sequences", "cloning"],
206
+ packages: ["seq", "dseq"],
207
+ },
208
+ {
209
+ slug: "complement",
210
+ term: "Complement",
211
+ category: "molecules",
212
+ definition: "The strand that pairs with a given strand: every A swapped for T, every C for G, and the reverse.",
213
+ detail:
214
+ "Written directly beneath the original, the complement reads from 3′ to 5′, which is backwards by the usual convention. That is why the reverse complement is usually the more useful thing to ask for.",
215
+ why: "It is the first step in working out what the other strand says.",
216
+ match: ["complement"],
217
+ related: ["reverse-complement", "base-pair", "strand-direction"],
218
+ lessons: ["sequences"],
219
+ packages: ["seq"],
220
+ },
221
+ {
222
+ slug: "reverse-complement",
223
+ term: "Reverse complement",
224
+ category: "molecules",
225
+ definition: "The opposite strand written in its own 5′ to 3′ direction: complement every base, then reverse the order.",
226
+ detail:
227
+ "Because the strands run in opposite directions, reading the partner strand the right way round means reading the complement from right to left. A sequence that equals its own reverse complement, such as GAATTC, is called palindromic.",
228
+ why: "A gene can lie on either strand, so software constantly has to switch to the other strand's point of view.",
229
+ match: ["reverse complement"],
230
+ related: ["complement", "strand-direction", "restriction-enzyme"],
231
+ lessons: ["sequences"],
232
+ packages: ["seq", "seqrecord"],
233
+ },
234
+ {
235
+ slug: "gc-content",
236
+ term: "GC content",
237
+ category: "molecules",
238
+ definition: "The fraction of the bases in a sequence that are G or C.",
239
+ detail:
240
+ "G–C pairs are more stable than A–T pairs, so DNA with a higher GC content needs more heat to separate. GC content also differs between organisms and between regions of a genome, which makes it a quick fingerprint of where a sequence came from.",
241
+ why: "It feeds directly into melting temperature, and so into every primer you design.",
242
+ match: ["GC content"],
243
+ related: ["base-pair", "melting-temperature", "primer"],
244
+ lessons: ["sequences"],
245
+ packages: ["seqtools"],
246
+ },
247
+ {
248
+ slug: "melting-temperature",
249
+ term: "Melting temperature",
250
+ category: "molecules",
251
+ definition: "The temperature at which half of the copies of a double-stranded DNA have separated into single strands.",
252
+ detail:
253
+ "Usually written Tm. It rises with length and with GC content, and it depends on the salt in the solution. For short pieces such as primers it can be estimated well from the sequence alone.",
254
+ why: "A PCR only works if both primers bind at the same temperature, so their melting temperatures have to match.",
255
+ match: ["melting temperatures", "melting temperature"],
256
+ related: ["gc-content", "primer", "pcr"],
257
+ lessons: ["sequences", "cloning"],
258
+ packages: ["seqtools", "pcr"],
259
+ },
260
+
261
+ // --- From gene to protein ---------------------------------------------------------------------
262
+ {
263
+ slug: "gene",
264
+ term: "Gene",
265
+ category: "genes",
266
+ definition: "A stretch of DNA that carries the instructions for one product, usually a protein.",
267
+ detail:
268
+ "A gene is more than its coding part. It has a promoter, where copying into RNA begins, and a terminator, where copying stops. Genes can lie on either strand, and in many organisms the coding part is split into pieces that are joined after copying.",
269
+ why: "Genes are the things most features in a sequence record describe.",
270
+ match: ["genes", "gene"],
271
+ related: ["feature", "transcription", "codon"],
272
+ lessons: ["sequences", "annotations"],
273
+ packages: ["seqfeature", "seqrecord"],
274
+ },
275
+ {
276
+ slug: "transcription",
277
+ term: "Transcription",
278
+ category: "genes",
279
+ definition: "Copying one strand of a gene into RNA.",
280
+ detail:
281
+ "RNA uses the same letters as DNA except that U takes the place of T. The copy, called messenger RNA, carries the gene's message to the machinery that builds proteins. In sequence terms transcription is simply replacing every T with U.",
282
+ why: "It is the first of the two steps between a gene and its protein.",
283
+ match: ["transcription", "transcribed"],
284
+ related: ["translation", "gene", "codon"],
285
+ lessons: ["sequences"],
286
+ packages: ["seq"],
287
+ },
288
+ {
289
+ slug: "translation",
290
+ term: "Translation",
291
+ category: "genes",
292
+ definition: "Reading messenger RNA three bases at a time to build a protein.",
293
+ detail:
294
+ "Each group of three bases names one amino acid, and the amino acids are joined in order into a chain. Translation normally begins at a start codon and ends at the first stop codon.",
295
+ why: "It is how software predicts the protein a piece of DNA encodes.",
296
+ match: ["translation"],
297
+ related: ["codon", "genetic-code", "reading-frame", "protein"],
298
+ lessons: ["sequences"],
299
+ packages: ["seq", "seqrecord"],
300
+ },
301
+ {
302
+ slug: "codon",
303
+ term: "Codon",
304
+ category: "genes",
305
+ definition: "Three consecutive bases that together specify one amino acid, or signal stop.",
306
+ detail:
307
+ "There are 64 possible codons and only 20 amino acids, so most amino acids are written by several codons. ATG both starts a protein and codes for methionine. In the standard code three codons, TAA, TAG and TGA, mean stop.",
308
+ why: "The codon is the unit of translation, and of most mutations that matter.",
309
+ match: ["codons", "codon"],
310
+ related: ["genetic-code", "reading-frame", "translation", "mutation"],
311
+ lessons: ["sequences"],
312
+ packages: ["seq"],
313
+ },
314
+ {
315
+ slug: "genetic-code",
316
+ term: "Genetic code",
317
+ category: "genes",
318
+ definition: "The table that says which amino acid each codon stands for.",
319
+ detail:
320
+ "The code is nearly the same in all living things, but not quite. Mitochondria and some microbes read a few codons differently, and the variants are catalogued as numbered tables. Translating with the wrong table gives the wrong protein.",
321
+ why: "Choosing the right table is the difference between a correct protein and a truncated one.",
322
+ match: ["genetic codes", "genetic code"],
323
+ related: ["codon", "translation"],
324
+ lessons: ["sequences"],
325
+ packages: ["seq"],
326
+ },
327
+ {
328
+ slug: "reading-frame",
329
+ term: "Reading frame",
330
+ category: "genes",
331
+ definition: "Which base you start counting codons from. Each strand can be read in three frames.",
332
+ detail:
333
+ "Shift the starting point by one base and every codon changes, so the same DNA spells three unrelated proteins per strand, six in all. A run of codons from a start to a stop with no stop in between is an open reading frame, or ORF, and is a candidate gene.",
334
+ why: "Finding the right frame is how genes are located in new sequence.",
335
+ match: ["reading frames", "reading frame"],
336
+ related: ["codon", "translation", "mutation"],
337
+ lessons: ["sequences"],
338
+ packages: ["seq", "seqtools"],
339
+ },
340
+ {
341
+ slug: "mutation",
342
+ term: "Mutation",
343
+ category: "genes",
344
+ definition: "A change in a DNA sequence.",
345
+ detail:
346
+ "A base can be substituted, or bases can be inserted or deleted. Within a gene, a substitution may leave the amino acid unchanged (silent), change it (missense) or create a stop (nonsense). An insertion or deletion that is not a multiple of three shifts the reading frame for everything after it.",
347
+ why: "Mutations are the raw material of evolution and the cause of many diseases, and comparing sequences is largely a matter of finding them.",
348
+ match: ["mutations", "mutation"],
349
+ related: ["codon", "reading-frame", "alignment"],
350
+ lessons: ["sequences", "alignment"],
351
+ packages: ["seq", "align"],
352
+ },
353
+ {
354
+ slug: "promoter",
355
+ term: "Promoter",
356
+ category: "genes",
357
+ definition: "The stretch of DNA just before a gene where the copying machinery attaches to begin transcription.",
358
+ detail:
359
+ "A promoter acts as the gene's on switch. A strong promoter means many RNA copies and a lot of protein; a weak one means little. In engineered DNA, the promoter is chosen to decide when and how much of a protein the cell makes.",
360
+ why: "Promoters are among the most commonly annotated features, and choosing one is a routine design decision.",
361
+ match: ["promoters", "promoter"],
362
+ related: ["gene", "transcription", "feature"],
363
+ lessons: ["annotations"],
364
+ packages: ["seqfeature", "features"],
365
+ },
366
+ {
367
+ slug: "exons-and-introns",
368
+ term: "Exons and introns",
369
+ category: "genes",
370
+ definition: "In animals, plants and fungi a gene is split into pieces: exons are kept, and the introns between them are removed from the RNA copy.",
371
+ detail:
372
+ "After a gene is transcribed, the introns are cut out and the exons joined, a step called splicing. Only the joined exons are translated. Bacterial genes are mostly continuous, with no introns.",
373
+ why: "It is why a gene's location in a database is often several ranges joined together and not one.",
374
+ match: ["exons", "introns", "exon", "intron"],
375
+ related: ["gene", "transcription", "feature"],
376
+ lessons: ["annotations"],
377
+ packages: ["seqfeature"],
378
+ },
379
+ {
380
+ slug: "start-and-stop-codons",
381
+ term: "Start and stop codons",
382
+ category: "genes",
383
+ definition: "The codons that mark where translation begins and ends.",
384
+ detail:
385
+ "Translation usually starts at ATG, which also codes for the amino acid methionine, so most proteins begin with it. It ends at the first stop codon in the same reading frame: TAA, TAG or TGA in the standard code. A stop codon adds no amino acid.",
386
+ why: "Finding them is how the beginning and end of a protein-coding region are located.",
387
+ match: ["start codon", "stop codons", "stop codon"],
388
+ related: ["codon", "open-reading-frame", "reading-frame", "genetic-code"],
389
+ lessons: ["sequences"],
390
+ packages: ["seq"],
391
+ },
392
+ {
393
+ slug: "open-reading-frame",
394
+ term: "Open reading frame",
395
+ category: "genes",
396
+ definition: "A run of codons that begins with a start codon and continues to the first stop codon, with no stop in between.",
397
+ detail:
398
+ "Usually shortened to ORF. In random sequence a stop codon turns up about once in every twenty codons, so a long stretch without one is unlikely to be chance and is a good candidate for a gene.",
399
+ why: "Scanning for long open reading frames is the simplest way to find genes in new sequence.",
400
+ match: ["open reading frames", "open reading frame", "ORF"],
401
+ related: ["start-and-stop-codons", "reading-frame", "gene"],
402
+ lessons: ["sequences"],
403
+ packages: ["seq", "seqtools"],
404
+ },
405
+
406
+ // --- Records and files ------------------------------------------------------------------------
407
+ {
408
+ slug: "feature",
409
+ term: "Feature",
410
+ category: "records",
411
+ definition: "A labelled region of a sequence, such as a gene, a promoter or a binding site.",
412
+ detail:
413
+ "A feature has a type, a location and a strand. The location may be a single range, several ranges joined together, or a range whose ends are only approximately known. A sequence together with its features and description is a record.",
414
+ why: "Features turn a string of letters into a map someone can use.",
415
+ match: ["features", "feature"],
416
+ related: ["gene", "coordinates", "plasmid"],
417
+ lessons: ["annotations"],
418
+ packages: ["seqfeature", "seqrecord", "seqedit", "features"],
419
+ },
420
+ {
421
+ slug: "plasmid",
422
+ term: "Plasmid",
423
+ category: "records",
424
+ definition: "A small circular DNA molecule, separate from the chromosome, that bacteria copy and pass on.",
425
+ detail:
426
+ "Laboratory plasmids carry an origin of replication so the cell copies them, a resistance gene so that cells holding the plasmid can be selected, and a place to insert the DNA you care about. A circle has no ends, so where the numbering starts is only a convention.",
427
+ why: "Plasmids are the standard vehicle for carrying engineered DNA into cells.",
428
+ match: ["plasmids", "plasmid"],
429
+ related: ["feature", "restriction-enzyme", "ligation"],
430
+ lessons: ["annotations", "cloning"],
431
+ packages: ["seqedit", "cloning", "seqmap", "dseq"],
432
+ },
433
+ {
434
+ slug: "coordinates",
435
+ term: "Zero-based and one-based coordinates",
436
+ category: "records",
437
+ definition: "Two ways of numbering positions: count the bases starting from 1, or count the gaps between them starting from 0.",
438
+ detail:
439
+ "Databases such as GenBank number bases from 1 and include both ends of a range. Most programming languages number from 0 and exclude the end. The same three bases are 3..5 in one system and 2 to 5 in the other, and mixing them up shifts everything by one.",
440
+ why: "Off-by-one errors between the two conventions are the most common bug in sequence software.",
441
+ match: ["0-based", "1-based"],
442
+ related: ["feature", "restriction-enzyme"],
443
+ lessons: ["annotations", "cloning"],
444
+ packages: ["seqfeature", "restriction"],
445
+ },
446
+ {
447
+ slug: "fasta",
448
+ term: "FASTA",
449
+ category: "records",
450
+ definition: "A plain-text sequence format: a line beginning with > that names the sequence, followed by the letters.",
451
+ detail:
452
+ "The sequence may be wrapped over several lines, and one file can hold many sequences one after another. FASTA stores nothing else, which is why almost every tool can read it.",
453
+ why: "It is the lowest common denominator for exchanging sequences.",
454
+ match: ["FASTA"],
455
+ related: ["fastq", "feature"],
456
+ lessons: ["files"],
457
+ packages: ["seqio"],
458
+ },
459
+ {
460
+ slug: "fastq",
461
+ term: "FASTQ and quality scores",
462
+ category: "records",
463
+ definition: "FASTA plus a quality score for every base, as written by sequencing machines.",
464
+ detail:
465
+ "Each score estimates the chance that the base is wrong. A score of 20 means 1 chance in 100, 30 means 1 in 1,000 and 40 means 1 in 10,000. To save space each score is stored as a single character, lined up beneath its base.",
466
+ why: "Quality scores let analysis ignore the bases a machine was unsure of.",
467
+ match: ["FASTQ", "quality scores", "quality score"],
468
+ related: ["fasta"],
469
+ lessons: ["files"],
470
+ packages: ["seqio"],
471
+ },
472
+
473
+ // --- At the bench -----------------------------------------------------------------------------
474
+ {
475
+ slug: "restriction-enzyme",
476
+ term: "Restriction enzyme",
477
+ category: "lab",
478
+ definition: "A protein that cuts DNA wherever it finds one specific short sequence.",
479
+ detail:
480
+ "Bacteria make these enzymes to destroy the DNA of invading viruses. Each recognises its own site, typically four to eight bases long, and cuts both strands at fixed points within or beside it. More than a thousand are known.",
481
+ why: "They are the scissors of molecular cloning, and predicting where they cut is the first step in planning it.",
482
+ match: ["restriction enzymes", "restriction enzyme"],
483
+ related: ["sticky-end", "blunt-end", "ligation", "gel-electrophoresis"],
484
+ lessons: ["cloning"],
485
+ packages: ["restriction", "cloning"],
486
+ },
487
+ {
488
+ slug: "sticky-end",
489
+ term: "Sticky end",
490
+ category: "lab",
491
+ definition: "A short single-stranded overhang left when an enzyme cuts the two strands a few bases apart.",
492
+ detail:
493
+ "The overhang can pair with any end carrying the complementary overhang, and with no other. Two fragments cut by the same enzyme therefore fit together, which is what makes cutting and pasting DNA predictable.",
494
+ why: "Whether two ends are compatible decides whether a planned ligation can work at all.",
495
+ match: ["sticky ends", "sticky end"],
496
+ related: ["blunt-end", "restriction-enzyme", "ligation"],
497
+ lessons: ["cloning"],
498
+ packages: ["restriction", "cloning", "dseq"],
499
+ },
500
+ {
501
+ slug: "blunt-end",
502
+ term: "Blunt end",
503
+ category: "lab",
504
+ definition: "An end with no overhang, left when an enzyme cuts both strands at the same position.",
505
+ detail:
506
+ "Any blunt end can be joined to any other, which is flexible but less efficient and gives no control over which way round a fragment goes in.",
507
+ why: "Knowing which enzymes leave blunt ends tells you when orientation has to be checked afterwards.",
508
+ match: ["blunt ends", "blunt end"],
509
+ related: ["sticky-end", "restriction-enzyme", "ligation"],
510
+ lessons: ["cloning"],
511
+ packages: ["restriction", "cloning", "dseq"],
512
+ },
513
+ {
514
+ slug: "ligation",
515
+ term: "Ligation",
516
+ category: "lab",
517
+ definition: "Joining two DNA ends into one continuous molecule, using the enzyme DNA ligase.",
518
+ detail:
519
+ "Ligase seals the backbone of each strand once two compatible ends have come together. Ligation is the reverse of a restriction cut: read the picture of a cut from bottom to top.",
520
+ why: "It is the paste in cut and paste.",
521
+ match: ["ligation", "ligase"],
522
+ related: ["sticky-end", "blunt-end", "plasmid"],
523
+ lessons: ["cloning"],
524
+ packages: ["cloning", "dseq"],
525
+ },
526
+ {
527
+ slug: "primer",
528
+ term: "Primer",
529
+ category: "lab",
530
+ definition: "A short single strand of DNA, usually 18 to 30 bases, that marks where copying should start.",
531
+ detail:
532
+ "A primer binds to the stretch of template it is complementary to, and the copying enzyme extends it from its 3′ end. Primers are made to order, so you choose exactly where they bind.",
533
+ why: "Primer design decides what a PCR amplifies and whether it works.",
534
+ match: ["primers", "primer"],
535
+ related: ["pcr", "melting-temperature", "strand-direction"],
536
+ lessons: ["cloning"],
537
+ packages: ["pcr", "seqtools"],
538
+ },
539
+ {
540
+ slug: "pcr",
541
+ term: "PCR",
542
+ category: "lab",
543
+ definition: "The polymerase chain reaction: a way of making millions of copies of one chosen stretch of DNA.",
544
+ detail:
545
+ "Two primers bind either side of the target, one on each strand, pointing towards each other. Each cycle of heating and cooling separates the strands, lets the primers bind, and copies the stretch between them, doubling the amount each time.",
546
+ why: "It is how the piece of DNA you want is obtained in the first place.",
547
+ match: ["PCR"],
548
+ related: ["primer", "melting-temperature", "gel-electrophoresis"],
549
+ lessons: ["cloning"],
550
+ packages: ["pcr"],
551
+ },
552
+ {
553
+ slug: "gel-electrophoresis",
554
+ term: "Gel electrophoresis",
555
+ category: "lab",
556
+ definition: "Sorting DNA fragments by size by pulling them through a gel with an electric field.",
557
+ detail:
558
+ "DNA is negatively charged, so it moves towards the positive electrode. The gel slows large fragments more than small ones, so fragments of one size gather into a band. A ladder of known sizes run alongside lets you read off how big each band is.",
559
+ why: "It is the everyday check that a digest or a PCR produced what was expected.",
560
+ match: ["gel electrophoresis", "gel"],
561
+ related: ["restriction-enzyme", "pcr", "base-pair"],
562
+ lessons: ["cloning"],
563
+ packages: ["gel"],
564
+ },
565
+ {
566
+ slug: "sequencing",
567
+ term: "Sequencing",
568
+ category: "lab",
569
+ definition: "Reading the order of the bases in a sample of DNA.",
570
+ detail:
571
+ "No machine reads a whole genome in one go. The DNA is broken into fragments, each fragment is read separately, and software pieces the results back together from where they overlap. Some machines produce very many short reads of a few hundred bases; others produce fewer reads that are thousands of bases long.",
572
+ why: "It is where nearly all sequence data comes from, and its limits explain why files hold fragments and quality scores.",
573
+ match: ["sequencing", "sequencers", "sequencer"],
574
+ related: ["read", "fastq", "genome"],
575
+ lessons: ["files"],
576
+ packages: ["seqio"],
577
+ },
578
+ {
579
+ slug: "read",
580
+ term: "Read",
581
+ category: "lab",
582
+ definition: "One stretch of sequence produced by a sequencing machine from a single fragment of DNA.",
583
+ detail:
584
+ "A sequencing run produces millions of reads. Each position in the original DNA is usually covered by many of them, and the number covering a position is called the coverage or depth. More coverage means more confidence that a base was read correctly.",
585
+ why: "A read is the unit a FASTQ file stores, one record per read.",
586
+ match: [],
587
+ related: ["sequencing", "fastq"],
588
+ lessons: ["files"],
589
+ packages: ["seqio"],
590
+ },
591
+ {
592
+ slug: "vector-and-insert",
593
+ term: "Vector and insert",
594
+ category: "lab",
595
+ definition: "The vector is the DNA molecule, usually a plasmid, used to carry a piece of DNA into a cell. The insert is the piece it carries.",
596
+ detail:
597
+ "Cloning means putting an insert into a vector. The vector is cut open, the insert is joined in, and the circle is closed again. The vector supplies everything the cell needs to keep and copy the molecule; the insert is the part you are interested in.",
598
+ why: "Every cloning plan is described as a vector plus one or more inserts.",
599
+ match: ["vectors", "vector"],
600
+ related: ["plasmid", "ligation", "restriction-enzyme", "gibson-assembly"],
601
+ lessons: ["cloning"],
602
+ packages: ["cloning", "dseq"],
603
+ },
604
+ {
605
+ slug: "transformation",
606
+ term: "Transformation",
607
+ category: "lab",
608
+ definition: "Getting DNA, usually a plasmid, into bacterial cells.",
609
+ detail:
610
+ "Bacteria are treated so that their outer layers become leaky for a moment, typically with a brief heat shock or an electric pulse, and some of them take up the plasmid. Only a small fraction do, which is why the next step is always selection.",
611
+ why: "It is the step that turns a tube of DNA into living cells that copy it.",
612
+ match: ["transformation"],
613
+ related: ["selection", "plasmid", "cell"],
614
+ lessons: ["cloning"],
615
+ packages: [],
616
+ },
617
+ {
618
+ slug: "selection",
619
+ term: "Selection",
620
+ category: "lab",
621
+ definition: "Keeping only the cells that took up a plasmid, usually by growing them with an antibiotic.",
622
+ detail:
623
+ "The plasmid carries a gene that makes the cell resistant to a particular antibiotic. When the cells are spread on a plate containing that antibiotic, only those with the plasmid survive. Each survivor multiplies into a visible spot called a colony, and every cell in a colony carries the same plasmid.",
624
+ why: "It is the reason almost every laboratory plasmid has a resistance gene among its features.",
625
+ match: ["antibiotic selection"],
626
+ related: ["transformation", "plasmid", "feature"],
627
+ lessons: ["cloning"],
628
+ packages: ["features"],
629
+ },
630
+ {
631
+ slug: "gibson-assembly",
632
+ term: "Gibson assembly",
633
+ category: "lab",
634
+ definition: "Joining DNA fragments whose ends overlap, in a single reaction and without restriction sites.",
635
+ detail:
636
+ "Each fragment is made so that its last 20 to 40 bases match the start of the next. In the reaction, one enzyme trims back one strand at every end to expose the matching stretches, which pair up; a second enzyme fills in the gaps and a third seals the joins. Several fragments can be joined at once, in a set order.",
637
+ why: "It has become one of the most common ways to build plasmids, and designing the overlaps is a job for software.",
638
+ match: ["Gibson assembly"],
639
+ related: ["ligation", "primer", "pcr", "vector-and-insert"],
640
+ lessons: ["cloning"],
641
+ packages: ["cloning", "assembly"],
642
+ },
643
+
644
+ // --- Comparing sequences ----------------------------------------------------------------------
645
+ {
646
+ slug: "alignment",
647
+ term: "Alignment",
648
+ category: "comparison",
649
+ definition: "Sequences arranged in rows so that positions believed to correspond sit in the same column.",
650
+ detail:
651
+ "Each column is a match, a mismatch or a gap. A scoring scheme rewards matches and penalises the others, and an algorithm finds the arrangement with the best total. A global alignment covers both sequences end to end; a local one finds only their best-matching parts.",
652
+ why: "Alignment is how similarity is measured, and almost every comparison starts from one.",
653
+ match: ["alignments", "alignment"],
654
+ related: ["gap", "mutation", "phylogenetic-tree", "motif"],
655
+ lessons: ["alignment", "phylogenetics"],
656
+ packages: ["align"],
657
+ },
658
+ {
659
+ slug: "gap",
660
+ term: "Gap",
661
+ category: "comparison",
662
+ definition: "A placeholder in an alignment where one sequence has bases and the other has none.",
663
+ detail:
664
+ "A gap stands for an insertion in one sequence or a deletion in the other; the alignment alone cannot say which. Opening a gap is usually penalised more heavily than extending one, because a single event often adds or removes several bases at once.",
665
+ why: "How gaps are scored changes which alignment comes out best.",
666
+ match: ["gaps", "gap"],
667
+ related: ["alignment", "mutation"],
668
+ lessons: ["alignment"],
669
+ packages: ["align"],
670
+ },
671
+ {
672
+ slug: "motif",
673
+ term: "Motif",
674
+ category: "comparison",
675
+ definition: "A short pattern that recurs in many sequences, such as the site a regulatory protein binds.",
676
+ detail:
677
+ "A motif is rarely one exact word. It is described by counting, for each position, how often each base appears among known examples. Those counts become scores, and sliding the scores along a new sequence finds likely sites.",
678
+ why: "Motifs are how binding sites and other signals are found in sequences nobody has studied yet.",
679
+ match: ["motifs", "motif"],
680
+ related: ["alignment", "feature"],
681
+ lessons: ["alignment"],
682
+ packages: ["motifs"],
683
+ },
684
+ {
685
+ slug: "phylogenetic-tree",
686
+ term: "Phylogenetic tree",
687
+ category: "comparison",
688
+ definition: "A branching diagram of descent: tips are sequences or species, and each fork is an inferred common ancestor.",
689
+ detail:
690
+ "Branch lengths usually stand for the amount of change. Trees are built from aligned sequences, either from the distances between them or by searching for the tree that needs the fewest changes.",
691
+ why: "Trees are how relationships are inferred, from the history of species to the spread of an outbreak.",
692
+ match: ["phylogenetic trees", "phylogenetic tree"],
693
+ related: ["clade", "newick", "alignment"],
694
+ lessons: ["phylogenetics"],
695
+ packages: ["phylo", "nexus"],
696
+ },
697
+ {
698
+ slug: "clade",
699
+ term: "Clade",
700
+ category: "comparison",
701
+ definition: "An ancestor together with all of its descendants: one complete branch of a tree.",
702
+ detail:
703
+ "Cut a tree at any branch and everything on the far side is a clade. Clades nest inside one another, and how often a clade reappears when the analysis is repeated on resampled data is a measure of how well supported it is.",
704
+ why: "Clades are the groupings a tree actually claims.",
705
+ match: ["clades", "clade"],
706
+ related: ["phylogenetic-tree", "newick"],
707
+ lessons: ["phylogenetics"],
708
+ packages: ["phylo"],
709
+ },
710
+ {
711
+ slug: "newick",
712
+ term: "Newick",
713
+ category: "comparison",
714
+ definition: "A way of writing a tree as text, using nested brackets.",
715
+ detail:
716
+ "Each pair of brackets is a fork and the names inside are its descendants, so ((A,B),C); says that A and B are closest relatives and C is further out. Branch lengths can follow a colon after each name.",
717
+ why: "Nearly every tree program reads and writes it.",
718
+ match: ["Newick"],
719
+ related: ["phylogenetic-tree", "clade"],
720
+ lessons: ["phylogenetics"],
721
+ packages: ["phylo", "nexus"],
722
+ },
723
+ {
724
+ slug: "homology",
725
+ term: "Homology",
726
+ category: "comparison",
727
+ definition: "Similarity between sequences that exists because they descend from a common ancestor.",
728
+ detail:
729
+ "Homology is a conclusion, not a measurement. Two sequences are either homologous or they are not, so it is not given as a percentage; what can be measured is how similar they are, and strong similarity is the evidence for homology. Homologous genes often do the same job, which is how the function of a newly sequenced gene is usually guessed.",
730
+ why: "It is the reasoning behind almost every sequence search: find something similar that is already understood.",
731
+ match: ["homology", "homologous"],
732
+ related: ["alignment", "identity-and-similarity", "phylogenetic-tree", "mutation"],
733
+ lessons: ["alignment", "phylogenetics"],
734
+ packages: ["align", "phylo"],
735
+ },
736
+ {
737
+ slug: "identity-and-similarity",
738
+ term: "Identity and similarity",
739
+ category: "comparison",
740
+ definition: "Two ways of scoring an alignment: the share of columns that match exactly, and the share that match or nearly match.",
741
+ detail:
742
+ "Percent identity counts only columns where the two letters are the same. For proteins, similarity also counts columns where one amino acid has been replaced by another of the same character, such as one positively charged amino acid for another. Similarity is therefore always at least as high as identity.",
743
+ why: "These are the two numbers most often quoted for how alike two sequences are, and they are easy to confuse.",
744
+ match: ["percent identity"],
745
+ related: ["alignment", "substitution-matrix", "homology"],
746
+ lessons: ["alignment"],
747
+ packages: ["align"],
748
+ },
749
+ {
750
+ slug: "substitution-matrix",
751
+ term: "Substitution matrix",
752
+ category: "comparison",
753
+ definition: "A table giving a score for aligning each letter with each other letter.",
754
+ detail:
755
+ "For proteins the scores come from counting which replacements actually occur in families of related proteins. A positive score means the pair is seen more often than chance would predict, and a negative score less often. BLOSUM62 is the most widely used; others suit closer or more distant relatives.",
756
+ why: "The matrix decides which alignment scores best, so choosing a different one can change the result.",
757
+ match: ["substitution matrices", "substitution matrix", "BLOSUM62"],
758
+ related: ["alignment", "identity-and-similarity", "amino-acid", "gap"],
759
+ lessons: ["alignment"],
760
+ packages: ["align"],
761
+ },
762
+ {
763
+ slug: "bootstrap",
764
+ term: "Bootstrap",
765
+ category: "comparison",
766
+ definition: "A way of measuring how well the data supports each branch of a tree, by rebuilding the tree many times from resampled data.",
767
+ detail:
768
+ "Columns of the alignment are drawn at random, with repeats allowed, to make a new alignment of the same size, and a tree is built from it. This is repeated a hundred or a thousand times. The support for a clade is the percentage of those trees in which it appears.",
769
+ why: "A tree always comes out fully resolved, whether or not the data justifies it. Bootstrap values say which parts to believe.",
770
+ match: ["bootstrap"],
771
+ related: ["phylogenetic-tree", "clade", "alignment"],
772
+ lessons: ["phylogenetics"],
773
+ packages: ["phylo", "nexus"],
774
+ },
775
+
776
+ // --- Structure --------------------------------------------------------------------------------
777
+ {
778
+ slug: "protein",
779
+ term: "Protein",
780
+ category: "structure",
781
+ definition: "A chain of amino acids that folds into a three-dimensional shape, and whose shape decides what it does.",
782
+ detail:
783
+ "Structures worked out by experiment are stored as lists of atom positions, organised as a hierarchy: a structure holds models, a model holds chains, a chain holds residues and a residue holds atoms.",
784
+ why: "Most of what a cell does is done by proteins, and their shape explains how.",
785
+ match: ["proteins", "protein"],
786
+ related: ["residue", "translation"],
787
+ lessons: ["sequences", "structures"],
788
+ packages: ["pdb", "seqtools"],
789
+ },
790
+ {
791
+ slug: "residue",
792
+ term: "Residue",
793
+ category: "structure",
794
+ definition: "One amino acid within a protein chain.",
795
+ detail:
796
+ "It is called a residue because a little of each amino acid is lost when it is joined to its neighbours. Every residue shares the same backbone atoms and differs in its side chain, which gives each amino acid its character.",
797
+ why: "Residues are the level at which structure and sequence line up.",
798
+ match: ["residues", "residue"],
799
+ related: ["protein"],
800
+ lessons: ["structures"],
801
+ packages: ["pdb"],
802
+ },
803
+ {
804
+ slug: "backbone-and-side-chain",
805
+ term: "Backbone and side chain",
806
+ category: "structure",
807
+ definition: "The two parts of every residue: the backbone, which is the same throughout the chain, and the side chain, which differs.",
808
+ detail:
809
+ "The backbone is a repeating run of three atoms per residue, a nitrogen and two carbons. The middle one, called the alpha carbon, is where the side chain attaches. Comparisons of protein shape often use only the alpha carbons, one point per residue.",
810
+ why: "Structure files name every atom this way, and most measurements pick out backbone atoms.",
811
+ match: ["side chains", "side chain"],
812
+ related: ["residue", "amino-acid", "secondary-structure", "rmsd"],
813
+ lessons: ["structures"],
814
+ packages: ["pdb"],
815
+ },
816
+ {
817
+ slug: "secondary-structure",
818
+ term: "Secondary structure",
819
+ category: "structure",
820
+ definition: "The regular local shapes a protein chain folds into, chiefly the alpha helix and the beta sheet.",
821
+ detail:
822
+ "In an alpha helix the chain coils like a spring, with about 3.6 residues to each turn. In a beta sheet, stretches of the chain called strands lie side by side. Both are held together by weak bonds between backbone atoms, and they are joined by less regular loops.",
823
+ why: "Helices and sheets are how protein shapes are described and drawn, and where a residue sits affects what a mutation there will do.",
824
+ match: ["secondary structure", "alpha helix", "beta sheet"],
825
+ related: ["protein", "residue", "backbone-and-side-chain"],
826
+ lessons: ["structures"],
827
+ packages: ["pdb", "seqtools"],
828
+ },
829
+ {
830
+ slug: "rmsd",
831
+ term: "RMSD",
832
+ category: "structure",
833
+ definition: "Root-mean-square deviation: a single number for how far apart two structures are once one has been laid over the other.",
834
+ detail:
835
+ "One structure is rotated and shifted to fit the other as closely as possible. The distance between each pair of matching atoms is then measured, and the RMSD is a kind of average of those distances, in ångströms. Zero means identical; for proteins, a value under about 2 Å usually means the two are very alike.",
836
+ why: "It is the standard way to say how similar two shapes are, or how far a prediction is from the real structure.",
837
+ match: ["RMSD"],
838
+ related: ["protein", "backbone-and-side-chain", "units"],
839
+ lessons: ["structures"],
840
+ packages: ["pdb", "svdsuperimposer"],
841
+ },
842
+ ];
843
+
844
+ /**
845
+ * Look a term up.
846
+ *
847
+ * @param slug - Its slug.
848
+ * @returns The term, or `undefined` if there is none by that slug.
849
+ *
850
+ * @example
851
+ * ```ts
852
+ * import { getEntry } from "@biolibs/glossary";
853
+ *
854
+ * getEntry("pcr")?.term; // "PCR"
855
+ * ```
856
+ */
857
+ export function getEntry(slug: string): GlossaryEntry | undefined {
858
+ return GLOSSARY.find((entry) => entry.slug === slug);
859
+ }
860
+
861
+ /**
862
+ * The term whose name is some text, ignoring case.
863
+ *
864
+ * @param name - The term, or one of the phrases that mean it.
865
+ * @returns The term, or `undefined` if no term goes by that name.
866
+ */
867
+ export function findEntryByName(name: string): GlossaryEntry | undefined {
868
+ const wanted = name.toLowerCase();
869
+ return GLOSSARY.find((entry) => entry.term.toLowerCase() === wanted || entry.match.some((m) => m.toLowerCase() === wanted));
870
+ }
871
+
872
+ /** The pictures shown in each lesson on the biolibs site, by the lesson's slug and then the term's. */
873
+ export const LESSON_FIGURES: Record<string, string[]> = {
874
+ sequences: ["reverse-complement", "codon", "reading-frame"],
875
+ annotations: ["feature", "plasmid"],
876
+ files: ["fasta", "fastq"],
877
+ alignment: ["alignment", "motif"],
878
+ phylogenetics: ["phylogenetic-tree"],
879
+ structures: ["protein"],
880
+ cloning: ["sticky-end", "pcr", "gel-electrophoresis"],
881
+ verification: [],
882
+ };
883
+
884
+ // --- Finding terms in running text --------------------------------------------------------------
885
+
886
+ const PHRASES = GLOSSARY.flatMap((entry) => entry.match.map((phrase) => ({ phrase, slug: entry.slug }))).sort(
887
+ (a, b) => b.phrase.length - a.phrase.length,
888
+ );
889
+ const escape = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
890
+ const PATTERN = new RegExp(`(?<![\\w-])(${PHRASES.map((p) => escape(p.phrase)).join("|")})(?![\\w-])`, "gi");
891
+ const SLUG_BY_PHRASE = new Map(PHRASES.map((p) => [p.phrase.toLowerCase(), p.slug]));
892
+
893
+ /** A stretch of text, and the term it mentions if it mentions one. */
894
+ export type TextPart = { text: string; slug?: string };
895
+
896
+ /**
897
+ * Split text at the first mention of each glossary term.
898
+ *
899
+ * @param text - Plain text.
900
+ * @param seen - Slugs already linked earlier on the page; matched terms are added to it, so each
901
+ * term is linked once per page and not on every mention.
902
+ * @param skip - Lower-case phrases to leave unlinked.
903
+ * @returns The text in pieces, in order, each either plain or the mention of one term.
904
+ *
905
+ * @example
906
+ * ```ts
907
+ * import { splitByTerms } from "@biolibs/glossary";
908
+ *
909
+ * splitByTerms("A primer binds.", new Set()).map((part) => part.slug ?? part.text);
910
+ * // [ "A ", "primer", " binds." ]
911
+ * ```
912
+ */
913
+ export function splitByTerms(text: string, seen: Set<string>, skip?: ReadonlySet<string>): TextPart[] {
914
+ const parts: TextPart[] = [];
915
+ let last = 0;
916
+ for (const match of text.matchAll(PATTERN)) {
917
+ const slug = SLUG_BY_PHRASE.get(match[0].toLowerCase());
918
+ if (!slug || seen.has(slug) || skip?.has(match[0].toLowerCase())) continue;
919
+ seen.add(slug);
920
+ if (match.index > last) parts.push({ text: text.slice(last, match.index) });
921
+ parts.push({ text: match[0], slug });
922
+ last = match.index + match[0].length;
923
+ }
924
+ if (last < text.length) parts.push({ text: text.slice(last) });
925
+ return parts;
926
+ }