Skip to main content

Python bindings for the Rust FFI minimap2 library. In development! Feedback appreciated!

Why?

PyO3 makes it very easy to create Python libraries via Rust. Further, we can use Polars to export results as a dataframe (which can be used as-is, or converted to Pandas). Python allows for faster experimentation with novel algorithms, integration into machine learning pipelines, and provides an opportunity for those not familiar with Rust nor C/C++ to use minimap2.

Current State

Very early alpha. Please use, and open an issue for any features you need that are missing, and for any bugs you find.

How to use

Requirements

Polars and PyArrow, these should be installed when you install minimappers2

Creating an Aligner Instance

aligner = map_ont()
aligner.threads(4)

If you want an alignment performed, rather than just matches, enable .cigar()

aligner = map_hifi()
aligner.cigar()

Please note, at this time the following syntax is NOT supported:

aligner = map_ont().threads(4).cigar()

Creating an index

aligner.index("ref.fa")

To save a built-index, for future processing use:

aligner.index_and_save("ref.fa", "ref.mmi")

Then next time you use the index will be faster if you use the saved index instead.

aligner.load_index("ref.mmi")

Aligning a Single Sequence

query = Sequence(seq_name, seq)
aligner.map1(query)

# Example
seq = "CCAGAACGTACAAGGAAATATCCTCAAATTATCCCAAGAATTGTCCGCAGGAAATGGGGATAATTTCAGAAATGAGAG"
result = aligner.map1(Sequence("MySeq", seq))

Where seq_name and seq are both strings. The output is a Polars DataFrame.

Aligning Multiple Sequences

seqs = [Sequence("name of seq 1", seq1), 
        Sequence("name of seq 2", seq1)]
result = aligner.map(seqs)

Example Notebook

Please see the example notebook for more examples.

Mapping a file

Please open an issue if you need to map files from this API.

Results

All results are returned as Polars dataframes. You can convert Polars dataframes to Pandas dataframes with .to_pandas()

  • Polars is the fastest dataframe library in the Python Ecosystem.
  • Polars provides a nice data bridge between Rust and Python.

For more information, please see the Polars User Guide or the Polars Guide for Pandas users.

Example of Results

Here is an image of the resulting dataframe Resulting Dataframe Image

NOTE Mapq, Cigar, and others will not show up unless .cigar() is enabled on the aligner itself.

Errors

As this is a very-early stage library, error checking is not yet implemented. When things crash you will likely need to restart your python interpreter (jupyter kernel). Let me know what happened and open an issue and I will get to it.

Compatability

  • Linux: Yes

  • Mac: Unknown

  • Windows: Unlikely

  • x86_64: Yes

  • aarch64: Unknown (open an issue)

  • neon: No (Open an issue)

  • Google Colab: Yes

Performance

Effort has been made to make this as performant as possible, but if you need more performance, please use minimap2 directly and import the results.

Citation

You should cite the minimap2 papers if you use this in your work.

Li, H. (2018). Minimap2: pairwise alignment for nucleotide sequences. Bioinformatics, 34:3094-3100. [doi:10.1093/bioinformatics/bty191][doi]

and/or:

Li, H. (2021). New strategies to improve minimap2 alignment accuracy. Bioinformatics, 37:4572-4574. [doi:10.1093/bioinformatics/btab705][doi2]

Changelog

0.1.5

  • Updated minimap2-rs, polars, pyo3 deps
  • Add new presets

0.1.4

  • Update pyo3, polars, minimap2-rs, and mimalloc deps

0.1.1

  • Update pyo3 and polars deps
  • Add with_seq for indexing TODO

0.1.0

  • Initial Functions implemented
  • Return results as Polars dfs

Funding

Genomics Aotearoa

Metadata

Release files for minimappers2 0.1.7

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

Source distribution (sdist)

Source distribution for minimappers2 0.1.7
File Size Uploaded Provenance Actions
minimappers2-0.1.7.tar.gz 2.1 MB Without provenance Details for minimappers2-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for minimappers2 0.1.7
File Interpreter ABI Platform Actions
minimappers2-0.1.7-cp37-abi3-manylinux_2_34_x86_64.whl CPython 3.7 abi3 Linux glibc 2.34+ x86-64 Details for minimappers2-0.1.7-cp37-abi3-manylinux_2_34_x86_64.whl

Total release size: 6.3 MB

Release files / minimappers2-0.1.7.tar.gz

Download URL minimappers2-0.1.7.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
c94b6a9b7fa807a3586719ce806a50e1d82800b86f704019f22e8220f12c4e3d
BLAKE2b-256 checksum
How to use checksums
b22b86702e9300f3883f778941045fcc59ae861f44f3f2ae828a7ff83eba1331
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.1

Release files / minimappers2-0.1.7-cp37-abi3-manylinux_2_34_x86_64.whl

Download URL minimappers2-0.1.7-cp37-abi3-manylinux_2_34_x86_64.whl
Size 4.2 MB
Tags CPython 3.7 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
22af4946fc0b7991a7891daceed8756738e98d3ae9b17ce17ee6b6a09842c708
BLAKE2b-256 checksum
How to use checksums
df7e0c98585122bb0c2c844cc2277b3a7fc55b54b70156dc750cafab7290ce08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.1

Security for minimappers2 0.1.7

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.

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