From 4b6ee3d75b3813e751f0bc75efac6380ee39181a Mon Sep 17 00:00:00 2001 From: Michael Macias Date: Fri, 20 Dec 2024 11:08:57 -0600 Subject: [PATCH] vcf/header/parser: Keep existing record in header on a duplicate ID error --- noodles-vcf/CHANGELOG.md | 4 +++ noodles-vcf/src/header/parser.rs | 25 ++++--------------- .../record/value/map/alternative_allele.rs | 11 +++----- .../header/parser/record/value/map/contig.rs | 11 +++----- .../header/parser/record/value/map/filter.rs | 11 +++----- .../header/parser/record/value/map/format.rs | 11 +++----- .../header/parser/record/value/map/info.rs | 11 +++----- .../header/parser/record/value/map/other.rs | 11 +++----- .../src/header/record/value/collection.rs | 5 +--- 9 files changed, 34 insertions(+), 66 deletions(-) diff --git a/noodles-vcf/CHANGELOG.md b/noodles-vcf/CHANGELOG.md index ecc78f4f3..b666f34c1 100644 --- a/noodles-vcf/CHANGELOG.md +++ b/noodles-vcf/CHANGELOG.md @@ -8,6 +8,10 @@ This can be used to read the raw VCF header. +### Changed + + * vcf/header/parser: Keep existing record in header on a duplicate ID error. + ## 0.69.0 - 2024-12-12 ### Changed diff --git a/noodles-vcf/src/header/parser.rs b/noodles-vcf/src/header/parser.rs index 3145a089d..f36761e9b 100644 --- a/noodles-vcf/src/header/parser.rs +++ b/noodles-vcf/src/header/parser.rs @@ -236,10 +236,7 @@ fn try_insert_info( .map(|(k, v)| self::Entry::Info(k, v)) .unwrap()) } - Entry::Occupied(entry) => { - let (id, _) = entry.swap_remove_entry(); - Err(ParseError::DuplicateInfoId(id)) - } + Entry::Occupied(entry) => Err(ParseError::DuplicateInfoId(entry.key().into())), } } @@ -262,10 +259,7 @@ fn try_insert_filter( .map(|(k, v)| self::Entry::Filter(k, v)) .unwrap()) } - Entry::Occupied(entry) => { - let (id, _) = entry.swap_remove_entry(); - Err(ParseError::DuplicateFilterId(id)) - } + Entry::Occupied(entry) => Err(ParseError::DuplicateFilterId(entry.key().into())), } } @@ -288,10 +282,7 @@ fn try_insert_format( .map(|(k, v)| self::Entry::Format(k, v)) .unwrap()) } - Entry::Occupied(entry) => { - let (id, _) = entry.swap_remove_entry(); - Err(ParseError::DuplicateFormatId(id)) - } + Entry::Occupied(entry) => Err(ParseError::DuplicateFormatId(entry.key().into())), } } @@ -314,10 +305,7 @@ fn try_insert_alternative_allele( .map(|(k, v)| self::Entry::AlternativeAllele(k, v)) .unwrap()) } - Entry::Occupied(entry) => { - let (id, _) = entry.swap_remove_entry(); - Err(ParseError::DuplicateAlternativeAlleleId(id)) - } + Entry::Occupied(entry) => Err(ParseError::DuplicateAlternativeAlleleId(entry.key().into())), } } @@ -340,10 +328,7 @@ fn try_insert_contig( .map(|(k, v)| self::Entry::Contig(k, v)) .unwrap()) } - Entry::Occupied(entry) => { - let (id, _) = entry.swap_remove_entry(); - Err(ParseError::DuplicateContigId(id)) - } + Entry::Occupied(entry) => Err(ParseError::DuplicateContigId(entry.key().into())), } } diff --git a/noodles-vcf/src/header/parser/record/value/map/alternative_allele.rs b/noodles-vcf/src/header/parser/record/value/map/alternative_allele.rs index eaea2e952..6171b43e2 100644 --- a/noodles-vcf/src/header/parser/record/value/map/alternative_allele.rs +++ b/noodles-vcf/src/header/parser/record/value/map/alternative_allele.rs @@ -123,13 +123,10 @@ fn try_insert( entry.insert(value); Ok(()) } - Entry::Occupied(entry) => { - let (t, _) = entry.swap_remove_entry(); - Err(ParseError::new( - id.clone(), - ParseErrorKind::DuplicateTag(Tag::Other(t)), - )) - } + Entry::Occupied(entry) => Err(ParseError::new( + id.clone(), + ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())), + )), } } diff --git a/noodles-vcf/src/header/parser/record/value/map/contig.rs b/noodles-vcf/src/header/parser/record/value/map/contig.rs index 37a0ddd4d..3b00dcef6 100644 --- a/noodles-vcf/src/header/parser/record/value/map/contig.rs +++ b/noodles-vcf/src/header/parser/record/value/map/contig.rs @@ -146,13 +146,10 @@ fn try_insert( entry.insert(value); Ok(()) } - Entry::Occupied(entry) => { - let (t, _) = entry.swap_remove_entry(); - Err(ParseError::new( - id.clone(), - ParseErrorKind::DuplicateTag(Tag::Other(t)), - )) - } + Entry::Occupied(entry) => Err(ParseError::new( + id.clone(), + ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())), + )), } } diff --git a/noodles-vcf/src/header/parser/record/value/map/filter.rs b/noodles-vcf/src/header/parser/record/value/map/filter.rs index e9e429265..463aa202b 100644 --- a/noodles-vcf/src/header/parser/record/value/map/filter.rs +++ b/noodles-vcf/src/header/parser/record/value/map/filter.rs @@ -134,13 +134,10 @@ fn try_insert( entry.insert(value); Ok(()) } - Entry::Occupied(entry) => { - let (t, _) = entry.swap_remove_entry(); - Err(ParseError::new( - id.clone(), - ParseErrorKind::DuplicateTag(Tag::Other(t)), - )) - } + Entry::Occupied(entry) => Err(ParseError::new( + id.clone(), + ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())), + )), } } diff --git a/noodles-vcf/src/header/parser/record/value/map/format.rs b/noodles-vcf/src/header/parser/record/value/map/format.rs index 9401b603e..d0a8aa3de 100644 --- a/noodles-vcf/src/header/parser/record/value/map/format.rs +++ b/noodles-vcf/src/header/parser/record/value/map/format.rs @@ -178,13 +178,10 @@ fn try_insert( entry.insert(value); Ok(()) } - Entry::Occupied(entry) => { - let (t, _) = entry.swap_remove_entry(); - Err(ParseError::new( - id.clone(), - ParseErrorKind::DuplicateTag(Tag::Other(t)), - )) - } + Entry::Occupied(entry) => Err(ParseError::new( + id.clone(), + ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())), + )), } } diff --git a/noodles-vcf/src/header/parser/record/value/map/info.rs b/noodles-vcf/src/header/parser/record/value/map/info.rs index 72ec7153d..8e8d2a547 100644 --- a/noodles-vcf/src/header/parser/record/value/map/info.rs +++ b/noodles-vcf/src/header/parser/record/value/map/info.rs @@ -178,13 +178,10 @@ fn try_insert( entry.insert(value); Ok(()) } - Entry::Occupied(entry) => { - let (t, _) = entry.swap_remove_entry(); - Err(ParseError::new( - id.clone(), - ParseErrorKind::DuplicateTag(Tag::Other(t)), - )) - } + Entry::Occupied(entry) => Err(ParseError::new( + id.clone(), + ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())), + )), } } diff --git a/noodles-vcf/src/header/parser/record/value/map/other.rs b/noodles-vcf/src/header/parser/record/value/map/other.rs index 4f6eefe49..8266ce443 100644 --- a/noodles-vcf/src/header/parser/record/value/map/other.rs +++ b/noodles-vcf/src/header/parser/record/value/map/other.rs @@ -283,13 +283,10 @@ fn try_insert( entry.insert(value); Ok(()) } - Entry::Occupied(entry) => { - let (t, _) = entry.swap_remove_entry(); - Err(ParseError::new( - id.clone(), - ParseErrorKind::DuplicateTag(Tag::Other(t)), - )) - } + Entry::Occupied(entry) => Err(ParseError::new( + id.clone(), + ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())), + )), } } diff --git a/noodles-vcf/src/header/record/value/collection.rs b/noodles-vcf/src/header/record/value/collection.rs index f641960d1..482412ac3 100644 --- a/noodles-vcf/src/header/record/value/collection.rs +++ b/noodles-vcf/src/header/record/value/collection.rs @@ -61,10 +61,7 @@ fn try_insert( entry.insert(m); Ok(()) } - Entry::Occupied(entry) => { - let (id, _) = entry.swap_remove_entry(); - Err(AddError::DuplicateId(id)) - } + Entry::Occupied(entry) => Err(AddError::DuplicateId(entry.key().into())), } }