VarSim — HGVS Variant Toolkit
Note on Naming: VarSim is an HGVS variant toolkit. It is not affiliated with, and should not be confused with, the "VarSim" read simulator (PMID: 25524895).
VarSim is a comprehensive toolkit for HGVS variant nomenclature — parsing, validation, normalization, backtranslation, format conversion, extraction, liftover, transcription, and translation. All powered by NCBI Entrez.
Installation
pip install varsim
Configuration
Set two environment variables to query NCBI Entrez:
EMAIL— (Required) A valid email so NCBI can contact you about query issues.API_KEY— (Recommended) An NCBI API key for higher query rates. Obtain one from your NCBI account settings.
Linux/macOS:
export EMAIL="your.email@example.com"
export API_KEY="your_api_key_here"
Windows (PowerShell):
$env:EMAIL="your.email@example.com"
$env:API_KEY="your_api_key_here"
Usage
import varsim
1. HGVS Parsing & Validation
Parse HGVS strings into structured objects or validate syntax and semantics.
| Function | Description |
|---|---|
parse(hgvs) |
Parse HGVS → HGVSTag (.acc, .prefix, .variant_type, .ref, .alt, .start_pos, …) |
is_valid(hgvs, ref_seq=None) |
Return True if syntax (and optionally semantics) passes |
validate(hgvs) |
Detailed validation → list of {"severity", "message"} dicts |
>>> tag = varsim.parse("NM_000207.3:c.1A>G")
>>> tag.variant_type, tag.ref, tag.alt
('substitution', 'A', 'G')
>>> varsim.validate("NM_000207.3:c.1A>G")
[]
>>> varsim.is_valid("NM_000207.3:c.1A>G", ref_seq="ATGCGTACG...")
True
2. HGVS Normalization
Normalize variants to canonical form per HGVS recommendations.
| Function | Description |
|---|---|
normalize(hgvs, ref_seq=None) |
Full pipeline: 3′ shift, ins→dup, allele minimization, range normalization |
normalizer.normalize_3prime_shift(hgvs, ref_seq) |
Shift variant as far 3′ as possible |
normalizer.ins_to_dup(hgvs, ref_seq) |
Convert insertion to duplication when applicable |
>>> varsim.normalize("c.4A>G", ref_seq="AAGC")
'c.2A>G'
>>> varsim.normalizer.ins_to_dup("NM_000207.3:c.4_5insA", ref_seq="TAAA")
'NM_000207.3:c.3dup'
3. Backtranslation
Determine which nucleotide changes could produce a given protein variant.
| Function | Description |
|---|---|
backtranslate(gene, p_hgvs) |
Protein → nucleotide backtranslation using the real MANE CDS |
backtranslate_protein(p_hgvs) |
Pure codon-table backtranslation (no gene fetch) |
>>> varsim.backtranslate_protein("p.(V42G)")
['c.125T>G']
>>> varsim.backtranslate("G6PD", "p.(V42G)") # validates against real CDS
['NM_001360016.2:c.125T>G']
4. Format Conversion
Convert between HGVS, VCF, and SPDI formats.
| Function | Description |
|---|---|
hgvs_to_vcf(hgvs, chrom=None) |
HGVS g./c. → VCF dict {CHROM, POS, REF, ALT} |
vcf_to_hgvs(chrom, pos, ref, alt, acc=None) |
VCF record → HGVS string |
hgvs_to_spdi(hgvs) |
HGVS → SPDI string |
spdi_to_hgvs(spdi, prefix="g.") |
SPDI → HGVS string |
c_to_p(c_hgvs, gene) |
Coding HGVS → protein HGVS |
>>> varsim.hgvs_to_vcf("NC_000023.11:g.123456A>G")
{'CHROM': 'NC_000023.11', 'POS': 123456, 'ID': '.', 'REF': 'A', 'ALT': 'G'}
>>> varsim.vcf_to_hgvs("X", 123456, "A", "G", acc="NC_000023.11")
'NC_000023.11:g.123456A>G'
5. Variant Extraction
Diff two sequences and produce the minimal HGVS description.
| Function | Description |
|---|---|
extract(ref_seq, obs_seq, acc="NM_000207.3", prefix="c.") |
Align & diff → HGVS string |
>>> varsim.extract("ATGC", "ATTC", prefix="c.")
'NM_000207.3:c.3G>T'
>>> varsim.extract("ATGC", "ATC", prefix="c.")
'NM_000207.3:c.3del'
6. Liftover
Remap genomic variants between assemblies via the NCBI Remap API.
| Function | Description |
|---|---|
liftover_g_to_assembly(hgvs, target_assembly="GRCh38") |
Lift g.HGVS between assemblies |
liftover_transcript(gene, c_hgvs, target_assembly="GRCh38") |
Transcript → genomic → liftover pipeline |
>>> varsim.liftover_g_to_assembly("NC_000001.10:g.12345A>G", "GRCh38")
'NC_000001.11:g.12345A>G'
>>> varsim.liftover_transcript("G6PD", "c.1A>G", "GRCh38")
'NC_000023.11:g.153760607T>C'
7. Transcription
Convert between coding and genomic coordinate systems using exon structure.
| Function | Description |
|---|---|
c_to_g(c_hgvs, gene) |
Coding (c.) → genomic (g.) coordinates |
g_to_c(g_hgvs, gene) |
Genomic (g.) → coding (c.) coordinates |
transcription.get_cds_exon_map(gene) |
Exon structure mapping (cDNA + genomic coordinates) |
>>> varsim.c_to_g("NM_001360016.2:c.1A>G", "G6PD")
'NC_000023.11:g.153760607A>G'
>>> varsim.transcription.get_cds_exon_map("G6PD")
[{'exon': 1, 'cds_start': 0, 'cds_end': 138, 'genomic_start': ..., 'strand': -1}, ...]
8. Translation
Translate coding variants to their protein consequences.
| Function | Description |
|---|---|
translate_variant(c_hgvs, gene) |
Coding → protein HGVS string |
translation.translate_variants(c_hgvs_list, gene) |
Batch translation for multiple c.HGVS strings |
get_protein_effect(c_hgvs, gene) |
Effect dict: effect_type, position, ref_aa, alt_aa, 1-letter + 3-letter p.HGVS |
>>> varsim.translate_variant("NM_000207.3:c.1A>G", "INS")
'NP_000198.1:p.(M1?)'
>>> eff = varsim.get_protein_effect("NM_000207.3:c.4A>G", "INS")
>>> eff["effect_type"]
'missense'
API Reference
| Category | Function | Brief |
|---|---|---|
| Parsing | parse(hgvs) / validate(hgvs) / is_valid(hgvs, ref_seq?) |
Parse → HGVSTag / detailed issues / bool check |
| Normalization | normalize(hgvs, ref_seq?) / normalizer.normalize_3prime_shift(...) / normalizer.ins_to_dup(...) |
Full normalization / 3′-shift / ins→dup |
| Backtranslation | backtranslate(gene, p_hgvs) / backtranslate_protein(p_hgvs) |
Protein → nucleotide via CDS / codon table |
| Conversion | hgvs_to_vcf(...) / vcf_to_hgvs(...) / hgvs_to_spdi(...) / spdi_to_hgvs(...) |
HGVS ↔ VCF ↔ SPDI |
c_to_p(c_hgvs, gene) |
Coding HGVS → protein HGVS | |
| Extraction | extract(ref, obs, acc?, prefix?) |
Diff two sequences → HGVS |
| Liftover | liftover_g_to_assembly(hgvs, target?) / liftover_transcript(gene, c_hgvs, target?) |
Assembly liftover / transcript→genomic→liftover |
| Transcription | c_to_g(c_hgvs, gene) / g_to_c(g_hgvs, gene) / transcription.get_cds_exon_map(gene) |
Coding ↔ genomic / exon structure |
| Translation | translate_variant(c_hgvs, gene) / get_protein_effect(c_hgvs, gene) |
c.HGVS → p.HGVS / detailed effect dict |
License
MIT License
Note on Naming: This package is not affiliated with the read simulator "VarSim" (PMID: 25524895).
Metadata
Release files for varsim 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| varsim-2.0.1.tar.gz | 47.7 kB | Without provenance | Details for varsim-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| varsim-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for varsim-2.0.1-py3-none-any.whl |
Total release size: 94.3 kB
Release files / varsim-2.0.1.tar.gz
| Download URL | varsim-2.0.1.tar.gz |
|---|---|
| Size | 47.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2680d1df29f5cd214b21465a492c9f1a38169b1c2b94114e8d8aec95df2804f1
|
|
BLAKE2b-256 checksum How to use checksums |
5e5f5e0a0c87868ead7339f481c3b49b02ae5537d972a39c7d72e9025951ce28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / varsim-2.0.1-py3-none-any.whl
| Download URL | varsim-2.0.1-py3-none-any.whl |
|---|---|
| Size | 46.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1494e400defa53605b9327d1883e139f6c03e9c25d3d69b132af9e43e8565aec
|
|
BLAKE2b-256 checksum How to use checksums |
13d1cafa52bbba56ab2a192bd56434ff0d56eddb564b40a6fb76bea36e93864f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for varsim 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.