Skip to content

HGVS Parsing API Reference

The gtars HGVS module parses Human Genome Variation Society (HGVS) variant nomenclature and converts variants to GA4GH VRS (Variant Representation Specification) identifiers. This enables reproducible variant identification across systems.

PrefixDescriptionExample
g.GenomicNC_000007.14:g.140753336A>T
c.Coding transcriptNM_004333.6:c.1799T>A
n.Non-coding transcriptNR_046018.2:n.100A>G
m.MitochondrialNC_012920.1:m.8993T>G
r.RNANM_004333.6:r.1799u>a
EditSyntaxDescription
SubstitutionA>TSingle nucleotide change
Deletiondel or delATGSequence removal
InsertioninsATGSequence insertion
Deletion-insertiondelinsATG or delATGinsCTCombined deletion and insertion
Duplicationdup or dupASequence duplication
NotationExampleDescription
Simple123Position 123
Range123_456Positions 123 through 456
Intronic (downstream)93+11 base into intron after exon position 93
Intronic (upstream)93-11 base into intron before exon position 93
5’ UTR-1414 bases upstream of CDS start
3’ UTR*3737 bases downstream of CDS end
  • p. (protein variants)
  • Repeat notation ([3], [5_10])
  • Complex variants with multiple changes
  • Mosaic/chimeric notation

use gtars_vrs::hgvs::{parse, HgvsVariant, ReferenceType};
let variant = parse("NC_000007.14:g.140753336A>T")?;
assert_eq!(variant.accession, "NC_000007.14");
assert_eq!(variant.reference_type, ReferenceType::G);
pub struct HgvsVariant<'a> {
/// Reference sequence accession (e.g., "NC_000007.14", "NM_004333.6")
/// OR gene symbol if no accession provided (e.g., "BRAF")
pub accession: &'a str,
/// Reference type (g., c., n., m., r., p.)
pub reference_type: ReferenceType,
/// Position and edit information
pub posedit: PosEdit<'a>,
/// Optional gene symbol in parentheses (e.g., "(BRAF)")
pub gene: Option<&'a str>,
}
pub struct Position {
/// Base position (1-based in HGVS; negative for 5' UTR)
pub base: i64,
/// Intronic offset (+ enters downstream intron, - enters upstream intron)
pub offset: i64,
/// Reference point for the position
pub datum: Datum,
}
pub enum Datum {
SeqStart, // Position relative to sequence start (g., n., m.)
CdsStart, // Position relative to CDS start (c.)
CdsEnd, // Position relative to CDS end (c.*N)
}

Required for converting c. and n. variants to genomic coordinates:

pub trait TranscriptProvider {
/// Map a transcript position to a genomic coordinate
fn tx_to_genome(
&self,
tx_accession: &str,
position: &Position,
) -> Result<(u64, String), HgvsError>;
/// Get the strand of a transcript (+1 or -1)
fn tx_strand(&self, tx_accession: &str) -> Result<i8, HgvsError>;
/// Get the genomic reference accession for a transcript
fn tx_accession_to_genomic(&self, tx_accession: &str) -> Result<String, HgvsError>;
/// Resolve a gene symbol to its MANE Select transcript accession
fn gene_to_mane_accession(&self, gene: &str) -> Option<String>;
}

Implementation of TranscriptProvider backed by a transcript store:

use gtars_reftx::ReftxStore;
use gtars_vrs::hgvs::ReftxProvider;
let store = ReftxStore::open("path/to/reftx.bin")?;
let provider = ReftxProvider::new(&store);
// Convert c. variant using MANE lookup
let (g_pos, chrom) = provider.tx_to_genome("BRAF", &position)?;
use gtars_vrs::hgvs::{parse, to_vrs_allele};
use gtars_refget::RefgetStore;
let variant = parse("NC_000007.14:g.140753336A>T")?;
let mut refget_store = RefgetStore::open("path/to/store")?;
let allele = to_vrs_allele(
&variant,
&mut refget_store,
"collection_digest",
&provider,
)?;
println!("VRS ID: {}", allele.compute_id());
use gtars_vrs::hgvs::hgvs_to_vrs_id;
let vrs_id = hgvs_to_vrs_id(
"NC_000007.14:g.140753336A>T",
&mut refget_store,
"collection_digest",
&provider,
)?;
// Returns: "ga4gh:VA.xxxxx"

from gtars.vrs.hgvs import parse_hgvs, hgvs_to_vrs_id
from gtars.reftx import TxStore
variant = parse_hgvs("NC_000007.14:g.140753336A>T")
print(variant.accession) # "NC_000007.14"
print(variant.reference_type) # "g"
print(variant.position) # 140753336
print(variant.edit) # "A>T"

Output:

NC_000007.14
g
140753336
A>T
from gtars.vrs.hgvs import hgvs_to_vrs_id
from gtars.refget import RefgetStore
store = RefgetStore("path/to/store")
vrs_id = hgvs_to_vrs_id(
"NC_000007.14:g.140753336A>T",
store=store,
collection="GRCh38"
)
print(vrs_id)

Output:

ga4gh:VA.7kHvwqLrmJqO3hVZ0CqYzCJeVQF_1DYn

Coding variants require a transcript store for coordinate mapping:

