Skip to content

Commit

Permalink
Refactor and update dependencies in snap module
Browse files Browse the repository at this point in the history
  • Loading branch information
horta committed May 16, 2024
1 parent 2c4f226 commit c3cb484
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 50 deletions.
Empty file added snap/deciphon_snap/__init__.py
Empty file.
3 changes: 1 addition & 2 deletions snap/deciphon_snap/amino.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
__all__ = ["AminoInterval", "make_amino_interval"]


class AminoInterval(PyInterval):
...
class AminoInterval(PyInterval): ...


def make_amino_interval(x: DomTBLCoord):
Expand Down
6 changes: 2 additions & 4 deletions snap/deciphon_snap/fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ def __len__(self):
return len(self.root)

@overload
def __getitem__(self, i: int) -> FASTAItem:
...
def __getitem__(self, i: int) -> FASTAItem: ...

@overload
def __getitem__(self, i: slice) -> FASTAList:
...
def __getitem__(self, i: slice) -> FASTAList: ...

def __getitem__(self, i: int | slice):
if isinstance(i, slice):
Expand Down
7 changes: 2 additions & 5 deletions snap/deciphon_snap/gff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from pydantic import BaseModel, RootModel


__all__ = ["GFFItem", "GFFList"]


Expand Down Expand Up @@ -34,12 +33,10 @@ def __len__(self):
return len(self.root)

@overload
def __getitem__(self, i: int) -> GFFItem:
...
def __getitem__(self, i: int) -> GFFItem: ...

@overload
def __getitem__(self, i: slice) -> GFFList:
...
def __getitem__(self, i: slice) -> GFFList: ...

def __getitem__(self, i: int | slice):
if isinstance(i, slice):
Expand Down
8 changes: 3 additions & 5 deletions snap/deciphon_snap/hit.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def matches(self):
assert self._interval is not None
assert self._match_list is not None
matches: list[Match] = []
offset = self._interval.pyinterval.start
offset = self._interval.py.start
for x in self._match_list[self.match_list_interval.slice]:
y = Match(raw=x.raw, start=x.start, end=x.end, position=offset)
if y.is_match_state or y.is_insert_state:
Expand All @@ -58,12 +58,10 @@ def __len__(self):
return len(self.root)

@overload
def __getitem__(self, i: int) -> Hit:
...
def __getitem__(self, i: int) -> Hit: ...

@overload
def __getitem__(self, i: slice) -> HitList:
...
def __getitem__(self, i: slice) -> HitList: ...

def __getitem__(self, i: int | slice):
if isinstance(i, slice):
Expand Down
9 changes: 5 additions & 4 deletions snap/deciphon_snap/hmmer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import os
from io import StringIO
from tempfile import NamedTemporaryFile

from h3result.h3result import H3Result as H3ResultRaw
from hmmer_tables.domtbl import read_domtbl, DomTBL
from hmmer_tables.tbl import read_tbl, TBL
from hmmer_tables.domtbl import DomTBL, read_domtbl
from hmmer_tables.tbl import TBL, read_tbl
from pydantic import BaseModel, ConfigDict

__all__ = ["H3Result"]
Expand Down Expand Up @@ -45,11 +46,11 @@ def domains_table(self) -> str:

@property
def tbl(self) -> TBL:
return read_tbl(stream=self.targets_table.split("\n"))
return read_tbl(stream=StringIO(self.targets_table))

@property
def domtbl(self) -> DomTBL:
return read_domtbl(stream=self.domains_table.split("\n"))
return read_domtbl(stream=StringIO(self.domains_table))

def __str__(self):
items = []
Expand Down
9 changes: 3 additions & 6 deletions snap/deciphon_snap/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,10 @@ def __len__(self):
return len(self.root)

@overload
def __getitem__(self, i: int) -> Match:
...
def __getitem__(self, i: int) -> Match: ...

@overload
def __getitem__(self, i: slice) -> MatchList:
...
def __getitem__(self, i: slice) -> MatchList: ...

def __getitem__(self, i: int | slice):
if isinstance(i, slice):
Expand Down Expand Up @@ -142,8 +140,7 @@ def amino(self):
return "".join(x.amino for x in iter(self))


class MatchListInterval(PyInterval):
...
class MatchListInterval(PyInterval): ...


class MatchListIntervalBuilder:
Expand Down
6 changes: 2 additions & 4 deletions snap/deciphon_snap/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ def __len__(self):
return len(self.root)

@overload
def __getitem__(self, i: int) -> Prod:
...
def __getitem__(self, i: int) -> Prod: ...

@overload
def __getitem__(self, i: slice) -> ProdList:
...
def __getitem__(self, i: slice) -> ProdList: ...

def __getitem__(self, i: int | slice):
if isinstance(i, slice):
Expand Down
3 changes: 1 addition & 2 deletions snap/deciphon_snap/query_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
__all__ = ["QueryInterval", "QueryIntervalBuilder"]


class QueryInterval(PyInterval):
...
class QueryInterval(PyInterval): ...


class QueryIntervalBuilder:
Expand Down
4 changes: 3 additions & 1 deletion snap/deciphon_snap/snap_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def __init__(self, filesystem):
window = int(row["window"])
hit = int(row["hit"])
profile = str(row["profile"])
with fs.open(f"{hmmer_dir}/{seq_id}/{window}/{hit}/{profile}.h3r", "rb") as f2:
with fs.open(
f"{hmmer_dir}/{seq_id}/{window}/{hit}/{profile}.h3r", "rb"
) as f2:
h3r = H3Result(raw=read_h3result(fileno=f2.fileno()))
window_start = int(row["window_start"])
window_stop = int(row["window_stop"])
Expand Down
13 changes: 6 additions & 7 deletions snap/deciphon_snap/view.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from functools import partial
from io import StringIO
from itertools import accumulate, chain
from typing import Optional

import tabulate
from hmmer_tables.query import DomAnnot, read_query
from pydantic import BaseModel
from tabulate import simple_separated_format, tabulate

from deciphon_snap.match import Match, MatchList
from deciphon_snap.prod import H3Result, Prod
Expand Down Expand Up @@ -37,7 +38,7 @@ def make_deciphon_steps(match_list: MatchList):


def make_hmmer_annot(h3result: H3Result):
hmmer_query = read_query(stream=h3result.domains.splitlines())
hmmer_query = read_query(stream=StringIO(h3result.domains))
assert len(hmmer_query.domains) == 1
return hmmer_query.domains[0]

Expand Down Expand Up @@ -196,11 +197,9 @@ def grab_query(x, i):
[None, None, "".join(score[sl]) + pad, "PP"],
]
table += row + [[None, None, None, None]]
tablefmt = tabulate.simple_separated_format(" ")
txt += str(
tabulate.tabulate(
table, tablefmt=tablefmt, colalign=("right", "right", "left", "left")
)
tablefmt = simple_separated_format(" ")
txt += tabulate(
table, tablefmt=tablefmt, colalign=("right", "right", "left", "left")
)
txt = txt.replace("&", "") + "\n"
return txt
Expand Down
20 changes: 10 additions & 10 deletions snap/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[tool.poetry]
name = "deciphon-snap"
version = "0.11.2"
version = "0.11.3"
description = "Reader for Deciphon snap files."
authors = ["Danilo Horta <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{ include = "deciphon_snap" }]

[tool.poetry.dependencies]
fsspec = { version = ">=2024.2.0" }
python = "^3.9"
h3result = ">=0.3.1"
tabulate = "^0"
fasta-reader = "^3.0.2"
deciphon-intervals = "^0.1.1"
prettytable = "^3.9.0"
pydantic = "^2.6.1"
hmmer-tables = "^0.6.0"
fsspec = ">=2024.5.0"
h3result = "^0.3"
tabulate = "^0.9"
fasta-reader = "^3.0"
deciphon-intervals = "^0.1"
prettytable = "^3.10"
pydantic = "^2.7"
hmmer-tables = "^0.6"

[tool.poetry.group.dev.dependencies]
pytest = ">=7.3.2"
pytest = "^8.2"

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit c3cb484

Please sign in to comment.