Skip to content
Back to skills

Pybedtools

ASecurity

Python genomic interval arithmetic with BEDTools, complementing pysam, polars, and query for downstream tables. Use when intersecting, merging, subtracting, shuffling, finding closest features, computing coverage, or converting BED, GFF, GTF, VCF, BAM, and pandas DataFrames into interval operations.

  • 8 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added September 12, 2026
toolspythonbash

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned September 12, 2026

npx -y skills add stanfish06/skillquarium --skill pybedtools --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pybedtools?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Pybedtools
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/stanfish06-pybedtools/badge)](https://www.skillsdirectory.com/skills/stanfish06-pybedtools)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: pybedtools
description: Python genomic interval arithmetic with BEDTools, complementing pysam, polars, and query for downstream tables. Use when intersecting, merging, subtracting, shuffling, finding closest features, computing coverage, or converting BED, GFF, GTF, VCF, BAM, and pandas DataFrames into interval operations.
---

# pybedtools

Use this skill for genome interval set operations from Python. It wraps BEDTools and is appropriate for ATAC-seq peaks, ChIP-seq peaks, blacklist filtering, enhancer/gene overlap, GWAS locus annotation, VCF region filtering, BAM coverage, and closest-feature queries.

## Setup

`pybedtools` requires both the Python package and the `bedtools` binary.

```bash
conda install -c bioconda bedtools pybedtools
```

Use `pip install pybedtools` only when `bedtools` is already available on `PATH`.

## Common Patterns

```python
import pybedtools

peaks = pybedtools.BedTool("peaks.bed").sort()
genes = pybedtools.BedTool("genes.gtf").sort()

overlap = peaks.intersect(genes, wa=True, wb=True)
merged = peaks.merge()
nearest = peaks.closest(genes, d=True)
coverage = genes.coverage(peaks)
```

DataFrame integration:

```python
bt = pybedtools.BedTool.from_dataframe(df[["chrom", "start", "end", "name"]])
out = bt.intersect("targets.bed", wa=True, wb=True).to_dataframe()
```

## Decision Rules

- Use `pysam` for low-level BAM/VCF reading and writing.
- Use `pybedtools` for set algebra over genomic intervals.
- Use `duckdb` or `polars` for large tabular aggregation after intervals are computed.
- Sort inputs before operations where BEDTools expects sorted data.

## Pitfalls

- BED is 0-based half-open; GFF/GTF/VCF are usually 1-based. Convert deliberately.
- Chromosome naming must match (`chr1` vs `1`).
- Temporary files can accumulate in long sessions; call `pybedtools.cleanup()` when appropriate.
- For reproducible randomization, set genome files and seeds explicitly in shuffle workflows.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.