sam-dealer
High-throughput, zero-IO parallel dispatcher for SAM/BAM/CRAM streams. Distributes reads by index (round-robin) to persistent workers with backpressure management.
Install
sam-dealer relies on lightweight system-level concurrency tools (GNU Parallel and mbuffer) to achieve its performance. The following installs sam-dealer with mamba. You can also use conda as a (slower) drop-in replacement. click is a widely used Python package and can be installed with pip. samtools, parallel, and mbuffer can be manually installed if not using mamba/conda.
mamba install -c conda-forge samtools parallel mbuffer click
pip install sam-dealer
Example
This command initiates 10 parallel persistent wc -l jobs receiving the input.bam header and a continuous stream of records, 100,000 at a time.
sam-dealer input.bam -N 100000 --jobs 10 "wc -l"
Help
sam-dealer --help
Description
sam-dealer facilitates parallel dispatch over blocks of consecutive SAM/BAM/CRAM records. SAM/BAM/CRAM files facilitate fetching genomic regions or individual read names, but not blocks of consecutive records. However, some bioinformatics tools, such as pairtools parse, which extracts Hi-C pairs from alignments, require name-sorted input. Even when records can be treated independently, batching over genomic regions is non-trivial and requires careful engineering for load-balancing to avoid job idling.
Existing solutions to this problem introduce their own problems. Splitting alignment files on disk results in substantial write amplification, requires disk I/O made slower by the need to seek between many inputs, and may delay data processing until the file has been completely split, slowing the development cycle. Although standard utilities like pysam can stream and dispatch records after serializing them as strings, this is slow and requires complex manual implementation.
sam-dealer combines standard tools to stream-dispatch SAM/BAM/CRAM records to persistent jobs simply, rapidly, and with low memory pressure. Conceptually, it works as follows:
- Spin up
Jpersistent jobs (user-specified CLI commands that each receive distinct block of records from the input SAM/BAM/CRAM file) - The input file is divided into
Jinput streams, one for each job. - Each input stream is formed by round-robin batching of
Nlinearly consecutive records at a time. The first job gets the firstNrecords, the second job gets the nextNrecords, and so on in a loop until all records have been processed. - Input streams flow through a memory buffer (one buffer per job) that spills to disk under memory pressure. This allows all jobs to run independently at maximum speed as long as their buffers are not full, without waiting for the previous job to finish consuming its next batch.
- Importantly, we do not initiate one job per batch. Instead, we initiate
Jjobs that receive the concatenation of the header and all the batches that belong to the job as a continuous stream viastdin. From the job's perspective, it is streaming in everyJth block ofNrecords over the entire input file.
Metadata
Release files for sam-dealer 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sam_dealer-0.1.0.tar.gz | 3.9 kB | Without provenance | Details for sam_dealer-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sam_dealer-0.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for sam_dealer-0.1.0-py2.py3-none-any.whl |
Total release size: 9.6 kB
Release files / sam_dealer-0.1.0.tar.gz
| Download URL | sam_dealer-0.1.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20bcc6178a88643bacb0957edf27a611ab9d1e028583fba84374593d982e0471
|
|
BLAKE2b-256 checksum How to use checksums |
798b30786a848b59fac7f6b7a01542127ef9f015cc56dad2668bc9c18132c7dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / sam_dealer-0.1.0-py2.py3-none-any.whl
| Download URL | sam_dealer-0.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0f98eafca61ede7849c2d450e71558dba56cacd425806aafc700e8b26fdf2bbd
|
|
BLAKE2b-256 checksum How to use checksums |
23276300b9e63ee562c4ed30550196ccd030cea59005b6228ce772a66d3c668e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Security for sam-dealer 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.