diff --git a/src/echolocator_lib/guis/aiohttp.py b/src/echolocator_lib/guis/aiohttp.py index 22197f7..6c51b01 100644 --- a/src/echolocator_lib/guis/aiohttp.py +++ b/src/echolocator_lib/guis/aiohttp.py @@ -571,10 +571,16 @@ async def __export_to_soakdb3(self, opaque, request_dict): crystal_well_filter, why="[EXPFIL] get list to be epxorted" ) + # Sort the list based on the (computed) row_first_position field. + sorted_models = sorted( + crystal_well_models, + key=lambda crystal_well_model: crystal_well_model.row_first_position(), + ) + logger.debug(f"[EXPFIL] found {len(crystal_well_models)} to be exported") # Export the crystal wells to the appropriate soakdb3 visit. - await self.__export_to_soakdb3_visit(visit_filter, crystal_well_models) + await self.__export_to_soakdb3_visit(visit_filter, sorted_models) # Make the list of droplocations to update with the exported flag. crystal_well_droplocation_models: List[CrystalWellDroplocationModel] = list() @@ -692,9 +698,16 @@ async def __export_to_csv(self, opaque, request_dict): crystal_plate_uuid, plate_crystal_well_models, ) in plates_crystal_well_models.items(): + + # Sort the list based on the (computed) row_first_position field. + sorted_models = sorted( + plate_crystal_well_models, + key=lambda crystal_well_model: crystal_well_model.row_first_position(), + ) + # Export the crystal wells for this plate to the appropriate csv file named for the plate. filename = await self.__export_to_csv_plate( - visit_filter, crystal_plate_uuid, plate_crystal_well_models + visit_filter, crystal_plate_uuid, sorted_models ) confirmations.append( diff --git a/tests/base.py b/tests/base.py index 8d8d6ee..8028a73 100644 --- a/tests/base.py +++ b/tests/base.py @@ -35,7 +35,7 @@ def __init__(self): self.tasks_execution_outputs = {} self.residuals = ["stdout.txt", "stderr.txt", "main.log"] - self.injected_count = 0 + self.__injected_count = 0 self.visit = "cm00001-1" self.__barcode_template = "98a%d" self.crystal_plate_uuid = None @@ -131,13 +131,33 @@ async def inject(self, xchembku, autolocation: bool, droplocation: bool): if self.crystal_plate_uuid is None: await self.inject_plate(xchembku) - self.injected_count += 1 - - filename = "/tmp/%03d.jpg" % (self.injected_count) + letter = "A" + if self.__injected_count > 3: + letter = "B" + + self.__injected_count += 1 + filename = "/tmp/%02d%s_1.jpg" % (self.__injected_count, letter) + position = "%s%02da" % (letter, self.__injected_count) + + positions = [ + "A01a", + "A02a", + "A03a", + "B01a", + "B02a", + "B02a", + "C01a", + "C02a", + "C03a", + "D01a", + "D02a", + "D03a", + ] + position = positions[self.__injected_count - 1] # Write well record. m = CrystalWellModel( - position="%02dA_1" % (self.injected_count), + position=position, filename=filename, crystal_plate_uuid=self.crystal_plate_uuid, ) @@ -148,11 +168,11 @@ async def inject(self, xchembku, autolocation: bool, droplocation: bool): # Add a crystal well autolocation. t = CrystalWellAutolocationModel( crystal_well_uuid=m.uuid, - number_of_crystals=self.injected_count, + number_of_crystals=self.__injected_count, well_centroid_x=400, well_centroid_y=500, - auto_target_x=self.injected_count * 10 + 0, - auto_target_y=self.injected_count * 10 + 1, + auto_target_x=self.__injected_count * 10 + 0, + auto_target_y=self.__injected_count * 10 + 1, ) await xchembku.originate_crystal_well_autolocations([t]) @@ -161,8 +181,8 @@ async def inject(self, xchembku, autolocation: bool, droplocation: bool): # Add a crystal well droplocation. t = CrystalWellDroplocationModel( crystal_well_uuid=m.uuid, - confirmed_target_x=self.injected_count * 100 + 2, - confirmed_target_y=self.injected_count * 100 + 3, + confirmed_target_x=self.__injected_count * 100 + 2, + confirmed_target_y=self.__injected_count * 100 + 3, is_usable=True, ) diff --git a/tests/test_export_to_csv.py b/tests/test_export_to_csv.py index bc56ee4..9e2ec2b 100644 --- a/tests/test_export_to_csv.py +++ b/tests/test_export_to_csv.py @@ -195,13 +195,16 @@ async def __export_wells(self, crystal_wells): # Check the well positions are those that are considered "confirmed". # The position constants are fromt the Swiss3 microns computation. - assert rows[0][0] == "02A_1" - assert int(rows[0][1]) == -561 - assert int(rows[0][2]) == -842 - assert rows[1][0] == "04A_1" - assert int(rows[1][1]) == 6 - assert int(rows[1][2]) == -274 - assert rows[2][0] == "05A_1" + # Note the order here: row_first_position gives get all letters in row 01 before any letters in row 02. + assert rows[0][0] == "B01a" + assert int(rows[0][1]) == 6 + assert int(rows[0][2]) == -274 + + assert rows[1][0] == "A02a" + assert int(rows[1][1]) == -561 + assert int(rows[1][2]) == -842 + + assert rows[2][0] == "B02a" assert int(rows[2][1]) == 289 assert int(rows[2][2]) == 9 diff --git a/tests/test_export_to_soakdb3.py b/tests/test_export_to_soakdb3.py index 5b1d43d..c2e83a1 100644 --- a/tests/test_export_to_soakdb3.py +++ b/tests/test_export_to_soakdb3.py @@ -211,13 +211,16 @@ async def __export_wells(self, crystal_wells): assert len(queried_models) == 3 # The position constants are fromt the Swiss3 microns computation. - assert queried_models[0].CrystalWell == "02A_1" - assert int(queried_models[0].EchoX) == -561 - assert int(queried_models[0].EchoY) == -842 - assert queried_models[1].CrystalWell == "04A_1" - assert int(queried_models[1].EchoX) == 6 - assert int(queried_models[1].EchoY) == -274 - assert queried_models[2].CrystalWell == "05A_1" + # Note the order here: row_first_position gives get all letters in row 01 before any letters in row 02. + assert queried_models[0].CrystalWell == "B01a" + assert int(queried_models[0].EchoX) == 6 + assert int(queried_models[0].EchoY) == -274 + + assert queried_models[1].CrystalWell == "A02a" + assert int(queried_models[1].EchoX) == -561 + assert int(queried_models[1].EchoY) == -842 + + assert queried_models[2].CrystalWell == "B02a" assert int(queried_models[2].EchoX) == 289 assert int(queried_models[2].EchoY) == 9 diff --git a/tests/test_fetch_image.py b/tests/test_fetch_image.py index c43bc42..e9793ae 100644 --- a/tests/test_fetch_image.py +++ b/tests/test_fetch_image.py @@ -205,7 +205,7 @@ async def __request_anchor(self, crystal_wells): Cookies.IMAGE_LIST_UX, ], Keywords.COMMAND: Commands.FETCH_IMAGE, - Keywords.CRYSTAL_WELL_INDEX: 2, # 04A_1 + Keywords.CRYSTAL_WELL_INDEX: 2, # B01a } response = await echolocator_guis_get_default().client_protocolj( @@ -218,7 +218,7 @@ async def __request_anchor(self, crystal_wells): record = response["record"] assert record is not None - assert record["position"] == "04A_1" + assert record["position"] == "B01a" # ------------------------------------------------------------------------------------- # Same query again, but rely on cookie for index. @@ -230,4 +230,4 @@ async def __request_anchor(self, crystal_wells): ) record = response["record"] - assert record["position"] == "04A_1" + assert record["position"] == "B01a"