Skip to main content

pydiffbind

Differential binding analysis for ChIP-seq / ATAC-seq in Python, modelled on R/Bioconductor DiffBind. Peaks + BAMs in, statistically differential sites out (DESeq2 via PyDESeq2).

Install

pip install .            # from this directory
# or for development
pip install -e ".[dev]"

Sample sheet (CSV)

SampleID Condition Replicate bamReads Peaks bamControl (optional)
t1 treated 1 t1.bam t1.narrowPeak input1.bam
t2 treated 2 t2.bam t2.narrowPeak input1.bam
c1 control 1 c1.bam c1.narrowPeak input1.bam
c2 control 2 c2.bam c2.narrowPeak input1.bam

BAMs must be coordinate-sorted and indexed (.bai). Peak files: narrowPeak (summits used) or BED. Extra columns (Tissue, Factor, batch...) can be used as covariates.

Python API

from pydiffbind import DBA

dba = DBA("samples.csv")
dba.count(summits=250, min_overlap=2, threads=4)   # consensus peaks + read counts
dba.normalize("rle")                                # 'rle' | 'lib' | 'tmm' | 'background'
dba.analyze("Condition", "treated", "control")      # log2FC = treated / control
sites = dba.report(fdr=0.05)                        # DataFrame of significant sites
dba.to_bed("gained.bed", fdr=0.05, direction="up")

dba.plot_pca(); dba.plot_correlation(); dba.plot_ma(); dba.plot_volcano()

Useful options of count(): summits (re-centre peaks, fixed width), blacklist="blacklist.bed", subtract_control=True, background=True (needed for normalize("background"), use when global binding changes), min_mapq, fragment_size (single-end extension), remove_dups. Add covariates (e.g. batch): dba.analyze("Condition", "treated", "control", covariates=["Batch"]).

Annotation (any species, user-supplied GTF/GFF3)

dba.analyze("Condition", "FIE", "Control")
dba.annotate("TAIR10.gtf.gz", promoter=(-2000, 500))   # GTF or GFF3, plain or .gz
sites = dba.report(fdr=0.05)          # adds feature, overlapping_genes, nearest_gene, distance_to_tss
genes = dba.gene_lists(fdr=0.05)      # {'up': [...], 'down': [...], 'all': [...]}
bg    = dba.tested_genes()            # background universe for GO/KEGG enrichment
dba.save_gene_lists("results/")       # up_genes.txt, down_genes.txt, background_genes.txt
dba.plot_annotation(); dba.plot_tss_distance()
  • Works with any species because the annotation comes from your file (human, mouse, Arabidopsis, rice...). Ensembl/GENCODE GTF, Ensembl Plants / TAIR / Araport11 / RAP-DB / MSU GFF3 are supported.
  • Chromosome names are matched leniently (chr1 = Chr1 = 1 = chr01; M/Mt, C/Pt).
  • overlapping_genes lists every gene whose body or promoter overlaps the region. Use this for broad marks (H3K27me3), where a domain spans several genes. nearest_gene is based on the nearest TSS.
  • feature is the genomic feature at the region centre: Promoter > 5UTR > 3UTR > Exon > Intron > Downstream > Intergenic.
  • Plant annotations often lack gene symbols: pass symbols="id_to_symbol.tsv" (two columns: gene_id, symbol).
  • NCBI RefSeq genomic.gtf: the symbol is in gene_id and the AT/Os locus in locus_tag. Use dba.annotate(gtf, id_attr="locus_tag") (CLI: --gtf-id-attr locus_tag) to get IDs like AT1G01010; symbols stay available as gene names. If your BAMs use Chr1-style names but the GTF uses accessions (NC_003070.9), pass chrom_map="map.tsv" (two columns: NC_003070.9<TAB>Chr1).
  • biotypes=["protein_coding"] restricts to selected gene biotypes.
  • distance_to_tss is signed: negative = upstream of the TSS in the gene's orientation.

ChIPseeker-style annotated table

