Skip to content

Commit da04da8

Browse files
michaelosthegekatroh
authored andcommitted
Use alphanumeric well IDs in .fluidics DataFrame index
Part of #38
1 parent 34fb75a commit da04da8

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

bletl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
NoMeasurementData,
2020
)
2121

22-
__version__ = "1.2.3"
22+
__version__ = "1.3.0"

bletl/parsing/blpro.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@
2525
logger = logging.getLogger("blpro")
2626

2727

28+
_MF_WELL_NUMC_TO_ID = {
29+
(colnumber + rownumber * 8): f"{row}{column:02d}"
30+
for colnumber, column in enumerate(range(1, 9))
31+
for rownumber, row in enumerate("CDEF")
32+
}
33+
"""Maps 0-based well numbers in MF mode by **C-style** counting order (→ then ↓) to alphanumeric well IDs."""
34+
35+
_MF_WELL_NUMF_TO_ID = {
36+
(rownumber + colnumber * 4): f"{row}{column:02d}"
37+
for rownumber, row in enumerate("CDEF")
38+
for colnumber, column in enumerate(range(1, 9))
39+
}
40+
"""Maps 0-based well numbers in MF mode by **Fortran-style** counting order (↓ then →) to alphanumeric well IDs."""
41+
42+
_MF_WELL_NUMM_TO_ID = {
43+
1 + (colnumber + rownumber * 8): f"{row}{column:02d}"
44+
for rownumber, row in enumerate("CDEF")
45+
for colnumber, column in enumerate(reversed(range(1, 9)) if rownumber % 2 else range(1, 9))
46+
}
47+
"""Maps 1-based well numbers in MF mode by **measurement counting order** (→→→ ↓ ←←← ↓ →→→ ...) to alphanumeric well IDs."""
48+
49+
2850
class BioLectorProParser(BLDParser):
2951
def parse(
3052
self,
@@ -329,6 +351,7 @@ def extract_fluidics(dfraw):
329351
("Temp_Ch4", "volume", float),
330352
]
331353
df = utils.__to_typed_cols__(dfraw[dfraw["Type"] == "F"], ocol_ncol_type)
354+
df["well"] = [_MF_WELL_NUMM_TO_ID[w] for w in df["well"]]
332355
df = df.sort_values(["well", "cycle"]).set_index(["well"])
333356
return standardize(df)
334357

@@ -348,6 +371,7 @@ def extract_valves_module(dfraw):
348371
df_valves.columns = ["cycle", "valve", "well", "acid", "base"]
349372
df_valves["valve"] = df_valves["valve"].str.replace("Valve ", "").astype(int)
350373
df_valves["well"] = df_valves["well"].str.replace("Well", "").astype(int)
374+
# TODO: Which numbering style is this?
351375
df_valves["acid"] = df_valves["acid"].str.replace("Sollvolumen (Acid) ", "", regex=False).astype(float)
352376
df_valves["base"] = df_valves["base"].str.replace("Sollvolumen (Base) ", "", regex=False).astype(float)
353377
df_valves = standardize(df_valves).set_index(["well", "valve", "cycle"])
@@ -357,6 +381,7 @@ def extract_valves_module(dfraw):
357381
df_module.columns = ["cycle", "module", "valve", "well", "volume"]
358382
df_module["valve"] = df_module["valve"].str.replace("Valve ", "").astype(int)
359383
df_module["well"] = df_module["well"].str.replace("Well ", "").astype(int)
384+
# TODO: Which numbering style is this?
360385
df_module["volume"] = df_module["volume"].str.replace("Volume ", "").astype(float)
361386
df_module = standardize(df_module).set_index(["well", "valve", "cycle"])
362387

tests/test_core.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import bletl
1111
from bletl import core, parsing, utils
12-
from bletl.parsing import bl1
12+
from bletl.parsing import bl1, blpro
1313

1414
dir_testfiles = pathlib.Path(pathlib.Path(__file__).absolute().parent, "data")
1515

@@ -595,3 +595,43 @@ def test_comments(self):
595595

596596
assert list(d_1.comments.columns) == list(d_p.comments.columns)
597597
return
598+
599+
600+
class TestBLProMF:
601+
def test_well_num_mappings(self):
602+
# C-style counts right then down
603+
assert blpro._MF_WELL_NUMC_TO_ID[0] == "C01"
604+
assert blpro._MF_WELL_NUMC_TO_ID[1] == "C02"
605+
assert blpro._MF_WELL_NUMC_TO_ID[7] == "C08"
606+
assert blpro._MF_WELL_NUMC_TO_ID[8] == "D01"
607+
assert blpro._MF_WELL_NUMC_TO_ID[31] == "F08"
608+
# F-style counts down then right
609+
assert blpro._MF_WELL_NUMF_TO_ID[0] == "C01"
610+
assert blpro._MF_WELL_NUMF_TO_ID[1] == "D01"
611+
assert blpro._MF_WELL_NUMF_TO_ID[2] == "E01"
612+
assert blpro._MF_WELL_NUMF_TO_ID[3] == "F01"
613+
assert blpro._MF_WELL_NUMF_TO_ID[4] == "C02"
614+
assert blpro._MF_WELL_NUMF_TO_ID[31] == "F08"
615+
# Measurement order style is 1-based and goes left/right vice versa
616+
assert blpro._MF_WELL_NUMM_TO_ID[1] == "C01"
617+
assert blpro._MF_WELL_NUMM_TO_ID[2] == "C02"
618+
assert blpro._MF_WELL_NUMM_TO_ID[8] == "C08"
619+
assert blpro._MF_WELL_NUMM_TO_ID[9] == "D08"
620+
assert blpro._MF_WELL_NUMM_TO_ID[16] == "D01"
621+
assert blpro._MF_WELL_NUMM_TO_ID[32] == "F01"
622+
pass
623+
624+
def test_issue_38(self):
625+
fp = dir_testfiles / "BLPro" / "18-FZJ-Test2--2018-02-07-10-01-11.csv"
626+
bldata = bletl.parse(fp)
627+
assert bldata.fluidics.index.name == "well"
628+
assert bldata.module.index.names == ["well", "valve", "cycle"]
629+
assert bldata.valves.index.names == ["well", "valve", "cycle"]
630+
# Check some initial and final well volumes against values shown in the BioLection
631+
assert bldata.fluidics.loc["C01", "volume"][0] == 800
632+
assert bldata.fluidics.loc["C01", "volume"][-1] == 1201.776
633+
assert bldata.fluidics.loc["D01", "volume"][-1] == 1204.892
634+
assert bldata.fluidics.loc["D02", "volume"][-1] == 954.68
635+
assert bldata.fluidics.loc["E06", "volume"][-1] == 913.16
636+
assert bldata.fluidics.loc["F01", "volume"][-1] == 1202.719
637+
pass

0 commit comments

Comments
 (0)