Skip to content

Commit

Permalink
adds crystal plate interface for making subwell positions
Browse files Browse the repository at this point in the history
  • Loading branch information
David Erb committed May 2, 2023
1 parent ef76b2d commit a62b5ea
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
38 changes: 38 additions & 0 deletions src/xchembku_api/crystal_plate_objects/interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from abc import ABC, abstractmethod
from typing import Dict, Optional, Tuple


class Interface(ABC):
"""
This is the required API interface for an Authorizer object.
"""

@abstractmethod
# ----------------------------------------------------------------------------------------
def get_well_count(self) -> int:
pass

# ----------------------------------------------------------------------------------------
@abstractmethod
def normalize_subwell_name(self, subwell_name: str) -> str:
"""
Converts the name given to the subwell by Luigi into the "position" format shown in soakdb3.
Args:
subwell_name (str): stem part of the subwell's image filename
Raises:
ValueError: the value does not follow the convention
Returns:
str: the displayable subwell position
"""
pass

# ----------------------------------------------------------------------------------------
@abstractmethod
def compute_drop_location_microns(
self,
crystal_well_record: Dict,
) -> Tuple[Optional[int], Optional[int]]:
pass
11 changes: 9 additions & 2 deletions src/xchembku_lib/crystal_plate_objects/crystal_plate_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
# Types which the CrystalPlateObjects factory can use to build an instance.
from xchembku_api.crystal_plate_objects.constants import ThingTypes

# Interface fulfilled by all CrystalPlateObject isntances.
from xchembku_api.crystal_plate_objects.interface import (
Interface as CrystalPlateInterface,
)

# Exceptions.
from xchembku_api.exceptions import NotFound

Expand Down Expand Up @@ -35,8 +40,10 @@ def get_treenode_names(self) -> List[str]:
return list(self.__treenode_names_to_thing_type.keys())

# ----------------------------------------------------------------------------------------
def build_object(self, specification):
""""""
def build_object(self, specification) -> CrystalPlateInterface:
"""
TODO: CrystalPlateObjects build_object method should return an interface.
"""

object_class = self.lookup_class(specification["type"])

Expand Down
7 changes: 5 additions & 2 deletions src/xchembku_lib/crystal_plate_objects/swiss3.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
# Types.
from xchembku_api.crystal_plate_objects.constants import ThingTypes

# Interface.
from xchembku_api.crystal_plate_objects.interface import Interface

logger = logging.getLogger(__name__)

thing_type = ThingTypes.SWISS3


class Swiss3(Thing):
class Swiss3(Thing, Interface):
""" """

__MICRONS_PER_PIXEL_X = 2.837
Expand All @@ -32,7 +35,7 @@ def get_well_count(self) -> int:
# ----------------------------------------------------------------------------------------
def normalize_subwell_name(self, subwell_name: str) -> str:
"""
Converts the name given to the subwell by Luigi into the format expected by the beamline.
Converts the name given to the subwell by Luigi into the "position" format shown in soakdb3.
Args:
subwell_name (str): stem part of the subwell's image filename
Expand Down
2 changes: 0 additions & 2 deletions tests/test_crystal_plate.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ class CrystalPlateTester(Base):

async def _main_coroutine(self, constants, output_directory):
""" """
self.__injected_count = 0

# Get the multiconf from the testing configuration yaml.
multiconf = self.get_multiconf()

Expand Down
4 changes: 4 additions & 0 deletions tests/test_swiss3.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def test(
assert position == "H12d"

# Check invalid name formats.
with pytest.raises(ValueError) as excinfo:
swiss3.normalize_subwell_name("98ab_273A_1")
assert "expected format" in str(excinfo.value)

with pytest.raises(ValueError) as excinfo:
swiss3.normalize_subwell_name("98ju_01H_1.jpg")
assert "expected format" in str(excinfo.value)
Expand Down

0 comments on commit a62b5ea

Please sign in to comment.