# 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
... 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/4f/0d/de64bb1f7eb1da95bb407f2c2d091e966d6079892317015a1794c3beea30/bedspec-0.6.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\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.6.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": "f79607b65685af5b6d0fef4aabb2c5da73e86d8d88ed8eb1f0bfa20d409e057e",
"md5": "04cc75090d7de790e4c12c63863bfb20",
"sha256": "2a9ec5353b88a961c9ca303de9eaa4980baee86e4baadfeac85046a7bafbb16d"
},
"downloads": -1,
"filename": "bedspec-0.6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "04cc75090d7de790e4c12c63863bfb20",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.10.0",
"size": 11398,
"upload_time": "2024-12-02T22:23:06",
"upload_time_iso_8601": "2024-12-02T22:23:06.853450Z",
"url": "https://files.pythonhosted.org/packages/f7/96/07b65685af5b6d0fef4aabb2c5da73e86d8d88ed8eb1f0bfa20d409e057e/bedspec-0.6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4f0dde64bb1f7eb1da95bb407f2c2d091e966d6079892317015a1794c3beea30",
"md5": "673caf77a86f8a2dcd67a7e4a6a7a3bf",
"sha256": "5c3ce89e7bbc2ec40bb1ec4fa2c67572195f3f995fe7275a0c4754fd89b13e9c"
},
"downloads": -1,
"filename": "bedspec-0.6.0.tar.gz",
"has_sig": false,
"md5_digest": "673caf77a86f8a2dcd67a7e4a6a7a3bf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.10.0",
"size": 11041,
"upload_time": "2024-12-02T22:23:08",
"upload_time_iso_8601": "2024-12-02T22:23:08.752439Z",
"url": "https://files.pythonhosted.org/packages/4f/0d/de64bb1f7eb1da95bb407f2c2d091e966d6079892317015a1794c3beea30/bedspec-0.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-02 22:23:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "clintval",
"github_project": "bedspec",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "bedspec"
}