An HTS-specs compliant BED toolkit.
Project description
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(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 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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f6c940540834c843e2762ae10f4946dad87843a80ab3955007a45ad8681bb58
|
|
| MD5 |
6783074a8813fefb1e4135973ff1d421
|
|
| BLAKE2b-256 |
070bda98bb3de3f3bc427e27a634a51a0692d4f3f5d6389f4247b769b3e24149
|
Provenance
The following attestation bundles were made for bedspec-0.7.0.tar.gz:
Publisher:
publish_bedspec.yml on clintval/bedspec
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bedspec-0.7.0.tar.gz -
Subject digest:
3f6c940540834c843e2762ae10f4946dad87843a80ab3955007a45ad8681bb58 - Sigstore transparency entry: 201106852
- Sigstore integration time:
-
Permalink:
clintval/bedspec@fa28b697300746e6a9a1a7857639af54a4f2af77 -
Branch / Tag:
refs/tags/0.7.0 - Owner: https://github.com/clintval
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_bedspec.yml@fa28b697300746e6a9a1a7857639af54a4f2af77 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ea935eb444f1e41fdc82e1fabb16ad751ed03f33d73bf6229acfd1262e2b7cc
|
|
| MD5 |
390cd1ac83d4aa00995e84fdf666a68a
|
|
| BLAKE2b-256 |
e9aa3a60dd3fecc9491ae7e7118675c31de0e27b92c3ca529673de75752ee1c8
|
Provenance
The following attestation bundles were made for bedspec-0.7.0-py3-none-any.whl:
Publisher:
publish_bedspec.yml on clintval/bedspec
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bedspec-0.7.0-py3-none-any.whl -
Subject digest:
8ea935eb444f1e41fdc82e1fabb16ad751ed03f33d73bf6229acfd1262e2b7cc - Sigstore transparency entry: 201106855
- Sigstore integration time:
-
Permalink:
clintval/bedspec@fa28b697300746e6a9a1a7857639af54a4f2af77 -
Branch / Tag:
refs/tags/0.7.0 - Owner: https://github.com/clintval
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_bedspec.yml@fa28b697300746e6a9a1a7857639af54a4f2af77 -
Trigger Event:
push
-
Statement type: