Skip to content

Commit 5fa3042

Browse files
Fix selection codes for plates with >15 rows
Also, the "only one column" is now called only by the functions that require it.
1 parent 2044d07 commit 5fa3042

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

robotools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from .utils import DilutionPlan, get_trough_wells
2121
from .worklists import BaseWorklist, CompatibilityError
2222

23-
__version__ = "1.11.0"
23+
__version__ = "1.11.1"
2424
__all__ = (
2525
"BaseWorklist",
2626
"CompatibilityError",

robotools/evotools/commands.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def evo_get_selection(rows: int, cols: int, selected: np.ndarray) -> str:
6868
Code string for well selection of pipetting actions in EvoWare scripts (.esc)
6969
"""
7070
# apply bit mask with 7 bits, adapted from function detailed in EvoWare manual
71-
selection = f"0{to_hex(cols)}{rows:02d}"
71+
selection = f"{to_hex(cols):0>2}{to_hex(rows):0>2}"
7272
bit_counter = 0
7373
bit_mask = 0
7474
for x in range(cols):
@@ -83,16 +83,6 @@ def evo_get_selection(rows: int, cols: int, selected: np.ndarray) -> str:
8383
if bit_counter > 0:
8484
selection += chr(bit_mask + 48)
8585

86-
# check if wells from more than one column are selected and raise Exception if so
87-
check = 0
88-
for column in selected.transpose():
89-
if sum(column) >= 1:
90-
check += 1
91-
if check >= 2:
92-
raise ValueError(
93-
"Wells from more than one column are selected.\nSelect only wells from one column per pipetting action."
94-
)
95-
9686
return selection
9787

9888

@@ -212,6 +202,16 @@ def prepare_evo_aspirate_dispense_parameters(
212202
return wells_list, labware_position, volume_list, liquid_class, tecan_tips
213203

214204

205+
def require_single_column_selection(selection: np.ndarray):
206+
"""Raises an error if wells from more than one column are selected."""
207+
ncols = np.any(selection > 0, axis=0).sum()
208+
if ncols >= 2:
209+
raise ValueError(
210+
"Wells from more than one column are selected.\nSelect only wells from one column per pipetting action."
211+
)
212+
return
213+
214+
215215
def evo_aspirate(
216216
*,
217217
n_rows: int,
@@ -283,6 +283,7 @@ def evo_aspirate(
283283

284284
# 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)
285285
selected = evo_make_selection_array(n_rows, n_columns, wells)
286+
require_single_column_selection(selected)
286287
# create code string containing information about target well(s)
287288
code_string = evo_get_selection(n_rows, n_columns, selected)
288289
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});'
@@ -359,6 +360,7 @@ def evo_dispense(
359360

360361
# 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)
361362
selected = evo_make_selection_array(n_rows, n_columns, wells)
363+
require_single_column_selection(selected)
362364
# create code string containing information about target well(s)
363365
code_string = evo_get_selection(n_rows, n_columns, selected)
364366
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});'

robotools/evotools/test_commands.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,12 @@
88
evo_wash,
99
prepare_evo_aspirate_dispense_parameters,
1010
prepare_evo_wash_parameters,
11+
require_single_column_selection,
1112
)
1213
from robotools.evotools.types import Tip
1314

1415

1516
def test_evo_get_selection():
16-
with pytest.raises(ValueError, match="from more than one column"):
17-
evo_get_selection(
18-
rows=2,
19-
cols=3,
20-
selected=np.array(
21-
[
22-
[True, False, False],
23-
[False, True, False],
24-
]
25-
),
26-
)
2717
selection = evo_get_selection(
2818
rows=2,
2919
cols=3,
@@ -35,6 +25,9 @@ def test_evo_get_selection():
3525
),
3626
)
3727
assert selection == "03023"
28+
29+
sel384 = evo_get_selection(16, 24, selected=np.full((16, 24), 1, dtype=bool))
30+
assert sel384.startswith("1810")
3831
pass
3932

4033

@@ -158,6 +151,13 @@ def test_prepare_evo_aspirate_dispense_parameters(self):
158151
assert actual == expected
159152

160153

154+
def test_require_single_column():
155+
require_single_column_selection(np.eye(1))
156+
with pytest.raises(ValueError, match="more than one"):
157+
require_single_column_selection(np.eye(2))
158+
pass
159+
160+
161161
class TestEvoAspirate:
162162
def test_evo_aspirate1(self) -> None:
163163
cmd = evo_aspirate(

0 commit comments

Comments
 (0)