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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bwamem-0.0.19.tar.gz.
File metadata
- Download URL: bwamem-0.0.19.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad9c5e192d129e314701040030067bb30ea8bcb094bcaa0d448bb95f396caf0b
|
|
| MD5 |
e59d8bb91a0529fede2c536311c2092c
|
|
| BLAKE2b-256 |
b2a5e60aba04826832a51c1f5fc3e982e6a43056b0aaf8246b0cb4c0b91e0fe2
|
Provenance
The following attestation bundles were made for bwamem-0.0.19.tar.gz:
Publisher:
publish.yml on y9c/bwamem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bwamem-0.0.19.tar.gz -
Subject digest:
ad9c5e192d129e314701040030067bb30ea8bcb094bcaa0d448bb95f396caf0b - Sigstore transparency entry: 652588739
- Sigstore integration time:
-
Permalink:
y9c/bwamem@dd2f4a4fa5978d91bd76ef13795170375ff0fd88 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/y9c
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dd2f4a4fa5978d91bd76ef13795170375ff0fd88 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bwamem-0.0.19-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: bwamem-0.0.19-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 376.3 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f48d47b00c82ac96bb0e17fb9dd2691b067232d5ddb67e3ea1b228de2b6e3e66
|
|
| MD5 |
1c7e493ec66fbe3a64db45aa31e8e192
|
|
| BLAKE2b-256 |
d367e604001159137c7587968b82ead7ea5c030b0af7cdcdda332ddf4cbdc123
|
Provenance
The following attestation bundles were made for bwamem-0.0.19-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on y9c/bwamem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bwamem-0.0.19-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
f48d47b00c82ac96bb0e17fb9dd2691b067232d5ddb67e3ea1b228de2b6e3e66 - Sigstore transparency entry: 652588772
- Sigstore integration time:
-
Permalink:
y9c/bwamem@dd2f4a4fa5978d91bd76ef13795170375ff0fd88 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/y9c
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dd2f4a4fa5978d91bd76ef13795170375ff0fd88 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bwamem-0.0.19-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: bwamem-0.0.19-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 376.3 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a221677b0a6c2396fccb624ee25347274950fe94750693dc25b19f783d375238
|
|
| MD5 |
b60f8353c10ecf6b178a678f37b9c64a
|
|
| BLAKE2b-256 |
f193bef325640dab682b218f53b6f60a3d168c035298ff7b0d48213bf087ec77
|
Provenance
The following attestation bundles were made for bwamem-0.0.19-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on y9c/bwamem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bwamem-0.0.19-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
a221677b0a6c2396fccb624ee25347274950fe94750693dc25b19f783d375238 - Sigstore transparency entry: 652588781
- Sigstore integration time:
-
Permalink:
y9c/bwamem@dd2f4a4fa5978d91bd76ef13795170375ff0fd88 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/y9c
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dd2f4a4fa5978d91bd76ef13795170375ff0fd88 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bwamem-0.0.19-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: bwamem-0.0.19-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 376.3 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b1b8bf21c2cf29771c2631ec7049ca43ca19333d03ef012ec2536d8c6d88b33
|
|
| MD5 |
2269cd8fe945bb9cb1e127f7a3e9d827
|
|
| BLAKE2b-256 |
c5a49ff192ede741cd5309945968c046dd007713255ee02a63a9898e7ee9bae5
|
Provenance
The following attestation bundles were made for bwamem-0.0.19-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on y9c/bwamem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bwamem-0.0.19-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
6b1b8bf21c2cf29771c2631ec7049ca43ca19333d03ef012ec2536d8c6d88b33 - Sigstore transparency entry: 652588793
- Sigstore integration time:
-
Permalink:
y9c/bwamem@dd2f4a4fa5978d91bd76ef13795170375ff0fd88 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/y9c
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dd2f4a4fa5978d91bd76ef13795170375ff0fd88 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bwamem-0.0.19-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: bwamem-0.0.19-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 376.3 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
136f9c0e5a5534703b336cb95b7b4f1f9bf7646508027d2d5a05521f0c8b3f16
|
|
| MD5 |
b74509d095296fd046a84679f14d0579
|
|
| BLAKE2b-256 |
2959e66b4e4ea730c01b97f58c18c1a0e28c106c5cdc63af7d48efae4db72b4a
|
Provenance
The following attestation bundles were made for bwamem-0.0.19-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on y9c/bwamem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bwamem-0.0.19-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
136f9c0e5a5534703b336cb95b7b4f1f9bf7646508027d2d5a05521f0c8b3f16 - Sigstore transparency entry: 652588814
- Sigstore integration time:
-
Permalink:
y9c/bwamem@dd2f4a4fa5978d91bd76ef13795170375ff0fd88 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/y9c
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dd2f4a4fa5978d91bd76ef13795170375ff0fd88 -
Trigger Event:
push
-
Statement type: