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
... 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.

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bedspec-0.7.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bedspec-0.7.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bedspec-0.7.0.tar.gz
Algorithm Hash digest
SHA256 3f6c940540834c843e2762ae10f4946dad87843a80ab3955007a45ad8681bb58
MD5 6783074a8813fefb1e4135973ff1d421
BLAKE2b-256 070bda98bb3de3f3bc427e27a634a51a0692d4f3f5d6389f4247b769b3e24149

See more details on using hashes here.

Provenance

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

Publisher: publish_bedspec.yml on clintval/bedspec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bedspec-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: bedspec-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bedspec-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ea935eb444f1e41fdc82e1fabb16ad751ed03f33d73bf6229acfd1262e2b7cc
MD5 390cd1ac83d4aa00995e84fdf666a68a
BLAKE2b-256 e9aa3a60dd3fecc9491ae7e7118675c31de0e27b92c3ca529673de75752ee1c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for bedspec-0.7.0-py3-none-any.whl:

Publisher: publish_bedspec.yml on clintval/bedspec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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