Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.15.6
rev: v0.16.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ long_description_content_type = text/markdown; charset=UTF-8; variant=GFM
url = https://github.com/biocpy/txdb
# Add here related links, for example:
project_urls =
Documentation = https://biocpy.github.io/txdb/
Documentation = https://biocpy.github.io/txdb/
Source = https://github.com/biocpy/txdb
# Changelog = https://pyscaffold.org/en/latest/changelog.html
# Tracker = https://github.com/pyscaffold/pyscaffold/issues
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if __name__ == "__main__":
try:
setup(use_scm_version={"version_scheme": "no-guess-dev"})
except: # noqa
except:
print(
"\n\nAn error occurred while building the project, "
"please ensure you have the most updated version of setuptools, "
Expand Down
2 changes: 1 addition & 1 deletion src/txdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
from .txdb import TxDb
from .txdbregistry import TxDbRegistry

__all__ = ["TxDb", "TxDbRegistry", "TxDbRecord"]
__all__ = ["TxDb", "TxDbRecord", "TxDbRegistry"]
23 changes: 10 additions & 13 deletions src/txdb/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from dataclasses import dataclass
from datetime import date, datetime
from typing import Optional

__author__ = "Jayaram Kancherla"
__copyright__ = "Jayaram Kancherla"
Expand All @@ -14,18 +13,18 @@ class TxDbRecord:
"""Container for a single TxDb entry."""

txdb_id: str
release_date: Optional[date]
release_date: date | None
url: str

organism: Optional[str] = None # e.g. "Hsapiens"
source: Optional[str] = None # e.g. "UCSC", "BioMart"
build: Optional[str] = None # e.g. "hg38.knownGene"
organism: str | None = None # e.g. "Hsapiens"
source: str | None = None # e.g. "UCSC", "BioMart"
build: str | None = None # e.g. "hg38.knownGene"

# Parsed from URL path (e.g. .../3.22/TxDb...)
bioc_version: Optional[str] = None
bioc_version: str | None = None

@classmethod
def from_config_entry(cls, txdb_id: str, entry: dict) -> "TxDbRecord":
def from_config_entry(cls, txdb_id: str, entry: dict) -> TxDbRecord:
"""Build a record from a TXDB_CONFIG entry:
{
"release_date": "YYYY-MM-DD", # optional
Expand All @@ -35,7 +34,7 @@ def from_config_entry(cls, txdb_id: str, entry: dict) -> "TxDbRecord":
url = entry["url"]

date_str = entry.get("release_date")
rel_date: Optional[date]
rel_date: date | None
if date_str:
rel_date = datetime.strptime(date_str, "%Y-%m-%d").date()
else:
Expand All @@ -62,10 +61,8 @@ def _parse_txdb_id(txdb_id: str):
into (organism, source, build).
"""
name = txdb_id
if name.startswith("TxDb."):
name = name[len("TxDb.") :]
if name.endswith(".sqlite"):
name = name[: -len(".sqlite")]
name = name.removeprefix("TxDb.")
name = name.removesuffix(".sqlite")

parts = name.split(".")
if len(parts) < 2:
Expand All @@ -77,7 +74,7 @@ def _parse_txdb_id(txdb_id: str):
return organism, source, build


def _parse_bioc_version(url: str) -> Optional[str]:
def _parse_bioc_version(url: str) -> str | None:
"""Extract the Bioconductor/AnnotationHub-like version from URL.

Example:
Expand Down
11 changes: 5 additions & 6 deletions src/txdb/txdb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sqlite3
from typing import List, Optional

from biocframe import BiocFrame
from genomicranges import GenomicRanges, SeqInfo
Expand Down Expand Up @@ -95,8 +94,8 @@ def _fetch_as_gr(
self,
table: str,
prefix: str,
columns: Optional[List[str]] = None,
filter: Optional[dict] = None,
columns: list[str] | None = None,
filter: dict | None = None,
) -> GenomicRanges:
"""Internal helper to fetch a table and convert to GenomicRanges.

Expand Down Expand Up @@ -165,7 +164,7 @@ def _fetch_as_gr(
seqinfo=self.seqinfo,
)

def transcripts(self, filter: Optional[dict] = None) -> GenomicRanges:
def transcripts(self, filter: dict | None = None) -> GenomicRanges:
"""Retrieve transcripts as a GenomicRanges object.

Args:
Expand All @@ -177,7 +176,7 @@ def transcripts(self, filter: Optional[dict] = None) -> GenomicRanges:
"""
return self._fetch_as_gr("transcript", "tx", filter=filter)

def exons(self, filter: Optional[dict] = None) -> GenomicRanges:
def exons(self, filter: dict | None = None) -> GenomicRanges:
"""Retrieve exons as a GenomicRanges object.

Args:
Expand All @@ -189,7 +188,7 @@ def exons(self, filter: Optional[dict] = None) -> GenomicRanges:
"""
return self._fetch_as_gr("exon", "exon", filter=filter)

def cds(self, filter: Optional[dict] = None) -> GenomicRanges:
def cds(self, filter: dict | None = None) -> GenomicRanges:
"""Retrieve coding sequences (CDS) as a GenomicRanges object.

Args:
Expand Down
8 changes: 4 additions & 4 deletions src/txdb/txdbregistry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sqlite3
from pathlib import Path
from typing import Any, Dict, Optional, Union
from typing import Any

from pybiocfilecache import BiocFileCache

Expand All @@ -19,7 +19,7 @@ class TxDbRegistry:

def __init__(
self,
cache_dir: Optional[Union[str, Path]] = None,
cache_dir: str | Path | None = None,
force: bool = False,
) -> None:
"""Initialize the TxDB registry.
Expand All @@ -39,7 +39,7 @@ def __init__(
self._cache_dir.mkdir(parents=True, exist_ok=True)
self._bfc = BiocFileCache(self._cache_dir)

self._registry_map: Dict[str, TxDbRecord] = {}
self._registry_map: dict[str, TxDbRecord] = {}

self._initialize_registry(force=force)

Expand Down Expand Up @@ -195,7 +195,7 @@ def load_db(self, txdb_id: str, force: bool = False) -> TxDb:
path = self.download(txdb_id, force=force)
return TxDb(path)

def _get_filepath(self, resource: Any) -> Optional[str]:
def _get_filepath(self, resource: Any) -> str | None:
"""Helper to extract absolute path from a BiocFileCache resource."""
if hasattr(resource, "rpath"):
rel_path = str(resource.rpath)
Expand Down
Loading