Skip to main content

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.LazyFrame to 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: String
  • consequences: List(ConsequenceEnum)
  • putative_impact: ImpactEnum
  • gene_symbol: String
  • gene_id: String
  • feature_type: String
  • feature_id: String
  • feature_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: String
  • hgvs_n: String
  • hgvs_c: String
  • hgvs_p: String
  • distance: Int32
  • strand: Int32
  • messages: 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.46.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mehari 0.46.0
File Size Uploaded
mehari-0.46.0.tar.gz 1.7 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for mehari 0.46.0
File Interpreter ABI Platform
mehari-0.46.0-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details
mehari-0.46.0-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details
mehari-0.46.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: 28.6 MB

Release files / mehari-0.46.0.tar.gz

Download URL mehari-0.46.0.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
a44d0c2adca2c44abd7442c84ea2e74e008a198344eea94f6359cd46f3c48a40
BLAKE2b-256 checksum
How to use checksums
51c28aef49a9e8c4bf92eaba66066a2f7489f2a4f88733099ce37c3cd2e2792e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / mehari-0.46.0-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL mehari-0.46.0-cp313-cp313-manylinux_2_28_x86_64.whl
Size 9.0 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
6fe865b207a30c946a8408f4771f656018188a5a060d4801851416fa34a70ad0
BLAKE2b-256 checksum
How to use checksums
68a97cc8723b535f9479059bcad151580355798fd4074795d4e99a0d0422436d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / mehari-0.46.0-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL mehari-0.46.0-cp312-cp312-manylinux_2_28_x86_64.whl
Size 9.0 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
dee422d4705293123caa0612cef4885b9fed1a65b0517003c14da2595330a871
BLAKE2b-256 checksum
How to use checksums
8baf6846467af2784796e30412754921d32d765805275c4c27febf37a1678ed4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / mehari-0.46.0-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL mehari-0.46.0-cp311-cp311-manylinux_2_28_x86_64.whl
Size 9.0 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
0bb4a709611ea49337735a2fdcdcc151c1197cefa7724f3632db4c042f445528
BLAKE2b-256 checksum
How to use checksums
f001f98edb78e401f7e1da4fe5febdbd5594b8b0de73e03df3502e3c64c692d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

This release

0.46.0 This release

4 release files

0.44.1

4 release files

0.44.0

4 release files

0.43.3

4 release files

0.42.0

4 release files

0.41.2

4 release files

0.41.1

4 release files

0.41.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page