fix: quote-aware VCF/BCF header key=value parser#70
Open
jmg421 wants to merge 1 commit into
Open
Conversation
The previous regex-based split in .bcfHeaderAsSimpleList used: strsplit(..., ',(?=Description=".*?")', perl=TRUE) strsplit(..., '(?<=[ID|Number|Type|Description])=', perl=TRUE) Both regexes fail when quoted Description (or other) values contain commas or '=' signs, e.g.: Description="IDs [VRS version=2.0.1;VRS-Python version=2.1.1]" CommandLineOptions="analysis_type=SelectVariants input_file=[]" Replace with .splitKeyVals(), a character-by-character quote-aware scanner that: 1. Splits on commas only outside double-quoted strings 2. Splits each field on the FIRST '=' only (keys never contain '=') The helper is hoisted to package scope so unit tests can access it via Rsamtools:::.splitKeyVals. Fixes VariantAnnotation#89, VariantAnnotation#80
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
scanBcfHeader()fails to parse structured VCF/BCF header lines whose quoted field values contain commas or=signs. Two cascading regex bugs in.bcfHeaderAsSimpleList():',(?=Description=".*?")' uses lazy.*?which still breaks when the quoted value contains=(e.g.Description="IDs [VRS version=2.0.1]")(?<=[ID|Number|Type|Description])=uses[...](character class, matches single charsI,D,|,…) instead of alternation, so it splits on=signs inside quoted values tooReproducing examples from the tracker:
Fix
Replace both
strsplitcalls with.splitKeyVals(), a character-by-character quote-aware scanner that:=only (key names never contain=)The helper is hoisted to package scope (was previously inlined) so unit tests and downstream packages can access it via
Rsamtools:::.splitKeyVals.Changes
R/methods-BcfFile.R— replace regex split with.splitKeyVals()inst/unitTests/test_BcfFile.R— 3 regression tests covering both issues + commas-in-quotesNEWS— changelog entry under v2.18References
readVcfdoesn't handle quoted=inhapmap_exome_chr22.vcf.gzcorrectly VariantAnnotation#80