ferro-hgvs 0.2.0

HGVS variant normalizer - part of the ferro bioinformatics toolkit
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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
//! Input preprocessor for normalizing HGVS input strings.
//!
//! The preprocessor applies corrections to common input errors before
//! parsing, based on the configured error handling mode.

use super::corrections::{
    correct_accession_prefix_case, correct_dash_characters, correct_missing_coordinate_prefix,
    correct_old_allele_format, correct_protein_arrow, correct_quote_characters, correct_whitespace,
    detect_position_zero, strip_trailing_annotation, DetectedCorrection,
};
use super::types::{ErrorType, ResolvedAction};
use super::ErrorConfig;
use crate::error::{Diagnostic, ErrorCode, FerroError, SourceSpan};

/// Warning about a correction made during preprocessing.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CorrectionWarning {
    /// The type of error that was corrected.
    pub error_type: ErrorType,
    /// Human-readable message about the correction.
    pub message: String,
    /// Position in the original input (start, end).
    pub span: Option<(usize, usize)>,
    /// The original value that was corrected.
    pub original: String,
    /// The corrected value.
    pub corrected: String,
}

impl CorrectionWarning {
    /// Create a new correction warning.
    pub fn new(
        error_type: ErrorType,
        message: impl Into<String>,
        span: Option<(usize, usize)>,
        original: impl Into<String>,
        corrected: impl Into<String>,
    ) -> Self {
        Self {
            error_type,
            message: message.into(),
            span,
            original: original.into(),
            corrected: corrected.into(),
        }
    }

    /// Create from a DetectedCorrection.
    pub fn from_correction(correction: &DetectedCorrection) -> Self {
        Self {
            error_type: correction.error_type,
            message: correction.warning_message(),
            span: Some((correction.start, correction.end)),
            original: correction.original.clone(),
            corrected: correction.corrected.clone(),
        }
    }
}

/// Result of preprocessing an input string.
#[derive(Debug, Clone)]
pub struct PreprocessResult {
    /// The original input.
    pub original: String,
    /// The preprocessed input (may be same as original if no corrections).
    pub preprocessed: String,
    /// Warnings generated during preprocessing.
    pub warnings: Vec<CorrectionWarning>,
    /// Whether preprocessing was successful (no rejected errors).
    pub success: bool,
    /// Error if preprocessing failed due to a rejected error.
    pub error: Option<FerroError>,
}

impl PreprocessResult {
    /// Create a successful result with no changes.
    pub fn unchanged(input: String) -> Self {
        Self {
            original: input.clone(),
            preprocessed: input,
            warnings: Vec::new(),
            success: true,
            error: None,
        }
    }

    /// Create a successful result with corrections.
    pub fn corrected(
        original: String,
        preprocessed: String,
        warnings: Vec<CorrectionWarning>,
    ) -> Self {
        Self {
            original,
            preprocessed,
            warnings,
            success: true,
            error: None,
        }
    }

    /// Create a failed result.
    pub fn failed(original: String, error: FerroError) -> Self {
        Self {
            original: original.clone(),
            preprocessed: original,
            warnings: Vec::new(),
            success: false,
            error: Some(error),
        }
    }

    /// Returns true if there were any corrections made.
    pub fn has_corrections(&self) -> bool {
        self.original != self.preprocessed
    }

    /// Returns true if there were any warnings.
    pub fn has_warnings(&self) -> bool {
        !self.warnings.is_empty()
    }
}

/// Input preprocessor that normalizes HGVS input strings.
#[derive(Debug, Clone)]
pub struct InputPreprocessor {
    /// The error handling configuration.
    config: ErrorConfig,
}

impl InputPreprocessor {
    /// Create a new preprocessor with the given configuration.
    pub fn new(config: ErrorConfig) -> Self {
        Self { config }
    }

    /// Create a preprocessor with strict mode.
    pub fn strict() -> Self {
        Self::new(ErrorConfig::strict())
    }

    /// Create a preprocessor with lenient mode.
    pub fn lenient() -> Self {
        Self::new(ErrorConfig::lenient())
    }

    /// Create a preprocessor with silent mode.
    pub fn silent() -> Self {
        Self::new(ErrorConfig::silent())
    }

