Skip to content

Commit

Permalink
added types
Browse files Browse the repository at this point in the history
  • Loading branch information
haeussma committed Jan 19, 2025
1 parent 9e31cdb commit a154261
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/pyeed/tools/abstract_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import tempfile
from abc import ABC, abstractmethod
from enum import Enum
from typing import Any

import httpx
from pydantic import BaseModel, PrivateAttr
Expand All @@ -23,15 +24,15 @@ class AbstractTool(BaseModel, ABC):
_service_url: str = PrivateAttr()
_tempdir_path: str = PrivateAttr()

def model_post_init(self, __context) -> None:
def model_post_init(self, __context: Any) -> None:
"""Create temporary directory."""
self._tempdir_path = tempfile.mkdtemp()

def _delete_temp_dir(self):
def _delete_temp_dir(self) -> None:
"""Deletes the temporary directory."""
shutil.rmtree(self._tempdir_path)

@abstractmethod
def run_service(self, data) -> httpx.Response:
def run_service(self, data: dict[str, Any]) -> httpx.Response:
"""Executes the service."""
pass
10 changes: 5 additions & 5 deletions src/pyeed/tools/clustalo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ClustalOmega(AbstractTool):
Class for ClustalOmega aligner running as a REST service.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()
self._service_url = ServiceURL.CLUSTALO.value

Expand All @@ -28,19 +28,19 @@ def create_file(self, multifasta: list[str]) -> dict[str, str]:
data = "\n".join(multifasta)
return {"file": data}

def extract_output_data(self, response) -> MultipleSeqAlignment:
def extract_output_data(self, response: str) -> MultipleSeqAlignment:
"""
Extracts the output data from the ClustalOmega container.
Returns:
MultiSequenceAlignment: The alignment result.
"""
alignment = AlignIO.read(io.StringIO(response), "clustal")
alignment: MultipleSeqAlignment = AlignIO.read(io.StringIO(response), "clustal") # type: ignore
self._delete_temp_dir()

return alignment
return alignment # type: ignore

def run_service(self, data) -> httpx.Response:
def run_service(self, data: list[str]) -> httpx.Response:
"""Executes the ClustalOmega service."""
file = self.create_file(data)
try:
Expand Down
10 changes: 10 additions & 0 deletions src/pyeed/tools/test_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pyeed import Pyeed
from pyeed.model import Protein

pyeed = Pyeed(
uri="bolt://localhost:7688",
user="neo4j",
password="12345678",
)

prots = Protein.nodes.all()

0 comments on commit a154261

Please sign in to comment.