imgt 0.1.0

Access the IMGT database from Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
use bincode::{Decode, Encode};
use mzcore::sequence::{Annotation, Peptidoform, Region, UnAmbiguous};
use serde::{Deserialize, Serialize};
use std::{fmt::Display, str::FromStr, sync::Arc};

use super::species::Species;

/// A selection of germlines from a single species.
#[derive(Debug, Decode, Deserialize, Encode, Serialize)]
pub struct Germlines {
    /// The species of this selection of germlines
    pub species: Species,
    /// All heavy chain options
    pub h: Chain,
    /// All kappa light chain options
    pub k: Chain,
    /// All lambda light chain options
    pub l: Chain,
    /// All iota chain options
    pub i: Chain,
}

impl Germlines {
    /// Create a new empty collection
    pub fn new(species: Species) -> Self {
        Self {
            species,
            h: Chain::default(),
            k: Chain::default(),
            l: Chain::default(),
            i: Chain::default(),
        }
    }

    /// Insert a germline into this collection
    pub fn insert(&mut self, germline: Germline) {
        match &germline.name.chain {
            ChainType::Heavy => self.h.insert(germline),
            ChainType::LightKappa => self.k.insert(germline),
            ChainType::LightLambda => self.l.insert(germline),
            ChainType::Iota => self.i.insert(germline),
        }
    }
}

impl<'a> IntoIterator for &'a Germlines {
    type IntoIter = std::array::IntoIter<(ChainType, &'a Chain), 4>;
    type Item = (ChainType, &'a Chain);

    fn into_iter(self) -> Self::IntoIter {
        [
            (ChainType::Heavy, &self.h),
            (ChainType::LightKappa, &self.k),
            (ChainType::LightLambda, &self.l),
            (ChainType::Iota, &self.i),
        ]
        .into_iter()
    }
}

impl Germlines {
    /// Iterate over the chains
    pub fn iter(
        &self,
    ) -> impl DoubleEndedIterator<Item = (ChainType, &Chain)> + ExactSizeIterator + '_ {
        [
            (ChainType::Heavy, &self.h),
            (ChainType::LightKappa, &self.k),
            (ChainType::LightLambda, &self.l),
            (ChainType::Iota, &self.i),
        ]
        .into_iter()
    }
}

#[cfg(feature = "rayon")]
use rayon::prelude::*;
#[cfg(feature = "rayon")]
impl<'a> IntoParallelIterator for &'a Germlines {
    type Iter = rayon::array::IntoIter<(ChainType, &'a Chain), 4>;
    type Item = (ChainType, &'a Chain);

    fn into_par_iter(self) -> Self::Iter {
        [
            (ChainType::Heavy, &self.h),
            (ChainType::LightKappa, &self.k),
            (ChainType::LightLambda, &self.l),
            (ChainType::Iota, &self.i),
        ]
        .into_par_iter()
    }
}

/// The intermediate representation for a chain
#[derive(Debug, Decode, Default, Deserialize, Encode, Serialize)]
pub struct Chain {
    /// All V/variable germlines
    pub variable: Vec<Arc<Germline>>,
    /// All J/joining germlines
    pub joining: Vec<Arc<Germline>>,
    /// All C/constant germlines
    pub c: Vec<Arc<Germline>>,
    /// All A constant germlines
    pub a: Vec<Arc<Germline>>,
    /// All D constant germlines
    pub d: Vec<Arc<Germline>>,
    /// All E constant germlines
    pub e: Vec<Arc<Germline>>,
    /// All G constant germlines
    pub g: Vec<Arc<Germline>>,
    /// All M constant germlines
    pub m: Vec<Arc<Germline>>,
    /// All O constant germlines
    pub o: Vec<Arc<Germline>>,
    /// All T constant germlines
    pub t: Vec<Arc<Germline>>,
}

impl Chain {
    /// # Panics
    /// It panics when it inserts an allele it has already placed (has to be filtered and ranked before)
    pub fn insert(&mut self, mut germline: Germline) {
        let db = match &germline.name.kind {
            GeneType::V => &mut self.variable,
            GeneType::J => &mut self.joining,
            GeneType::C(None) => &mut self.c,
            GeneType::C(Some(Constant::A)) => &mut self.a,
            GeneType::C(Some(Constant::D)) => &mut self.d,
            GeneType::C(Some(Constant::E)) => &mut self.e,
            GeneType::C(Some(Constant::G)) => &mut self.g,
            GeneType::C(Some(Constant::M)) => &mut self.m,
            GeneType::C(Some(Constant::O)) => &mut self.o,
            GeneType::C(Some(Constant::T)) => &mut self.t,
        };

        match db.binary_search_by_key(&germline.name, |g| g.name.clone()) {
            // If there are multiple copies of the same region keep the one with the most annotations + regions
            Ok(index) => {
                match db[index]
                    .alleles
                    .binary_search_by_key(&germline.alleles[0].0, |a| a.0)
                {
                    Ok(_allele_index) => {
                        // if germline.alleles[0].1.sequence
                        //     == db[index].alleles[allele_index].1.sequence
                        // {
                        //     db[index].alleles[allele_index].2 = format!(
                        //         "{}|{}",
                        //         db[index].alleles[allele_index].2, germline.alleles[0].2
                        //     );
                        // } else {
                        //     let mut found = false;
                        //     for existing in &mut db[index].duplicates {
                        //         if existing.1.sequence == germline.alleles[0].1.sequence {
                        //             existing.2 =
                        //                 format!("{}|{}", existing.2, germline.alleles[0].2);
                        //             found = true;
                        //         }
                        //     }
                        //     if !found {
                        //         db[index].duplicates.push(germline.alleles.pop().unwrap())
                        //     }
                        // }
                        // if germline.alleles[0].1.conserved.len()
                        //     + germline.alleles[0].1.regions.len()
                        //     > db[index].alleles[allele_index].1.conserved.len()
                        //         + db[index].alleles[allele_index].1.regions.len()
                        // {
                        //     db[index].alleles[allele_index] = germline.alleles.pop().unwrap()
                        // }
                        panic!(
                            "Not allowed to have multiple sequences for one allele in a germline"
                        )
                    }
                    Err(allele_index) => Arc::get_mut(&mut db[index])
                        .map(|g| {
                            g.alleles
                                .insert(allele_index, germline.alleles.pop().unwrap())
                        })
                        .expect("Multiple copies of Arc while building IMGT structure"),
                }
            }
            Err(index) => db.insert(index, Arc::new(germline)),
        }
    }

    /// Create a row for use in the documentation of the numbers of different sequences available
    pub fn doc_row(&self) -> String {
        format!(
            "|{}/{}|{}/{}|{}/{}|",
            self.variable.len(),
            self.variable.iter().map(|g| g.alleles.len()).sum::<usize>(),
            self.joining.len(),
            self.joining.iter().map(|g| g.alleles.len()).sum::<usize>(),
            self.c.len()
                + self.a.len()
                + self.d.len()
                + self.e.len()
                + self.g.len()
                + self.m.len()
                + self.o.len()
                + self.t.len(),
            self.c.iter().map(|g| g.alleles.len()).sum::<usize>()
                + self.a.iter().map(|g| g.alleles.len()).sum::<usize>()
                + self.d.iter().map(|g| g.alleles.len()).sum::<usize>()
                + self.e.iter().map(|g| g.alleles.len()).sum::<usize>()
                + self.g.iter().map(|g| g.alleles.len()).sum::<usize>()
                + self.m.iter().map(|g| g.alleles.len()).sum::<usize>()
                + self.o.iter().map(|g| g.alleles.len()).sum::<usize>()
                + self.t.iter().map(|g| g.alleles.len()).sum::<usize>(),
        )
    }
}

impl<'a> IntoIterator for &'a Chain {
    type IntoIter = std::array::IntoIter<(GeneType, &'a [Arc<Germline>]), 10>;
    type Item = (GeneType, &'a [Arc<Germline>]);

    fn into_iter(self) -> Self::IntoIter {
        [
            (GeneType::V, self.variable.as_slice()),
            (GeneType::J, self.joining.as_slice()),
            (GeneType::C(None), self.c.as_slice()),
            (GeneType::C(Some(Constant::A)), self.a.as_slice()),
            (GeneType::C(Some(Constant::D)), self.d.as_slice()),
            (GeneType::C(Some(Constant::E)), self.e.as_slice()),
            (GeneType::C(Some(Constant::G)), self.g.as_slice()),
            (GeneType::C(Some(Constant::M)), self.m.as_slice()),
            (GeneType::C(Some(Constant::O)), self.o.as_slice()),
            (GeneType::C(Some(Constant::T)), self.t.as_slice()),
        ]
        .into_iter()
    }
}

impl Chain {
    /// Iterate over the genes
    pub fn iter(
        &self,
    ) -> impl DoubleEndedIterator<Item = (GeneType, &[Arc<Germline>])> + ExactSizeIterator + '_
    {
        [
            (GeneType::V, self.variable.as_slice()),
            (GeneType::J, self.joining.as_slice()),
            (GeneType::C(None), self.c.as_slice()),
            (GeneType::C(Some(Constant::A)), self.a.as_slice()),
            (GeneType::C(Some(Constant::D)), self.d.as_slice()),
            (GeneType::C(Some(Constant::E)), self.e.as_slice()),
            (GeneType::C(Some(Constant::G)), self.g.as_slice()),
            (GeneType::C(Some(Constant::M)), self.m.as_slice()),
            (GeneType::C(Some(Constant::O)), self.o.as_slice()),
            (GeneType::C(Some(Constant::T)), self.t.as_slice()),
        ]
        .into_iter()
    }
}

#[cfg(feature = "rayon")]
impl<'a> IntoParallelIterator for &'a Chain {
    type Iter = rayon::array::IntoIter<(GeneType, &'a [Arc<Germline>]), 10>;
    type Item = (GeneType, &'a [Arc<Germline>]);

    fn into_par_iter(self) -> Self::Iter {
        [
            (GeneType::V, self.variable.as_slice()),
            (GeneType::J, self.joining.as_slice()),
            (GeneType::C(None), self.c.as_slice()),
            (GeneType::C(Some(Constant::A)), self.a.as_slice()),
            (GeneType::C(Some(Constant::D)), self.d.as_slice()),
            (GeneType::C(Some(Constant::E)), self.e.as_slice()),
            (GeneType::C(Some(Constant::G)), self.g.as_slice()),
            (GeneType::C(Some(Constant::M)), self.m.as_slice()),
            (GeneType::C(Some(Constant::O)), self.o.as_slice()),
            (GeneType::C(Some(Constant::T)), self.t.as_slice()),
        ]
        .into_par_iter()
    }
}

/// Intermediate representation for germline
#[derive(Clone, Debug, Decode, Deserialize, Encode, Serialize)]
pub struct Germline {
    /// The species for this germline
    pub species: Species,
    /// The name for the germline
    pub name: Gene,
    /// All alleles
    pub alleles: Vec<(usize, AnnotatedSequence)>,
}

impl<'a> IntoIterator for &'a Germline {
    type IntoIter = std::slice::Iter<'a, (usize, AnnotatedSequence)>;
    type Item = &'a (usize, AnnotatedSequence);

    fn into_iter(self) -> Self::IntoIter {
        self.alleles.iter()
    }
}

impl Germline {
    /// Iterate over the sequences
    pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter {
        self.into_iter()
    }
}

#[cfg(feature = "rayon")]
impl<'a> IntoParallelIterator for &'a Germline {
    type Iter = rayon::slice::Iter<'a, (usize, AnnotatedSequence)>;
    type Item = &'a (usize, AnnotatedSequence);

    fn into_par_iter(self) -> Self::Iter {
        self.alleles.par_iter()
    }
}

/// Intermediate representation for annotated sequence
#[derive(Clone, Debug, Decode, Deserialize, Encode, Serialize)]
pub struct AnnotatedSequence {
    /// The sequence
    pub sequence: Peptidoform<UnAmbiguous>,
    /// The different regions in the sequence, defined by their name and length
    pub regions: Vec<(Region, usize)>,
    /// 0 based locations of single amino acid annotations, overlapping with the regions defined above
    pub annotations: Vec<(Annotation, usize)>,
}

impl AnnotatedSequence {
    /// Create a new annotated sequence
    pub fn new(
        sequence: Peptidoform<UnAmbiguous>,
        regions: Vec<(Region, usize)>,
        mut conserved: Vec<(Annotation, usize)>,
    ) -> Self {
        conserved.sort_unstable_by_key(|c| c.1);
        Self {
            sequence,
            regions,
            annotations: conserved,
        }
    }
}

/// A germline gene name, broken up in its constituent parts.
#[derive(
    Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize, Hash, Decode, Encode,
)]
pub struct Gene {
    /// The chain of this gene (heavy/kappa etc)
    pub chain: ChainType,
    /// The kind of gene (V/J/C)
    pub kind: GeneType,
    /// If present the additional number _IGHV_ **(I)**
    pub number: Option<usize>,
    /// The family indicators _IGHV_ **-1D**
    pub family: Vec<(Option<usize>, String)>,
}

impl Display for Gene {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        const fn to_roman(n: usize) -> &'static str {
            [
                "0", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X",
            ][n]
        }

        write!(
            f,
            "IG{}{}{}{}",
            self.chain,
            self.kind,
            self.number
                .as_ref()
                .map_or_else(String::new, |n| format!("({})", to_roman(*n))),
            if self.number.is_some() && !self.family.is_empty() {
                "-"
            } else {
                ""
            }
        )?;

        let mut first = true;
        let mut last_str = false;
        for element in &self.family {
            if !first && !last_str {
                write!(f, "-")?;
            }
            write!(
                f,
                "{}{}",
                element.0.map(|i| i.to_string()).unwrap_or_default(),
                element.1
            )?;
            last_str = !element.1.is_empty();
            first = false;
        }
        Ok(())
    }
}

impl Gene {
    /// Get an IMGT name with allele, eg IGHV3-23*03
    /// # Errors
    /// If not recognised as a name, returns a description of the error.
    #[expect(clippy::missing_panics_doc)] // Cannot panic
    pub fn from_imgt_name_with_allele(s: &str) -> Result<(Self, usize), String> {
        let s = s.split(" or ").next().unwrap(); // Just ignore double names
        let (gene, tail) = Self::from_imgt_name_internal(s)?;
        if tail.is_empty() {
            return Ok((gene, 1));
        }
        let allele = tail.strip_prefix('*').map_or_else(
            || Err(format!("Invalid allele spec: `{tail}`")),
            |tail| {
                tail.parse()
                    .map_err(|_| format!("Invalid allele spec: `{}`", &tail))
            },
        )?;
        Ok((gene, allele))
    }

    /// Get an IMGT name, eg IGHV3-23
    /// # Errors
    /// If not recognised as a name, returns a description of the error.
    pub fn from_imgt_name(s: &str) -> Result<Self, String> {
        Self::from_imgt_name_internal(s).map(|(gene, _)| gene)
    }

    /// # Errors
    /// If not recognised as a name, returns a description of the error.
    fn from_imgt_name_internal(s: &str) -> Result<(Self, &str), String> {
        #[expect(clippy::missing_panics_doc)] // Cannot panic
        fn parse_name(s: &str) -> (Option<(Option<usize>, String)>, &str) {
            let num = s
                .chars()
                .take_while(char::is_ascii_digit)
                .collect::<String>();
            let tail = s
                .chars()
                .skip(num.len())
                .take_while(char::is_ascii_alphabetic)
                .collect::<String>();
            let rest = &s[num.len() + tail.len()..];
            if num.is_empty() && tail.is_empty() {
                return (None, s);
            }
            let num = if num.is_empty() {
                None
            } else {
                Some(num.parse().unwrap())
            };
            (Some((num, tail)), rest)
        }

        fn from_roman(s: &str) -> Option<usize> {
            match s {
                "" | "I" => Some(1),
                "" | "II" => Some(2),
                "" | "III" => Some(3),
                "" | "IV" => Some(4),
                "" | "V" => Some(5),
                "" | "VI" => Some(6),
                "" | "VII" => Some(7),
                "" | "VIII" => Some(8),
                "" | "IX" => Some(9),
                "" | "X" => Some(10),
                _ => None,
            }
        }

        if s.starts_with("IG") {
            let chain = s[2..3]
                .parse()
                .map_err(|()| format!("Invalid chain: `{}`", &s[2..3]))?;
            let gene = s[3..4]
                .parse()
                .map_err(|()| format!("Invalid gene: `{}`", &s[3..4]))?;
            let mut start = 4;
            let number = if s.len() > 4 && &s[4..5] == "(" {
                let end = s[5..]
                    .find(')')
                    .ok_or_else(|| format!("Invalid gene number `{}` out of `{}`", &s[4..], s))?;
                start += end + 2;
                Some(from_roman(&s[5..5 + end]).ok_or_else(|| {
                    format!("Invalid roman numeral (or too big) `{}`", &s[5..5 + end])
                })?)
            } else {
                None
            };
            let tail = &s[start..];
            let mut tail = tail.trim_start_matches('-');
            let mut family = Vec::new();
            while let (Some(branch), t) = parse_name(tail) {
                family.push(branch);
                tail = t.trim_start_matches('-');
            }

            Ok((
                Self {
                    chain,
                    kind: gene,
                    number,
                    family,
                },
                tail,
            ))
        } else {
            Err("Gene name does not start with IG")?
        }
    }
}

/// Any chain type of germline
#[derive(
    Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Decode, Encode,
)]
pub enum ChainType {
    /// Heavy chain
    Heavy = 0,
    /// Light kappa chain
    LightKappa,
    /// Light lambda chain
    LightLambda,
    /// Fish I kind
    Iota,
}

impl TryFrom<usize> for ChainType {
    type Error = ();
    fn try_from(i: usize) -> Result<Self, Self::Error> {
        match i {
            0 => Ok(Self::Heavy),
            1 => Ok(Self::LightKappa),
            2 => Ok(Self::LightLambda),
            3 => Ok(Self::Iota),
            _ => Err(()),
        }
    }
}

impl FromStr for ChainType {
    type Err = ();
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "H" => Ok(Self::Heavy),
            "κ" | "K" => Ok(Self::LightKappa),
            "λ" | "L" => Ok(Self::LightLambda),
            "ι" | "I" => Ok(Self::Iota),
            _ => Err(()),
        }
    }
}

