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.5.0.tar.gz (125.3 kB view details)

Uploaded Source

Built Distributions

bedspec-0.5.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.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl (331.6 kB view details)

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

bedspec-0.5.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.5.0.tar.gz.

File metadata

  • Download URL: bedspec-0.5.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.5.0.tar.gz
Algorithm Hash digest
SHA256 4cea5903b3cbd8222f86b8d3ff4ad35ee660d150975ccaef938afd56e586fb92
MD5 fefd481a2e455c35abed89a5d6401d69
BLAKE2b-256 46696bec51d55f02c6ad62d59842e00c40d306d7a2cdba8b3df54e50814b69f3

See more details on using hashes here.

Provenance

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

Publisher: publish_bedspec.yml on clintval/bedspec

Attestations:

File details

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

File metadata

File hashes

Hashes for bedspec-0.5.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 3373744581c4b92b342e714c4669c72401a318539f6c59aa519c9e89ae096464
MD5 7692b2102a85f260ea7d860402c7d6b4
BLAKE2b-256 4655ad42dd312b1a2a2a4c561c565dd88a60dcaa772fc78583c4a66a8f2fb061

See more details on using hashes here.

Provenance

The following attestation bundles were made for bedspec-0.5.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.5.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.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc8d96f3e4b57a8df4941b0ef87f796697e1631d9b38df6e141058b5f24c04f7
MD5 dc6abdc38ce1cfc66533f1cbf674f2d9
BLAKE2b-256 416414a1cdcc74935cf48ac414ef57b5a57f14d8782eb3fd798471d839fd6884

See more details on using hashes here.

Provenance

The following attestation bundles were made for bedspec-0.5.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.5.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for bedspec-0.5.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d7670afb35c24ecdf77beb9a97248b3122ceaf31a048ed18067022106f93e755
MD5 82477e893f5e20f7baf4f385af67742d
BLAKE2b-256 fc80b04f30b964208d6fda8e7652352859fdc0c6f5bd17fc0c84d7a0f443a4c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for bedspec-0.5.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