Skip to main content

Mappluspy: mm2-plus Python Binding

Mappluspy provides a convenient interface to mm2-plus, an optimized minimap2-compatible C/C++ program to align genomic and transcript nucleotide sequences.

Mappluspy is built on the code base and public API design of mappy, the official minimap2 Python binding by Heng Li. We gratefully credit mappy and minimap2 for the original binding interface and implementation. The key difference is that mappluspy uses mm2-plus as the base aligner rather than upstream minimap2.

To maintain consistency with mappy for users moving between minimap2 and mm2-plus, the API descriptions and examples below are adapted from the mappy documentation and modified to use mappluspy.

Installation

Mappluspy depends on zlib. It can be installed with pip:

pip install --user mappluspy

or from the mm2-plus GitHub repository (Cython required):

git clone https://github.com/at-cg/mm2-plus
cd mm2-plus
python3 -m pip install .

Usage

The following Python script demonstrates the key functionality of mappluspy:

import mappluspy as mp

a = mp.Aligner("test/MT-human.fa")  # load or build index
if not a:
    raise Exception("ERROR: failed to load/build index")

s = a.seq("MT_human", 100, 200)     # retrieve a subsequence from the index
print(mp.revcomp(s))                # reverse complement

for name, seq, qual in mp.fastx_read("test/MT-orang.fa"):  # read a fasta/q sequence
    for hit in a.map(seq):  # traverse alignments
        print("{}\t{}\t{}\t{}".format(hit.ctg, hit.r_st, hit.r_en, hit.cigar_str))

APIs

Mappluspy implements two classes and two global functions.

Class mappluspy.Aligner

mappluspy.Aligner(fn_idx_in=None, preset=None, ...)

This constructor accepts the following arguments:

  • fn_idx_in: index or sequence file name. mm2-plus automatically tests the file type. If a sequence file is provided, mm2-plus builds an index. The sequence file can be optionally gzip'd. This option has no effect if seq is set.
  • seq: a single sequence to index. The sequence name will be set to N/A.
  • preset: minimap2/mm2-plus preset. Currently, mm2-plus supports the following presets: sr for single-end short reads; map-pb for PacBio read-to-reference mapping; map-ont for Oxford Nanopore read mapping; splice for long-read spliced alignment; asm5 for assembly-to-assembly alignment; asm10 for full genome alignment of closely related species. Note that the Python module does not support all-vs-all read overlapping.
  • k: k-mer length, no larger than 28
  • w: minimizer window size, no larger than 255
  • min_cnt: minimum number of minimizers on a chain
  • min_chain_score: minimum chaining score
  • bw: chaining and alignment band width (initial chaining and extension)
  • bw_long: chaining and alignment band width (RMQ-based rechaining and closing gaps)
  • best_n: max number of alignments to return
  • n_threads: number of indexing threads; 3 by default
  • extra_flags: additional flags defined in minimap.h
  • fn_idx_out: name of file to which the index is written. This parameter has no effect if seq is set.
  • scoring: scoring system. It is a tuple/list consisting of 4, 6 or 7 positive integers. The first 4 elements specify match scoring, mismatch penalty, gap open and gap extension penalty. The 5th and 6th elements, if present, set long-gap open and long-gap extension penalty. The 7th sets a mismatch penalty involving ambiguous bases.
mappluspy.Aligner.map(seq, seq2=None, cs=False, MD=False)

This method aligns seq against the index. It is a generator, yielding a series of mappluspy.Alignment objects. If seq2 is present, mappluspy performs paired-end alignment, assuming the two ends are in the FR orientation. Alignments of the two ends can be distinguished by the read_num field (see Class mappluspy.Alignment below). Argument cs asks mappluspy to generate the cs tag; MD is similar. These two arguments might slightly degrade performance and are not enabled by default.

mappluspy.Aligner.seq(name, start=0, end=0x7fffffff)

This method retrieves a (sub)sequence from the index and returns it as a Python string. None is returned if name is not present in the index or the start/end coordinates are invalid.

mappluspy.Aligner.seq_names

This property gives the array of sequence names in the index.

Class mappluspy.Alignment

