Reading Variants: HGVS Format Validation
Why validate before you parse
Genomic variant datasets frequently exhibit heterogeneity across legacy formats, unstructured annotations, and syntax discrepancies. Before executing downstream analysis, variant strings should be validated against formal notation standards, such as the Human Genome Variation Society HGVS format for coding-DNA substitutions:
NM_000546.5:c.215C>G
└──────┬──────┘ └┬┘ │└│
transcript pos ref alt
This exercise specifically validates single nucleotide substitutions (ref>alt). Indels, complex rearrangements, and duplications (such as c.5266dupC) are outside this scope and should resolve to the INVALID branch.
Your task
Complete parse_hgvs so that:
- A string matching
HGVS_PATTERNreturns"<transcript> pos=<position> ref=<ref> alt=<alt>". - Any other format, including valid HGVS expressions representing alternative mutation types, returns
"INVALID".
Unlike the transcription puzzle, this script reads its input from a
CLI argument (via argparse) rather than stdin, so the test
harness will invoke it as:
python solution.py "NM_000546.5:c.215C>G"
A known_variants.txt mock file is provided in the sandbox if you
want extra strings to experiment with beyond the graded test cases.
Test cases · 3
| # | via | input | expected stdout |
|---|---|---|---|
| 1 | argv | NM_000546.5:c.215C>G | NM_000546.5 pos=215 ref=C alt=G |
| 2 | argv | NM_007294.4:c.5266dupC | INVALID |
| 3 | argv | not-a-variant | INVALID |