Skip to content

Commit

Permalink
Use alphanumeric well IDs in .fluidics DataFrame index
Browse files Browse the repository at this point in the history
Part of #38
  • Loading branch information
michaelosthege authored and katroh committed Jun 20, 2023
1 parent 34fb75a commit da04da8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bletl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
NoMeasurementData,
)

__version__ = "1.2.3"
__version__ = "1.3.0"
25 changes: 25 additions & 0 deletions bletl/parsing/blpro.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@
logger = logging.getLogger("blpro")


_MF_WELL_NUMC_TO_ID = {
(colnumber + rownumber * 8): f"{row}{column:02d}"
for colnumber, column in enumerate(range(1, 9))
for rownumber, row in enumerate("CDEF")
}
"""Maps 0-based well numbers in MF mode by **C-style** counting order (→ then ↓) to alphanumeric well IDs."""

_MF_WELL_NUMF_TO_ID = {
(rownumber + colnumber * 4): f"{row}{column:02d}"
for rownumber, row in enumerate("CDEF")
for colnumber, column in enumerate(range(1, 9))
}
"""Maps 0-based well numbers in MF mode by **Fortran-style** counting order (↓ then →) to alphanumeric well IDs."""

_MF_WELL_NUMM_TO_ID = {
1 + (colnumber + rownumber * 8): f"{row}{column:02d}"
for rownumber, row in enumerate("CDEF")
for colnumber, column in enumerate(reversed(range(1, 9)) if rownumber % 2 else range(1, 9))
}
"""Maps 1-based well numbers in MF mode by **measurement counting order** (→→→ ↓ ←←← ↓ →→→ ...) to alphanumeric well IDs."""


class BioLectorProParser(BLDParser):
def parse(
self,
Expand Down Expand Up @@ -329,6 +351,7 @@ def extract_fluidics(dfraw):
("Temp_Ch4", "volume", float),
]
df = utils.__to_typed_cols__(dfraw[dfraw["Type"] == "F"], ocol_ncol_type)
df["well"] = [_MF_WELL_NUMM_TO_ID[w] for w in df["well"]]
df = df.sort_values(["well", "cycle"]).set_index(["well"])
return standardize(df)

Expand All @@ -348,6 +371,7 @@ def extract_valves_module(dfraw):
df_valves.columns = ["cycle", "valve", "well", "acid", "base"]
df_valves["valve"] = df_valves["valve"].str.replace("Valve ", "").astype(int)
df_valves["well"] = df_valves["well"].str.replace("Well", "").astype(int)
# TODO: Which numbering style is this?
df_valves["acid"] = df_valves["acid"].str.replace("Sollvolumen (Acid) ", "", regex=False).astype(float)
df_valves["base"] = df_valves["base"].str.replace("Sollvolumen (Base) ", "", regex=False).astype(float)
df_valves = standardize(df_valves).set_index(["well", "valve", "cycle"])
Expand All @@ -357,6 +381,7 @@ def extract_valves_module(dfraw):
df_module.columns = ["cycle", "module", "valve", "well", "volume"]
df_module["valve"] = df_module["valve"].str.replace("Valve ", "").astype(int)
df_module["well"] = df_module["well"].str.replace("Well ", "").astype(int)
# TODO: Which numbering style is this?
df_module["volume"] = df_module["volume"].str.replace("Volume ", "").astype(float)
df_module = standardize(df_module).set_index(["well", "valve", "cycle"])

Expand Down
42 changes: 41 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import bletl
from bletl import core, parsing, utils
from bletl.parsing import bl1
from bletl.parsing import bl1, blpro

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

Expand Down Expand Up @@ -595,3 +595,43 @@ def test_comments(self):

assert list(d_1.comments.columns) == list(d_p.comments.columns)
return


class TestBLProMF:
def test_well_num_mappings(self):
# C-style counts right then down
assert blpro._MF_WELL_NUMC_TO_ID[0] == "C01"
assert blpro._MF_WELL_NUMC_TO_ID[1] == "C02"
assert blpro._MF_WELL_NUMC_TO_ID[7] == "C08"
assert blpro._MF_WELL_NUMC_TO_ID[8] == "D01"
assert blpro._MF_WELL_NUMC_TO_ID[31] == "F08"
# F-style counts down then right
assert blpro._MF_WELL_NUMF_TO_ID[0] == "C01"
assert blpro._MF_WELL_NUMF_TO_ID[1] == "D01"
assert blpro._MF_WELL_NUMF_TO_ID[2] == "E01"
assert blpro._MF_WELL_NUMF_TO_ID[3] == "F01"
assert blpro._MF_WELL_NUMF_TO_ID[4] == "C02"
assert blpro._MF_WELL_NUMF_TO_ID[31] == "F08"
# Measurement order style is 1-based and goes left/right vice versa
assert blpro._MF_WELL_NUMM_TO_ID[1] == "C01"
assert blpro._MF_WELL_NUMM_TO_ID[2] == "C02"
assert blpro._MF_WELL_NUMM_TO_ID[8] == "C08"
assert blpro._MF_WELL_NUMM_TO_ID[9] == "D08"
assert blpro._MF_WELL_NUMM_TO_ID[16] == "D01"
assert blpro._MF_WELL_NUMM_TO_ID[32] == "F01"
pass

def test_issue_38(self):
fp = dir_testfiles / "BLPro" / "18-FZJ-Test2--2018-02-07-10-01-11.csv"
bldata = bletl.parse(fp)
assert bldata.fluidics.index.name == "well"
assert bldata.module.index.names == ["well", "valve", "cycle"]
assert bldata.valves.index.names == ["well", "valve", "cycle"]
# Check some initial and final well volumes against values shown in the BioLection
assert bldata.fluidics.loc["C01", "volume"][0] == 800
assert bldata.fluidics.loc["C01", "volume"][-1] == 1201.776
assert bldata.fluidics.loc["D01", "volume"][-1] == 1204.892
assert bldata.fluidics.loc["D02", "volume"][-1] == 954.68
assert bldata.fluidics.loc["E06", "volume"][-1] == 913.16
assert bldata.fluidics.loc["F01", "volume"][-1] == 1202.719
pass

0 comments on commit da04da8

Please sign in to comment.