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

Uploaded Source

Built Distributions

bedspec-0.3.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.3.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.3.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.3.0.tar.gz.

File metadata

  • Download URL: bedspec-0.3.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.3.0.tar.gz
Algorithm Hash digest
SHA256 b0d59dce40f65f9d2e37b28544c73bd1b092856286525296ea0cf33ad60d8c54
MD5 c0b8a0eeccea5f7c93dd9ac6237e616e
BLAKE2b-256 0c8a3ec1f72c23baa95bac66b7a85cbceb281eca12a134a939a43908a30b3439

See more details on using hashes here.

Provenance

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

Publisher: publish_bedspec.yml on clintval/bedspec

Attestations:

File details

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

File metadata

File hashes

Hashes for bedspec-0.3.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 088254a9fb6abb16d17570f987e5b488c89242b0fc37e6cf48c95d48bee764d1
MD5 61dff861dc18aeb5de5a621b1eb22da3
BLAKE2b-256 b337ea8722769749646e088f075cbbc856593a77cb2085c97abecf34f8f73464

See more details on using hashes here.

Provenance

The following attestation bundles were made for bedspec-0.3.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.3.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.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4e7c6a1a6b1ae6c23d5d8f1c7e6ef0b72372b594c4b769966541676ceaabed75
MD5 ea02d16f24b37e69b03997446b5bec59
BLAKE2b-256 68e2169469c042b628d1d8fd855a32c9854c435285103833a6cd1128a377915d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bedspec-0.3.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 eee524cffab5bc8f3451fa5c9f55296510278ad3513b019cbd05eb30da592a15
MD5 7404732b887bd603289cb83bc5b70d48
BLAKE2b-256 ce9a21d5e2d8e1508136a1e7cff76d6e902caa0cf5aca18d8a45dffbc586628b

See more details on using hashes here.

Provenance

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