hgvs - manipulate biological sequence variants according to Human Genome Variation Society recommendations
The hgvs package provides a Python library to parse, format, validate,
normalize, and map sequence variants according to Variation
Nomenclature (aka Human Genome Variation
Society) recommendations.
Specifically, the hgvs package focuses on the subset of the HGVS
recommendations that precisely describe sequence-level variation
relevant to the application of high-throughput sequencing to clinical
diagnostics. The package does not attempt to cover the full scope of
HGVS recommendations. Please refer to
issues for limitations.

Latest Release

Development

Features
- Parsing is based on formal grammar.
- An easy-to-use object model that represents most variant types
(SNVs, indels, dups, inversions, etc) and concepts (intronic
offsets, uncertain positions, intervals)
- A variant normalizer that rewrites variants in canonical forms and
substitutes reference sequences (if reference and transcript
sequences differ)
- Formatters that generate HGVS strings from internal representations
- Tools to map variants between genome, transcript, and protein
sequences
- Reliable handling of regions genome-transcript discrepancies
- Pluggable data providers support alternative sources of transcript
mapping data
- Extensive automated tests, including those for all variant types and
"problematic" transcripts
- Easily installed using remote data sources. Installation with local
data sources is straightforward and completely obviates network
access
Citation
Wang M, Callenberg KM, Dalgleish R, Fedtsov A, Fox N, Freeman PJ, et al.
hgvs: A Python package for manipulating sequence variants using HGVS nomenclature: 2018 Update.
Hum Mutat. 2018. doi:10.1002/humu.23615
Important Notes
- You are encouraged to browse
issues. All known issues
are listed there. Please report any issues you find.
- Use a pip package specification to stay within minor releases.
For example,
hgvs>=1.5,<1.6. hgvs uses Semantic
Versioning.
Installing HGVS Locally
Important: For more detailed installation and configuration
instructions, see the HGVS readthedocs
Prerequisites
python3
hgvs uses psycopg with its
prebuilt binary wheels to talk to UTA, so no PostgreSQL client
libraries or compiler are required for a standard install.
Installation Steps
By default, hgvs uses remote data sources, which makes
installation easy. If you would like to use local instances of the data sources, see the readthedocs.
-
Create a virtual environment using your preferred method.
Example:
python3 -m venv venv
-
Run the following commands in your virtual environment:
source venv/bin/activate
pip install --upgrade setuptools
pip install hgvs
See Installation
instructions
for details, including instructions for installing Universal Transcript
Archive (UTA) and
SeqRepo locally.
Examples and Usage
See examples and readthedocs for usage.
Developer Setup
The hgvs package is a community effort. Please see
Contributing to get
started in submitting source code, tests, or documentation. Thanks for getting
involved!
Install Prerequisites
These tools are required to get started:
- git: Version control system
- GNU make: Current mechanism for consistent invocation of developer tools.
- uv: An extremely fast Python package and project manager, written in Rust.
MacOS or Linux Systems
Linux (Debian-based systems)
You may also install using distribution packages:
sudo apt install git make
Then install uv using the uv installation instructions.
One-time development setup
Create a Python virtual environment, install dependencies, install git hooks (prek), and install an editable package:
make devready
Development
N.B. Developers are expected to use make to invoke tools to
ensure consistency with the CI/CD pipelines. Type make to see a list of
supported targets. A subset are listed here:
» make
🌟🌟 biocommons conventional make targets 🌟🌟
Using these targets promots consistency between local development and ci/cd commands.
usage: make [target ...]
BASIC USAGE
help Display help message
SETUP, INSTALLATION, PACKAGING
devready Prepare local dev env: Create virtual env, install the git hooks (prek)
build Build package
publish publish package to PyPI
FORMATTING, TESTING, AND CODE QUALITY
cqa Run code quality assessments
test Test the code with pytest
test-coverage Test the code with pytest and generate coverage report
test-matrix Test with each supported Python version (via nox)
DOCUMENTATION
docs-serve Build and serve the documentation
docs-test Test if documentation can be built without errors
docs-deploy Deploy documentation (no-op: Read the Docs builds hgvs docs)
CLEANUP
clean Remove temporary and backup files
cleaner Remove files and directories that are easily rebuilt
cleanest Remove all files that can be rebuilt
distclean Remove untracked files and other detritus
Testing
make test # tests, no coverage
make test-coverage # tests with coverage; writes coverage.xml
make test-matrix # `make test` on each Python version listed in pyproject.toml classifiers (nox)
make test is the test command everywhere: locally, in each nox session, and in each CI matrix leg. One CI leg runs make test-coverage and uploads to Codecov instead.
Known limitation: nox does not forward arguments, so nox -- -k foo runs the full suite. Run one version with uv run nox -s tests-3.11, or a subset on one version with uv run --isolated --python 3.11 pytest -k foo (--isolated leaves .venv untouched).
VS Code
Testing → Configure Python Tests → pytest → root directory. No other settings are needed; coverage is off by default, so breakpoints work.
Coverage gate
Codecov’s codecov/project status fails when coverage drops more than 0.5% from the base commit. Make codecov/project a required status check in branch protection, or the gate does nothing.
Test data cache
Existing tests use a cache that is committed with the repo to ensure that tests do not require external networking. To develop new tests, which requires loading the cache, you should install UTA and Seqrepo (and the rest service) locally.
docker compose --project-name biocommons -f ./misc/docker-compose.yml up
IMPORTANT: Loading the test caches is currently hampered by
#551,
#760, and
#761. To load reliably, use
make test-relearn-iteratively for now.
评论