    /// Get the resolved action for an error type.
    fn action_for(&self, error_type: ErrorType) -> ResolvedAction {
        self.config.action_for(error_type)
    }

    /// Preprocess the input string.
    ///
    /// Applies corrections based on the configured error handling mode.
    pub fn preprocess(&self, input: &str) -> PreprocessResult {
        // Start with the original input
        let mut current = input.to_string();
        let mut all_warnings = Vec::new();

        // Phase 1: Check for position zero (never correctable, always rejected)
        // Position zero is a fundamental HGVS error that cannot be auto-corrected,
        // so we always reject it regardless of the error handling mode.
        if let Some(pos) = detect_position_zero(&current) {
            return PreprocessResult::failed(
                input.to_string(),
                FerroError::parse_with_diagnostic(
                    pos,
                    "Position 0 is not valid in HGVS notation",
                    Diagnostic::new()
                        .with_code(ErrorCode::InvalidPosition)
                        .with_span(SourceSpan::new(pos, pos + 1))
                        .with_source(input)
                        .with_hint("HGVS positions start at 1, not 0"),
                ),
            );
        }

        // Phase 2: Normalize dash characters
        let (corrected, corrections) = correct_dash_characters(&current);
        if !corrections.is_empty() {
            let action = self.action_for(ErrorType::WrongDashCharacter);
            match action {
                ResolvedAction::Reject => {
                    let first = &corrections[0];
                    return PreprocessResult::failed(
                        input.to_string(),
                        FerroError::parse_with_diagnostic(
                            first.start,
                            format!("Invalid dash character '{}', expected '-'", first.original),
                            Diagnostic::new()
                                .with_code(ErrorCode::UnexpectedChar)
                                .with_span(SourceSpan::new(first.start, first.end))
                                .with_source(input)
                                .with_suggestion(corrected.clone()),
                        ),
                    );
                }
                ResolvedAction::WarnCorrect => {
                    for c in &corrections {
                        all_warnings.push(CorrectionWarning::from_correction(c));
                    }
                    current = corrected;
                }
                ResolvedAction::SilentCorrect => {
                    current = corrected;
                }
                ResolvedAction::Accept => {
                    // Keep original
                }
            }
        }

        // Phase 3: Normalize quote characters
        let (corrected, corrections) = correct_quote_characters(&current);
        if !corrections.is_empty() {
            let action = self.action_for(ErrorType::WrongQuoteCharacter);
            match action {
                ResolvedAction::Reject => {
                    let first = &corrections[0];
                    return PreprocessResult::failed(
                        input.to_string(),
                        FerroError::parse_with_diagnostic(
                            first.start,
                            format!(
                                "Invalid quote character '{}', expected regular quotes",
                                first.original
                            ),
                            Diagnostic::new()
                                .with_code(ErrorCode::UnexpectedChar)
                                .with_span(SourceSpan::new(first.start, first.end))
                                .with_source(input)
                                .with_suggestion(corrected.clone()),
                        ),
                    );
                }
                ResolvedAction::WarnCorrect => {
                    for c in &corrections {
                        all_warnings.push(CorrectionWarning::from_correction(c));
                    }
                    current = corrected;
                }
                ResolvedAction::SilentCorrect => {
                    current = corrected;
                }
                ResolvedAction::Accept => {}
            }
        }

        // Phase 4: Normalize whitespace
        let (corrected, corrections) = correct_whitespace(&current);
        if !corrections.is_empty() {
            let action = self.action_for(ErrorType::ExtraWhitespace);
            match action {
                ResolvedAction::Reject => {
                    let first = &corrections[0];
                    return PreprocessResult::failed(
                        input.to_string(),
                        FerroError::parse_with_diagnostic(
                            first.start,
                            "Extra whitespace in HGVS description",
                            Diagnostic::new()
                                .with_code(ErrorCode::UnexpectedChar)
                                .with_span(SourceSpan::new(first.start, first.end))
                                .with_source(input)
                                .with_suggestion(corrected.clone()),
                        ),
                    );
                }
                ResolvedAction::WarnCorrect => {
                    for c in &corrections {
                        all_warnings.push(CorrectionWarning::from_correction(c));
                    }
                    current = corrected;
                }
                ResolvedAction::SilentCorrect => {
                    current = corrected;
                }
                ResolvedAction::Accept => {}
            }
        }

        // Phase 5: Correct accession prefix case
        let (corrected, corrections) = correct_accession_prefix_case(&current);
        if !corrections.is_empty() {
            let action = self.action_for(ErrorType::LowercaseAccessionPrefix);
            match action {
                ResolvedAction::Reject => {
                    let first = &corrections[0];
                    return PreprocessResult::failed(
                        input.to_string(),
                        FerroError::parse_with_diagnostic(
                            first.start,
                            format!(
                                "Lowercase accession prefix '{}', expected uppercase",
                                first.original
                            ),
                            Diagnostic::new()
                                .with_code(ErrorCode::InvalidAccession)
                                .with_span(SourceSpan::new(first.start, first.end))
                                .with_source(input)
                                .with_suggestion(corrected.clone()),
                        ),
                    );
                }
                ResolvedAction::WarnCorrect => {
                    for c in &corrections {
                        all_warnings.push(CorrectionWarning::from_correction(c));
                    }
                    current = corrected;
                }
                ResolvedAction::SilentCorrect => {
                    current = corrected;
                }
                ResolvedAction::Accept => {}
            }
        }

        // Phase 6: Correct protein arrow syntax
        let (corrected, corrections) = correct_protein_arrow(&current);
        if !corrections.is_empty() {
            let action = self.action_for(ErrorType::ProteinSubstitutionArrow);
            match action {
                ResolvedAction::Reject => {
                    let first = &corrections[0];
                    return PreprocessResult::failed(
                        input.to_string(),
                        FerroError::parse_with_diagnostic(
                            first.start,
                            "Arrow '>' in protein substitution is not standard HGVS",
                            Diagnostic::new()
                                .with_code(ErrorCode::InvalidEdit)
                                .with_span(SourceSpan::new(first.start, first.end))
                                .with_source(input)
                                .with_suggestion(corrected.clone())
                                .with_hint("Use p.Val600Glu instead of p.Val600>Glu"),
                        ),
                    );
                }
                ResolvedAction::WarnCorrect => {
                    for c in &corrections {
                        all_warnings.push(CorrectionWarning::from_correction(c));
                    }
                    current = corrected;
                }
                ResolvedAction::SilentCorrect => {
                    current = corrected;
                }
                ResolvedAction::Accept => {}
            }
        }

        // Phase 7: Infer missing coordinate prefix for genomic accessions
        let (corrected, corrections) = correct_missing_coordinate_prefix(&current);
        if !corrections.is_empty() {
            let action = self.action_for(ErrorType::MissingCoordinatePrefix);
            match action {
                ResolvedAction::Reject => {
                    let first = &corrections[0];
                    return PreprocessResult::failed(
                        input.to_string(),
                        FerroError::parse_with_diagnostic(
                            first.start,
                            "Missing coordinate type prefix (e.g., 'g.' for genomic)",
                            Diagnostic::new()
                                .with_code(ErrorCode::InvalidAccession)
                                .with_span(SourceSpan::new(first.start, first.end))
                                .with_source(input)
                                .with_suggestion(corrected.clone())
                                .with_hint("For genomic accessions (NC_, NG_), add 'g.' before the position"),
                        ),
                    );
                }
                ResolvedAction::WarnCorrect => {
                    for c in &corrections {
                        all_warnings.push(CorrectionWarning::from_correction(c));
                    }
                    current = corrected;
                }
                ResolvedAction::SilentCorrect => {
                    current = corrected;
                }
                ResolvedAction::Accept => {}
            }
        }

        // Phase 8: Strip trailing protein annotations (e.g., "(p.Lys236=)")
        let (corrected, corrections) = strip_trailing_annotation(&current);
        if !corrections.is_empty() {
            let action = self.action_for(ErrorType::TrailingAnnotation);
            match action {
                ResolvedAction::Reject => {
                    let first = &corrections[0];
                    return PreprocessResult::failed(
                        input.to_string(),
                        FerroError::parse_with_diagnostic(
                            first.start,
                            format!(
                                "Trailing annotation '{}' is not valid HGVS syntax",
                                first.original
                            ),
                            Diagnostic::new()
                                .with_code(ErrorCode::UnexpectedChar)
                                .with_span(SourceSpan::new(first.start, first.end))
                                .with_source(input)
                                .with_suggestion(corrected.clone())
                                .with_hint("Protein consequence annotations should be separate from the HGVS expression"),
                        ),
                    );
                }
                ResolvedAction::WarnCorrect => {
                    for c in &corrections {
                        all_warnings.push(CorrectionWarning::from_correction(c));
                    }
                    current = corrected;
                }
                ResolvedAction::SilentCorrect => {
                    current = corrected;
                }
                ResolvedAction::Accept => {}
            }
        }

        // Phase 9: Correct old allele format (e.g., ":[c.100A>G;c.200C>T]" → ":c.[100A>G;200C>T]")
        let (corrected, corrections) = correct_old_allele_format(&current);
        if !corrections.is_empty() {
            let action = self.action_for(ErrorType::OldAlleleFormat);
            match action {
                ResolvedAction::Reject => {
                    let first = &corrections[0];
                    return PreprocessResult::failed(
                        input.to_string(),
                        FerroError::parse_with_diagnostic(
                            first.start,
                            "Old/deprecated allele format with coordinate type inside brackets",
                            Diagnostic::new()
                                .with_code(ErrorCode::InvalidEdit)
                                .with_span(SourceSpan::new(first.start, first.end))
                                .with_source(input)
                                .with_suggestion(corrected.clone())
                                .with_hint(
                                    "Use c.[edit1;edit2] format instead of [c.edit1;c.edit2]",
                                ),
                        ),
                    );
                }
                ResolvedAction::WarnCorrect => {
                    for c in &corrections {
                        all_warnings.push(CorrectionWarning::from_correction(c));
                    }
                    current = corrected;
                }
                ResolvedAction::SilentCorrect => {
                    current = corrected;
                }
                ResolvedAction::Accept => {}
            }
        }

        // Return result
        if current == input && all_warnings.is_empty() {
            PreprocessResult::unchanged(input.to_string())
        } else {
            PreprocessResult::corrected(input.to_string(), current, all_warnings)
        }
    }
}

