Skip to main content

A Python wrapper for BBTools

Project description

bbmapy

A Python wrapper for BBTools. Current version of bbmapy is v39.55.

Installation

conda install -c bioconda -c conda-forge bbmapy # not yet available on conda-forge

Also available on pip (but does not ensure java is available):

pip install bbmapy

Usage

bbmapy let's you call bbtools stuff from python. To the shell only one CLI is available:

  • bbmapy-test: Run tests to verify installation

Example

from bbmapy import bbmap

# Run bbmap.sh
bbmap.bbmap(
    in1="reads1.fastq",
    in2="reads2.fastq",
    out="mapped.sam",
    ref="reference.fasta"
)

Dependencies

  • Python >= 3.9
  • rich
  • install-jdk (this will be used to install a JRE if needed)

Usage

After installation, you can use bbmapy in your Python scripts like this:

from bbmapy import bbduk

# Basic usage
bbduk(
    in_file="input.fastq",
    out="output.fastq",
    ktrim="r",
    k="23",
    mink="11",
    hdist="1",
    tbo=True,
    tpe=True,
    minlen="45",
    ref="adapters",
    ftm="5",
    maq="6",
    maxns="1",
    ordered=True,
    threads="4",
    overwrite="t",
    stats="stats.txt"
)

Using Java flags alongside other arguments

bbduk(
    Xmx="2g",  # Set maximum heap size
    da=True,   # Enable assertions
    eoom=True, # Enable out-of-memory termination
    in_file="input.fastq",
    out="output.fastq",
    ktrim="r",
    k="23"
)

To capture output

You need to set capture_output=True in the function call, AND out="stdout.fastq" (or any other file format you like).

stdout, stderr = bbduk(
    capture_output=True,
    Xmx="2g",
    in_file="input.fastq",
    out="stdout.fastq",
    # ... other parameters ...
)

Getting java executable

Can be a pain, see this PR discussion.
bioconda's recipes that require java will usually bring a really bloated set of stuff. not good. way too much useless bandwidth (I see no reason that getting bbmap would require alsa).
But pip and bioconda recipies allow using other pip and conda recipes. Good. A workaround - adding a custom function that recognizes the os + arch and fetches during install or test.
Technically - this does not count as preloading a binary/executable. The actual JRE is tiny, and getting it can be done via install-jdk.

tl;dr: after installing from pypi (via pip/uv/pixi)

bbmapy-ensure-java

Notes:

  • in can be a protected word in python and other code, it is replaced by in_file in function calls. in1, in2 are still valid.
  • Java flags (such as Xmx, Xms, da, ea, eoom) are automatically recognized and handled appropriately. Include them in your function calls just like any other argument.
  • the capture_output argument might be switched (stderr --> out and vice verse).
  • Flags (i.e. argument that do not take value in the OG bbmap version) are set with Boolean values. e.g.:
flag : True

Not to be mistaken for lower case, fouble qouted "true" and "false" for boolian arguments to be passed to bbtools, e.g.:

argument : "true"

Citation

BBMerge manuscript: https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0185056 Please cite this paper if you use bbmap in your work.

License

This project is only a wrapper, please see the actual bbtools repository for (license)[https://bitbucket.org/berkeleylab/jgi-bbtools/src/master/license.txt] etc.
Neither the developers of bbtools nor of bbmapy take any responsibility for how you use this code. All accountability is on you.

Acknowledgments

This project only (crudely) wraps BBTools (a.k.a bbmap), which is developed by Brian Bushnell.
If you use bbmapy and things don't quite work like you'd like, don't expect the developer of bbmap to help you with this whacky python wrapper.
Please see the BBTools website for more information about the underlying tools.

to build and upload to pypi

rm -rf dist build egg-info
pixi run python bbmapy/update.py # fetch latest version of bbtools and update version in pyproject.toml
rm bbmapy/vendor/bbmap/pytools -rf # remove the pytools folder
pixi run pip install --upgrade build twine
python -m build
twine upload dist/*

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

bbmapy-0.0.55.tar.gz (16.5 MB view details)

Uploaded Source

Built Distribution

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

bbmapy-0.0.55-py3-none-any.whl (18.7 MB view details)

Uploaded Python 3

File details

Details for the file bbmapy-0.0.55.tar.gz.

File metadata

  • Download URL: bbmapy-0.0.55.tar.gz
  • Upload date:
  • Size: 16.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for bbmapy-0.0.55.tar.gz
Algorithm Hash digest
SHA256 641b94a00d3582dcdfb56ca736b10abb92c7e54c9785097b0b79c140a746bfed
MD5 b840e9dae0eb659893ec0aa92ae11c1b
BLAKE2b-256 5814b40c34cd7be8eb0a93b0373ba70c5968904b25b5c228532f7943a2ef6173

See more details on using hashes here.

File details

Details for the file bbmapy-0.0.55-py3-none-any.whl.

File metadata

  • Download URL: bbmapy-0.0.55-py3-none-any.whl
  • Upload date:
  • Size: 18.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for bbmapy-0.0.55-py3-none-any.whl
Algorithm Hash digest
SHA256 abd9c272e7f8682dda898b604c57b54e29b3a9ca1cc4d5b0ea72cef1bc1c2add
MD5 a2f5d8c744072b0ea48d0605c8f67a0d
BLAKE2b-256 03907342eda24e0fc69b86011bc8d0f4a1223df88d281ae847a193c11e586251

See more details on using hashes here.

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