Skip to main content

Parallelizing operations on SAM/BAM files

SAM/BAM files are typically large, thus, operations on these files are time intensive. This project provides tools to parallelize operations on SAM/BAM files. The workflow follows:

  1. Split BAM/SAM file in n chunks
  2. Perform operation in each chunk in a dedicated process and save resulting SAM/BAM chunk
  3. Merge results back into a single SAM/BAM file

Depends on:

  1. Samtools

Installation

pip3 install parallelbam

or

  1. Git clone project
  2. cd to cloned project directory
  3. sudo python3 setup.py install

Better to install within an environment, such as a conda environment, to avoid path conflicts with the included bash scripts.

Usage

There is one main function named parallelizedBAMoperation. This function takes as mandatory arguments:

  1. path to original bam file (should be ordered)
  2. a callable function to perform the operation on each bam file chunk

The callable function must accept the following two first arguments:

  1. path to input bam file and
  2. path to resulting output bam file

in this order.

TODO

  1. The current way to include bash scripts in the package, while working, seems awkward. Perhaps including bash code directly in subprocess would be simpler
  2. Having permission error in some installations upon calling splitBAM.sh, can one make it executable during installation?
from parallelbam.parallelbam import parallelizeBAMoperation, getNumberOfReads

As an example, let's create a function that simply copies a bam file to another directory (does nothing to the bam file). When calling this function in parallelizeBAMoperation it will imply split the BAM file in chunks and the merge them back into a single BAM, whih sould be identical to the first one. We will split the BAM file in 8 chunks, and are dummy function will be called in separate process for each chunk.

import shutil

def foo(input_bam, output_bam):
    shutil.copyfile(input_bam, output_bam)
    
    
parallelizeBAMoperation('sample.bam',
                        foo, output_dir=None,
                        n_processes=8)

To check that the processed bam file, after merging the 8 chunks, contains the same number of reads we can call getNumberOfReads.

getNumberOfReads('sample.bam')
11825588
getNumberOfReads('processed.bam')
11825588

Release files for parallelbam 0.0.19

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parallelbam 0.0.19
File Size Uploaded
parallelbam-0.0.19.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for parallelbam 0.0.19
File Interpreter ABI Platform
parallelbam-0.0.19-py3-none-any.whl Python 3 none any Details

Total release size: 21.0 kB

Release files / parallelbam-0.0.19.tar.gz

Download URL parallelbam-0.0.19.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8a6eaf419f0baf3627a8b1c79d1f5641ba1d4c60813ab129e4690a15490fd746
BLAKE2b-256 checksum
How to use checksums
c0f43eef0ad8d066b1ee4e3b15397416412a17f19ef804dd594fed626d5f45fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.7

Release files / parallelbam-0.0.19-py3-none-any.whl

Download URL parallelbam-0.0.19-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52b3372366023793b8df92f08011f1bc30a9a9e1d8bd2c9acbefc5406185c092
BLAKE2b-256 checksum
How to use checksums
e36af3fbeeaa20b28db9d9014333247e9e13e9621ff5fa8c03e44828ba96c057
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.0.19 This release

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

1 release file

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page