Why validate before you parse
Real variant call sets are messy: free-text annotations, mixed notations, and the occasional typo. Before any downstream tool touches a variant string, it's worth confirming it actually matches the notation you expect — here, a simple coding-DNA substitution in HGVS format:
NM_000546.5:c.215C>G
└──────┬──────┘ └┬┘ │└│
transcript pos ref alt
This puzzle only covers substitutions (ref>alt), not insertions,
deletions, or duplications like c.5266dupC — those should fall
through to your INVALID branch.
Your task
Complete parse_hgvs so that:
- A string matching
HGVS_PATTERNreturns"<transcript> pos=<position> ref=<ref> alt=<alt>". - Anything else — including valid-looking HGVS notations that use a
different mutation type — 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 |