mehari
Python bindings for the mehari Rust library.
Features
- Single variants: Annotate a single variant using a format string (
chr:pos:ref:alt) or keyword arguments. - Multiple variants (experimental): Evaluate the compound effect of multiple variants.
- DataFrames: Process batches of variants by passing a
polars.DataFrame. - LazyFrames: Support for
polars.LazyFrameto process large datasets (like Parquet files) without loading everything into memory.
Usage
Initialize SeqvarsAnnotator with your transcript database (see
mehari-data-tx) and a reference genome (FASTA, uncompressed,
with index).
from mehari import SeqvarsAnnotator
annotator = SeqvarsAnnotator(
transcript_db_paths=["path/to/txs.bin.zst"],
reference_path="path/to/reference.fa"
)
To annotate a single variant either use colon separated format string or keyword arguments:
result1 = annotator.annotate("17:41197701:G:C")
result2 = annotator.annotate(chromosome="3", position=193332511, reference="G", alternative="T")
To annotate multiple phased variants together as a single compound event (Experimental):
Note: Mehari does not infer phasing. When using
annotate_multiple, mehari assumes all provided variants are on the same chromosome, exist on the same haplotype, and do not overlap.
result1 = annotator.annotate_multiple(["1:37799635:TA:A", "1:37799639:C:CG"])
result2 = annotator.annotate_multiple([
{"chromosome": "1", "position": 37799635, "reference": "TA", "alternative": "A"},
{"chromosome": "1", "position": 37799639, "reference": "C", "alternative": "CG"}
])
To annotate a batch of variants, pass a polars.DataFrame or polars.LazyFrame.
import polars as pl
df = pl.DataFrame(
{
"chromosome": ["17", "3"],
"position": [41197701, 193332511],
"reference": ["G", "G"],
"alternative": ["C", "T"],
},
schema={
"chromosome": pl.Categorical, "position": pl.Int32,
"reference": pl.String, "alternative": pl.String
}
)
annotated_df = annotator.annotate(df)
Schemas and types
Enums
Mehari exports its internal enums to Python so you can use them for filtering or comparisons:
from mehari import ConsequenceEnum, ImpactEnum
DataFrame Schema
When annotating a DataFrame or LazyFrame, mehari appends an "annotation" column.
This column is a polars List(Struct) with the following fields:
allele:Stringconsequences:List(ConsequenceEnum)putative_impact:ImpactEnumgene_symbol:Stringgene_id:Stringhgnc_id:Stringfeature_type:Stringfeature_id:Stringfeature_biotype:List(String)feature_tags:List(String)rank:Struct(ord: Int32, total: Int32)cdna_pos:Struct(ord: Int32, total: Int32)cds_pos:Struct(ord: Int32, total: Int32)protein_pos:Struct(ord: Int32, total: Int32)hgvs_g:Stringhgvs_n:Stringhgvs_c:Stringhgvs_p:Stringdistance:Int32strand:Int32messages:List(String)
Building a transcript database
To build a transcript database, you can use the build_transcript_db function:
from mehari import build_transcript_db
build_transcript_db(
assembly="grch38",
annotation=["grch38.gff.gz"],
transcript_sequences="grch38.fasta",
transcript_source="ensembl",
output="grch38.bin.zst"
)
This may take a while (several minutes for GRCh38 + Ensembl).
Most of the time goes into compressing the database at the default compression_level=19.
To show a progress bar for each step, pass a tqdm-compatible class as progress, for example progress=tqdm.auto.tqdm.
To follow the steps in between, enable logging.
Logging
mehari writes its log messages to Python's logging module, under the logger mehari.
By default, Python shows only warnings and errors.
To also see progress messages, enable the INFO level:
import logging
logging.basicConfig(level=logging.INFO)
Configure logging before you create a SeqvarsAnnotator or call build_transcript_db.
mehari caches the log levels and rereads them only when one of these two starts.
Metadata
Release files for mehari 0.47.0
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 | |
|---|---|---|---|---|
| mehari-0.47.0.tar.gz | 1.8 MB | Without provenance | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mehari-0.47.0-cp313-cp313-manylinux_2_28_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.28+ x86-64 | Details |
| mehari-0.47.0-cp312-cp312-manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64 | Details |
| mehari-0.47.0-cp311-cp311-manylinux_2_28_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.28+ x86-64 | Details |
Total release size: 31.4 MB
Release files / mehari-0.47.0.tar.gz
| Download URL | mehari-0.47.0.tar.gz |
|---|---|
| Size | 1.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11a3ae3ffbe5710655f7b92fd2700a5c662524274ace01424db2bed3e6eb02f2
|
|
BLAKE2b-256 checksum How to use checksums |
2df09bed4de9b6e6467efa2b710e1c9b3ad443a818a79c12031fe85670210b7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / mehari-0.47.0-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | mehari-0.47.0-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 9.9 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
d779e28f68981d085d20b3ad2ca1a457fc4b25d3f9fcba067113de98e254d2b2
|
|
BLAKE2b-256 checksum How to use checksums |
c03b4b3ff9928ad00dd5c27e245f8b56337c7a24cfdbe12bdb4c200a330050b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / mehari-0.47.0-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | mehari-0.47.0-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 9.9 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
4df9ebc2963d00a4585742eb747519e5b1321e1c40a5344ce67b095f342b9b2b
|
|
BLAKE2b-256 checksum How to use checksums |
45f1ec42103e019c897535d6caa39735c7fc8e96ec4376e36b2d1335684e367a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Release files / mehari-0.47.0-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | mehari-0.47.0-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 9.9 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
7486b41c08465d31418c913107eafbfeaa8971cbc547502394f86c737d095b79
|
|
BLAKE2b-256 checksum How to use checksums |
676609dd93d036fda6a4e60e992a20cf32d6723114a2a5df17b1aa9e1d193491
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.15.0
|
Security for mehari 0.47.0
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.