Skip to main content

An HTS-specs compliant BED toolkit.

Project description

bedspec

PyPi Release CI Python Versions basedpyright mypy Poetry Ruff

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(temp_file.name, Bed3) as writer:
...     writer.write(bed)

Reading

>>> from bedspec import BedReader
>>> 
>>> with BedReader.from_path(temp_file.name, Bed3) 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

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 features
  • overlaps: test if any overlapping features exist
  • enclosed_by: return those enclosed by the input feature
  • enclosing: 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(eq=True)
... class Bed3Plus1(SimpleBed):
...     refname: str
...     start: int
...     end: int
...     my_custom_field: float | None

Development and Testing

See the contributing guide for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bedspec-0.4.0.tar.gz (125.3 kB view details)

Uploaded Source

Built Distributions

bedspec-0.4.0-cp312-cp312-musllinux_1_1_x86_64.whl (336.8 kB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

bedspec-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl (331.7 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

bedspec-0.4.0-cp312-cp312-macosx_14_0_arm64.whl (113.9 kB view details)

Uploaded CPython 3.12 macOS 14.0+ ARM64

File details

Details for the file bedspec-0.4.0.tar.gz.

File metadata

  • Download URL: bedspec-0.4.0.tar.gz
  • Upload date:
  • Size: 125.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for bedspec-0.4.0.tar.gz
Algorithm Hash digest
SHA256 f53ae7c73329c1165fb2efc859cc3f9c630048b7f47f83e688a9603e351588ee
MD5 e28f344e5da4f45b3cd8d8b44f10af40
BLAKE2b-256 b26373039f72cbfd3c9debe4c6df2f45d04da8aa5d85dab433177e08158964b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for bedspec-0.4.0.tar.gz:

Publisher: publish_bedspec.yml on clintval/bedspec

Attestations:

File details

Details for the file bedspec-0.4.0-cp312-cp312-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for bedspec-0.4.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3524cf958a8b01238e1956867542c3264328c8f4a1f787daea4a54f8ad7aff50
MD5 7522ece3b2ead571402e533a999db04d
BLAKE2b-256 8539b78b870182b420bd9ca0ceadce594f7a556eeea0a3e8eb3fb94e92a7861b

See more details on using hashes here.

Provenance

The following attestation bundles were made for bedspec-0.4.0-cp312-cp312-musllinux_1_1_x86_64.whl:

Publisher: publish_bedspec.yml on clintval/bedspec

Attestations:

File details

Details for the file bedspec-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bedspec-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aeb5ab014a85b50ed5f3f9203659004d23eeb3d1515aa67fc77c6908060ea474
MD5 a4476ca97eb689f85398ce4af33735da
BLAKE2b-256 be81c3bc941d4b6d57cca35678134fa8384568c633779e2d72e601d812a3fd83

See more details on using hashes here.

Provenance

The following attestation bundles were made for bedspec-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl:

Publisher: publish_bedspec.yml on clintval/bedspec

Attestations:

File details

Details for the file bedspec-0.4.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for bedspec-0.4.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c327e296fb71364a2d75b53f398543e6c735b4d1cc2fde7560d3a39653a86e9b
MD5 3cfb9a36501556d9987a64ceadb71c60
BLAKE2b-256 617eb8d8b897c5a1c8fb5f5a1a81884bf64f961ad2c9b0d2bab683bd3e9591ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for bedspec-0.4.0-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: publish_bedspec.yml on clintval/bedspec

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page