from gtars.vrs.hgvs import hgvs_to_vrs_id
from gtars.refget import RefgetStore
from gtars.reftx import TxStore
refget_store = RefgetStore("path/to/store")
tx_store = TxStore("path/to/reftx.bin")
vrs_id = hgvs_to_vrs_id(
"NM_004333.6:c.1799T>A",
store=refget_store,
collection="GRCh38",
tx_store=tx_store
)
print(vrs_id)

Output:

ga4gh:VA.7kHvwqLrmJqO3hVZ0CqYzCJeVQF_1DYn

When a gene symbol is provided instead of a transcript accession, the system automatically resolves to the MANE Select transcript:

vrs_id = hgvs_to_vrs_id(
"BRAF:c.1799T>A",
store=refget_store,
collection="GRCh38",
tx_store=tx_store
)
# Internally resolves BRAF -> NM_004333.6, then maps c.1799 -> chr7:140753336
print(vrs_id)

Output:

ga4gh:VA.7kHvwqLrmJqO3hVZ0CqYzCJeVQF_1DYn

Convert HGVS notation to VRS ID:

Terminal window
gtars hgvs-to-vrs "NC_000007.14:g.140753336A>T" --store /path/to/store --collection GRCh38

Output:

ga4gh:VA.7kHvwqLrmJqO3hVZ0CqYzCJeVQF_1DYn

Options:

OptionDescription
--store, -sPath to RefgetStore
--collection, -cCollection digest or name
--tx-store, -tPath to transcript store (required for c./n. variants)
--output, -oOutput format: id (default), json, allele

Process multiple HGVS variants from a file:

Terminal window
gtars hgvs-to-vrs --input variants.txt --store /path/to/store --collection GRCh38 --tx-store /path/to/reftx.bin

Input file format (one HGVS per line):

NC_000007.14:g.140753336A>T
NM_004333.6:c.1799T>A
BRAF:c.1799T>A

Output:

NC_000007.14:g.140753336A>T ga4gh:VA.7kHvwqLrmJqO3hVZ0CqYzCJeVQF_1DYn
NM_004333.6:c.1799T>A ga4gh:VA.7kHvwqLrmJqO3hVZ0CqYzCJeVQF_1DYn
BRAF:c.1799T>A ga4gh:VA.7kHvwqLrmJqO3hVZ0CqYzCJeVQF_1DYn
Terminal window
gtars hgvs-to-vrs "NC_000007.14:g.140753336A>T" --store /path/to/store --collection GRCh38 --output json

Output:

{
"hgvs": "NC_000007.14:g.140753336A>T",
"vrs_id": "ga4gh:VA.7kHvwqLrmJqO3hVZ0CqYzCJeVQF_1DYn",
"allele": {
"location": {
"sequenceReference": {
"refgetAccession": "SQ.F-LrLMe1SRpfUZHkQmvkVgo2azJq"
},
"start": 140753335,
"end": 140753336
},
"state": {
"sequence": "T"
}
}
}

# BRAF V600E mutation
vrs_id = hgvs_to_vrs_id("NC_000007.14:g.140753336A>T", store=store, collection="GRCh38")
# Same mutation in coding coordinates
vrs_id = hgvs_to_vrs_id(
"NM_004333.6:c.1799T>A",
store=store,
collection="GRCh38",
tx_store=tx_store
)
# Splice site variant
vrs_id = hgvs_to_vrs_id(
"NM_004333.6:c.93+1G>A",
store=store,
collection="GRCh38",
tx_store=tx_store
)
# 3-base deletion
vrs_id = hgvs_to_vrs_id(
"NC_000007.14:g.140753336_140753338del",
store=store,
collection="GRCh38"
)
# Uses MANE Select transcript (NM_004333.6) for BRAF
vrs_id = hgvs_to_vrs_id(
"BRAF:c.1799T>A",
store=store,
collection="GRCh38",
tx_store=tx_store
)

pub enum HgvsError {
/// HGVS string could not be parsed
ParseError { input: String, detail: String },
/// Reference sequence not found in collection
AccessionNotFound { accession: String, collection: String },
/// Transcript not found in transcript store
TranscriptNotFound(String),
/// Gene has no MANE Select transcript
NoManeTranscript { gene: String },
/// Attempted c./n. conversion without a transcript provider
NoTranscriptProvider { accession: String },
/// Coordinate mapping failed
MappingError { accession: String, detail: String },
/// Reference type not supported (e.g., p.)
UnsupportedReferenceType(ReferenceType),
/// Edit type not supported (e.g., inv)
UnsupportedEdit(String),
/// Refget store operation failed
RefgetError(String),
}
ErrorCauseSolution
ParseErrorInvalid HGVS syntaxCheck variant notation against HGVS specification
AccessionNotFoundAccession not in collectionVerify accession matches reference assembly
TranscriptNotFoundTranscript not in storeEnsure transcript store includes the accession
NoManeTranscriptGene has no MANE designationUse specific transcript accession instead of gene symbol
NoTranscriptProviderc./n. variant without transcript storeProvide tx_store parameter
MappingErrorPosition outside transcript boundsCheck position is valid for the transcript
from gtars.vrs.hgvs import hgvs_to_vrs_id, HgvsError
try:
vrs_id = hgvs_to_vrs_id("INVALID:c.123A>T", store=store, collection="GRCh38")
except HgvsError as e:
print(f"HGVS error: {e}")