This class describes an alignment. An object of this class has the following properties:

  • ctg: name of the reference sequence the query is mapped to
  • ctg_len: total length of the reference sequence
  • r_st and r_en: start and end positions on the reference
  • q_st and q_en: start and end positions on the query
  • strand: +1 if on the forward strand; -1 if on the reverse strand
  • mapq: mapping quality
  • blen: length of the alignment, including both alignment matches and gaps but excluding ambiguous bases.
  • mlen: length of the matching bases in the alignment, excluding ambiguous base matches.
  • NM: number of mismatches, gaps and ambiguous positions in the alignment
  • trans_strand: transcript strand. +1 if on the forward strand; -1 if on the reverse strand; 0 if unknown
  • is_primary: if the alignment is primary (typically the best and the first to generate)
  • read_num: read number that the alignment corresponds to; 1 for the first read and 2 for the second read
  • cigar_str: CIGAR string
  • cigar: CIGAR returned as an array of shape (n_cigar,2). The two numbers give the length and the operator of each CIGAR operation.
  • MD: the MD tag as in the SAM format. It is an empty string unless the MD argument is applied when calling mappluspy.Aligner.map().
  • cs: the cs tag.

An Alignment object can be converted to a string with str() in the following format:

q_st  q_en  strand  ctg  ctg_len  r_st  r_en  mlen  blen  mapq  cg:Z:cigar_str

It is effectively the PAF format without the QueryName and QueryLength columns (the first two columns in PAF).

Miscellaneous Functions

mappluspy.fastx_read(fn, read_comment=False)

This generator function opens a FASTA/FASTQ file and yields a (name,seq,qual) tuple for each sequence entry. The input file may be optionally gzip'd. If read_comment is True, this generator yields a (name,seq,qual,comment) tuple instead.

mappluspy.revcomp(seq)

Return the reverse complement of DNA string seq. This function recognizes IUB code and preserves the letter cases. Uracil U is complemented to A.

Metadata

Release files for mappluspy 1.30.1

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

Source distribution (sdist)

Source distribution for mappluspy 1.30.1
File Size Uploaded Provenance Actions
mappluspy-1.30.1.tar.gz 298.5 kB Without provenance Details for mappluspy-1.30.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for mappluspy 1.30.1
File Actions
mappluspy-1.30.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for mappluspy-1.30.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
mappluspy-1.30.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for mappluspy-1.30.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
mappluspy-1.30.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for mappluspy-1.30.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
mappluspy-1.30.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details for mappluspy-1.30.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
mappluspy-1.30.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details for mappluspy-1.30.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Total release size: 6.8 MB

Release files / mappluspy-1.30.1.tar.gz

Download URL mappluspy-1.30.1.tar.gz
Size 298.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9b7bce87771156c6f4b41e7314cac9e2b1c0b317dc60b6c8d2f95fe3f6f590f7
BLAKE2b-256 checksum
How to use checksums
9b3a42bbd2b375b64c5fd12962f30fa7b0559cfafa6c653adeceffeed96c2c9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release files / mappluspy-1.30.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL mappluspy-1.30.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
244ff6be1f354f6cd916892b9bb83cbf108cf3bb18746fbca5b84a0593ea2e50
BLAKE2b-256 checksum
How to use checksums
f0666e015cd7c0e4608a30e5637dc622178204c5a3608bd4557c571a0237a09f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release files / mappluspy-1.30.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL mappluspy-1.30.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
03afd50fc5603722dab3bf84644097b2e5fc26b174d0b90dd06230e19ed83bd5
BLAKE2b-256 checksum
How to use checksums
804d0a8a22e4075e225cd98ed0e9933b2c0c71d5c9050bf2669e091107e01091
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release files / mappluspy-1.30.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL mappluspy-1.30.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
2554f20c5a46d4555224237e06f94aca36db3ca1877b6a31a36cc3d169858ae9
BLAKE2b-256 checksum
How to use checksums
0012576f43b17dabcd84e9c7ddcdabbd42cf381f39eaaced97f97a825f8544c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release files / mappluspy-1.30.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL mappluspy-1.30.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ce3eba2093d1801d58023ef66e5caeac763aae6eaf25334e003ed1d6889fad67
BLAKE2b-256 checksum
How to use checksums
0c0017d27e95f234e632294586959ffe254a9e29eae514f0ce4bc6e1f937fe19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release files / mappluspy-1.30.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL mappluspy-1.30.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
d999ab0ce1825ae883e3c9e16f9813892f216fbec9aaa019d1a206ef4b43857f
BLAKE2b-256 checksum
How to use checksums
0d970ad21dfa68d4bfbac3586991bc6125bf215d59d346d5aa586827997e0810
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Security for mappluspy 1.30.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.

Release history Release notifications | RSS feed

This release

1.30.1 This release

6 release files No provenance

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