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.41.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.41-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.41-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.41-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.41-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

File details

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

File metadata

  • Download URL: bwamem-0.0.41.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.41.tar.gz
Algorithm Hash digest
SHA256 002a5e2c93d4be4630a8dada9d5f337dc4dc1df039dfc6ad18f574592a84c4ae
MD5 0f78b411af5b8b98980ff7b0aee13877
BLAKE2b-256 02b52de366cee86ac053ce3c734dda9fc7db87aad3d3c0a5da2d95f484e3f2e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.41.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.41-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bwamem-0.0.41-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d8f25940456e32b5a4db206bcdd6ccbf5b784f753ccd5a4ae7bc6510bc191e3f
MD5 e10ade8d9a72a762049356c6d89c3a95
BLAKE2b-256 55736e72473a75b66c610211e580070ded401d7a280f2d630d9389bf8d58ae39

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.41-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.41-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bwamem-0.0.41-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2fb708b5bb9ca49a9b3d53535e9ac30560450d812294b1edc46dff52f75f4d8f
MD5 4f4f27f59b9e9882e864b699cb99b68e
BLAKE2b-256 da9f9e2a3def611a5171aa2a8a913e3b8fca5dba8bcfe6e28574ac46daa44d20

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.41-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.41-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bwamem-0.0.41-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fede4c53da6c883980512211d873a8e8d359a069f4eb41f3a5d8719bcf780498
MD5 9065f90e3d579aa7ee8b574a3ef53641
BLAKE2b-256 c4c054d98397abd35669f44ae476333b2ba331cdc244ea4a520fb79e66f0ad0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.41-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.41-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bwamem-0.0.41-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9be9287eae242725df20ae4347df08ab9e228fd3218cb1e7fd903278f873cba8
MD5 b1ff4c5592566039ace81d328de9bb20
BLAKE2b-256 63ccefd0affa62bbe045934a84ccd0bd040b059ad5e95c78046c955883cd01a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for bwamem-0.0.41-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.

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