Skip to main content

Bindings to bwa aligner

Project description

bwamem

Python bindings for the BWA-MEM aligner.

Installation

pip install bwamem

Usage

Build Index

from bwamem import BwaIndexer

indexer = BwaIndexer()
index_path = indexer.build_index('reference.fa')

Single-End Alignment

from bwamem import BwaAligner

aligner = BwaAligner('path/to/index')
alignments = aligner.align('ACGATCGCGATCGA')

for aln in alignments:
    print(f'{aln.ctg}:{aln.r_st} strand={aln.strand} mapq={aln.mapq}')

Paired-End Alignment

read1 = 'ACGATCGCGATCGA'
read2 = 'TTCGATCGATCGAT'

paired_alignments = aligner.align(read1, read2)

for pe_aln in paired_alignments:
    print(f'Insert size: {pe_aln.insert_size}, Proper pair: {pe_aln.is_proper_pair}')

Retrieve Sequences from Index

# Get full sequence
seq = aligner.seq('chr1')

# Get subsequence
subseq = aligner.seq('chr1', start=100, end=200)

Monitor Index Building Progress

from bwamem import BwaIndexer

# Progress messages are captured by default (no console spam)
indexer = BwaIndexer(capture_progress=True)
index_path = indexer.build_index('genome.fasta')

# Check progress info
progress = indexer.get_progress()
print(f"Status: {progress['status']}")
print(f"Iterations: {progress['iterations']}")
print(f"Characters processed: {progress['characters_processed']}")

# Get progress percentage (if available)
if indexer.progress_percent:
    print(f"Progress: {indexer.progress_percent:.1f}%")

# Access all captured messages
for msg in progress['messages']:
    print(msg)

Control Index Building Verbosity

from bwamem import BwaIndexer

# Verbosity levels:
# 0 = silent (no output)
# 1 = quiet (only warnings/errors) - default
# 2 = normal (standard BWA messages)
# 3+ = debug (verbose output)

# Silent mode
indexer = BwaIndexer(verbose=0)
indexer.build_index('genome.fasta')

# Normal mode with progress messages shown in console
indexer = BwaIndexer(verbose=2, capture_progress=False)
indexer.build_index('genome.fasta')

# Debug mode with captured progress
indexer = BwaIndexer(verbose=3, capture_progress=True)
indexer.build_index('genome.fasta')

# Custom algorithm and block size
indexer = BwaIndexer(algorithm='bwtsw', block_size=50000000)
indexer.build_index('genome.fasta')

Read FASTA/FASTQ Files

from bwamem import fastx_read, read_paired_fastx

# Single-end (supports both FASTA and FASTQ)
for read in fastx_read('sequences.fasta.gz'):
    print(f'{read.name}: {read.sequence}')

# Paired-end
for read1, read2 in read_paired_fastx('R1.fastq', 'R2.fastq'):
    print(f'{read1.name}, {read2.name}')

Custom Options

# Specify alignment parameters
aligner = BwaAligner('path/to/index', options='-x ont2d -A 1 -B 0')

# Set custom insert size for paired-end reads
aligner = BwaAligner('path/to/index', insert_model=(500, 50))
paired_alignments = aligner.align(read1, read2)

Alignment Attributes

Each Alignment object contains the following attributes:

Attribute Description
ctg Contig/reference name
r_st Reference start position (0-based)
r_en Reference end position (property)
strand Strand: +1 for forward, -1 for reverse
q_st, q_en Query start/end positions
mapq Mapping quality score
cigar CIGAR as list of [length, op] pairs
cigar_str CIGAR string (property)
NM Edit distance
score Alignment score
is_primary Primary alignment flag

Calculated properties (computed on demand): r_en, cigar_str, blen, mlen

CIGAR operations: 0=M (match), 1=I (insertion), 2=D (deletion), 3=N (skip), 4=S (soft-clip), 5=H (hard-clip)

PairedAlignment contains: read1, read2 (Alignment objects), is_proper_pair (bool), insert_size (int or None)

License

  • Python bindings: Mozilla Public License 2.0
  • BWA: GNU General Public License v3.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bwamem-0.0.42.tar.gz (1.1 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bwamem-0.0.42-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (387.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

bwamem-0.0.42-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (387.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

bwamem-0.0.42-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (387.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

bwamem-0.0.42-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (387.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

bwamem-0.0.42-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (387.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

bwamem-0.0.42-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (409.3 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file bwamem-0.0.42.tar.gz.

File metadata

  • Download URL: bwamem-0.0.42.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bwamem-0.0.42.tar.gz
Algorithm Hash digest
SHA256 8ec87e8dfc08fd0d00040d4cdbc680f897a1d15d4e18b365e34ee5dff2b08371
MD5 25b402f2d6e3ff7dac3a6c3939c848c2
BLAKE2b-256 c787a4b71afe9b2867fd0fd4b3e64ab4a852a7331a4f289ff068064c3ba861b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.42.tar.gz:

Publisher: publish.yml on y9c/bwamem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bwamem-0.0.42-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bwamem-0.0.42-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 24d20cf1ee69ddf5071e5eb2d18525f131c5a2901d43c129a8879a4c3b7b9a26
MD5 700c6a4902de7183707276d644f7f69a
BLAKE2b-256 c960108571c292ac10fe62b7e18ac7292e5f9d0c2b502a2b68e85c150c23eb4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.42-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on y9c/bwamem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bwamem-0.0.42-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bwamem-0.0.42-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0bbec461b8754378aacd558e575b29f4f8e6ce462b4579deb63e8e5aecf1a02
MD5 65732ac2a0f22167064162247fe3b446
BLAKE2b-256 936cc6a6e02f288edab4b47db2b81c0b25be2435cf40c468e34319a728aa284e

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.42-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on y9c/bwamem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bwamem-0.0.42-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bwamem-0.0.42-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8dedea26549b0d97c64580b2e535b67fc159350a10197c55f4aa6dbcbc5ea441
MD5 b00d11f5aaaee95113483627fbfdd2f1
BLAKE2b-256 1b5f12cabd24c00f45aab3fc1b6b97f3daf02ad371024f3bc563567ac82893f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.42-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on y9c/bwamem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bwamem-0.0.42-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bwamem-0.0.42-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a190a1e4c7769c36ed1bab98188b273715c4e270aada596cfbb2eadef22a3bef
MD5 3f7fca51d958ce5547d9928dd1760ca0
BLAKE2b-256 3840ebd635b5b356077aa12584a0d50652cce19e04cf7d5a53d59f720f0e7a44

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.42-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on y9c/bwamem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bwamem-0.0.42-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bwamem-0.0.42-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be7e6af152d5ea9720c8cf0411943a01bbdcfb74c8dbc235e468da9dbb7555d0
MD5 be98d134405b1cd53a0a60670e46c6ca
BLAKE2b-256 501897e3affcaac95c678f0fecb6543598c2bc5a64dde6efdfd7571b33d8d7aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.42-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on y9c/bwamem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bwamem-0.0.42-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bwamem-0.0.42-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7589cd7797ffa447093a49cb49e3f263e6509e335972ebbf3791b2c624dcfaf5
MD5 d978a977c96a5fda0b4209eca7f5597d
BLAKE2b-256 fcb0cd3e516781bc01fbf9e490e91cb788582b2c7a62a57e4121da3240136586

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.42-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on y9c/bwamem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page