Skip to main content

Bam2cell

Latest PyPI Version Downloads tests DOI

A package to split a BAM file based on cell type annotation in AnnData objects.

Usage and Examples

There are two modes sequential and parallel. The sequential mode will process cell types one by one but is more disk space friendly, the parallel is more disk space hungry but faster, since it process all cell types at the same time.

A minimal example is shown here:

⚠️ Note: The barcodes should not contain suffix or prefix. Use `clean_bcs()` to remove them.

import bam2cell
import anndata as ad

adata = ad.read_h5ad("data/adata.h5ad")

generator = bam2cell.GenerateCellTypeBAM(adata, 
                                         annot_key="annotation",
                                         output_path="data/",
                                         input_bam="data/AllCellsSorted_toy.bam",
                                         tmp_path="data/",
                                         workers=8,
                                         )
generator.process_all_parallel()  # Case 1 - Process all cell types at the same time
generator.process_cts_sequential() # Case 2 - Process cell types one by one

For a more advanced usage, you can use the function bam2cell, which allow to process an AnnData with multiple samples.

import bam2cell
import anndata as ad
import pandas as pd

adata = ad.read_h5ad("data/adata.h5ad")
artificial_batch = ["batch1"] * 100 + ["batch2"] * 91
adata.obs["batch"] = pd.Categorical(artificial_batch)
adata.obs["bam_path"] = "data/AllCellsSorted_toy.bam"

bam2cell.bam2cell(adata,
                  annot_key="annotation",
                  input_bam=None,  # Only when we have 1 batch in the AnnData
                  output_path="data/",  
                  tmp_path="data/",
                  bam_key="bam_path",  # For each barcode we have the path to the BAM file
                  batch_key="batch",  
                  mode="parallel",
                  suffix=None,  # Suffix in the barcode to be removed (e.g., BC-1-suffix --> BC-1)
                  prefix=None,  # Prefix in the BC to be removed (e.g., prefix-BC-1 --> BC-1) 
                  workers=8
                  )

Installation

You need to have Python 3.10 or newer installed on your system. There are several alternative options to install bam2cell:

  1. Install the latest release of bam2cell from PyPI:
pip install bam2cell  
  1. Install the latest development version:
pip install git+https://github.com/davidrm-bio/bam2cell.git@main

Metadata

Release files for bam2cell 0.2

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

Source distribution (sdist)

Source distribution for bam2cell 0.2
File Size Uploaded Provenance Actions
bam2cell-0.2.tar.gz 7.7 kB With provenance Details for bam2cell-0.2.tar.gz

Built distribution (wheel)

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

Total release size: 16.3 kB

Release files / bam2cell-0.2.tar.gz

Download URL bam2cell-0.2.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7d46b1bb779dafd751312556ccc2b9f7d6d73e4231b9872424e0c084e2af3751
BLAKE2b-256 checksum
How to use checksums
f6d9cba5001c48dea2a5d01a0ffa601ce303c9047ba6949b2df2c36f5474518d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 22, 2025.

Transparency log

Release files / bam2cell-0.2-py3-none-any.whl

Download URL bam2cell-0.2-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd266d013fef5fcc1ad9ee981c283d9c7321aaaf983998da63808ea85414cc4d
BLAKE2b-256 checksum
How to use checksums
80d7be56ce5c07e8748e53e08141e88a3ba61d6d170b22977b8f6c6259020964
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 22, 2025.

Transparency log

Security for bam2cell 0.2

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bam2cell-0.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 22, 2025.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files Full provenance

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