Skip to content

Commit

Permalink
changes export sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
David Erb committed Jun 15, 2023
1 parent 72190cd commit 5bf9842
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 29 deletions.
17 changes: 15 additions & 2 deletions src/echolocator_lib/guis/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
40 changes: 30 additions & 10 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand All @@ -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])
Expand All @@ -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,
)

Expand Down
17 changes: 10 additions & 7 deletions tests/test_export_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 10 additions & 7 deletions tests/test_export_to_soakdb3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions tests/test_fetch_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.
Expand All @@ -230,4 +230,4 @@ async def __request_anchor(self, crystal_wells):
)

record = response["record"]
assert record["position"] == "04A_1"
assert record["position"] == "B01a"

0 comments on commit 5bf9842

Please sign in to comment.