dba.annotate() also builds a transcript-level, ChIPseeker-style annotation, and the results can be written in the DiffBind + ChIPseeker column layout:

dba.export_chipseeker("annotated_significant.tsv", fdr=0.05)                   # significant sites
dba.export_chipseeker("annotated_all.tsv", only_significant=False)             # every tested site

Columns: seqnames start end width strand Conc Conc_<g1> Conc_<g2> Fold p.value FDR annotation geneChr geneStart geneEnd geneLength geneStrand geneId transcriptId distanceToTSS TAIR (last column name via id_column=).

  • start is 1-based; Conc* = log2(mean normalized count + 1); Fold = DESeq2 log2 fold change (group1/group2).
  • annotation labels: Promoter (<=1kb), Promoter (1-2kb), 5' UTR, 3' UTR, Exon (tx/gene, exon 3 of 7), Intron (tx/gene, intron 2 of 6), Downstream (<=300bp), Distal Intergenic (priority in that order).
  • The nearest transcript TSS defines geneId, transcriptId, geneStart/End, geneStrand (1 = +, 2 = -) and distanceToTSS (to the nearest region edge; negative = upstream; 0 if the TSS lies inside the region).
  • Whole-region overlap is used (not just the centre). UTRs come from five_prime_utr/three_prime_utr records or, when absent (e.g. NCBI GTF), are inferred from CDS. Missing transcript IDs are reported as NA.
  • Settings: annotate(..., tss_region=(-3000, 3000), cs_downstream=300).
  • CLI writes annotated_significant.tsv and annotated_all_sites.tsv when --gtf is given (--tss-up, --tss-down, --cs-downstream, --id-column). Gene lists from the same IDs: --gene-lists-by chipseeker.

Command line

pydiffbind samples.csv --group1 treated --group2 control --summits 250 \
    --normalize rle --threads 4 -o results/

With annotation:

pydiffbind samples.csv --group1 FIE --group2 Control --summits 0 --normalize background \
    --gtf TAIR10.gtf.gz --promoter-up 2000 --promoter-down 500 -o results/

Also writes gene lists (IDs and names_ symbols), feature-distribution and TSS-distance plots.

Writes raw_counts.csv, normalized_counts.csv, all_results.csv, significant.csv and PCA/correlation/MA/volcano PNGs.

Notes / differences from DiffBind

  • Counting uses pysam in pure Python; for very large datasets pre-count with featureCounts and extend count.py. Parallelism is per-BAM (threads).
  • Paired-end BAMs are auto-detected and counted per fragment; single-end reads are extended to fragment_size.
  • Control subtraction scales input counts by library size and floors at 1.
  • Only DESeq2 is supported as the test engine. Not yet implemented: edgeR, Venn plots, blocking designs beyond covariates.

Tests

pytest   # simulates BAMs with known differential sites and checks they are recovered

Metadata

Release files for pydiffbind 0.3.0

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

Source distribution (sdist)

Source distribution for pydiffbind 0.3.0
File Size Uploaded Provenance Actions
pydiffbind-0.3.0.tar.gz 32.8 kB Without provenance Details for pydiffbind-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 62.6 kB

Release files / pydiffbind-0.3.0.tar.gz

Download URL pydiffbind-0.3.0.tar.gz
Size 32.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7ee73f458cb4fd24db82311822fe9825135f105721063efdf1b2ea9fb30139ed
BLAKE2b-256 checksum
How to use checksums
80449647e75d75955b4c33edc93ad31c5d2aa2e8d7d4f840ac87060918eddb45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / pydiffbind-0.3.0-py3-none-any.whl

Download URL pydiffbind-0.3.0-py3-none-any.whl
Size 29.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16a38e07636df180de1a023d7b7275ad3e49a296e1940b245e5d2998e1f1bdd8
BLAKE2b-256 checksum
How to use checksums
10f3dbdb8820cac94d67792a2e85c3b095b7841792f2e1046698da0f1e3f7af8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for pydiffbind 0.3.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.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files No 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