pythonforbio.
[WASM idle]
Genomics Basics02/02

Reading Variants: HGVS Format Validation

Starting sandbox…
Intermediatepuzzle3 tests

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_PATTERN returns "<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

#viainputexpected stdout
1argvNM_000546.5:c.215C>GNM_000546.5 pos=215 ref=C alt=G
2argvNM_007294.4:c.5266dupCINVALID
3argvnot-a-variantINVALID
starter

No output yet — run the code to populate this drawer.

DNA to mRNA: Transcriptionend of path