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)

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

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

bwamem-0.0.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (375.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

bwamem-0.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (375.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

bwamem-0.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (375.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: bwamem-0.0.7.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.7.tar.gz
Algorithm Hash digest
SHA256 47d43d88169604b19be6f5deba83bbdf05ba92b0530bddaeca84798a07216004
MD5 6d2aaab7d3b2f69cfcb4b158265efa4f
BLAKE2b-256 65daaf6f5a68bf9664680363aa43def10484a3533b6241c5f56c6166b1a74950

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bwamem-0.0.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 33a8f81bc093e3a79da699f25ca4c0f30af4421e2713c2059572de81dbfd941b
MD5 c200b185ca619d8e743f04a04a3d37dd
BLAKE2b-256 9f731a01b2bd4b5c95a8f92cc403bb7ea95bf3563de344b56b7d53fa3ad7ee42

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bwamem-0.0.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c17d1d161542392d6f39e68c918570033dd50196b6b52671ddbd7dbb7d11dc49
MD5 310a83f30e088d3a2d6f932d445caa31
BLAKE2b-256 bd1c0995873cb3fc6a66a02fa4a7ca2cf5533ff11ea0a0bebf1ebdec69c978cc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bwamem-0.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5446512e9fcef6e81a25cc33d45fb94deb83658affdce341f5d9bc98f212f1d
MD5 a0b70d1ff5cbfb83cb892c9dfd6ed807
BLAKE2b-256 ec7869613c912724b4cdba7f3df7529987c9ae3413ae86b8d60650db059b1021

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bwamem-0.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1aae9ec61fbcadd6ecd2c17baa00f54aa40f57836e70211136de3d5fb061a99c
MD5 e0d546db931249c9c3d7f28e4b6ac7a8
BLAKE2b-256 201bdca2d95000f742f387304e31e78bd925e41cfa8f88905a312d0d982241ac

See more details on using hashes here.

Provenance

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