impl Display for ChainType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                Self::Heavy => "H",
                Self::LightKappa => "K",
                Self::LightLambda => "L",
                Self::Iota => "I",
            }
        )
    }
}

/// Any gene in a germline, eg variable, joining
#[derive(
    Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Decode, Encode,
)]
pub enum GeneType {
    /// Variable
    V,
    /// Joining
    J,
    /// Constant, potentially with the type of constant given as well
    C(Option<Constant>),
}

/// Any type of constant gene
#[allow(missing_docs)]
#[derive(
    Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Decode, Encode,
)]
pub enum Constant {
    A,
    D,
    E,
    G,
    M,
    O,
    // DD,
    // MD,
    T,
}

impl FromStr for GeneType {
    type Err = ();
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "V" => Ok(Self::V),
            "J" => Ok(Self::J),
            "C" => Ok(Self::C(None)),
            "α" | "A" => Ok(Self::C(Some(Constant::A))),
            "δ" | "D" => Ok(Self::C(Some(Constant::D))),
            "ε" | "E" => Ok(Self::C(Some(Constant::E))),
            "ɣ" | "G" => Ok(Self::C(Some(Constant::G))),
            "μ" | "M" => Ok(Self::C(Some(Constant::M))),
            "ο" | "O" => Ok(Self::C(Some(Constant::O))),
            "τ" | "T" => Ok(Self::C(Some(Constant::T))),
            // "DD" => Ok(Self::C(Some(Constant::DD))),
            // "MD" => Ok(Self::C(Some(Constant::MD))),
            _ => Err(()),
        }
    }
}

impl Display for GeneType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                Self::V => "V",
                Self::J => "J",
                Self::C(None) => "C",
                Self::C(Some(Constant::A)) => "A",
                Self::C(Some(Constant::D)) => "D",
                Self::C(Some(Constant::E)) => "E",
                Self::C(Some(Constant::G)) => "G",
                Self::C(Some(Constant::M)) => "M",
                Self::C(Some(Constant::O)) => "O",
                // Self::C(Some(Constant::DD)) => "DD",
                // Self::C(Some(Constant::MD)) => "MD",
                Self::C(Some(Constant::T)) => "T",
            }
        )
    }
}

#[expect(clippy::missing_panics_doc)]
#[test]
fn imgt_names() {
    assert_eq!(
        Gene::from_imgt_name_with_allele("IGHV3-23*03")
            .map(|(g, a)| (g.to_string(), a))
            .unwrap(),
        ("IGHV3-23".to_string(), 3)
    );
    assert_eq!(
        Gene::from_imgt_name_with_allele("IGKV6-d*01")
            .map(|(g, a)| (g.to_string(), a))
            .unwrap(),
        ("IGKV6-d".to_string(), 1)
    );
}