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

indexer = BwaIndexer()
# Progress messages are captured by default (no console spam)
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

indexer = 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.build_index('genome.fasta', verbose=0)

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

# Debug mode
indexer.build_index('genome.fasta', verbose=3)

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.14.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.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (376.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

bwamem-0.0.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (376.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

bwamem-0.0.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (376.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

bwamem-0.0.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (376.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: bwamem-0.0.14.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.14.tar.gz
Algorithm Hash digest
SHA256 d1b2830a40e08e6a93474dd1287c1b4a76517a16fff75883148f8d34e16379ca
MD5 0b910717ede0e8dbff96e1f1a016d0e6
BLAKE2b-256 e7726309e6e1fbcff2c071933456118664439f0eedefff329ea30ecb825f10db

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bwamem-0.0.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 43a76792a9daf050ddf6ac6e6ed88fcae57b3945945e60771222fe61c99b6e3c
MD5 bc032decb1778e2022693adc985b0af1
BLAKE2b-256 990e632803ae4472f917fa620e271cba4372b6c2d8afee0d0e5d2842d2a0a4b4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bwamem-0.0.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 74ec8c8a6bbca8671941945dda8701a410e5029c70ea25579277e95c1a27f8c7
MD5 ac62c04476721cd6ed9c6257cfa732b7
BLAKE2b-256 9c3d4a99f3bf41787b0fe04a000effa2a9b2f5b4da568edfbd9a149535d6ce36

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bwamem-0.0.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8e124844e433e7d2247fb954f7fd8f94d9f6121a0d9c12a19ebc487cddd59b72
MD5 6928184860effb86f252429556692d4d
BLAKE2b-256 a9797e954456a9c0524e7c326945967d9565c2c296ca2023d00d49d562de3bc7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bwamem-0.0.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec760973fbb704cbfbb9a8757f678f7f81041473d31bed4de400e5d6fcee20ac
MD5 4e58d69154d2cc8ee94916802c90a719
BLAKE2b-256 96e991a310ec9edc7ed8a2716670806c3d3c59290126d17ba5069985283c469d

See more details on using hashes here.

Provenance

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