impl Default for InputPreprocessor {
    fn default() -> Self {
        Self::strict()
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::error_handling::ErrorOverride;

    // PreprocessResult tests
    #[test]
    fn test_preprocess_result_unchanged() {
        let result = PreprocessResult::unchanged("c.100A>G".to_string());
        assert!(result.success);
        assert!(!result.has_corrections());
        assert!(!result.has_warnings());
        assert_eq!(result.original, "c.100A>G");
        assert_eq!(result.preprocessed, "c.100A>G");
    }

    #[test]
    fn test_preprocess_result_corrected() {
        let result = PreprocessResult::corrected(
            "c.100\u{2013}200del".to_string(),
            "c.100-200del".to_string(),
            vec![CorrectionWarning::new(
                ErrorType::WrongDashCharacter,
                "test warning",
                Some((5, 8)),
                "\u{2013}",
                "-",
            )],
        );
        assert!(result.success);
        assert!(result.has_corrections());
        assert!(result.has_warnings());
    }

    // InputPreprocessor strict mode tests
    #[test]
    fn test_preprocessor_strict_valid_input() {
        let preprocessor = InputPreprocessor::strict();
        let result = preprocessor.preprocess("c.100A>G");
        assert!(result.success);
        assert!(!result.has_corrections());
    }

    #[test]
    fn test_preprocessor_strict_rejects_en_dash() {
        let preprocessor = InputPreprocessor::strict();
        let result = preprocessor.preprocess("c.100\u{2013}200del");
        assert!(!result.success);
        assert!(result.error.is_some());
    }

    #[test]
    fn test_preprocessor_strict_rejects_whitespace() {
        let preprocessor = InputPreprocessor::strict();
        let result = preprocessor.preprocess("  c.100A>G  ");
        assert!(!result.success);
    }

    #[test]
    fn test_preprocessor_strict_rejects_position_zero() {
        let preprocessor = InputPreprocessor::strict();
        let result = preprocessor.preprocess("c.0A>G");
        assert!(!result.success);
        assert!(result.error.is_some());
    }

    // InputPreprocessor lenient mode tests
    #[test]
    fn test_preprocessor_lenient_corrects_en_dash() {
        let preprocessor = InputPreprocessor::lenient();
        let result = preprocessor.preprocess("c.100\u{2013}200del");
        assert!(result.success);
        assert_eq!(result.preprocessed, "c.100-200del");
        assert!(result.has_warnings());
    }

    #[test]
    fn test_preprocessor_lenient_corrects_whitespace() {
        let preprocessor = InputPreprocessor::lenient();
        let result = preprocessor.preprocess("  c.100A>G  ");
        assert!(result.success);
        assert_eq!(result.preprocessed, "c.100A>G");
        assert!(result.has_warnings());
    }

    #[test]
    fn test_preprocessor_lenient_corrects_protein_arrow() {
        let preprocessor = InputPreprocessor::lenient();
        let result = preprocessor.preprocess("p.Val600>Glu");
        assert!(result.success);
        assert_eq!(result.preprocessed, "p.Val600Glu");
        assert!(result.has_warnings());
    }

    #[test]
    fn test_preprocessor_lenient_rejects_position_zero() {
        let preprocessor = InputPreprocessor::lenient();
        let result = preprocessor.preprocess("c.0A>G");
        // Position zero is always rejected
        assert!(!result.success);
    }

    // InputPreprocessor silent mode tests
    #[test]
    fn test_preprocessor_silent_corrects_without_warnings() {
        let preprocessor = InputPreprocessor::silent();
        let result = preprocessor.preprocess("c.100\u{2013}200del");
        assert!(result.success);
        assert_eq!(result.preprocessed, "c.100-200del");
        assert!(!result.has_warnings());
    }

    #[test]
    fn test_preprocessor_silent_corrects_multiple() {
        let preprocessor = InputPreprocessor::silent();
        let result = preprocessor.preprocess("  nm_000088.3:c.100\u{2013}200del  ");
        assert!(result.success);
        assert_eq!(result.preprocessed, "NM_000088.3:c.100-200del");
        assert!(!result.has_warnings());
    }

    // Override tests
    #[test]
    fn test_preprocessor_override_reject_in_lenient() {
        let config = ErrorConfig::lenient()
            .with_override(ErrorType::WrongDashCharacter, ErrorOverride::Reject);
        let preprocessor = InputPreprocessor::new(config);
        let result = preprocessor.preprocess("c.100\u{2013}200del");
        assert!(!result.success);
    }

    #[test]
    fn test_preprocessor_override_silent_in_lenient() {
        let config = ErrorConfig::lenient()
            .with_override(ErrorType::WrongDashCharacter, ErrorOverride::SilentCorrect);
        let preprocessor = InputPreprocessor::new(config);
        let result = preprocessor.preprocess("c.100\u{2013}200del");
        assert!(result.success);
        assert!(!result.has_warnings()); // Silent = no warnings
    }

    #[test]
    fn test_preprocessor_override_correct_in_strict() {
        let config = ErrorConfig::strict()
            .with_override(ErrorType::WrongDashCharacter, ErrorOverride::WarnCorrect);
        let preprocessor = InputPreprocessor::new(config);
        let result = preprocessor.preprocess("c.100\u{2013}200del");
        assert!(result.success);
        assert!(result.has_warnings());
        assert_eq!(result.preprocessed, "c.100-200del");
    }

    // CorrectionWarning tests
    #[test]
    fn test_correction_warning_from_correction() {
        let correction =
            DetectedCorrection::new(ErrorType::WrongDashCharacter, "\u{2013}", "-", 5, 8);
        let warning = CorrectionWarning::from_correction(&correction);
        assert_eq!(warning.error_type, ErrorType::WrongDashCharacter);
        assert!(warning.message.contains("dash"));
        assert_eq!(warning.span, Some((5, 8)));
    }

    // Trailing annotation tests
    #[test]
    fn test_preprocessor_strict_rejects_trailing_annotation() {
        let preprocessor = InputPreprocessor::strict();
        let result = preprocessor.preprocess("NM_000088.3:c.459A>G (p.Lys153=)");
        assert!(!result.success);
        assert!(result.error.is_some());
    }

    #[test]
    fn test_preprocessor_lenient_strips_trailing_annotation() {
        let preprocessor = InputPreprocessor::lenient();
        let result = preprocessor.preprocess("NM_000088.3:c.459A>G (p.Lys153=)");
        assert!(result.success);
        assert_eq!(result.preprocessed, "NM_000088.3:c.459A>G");
        assert!(result.has_warnings());
    }

    #[test]
    fn test_preprocessor_silent_strips_trailing_annotation() {
        let preprocessor = InputPreprocessor::silent();
        let result = preprocessor.preprocess("NM_000088.3:c.459A>G (p.Lys153=)");
        assert!(result.success);
        assert_eq!(result.preprocessed, "NM_000088.3:c.459A>G");
        assert!(!result.has_warnings());
    }

    #[test]
    fn test_preprocessor_lenient_clinvar_pattern() {
        let preprocessor = InputPreprocessor::lenient();
        let result = preprocessor.preprocess("NM_003467.3(CXCR4):c.708G>A (p.Lys236=)");
        assert!(result.success);
        assert_eq!(result.preprocessed, "NM_003467.3(CXCR4):c.708G>A");
    }

    #[test]
    fn test_preprocessor_override_accept_trailing_annotation() {
        // Also need to override whitespace handling since there's a space before the annotation
        let config = ErrorConfig::strict()
            .with_override(ErrorType::ExtraWhitespace, ErrorOverride::SilentCorrect)
            .with_override(ErrorType::TrailingAnnotation, ErrorOverride::WarnCorrect);
        let preprocessor = InputPreprocessor::new(config);
        let result = preprocessor.preprocess("NM_000088.3:c.459A>G (p.Lys153=)");
        assert!(result.success);
        assert_eq!(result.preprocessed, "NM_000088.3:c.459A>G");
        assert!(result.has_warnings());
    }

    #[test]
    fn test_preprocessor_override_trailing_annotation_no_space() {
        // Test without the space - only TrailingAnnotation override needed
        let config = ErrorConfig::strict()
            .with_override(ErrorType::TrailingAnnotation, ErrorOverride::WarnCorrect);
        let preprocessor = InputPreprocessor::new(config);
        let result = preprocessor.preprocess("NM_000088.3:c.459A>G(p.Lys153=)");
        assert!(result.success);
        assert_eq!(result.preprocessed, "NM_000088.3:c.459A>G");
        assert!(result.has_warnings());
    }

    // Missing coordinate prefix tests
    #[test]
    fn test_preprocessor_strict_rejects_missing_prefix() {
        let preprocessor = InputPreprocessor::strict();
        let result = preprocessor.preprocess("NC_000017.11:12345A>G");
        assert!(!result.success);
        assert!(result.error.is_some());
    }

    #[test]
    fn test_preprocessor_lenient_adds_missing_prefix() {
        let preprocessor = InputPreprocessor::lenient();
        let result = preprocessor.preprocess("NC_000017.11:12345A>G");
        assert!(result.success);
        assert_eq!(result.preprocessed, "NC_000017.11:g.12345A>G");
        assert!(result.has_warnings());
    }

    #[test]
    fn test_preprocessor_lenient_adds_missing_prefix_uncertain() {
        let preprocessor = InputPreprocessor::lenient();
        let result = preprocessor.preprocess("NC_000017.11:(?_31094927)_(31377677_?)del");
        assert!(result.success);
        assert_eq!(
            result.preprocessed,
            "NC_000017.11:g.(?_31094927)_(31377677_?)del"
        );
    }

    #[test]
    fn test_preprocessor_silent_adds_missing_prefix() {
        let preprocessor = InputPreprocessor::silent();
        let result = preprocessor.preprocess("NC_000017.11:12345A>G");
        assert!(result.success);
        assert_eq!(result.preprocessed, "NC_000017.11:g.12345A>G");
        assert!(!result.has_warnings());
    }
}