Genomics Basics02/02
Starting sandbox…
Intermediate·3 graded tests

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

exerciseEvery submission runs independently in a fresh namespace.

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