bedspec
An HTS-specs compliant BED toolkit.
Installation
The package can be installed with pip:
pip install bedspec
Quickstart
Building a BED Feature
>>> from bedspec import Bed3
>>>
>>> bed = Bed3("chr1", start=2, end=8)
Writing
>>> from bedspec import BedWriter
>>> from tempfile import NamedTemporaryFile
>>>
>>> temp_file = NamedTemporaryFile(mode="w+t", suffix=".txt")
>>>
>>> with BedWriter.from_path[Bed3](temp_file.name) as writer:
... writer.write(bed)
Reading
>>> from bedspec import BedReader
>>>
>>> with BedReader.from_path[Bed3](temp_file.name) as reader:
... for bed in reader:
... print(bed)
Bed3(refname='chr1', start=2, end=8)
BED Types
This package provides builtin classes for the following BED formats:
>>> from bedspec import Bed2
>>> from bedspec import Bed3
>>> from bedspec import Bed4
>>> from bedspec import Bed5
>>> from bedspec import Bed6
>>> from bedspec import Bed12
>>> from bedspec import BedGraph
>>> from bedspec import BedPE
For BED files with extra columns (BEDn+m), use Bed3N, Bed4N, Bed5N, Bed6N, or Bed12N.
Each is its BED type plus an extra field that keeps any further columns as text.
>>> from bedspec import Bed6N
>>>
>>> _ = open(temp_file.name, "w").write("chr1\t5\t9\tpeak\t7\t-\t3.2\t0.01\n")
>>>
>>> with BedReader.from_path[Bed6N](temp_file.name) as reader:
... for bed in reader:
... print(bed.name, bed.extra)
peak ('3.2', '0.01')
Overlap Detection
Use a fast overlap detector for any collection of interval types, including third-party:
>>> from bedspec import Bed3, Bed4
>>> from bedspec.overlap import OverlapDetector
>>>
>>> bed1 = Bed3("chr1", start=1, end=4)
>>> bed2 = Bed3("chr1", start=5, end=9)
>>>
>>> detector = OverlapDetector[Bed3]([bed1, bed2])
>>>
>>> my_feature = Bed4("chr1", start=2, end=3, name="hi-mom")
>>> detector.overlaps(my_feature)
True
The overlap detector supports the following operations:
overlapping: return all overlapping featuresoverlaps: test if any overlapping features existenclosed_by: return those enclosed by the input featureenclosing: return those enclosing the input feature
Custom BED Types
To create a custom BED record, inherit from the relevant BED-type (PointBed, SimpleBed, PairBed).
For example, to create a custom BED3+1 class:
>>> from dataclasses import dataclass
>>>
>>> from bedspec import SimpleBed
>>>
>>> @dataclass
... class Bed3Plus1(SimpleBed):
... refname: str
... start: int
... end: int
... my_custom_field: float | None
You can also inherit and extend a pre-existing BED class:
>>> from dataclasses import dataclass
>>>
>>> from bedspec import Bed3
>>>
>>> @dataclass
... class Bed3Plus1(Bed3):
... my_custom_field: float | None
>>>
>>> Bed3Plus1(refname="chr1", start=2, end=3, my_custom_field=0.1)
Bed3Plus1(refname='chr1', start=2, end=3, my_custom_field=0.1)
Development and Testing
See the contributing guide for more information.
Metadata
Release files for bedspec 1.0.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 | |
|---|---|---|---|
| bedspec-1.0.0.tar.gz | 16.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bedspec-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.9 kB
Release files / bedspec-1.0.0.tar.gz
| Download URL | bedspec-1.0.0.tar.gz |
|---|---|
| Size | 16.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6cd9754ffd05008083e033024e3112b1f35eda74ae260a35ad6c148d7dcbca5d
|
|
BLAKE2b-256 checksum How to use checksums |
6328014dbeae48a2e29fc38350c959ad2be77037e2c20880abff72566adffebc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 29, 2026.
Transparency logRelease files / bedspec-1.0.0-py3-none-any.whl
| Download URL | bedspec-1.0.0-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a4fb62011777f9fac3109e6f6fae2c9cfe930676d074a3c1e4cf32a9a8c5cdb
|
|
BLAKE2b-256 checksum How to use checksums |
e7297bc30b13e407778702481dc292080102d93430b48dafde43b3aa6bb786da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 29, 2026.
Transparency log