Skip to content

Commit

Permalink
Fix selection codes for plates with >15 rows
Browse files Browse the repository at this point in the history
Also, the "only one column" is now called only by the functions that require it.
  • Loading branch information
michaelosthege committed Sep 15, 2024
1 parent 2044d07 commit 5fa3042
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion robotools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .utils import DilutionPlan, get_trough_wells
from .worklists import BaseWorklist, CompatibilityError

__version__ = "1.11.0"
__version__ = "1.11.1"
__all__ = (
"BaseWorklist",
"CompatibilityError",
Expand Down
24 changes: 13 additions & 11 deletions robotools/evotools/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def evo_get_selection(rows: int, cols: int, selected: np.ndarray) -> str:
Code string for well selection of pipetting actions in EvoWare scripts (.esc)
"""
# apply bit mask with 7 bits, adapted from function detailed in EvoWare manual
selection = f"0{to_hex(cols)}{rows:02d}"
selection = f"{to_hex(cols):0>2}{to_hex(rows):0>2}"
bit_counter = 0
bit_mask = 0
for x in range(cols):
Expand All @@ -83,16 +83,6 @@ def evo_get_selection(rows: int, cols: int, selected: np.ndarray) -> str:
if bit_counter > 0:
selection += chr(bit_mask + 48)

# check if wells from more than one column are selected and raise Exception if so
check = 0
for column in selected.transpose():
if sum(column) >= 1:
check += 1
if check >= 2:
raise ValueError(
"Wells from more than one column are selected.\nSelect only wells from one column per pipetting action."
)

return selection


Expand Down Expand Up @@ -212,6 +202,16 @@ def prepare_evo_aspirate_dispense_parameters(
return wells_list, labware_position, volume_list, liquid_class, tecan_tips


def require_single_column_selection(selection: np.ndarray):
"""Raises an error if wells from more than one column are selected."""
ncols = np.any(selection > 0, axis=0).sum()
if ncols >= 2:
raise ValueError(
"Wells from more than one column are selected.\nSelect only wells from one column per pipetting action."
)
return


def evo_aspirate(
*,
n_rows: int,
Expand Down Expand Up @@ -283,6 +283,7 @@ def evo_aspirate(

# convert selection from list of well ids to numpy array with same dimensions as target labware (1: well is selected, 0: well is not selected)
selected = evo_make_selection_array(n_rows, n_columns, wells)
require_single_column_selection(selected)
# create code string containing information about target well(s)
code_string = evo_get_selection(n_rows, n_columns, selected)
return f'B;Aspirate({tip_selection},"{liquid_class}",{tip_volumes}0,0,0,0,{labware_position[0]},{labware_position[1]},1,"{code_string}",0,{arm});'
Expand Down Expand Up @@ -359,6 +360,7 @@ def evo_dispense(

# convert selection from list of well ids to numpy array with same dimensions as target labware (1: well is selected, 0: well is not selected)
selected = evo_make_selection_array(n_rows, n_columns, wells)
require_single_column_selection(selected)
# create code string containing information about target well(s)
code_string = evo_get_selection(n_rows, n_columns, selected)
return f'B;Dispense({tip_selection},"{liquid_class}",{tip_volumes}0,0,0,0,{labware_position[0]},{labware_position[1]},1,"{code_string}",0,{arm});'
Expand Down
22 changes: 11 additions & 11 deletions robotools/evotools/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,12 @@
evo_wash,
prepare_evo_aspirate_dispense_parameters,
prepare_evo_wash_parameters,
require_single_column_selection,
)
from robotools.evotools.types import Tip


def test_evo_get_selection():
with pytest.raises(ValueError, match="from more than one column"):
evo_get_selection(
rows=2,
cols=3,
selected=np.array(
[
[True, False, False],
[False, True, False],
]
),
)
selection = evo_get_selection(
rows=2,
cols=3,
Expand All @@ -35,6 +25,9 @@ def test_evo_get_selection():
),
)
assert selection == "03023"

sel384 = evo_get_selection(16, 24, selected=np.full((16, 24), 1, dtype=bool))
assert sel384.startswith("1810")
pass


Expand Down Expand Up @@ -158,6 +151,13 @@ def test_prepare_evo_aspirate_dispense_parameters(self):
assert actual == expected


def test_require_single_column():
require_single_column_selection(np.eye(1))
with pytest.raises(ValueError, match="more than one"):
require_single_column_selection(np.eye(2))
pass


class TestEvoAspirate:
def test_evo_aspirate1(self) -> None:
cmd = evo_aspirate(
Expand Down

0 comments on commit 5fa3042

Please sign in to comment.