# bedspec
[![PyPi Release](https://badge.fury.io/py/bedspec.svg)](https://badge.fury.io/py/bedspec)
[![CI](https://github.com/clintval/bedspec/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/clintval/bedspec/actions/workflows/tests.yml?query=branch%3Amain)
[![Python Versions](https://img.shields.io/badge/python-3.10_|_3.11_|_3.12-blue)](https://github.com/clintval/typeline)
[![basedpyright](https://img.shields.io/badge/basedpyright-checked-42b983)](https://docs.basedpyright.com/latest/)
[![mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://docs.astral.sh/ruff/)
An HTS-specs compliant BED toolkit.
## Installation
The package can be installed with `pip`:
```console
pip install bedspec
```
## Quickstart
### Building a BED Feature
```pycon
>>> from bedspec import Bed3
>>>
>>> bed = Bed3("chr1", start=2, end=8)
```
### Writing
```pycon
>>> 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
```pycon
>>> 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:
```pycon
>>> 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:
```pycon
>>> 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:
```pycon
>>> 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](./CONTRIBUTING.md) for more information.
Raw data
{
"_id": null,
"home_page": "https://github.com/clintval/bedspec",
"name": "bedspec",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0.0,>=3.10.0",
"maintainer_email": null,
"keywords": "bioinformatics, BED, NGS, HTS, interval",
"author": "Clint Valentine",
"author_email": "valentine.clint@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/46/69/6bec51d55f02c6ad62d59842e00c40d306d7a2cdba8b3df54e50814b69f3/bedspec-0.5.0.tar.gz",
"platform": null,
"description": "# bedspec\n\n[![PyPi Release](https://badge.fury.io/py/bedspec.svg)](https://badge.fury.io/py/bedspec)\n[![CI](https://github.com/clintval/bedspec/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/clintval/bedspec/actions/workflows/tests.yml?query=branch%3Amain)\n[![Python Versions](https://img.shields.io/badge/python-3.10_|_3.11_|_3.12-blue)](https://github.com/clintval/typeline)\n[![basedpyright](https://img.shields.io/badge/basedpyright-checked-42b983)](https://docs.basedpyright.com/latest/)\n[![mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)\n[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://docs.astral.sh/ruff/)\n\nAn HTS-specs compliant BED toolkit.\n\n## Installation\n\nThe package can be installed with `pip`:\n\n```console\npip install bedspec\n```\n\n## Quickstart\n\n### Building a BED Feature\n\n```pycon\n>>> from bedspec import Bed3\n>>> \n>>> bed = Bed3(\"chr1\", start=2, end=8)\n\n```\n\n### Writing\n\n```pycon\n>>> from bedspec import BedWriter\n>>> from tempfile import NamedTemporaryFile\n>>> \n>>> temp_file = NamedTemporaryFile(mode=\"w+t\", suffix=\".txt\")\n>>>\n>>> with BedWriter.from_path(temp_file.name, Bed3) as writer:\n... writer.write(bed)\n\n```\n\n### Reading\n\n```pycon\n>>> from bedspec import BedReader\n>>> \n>>> with BedReader.from_path(temp_file.name, Bed3) as reader:\n... for bed in reader:\n... print(bed)\nBed3(refname='chr1', start=2, end=8)\n\n```\n\n### BED Types\n\nThis package provides builtin classes for the following BED formats:\n\n```pycon\n>>> from bedspec import Bed2\n>>> from bedspec import Bed3\n>>> from bedspec import Bed4\n>>> from bedspec import Bed5\n>>> from bedspec import Bed6\n>>> from bedspec import Bed12\n>>> from bedspec import BedGraph\n>>> from bedspec import BedPE\n\n```\n\n### Overlap Detection\n\nUse a fast overlap detector for any collection of interval types, including third-party:\n\n```pycon\n>>> from bedspec import Bed3, Bed4\n>>> from bedspec.overlap import OverlapDetector\n>>>\n>>> bed1 = Bed3(\"chr1\", start=1, end=4)\n>>> bed2 = Bed3(\"chr1\", start=5, end=9)\n>>> \n>>> detector = OverlapDetector[Bed3]([bed1, bed2])\n>>> \n>>> my_feature = Bed4(\"chr1\", start=2, end=3, name=\"hi-mom\")\n>>> detector.overlaps(my_feature)\nTrue\n\n```\n\nThe overlap detector supports the following operations:\n\n- `overlapping`: return all overlapping features\n- `overlaps`: test if any overlapping features exist\n- `enclosed_by`: return those enclosed by the input feature\n- `enclosing`: return those enclosing the input feature\n\n### Custom BED Types\n\nTo create a custom BED record, inherit from the relevant BED-type (`PointBed`, `SimpleBed`, `PairBed`).\n\nFor example, to create a custom BED3+1 class:\n\n```pycon\n>>> from dataclasses import dataclass\n>>> \n>>> from bedspec import SimpleBed\n>>> \n>>> @dataclass(eq=True)\n... class Bed3Plus1(SimpleBed):\n... refname: str\n... start: int\n... end: int\n... my_custom_field: float | None\n\n```\n\n## Development and Testing\n\nSee the [contributing guide](./CONTRIBUTING.md) for more information.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "An HTS-specs compliant BED toolkit.",
"version": "0.5.0",
"project_urls": {
"Homepage": "https://github.com/clintval/bedspec",
"Repository": "https://github.com/clintval/bedspec"
},
"split_keywords": [
"bioinformatics",
" bed",
" ngs",
" hts",
" interval"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fc80b04f30b964208d6fda8e7652352859fdc0c6f5bd17fc0c84d7a0f443a4c1",
"md5": "82477e893f5e20f7baf4f385af67742d",
"sha256": "d7670afb35c24ecdf77beb9a97248b3122ceaf31a048ed18067022106f93e755"
},
"downloads": -1,
"filename": "bedspec-0.5.0-cp312-cp312-macosx_14_0_arm64.whl",
"has_sig": false,
"md5_digest": "82477e893f5e20f7baf4f385af67742d",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": "<4.0.0,>=3.10.0",
"size": 113883,
"upload_time": "2024-11-13T21:29:19",
"upload_time_iso_8601": "2024-11-13T21:29:19.265843Z",
"url": "https://files.pythonhosted.org/packages/fc/80/b04f30b964208d6fda8e7652352859fdc0c6f5bd17fc0c84d7a0f443a4c1/bedspec-0.5.0-cp312-cp312-macosx_14_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "416414a1cdcc74935cf48ac414ef57b5a57f14d8782eb3fd798471d839fd6884",
"md5": "dc6abdc38ce1cfc66533f1cbf674f2d9",
"sha256": "cc8d96f3e4b57a8df4941b0ef87f796697e1631d9b38df6e141058b5f24c04f7"
},
"downloads": -1,
"filename": "bedspec-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "dc6abdc38ce1cfc66533f1cbf674f2d9",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": "<4.0.0,>=3.10.0",
"size": 331649,
"upload_time": "2024-11-13T21:29:21",
"upload_time_iso_8601": "2024-11-13T21:29:21.528099Z",
"url": "https://files.pythonhosted.org/packages/41/64/14a1cdcc74935cf48ac414ef57b5a57f14d8782eb3fd798471d839fd6884/bedspec-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4655ad42dd312b1a2a2a4c561c565dd88a60dcaa772fc78583c4a66a8f2fb061",
"md5": "7692b2102a85f260ea7d860402c7d6b4",
"sha256": "3373744581c4b92b342e714c4669c72401a318539f6c59aa519c9e89ae096464"
},
"downloads": -1,
"filename": "bedspec-0.5.0-cp312-cp312-musllinux_1_1_x86_64.whl",
"has_sig": false,
"md5_digest": "7692b2102a85f260ea7d860402c7d6b4",
"packagetype": "bdist_wheel",
"python_version": "cp312",
"requires_python": "<4.0.0,>=3.10.0",
"size": 336819,
"upload_time": "2024-11-13T21:29:23",
"upload_time_iso_8601": "2024-11-13T21:29:23.374823Z",
"url": "https://files.pythonhosted.org/packages/46/55/ad42dd312b1a2a2a4c561c565dd88a60dcaa772fc78583c4a66a8f2fb061/bedspec-0.5.0-cp312-cp312-musllinux_1_1_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "46696bec51d55f02c6ad62d59842e00c40d306d7a2cdba8b3df54e50814b69f3",
"md5": "fefd481a2e455c35abed89a5d6401d69",
"sha256": "4cea5903b3cbd8222f86b8d3ff4ad35ee660d150975ccaef938afd56e586fb92"
},
"downloads": -1,
"filename": "bedspec-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "fefd481a2e455c35abed89a5d6401d69",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.10.0",
"size": 125348,
"upload_time": "2024-11-13T21:29:25",
"upload_time_iso_8601": "2024-11-13T21:29:25.561722Z",
"url": "https://files.pythonhosted.org/packages/46/69/6bec51d55f02c6ad62d59842e00c40d306d7a2cdba8b3df54e50814b69f3/bedspec-0.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-13 21:29:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "clintval",
"github_project": "bedspec",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "bedspec"
}