Skip to content

Commit e66216c

Browse files
committed
Changed the logic to get the number of wells
1 parent ef95d83 commit e66216c

3 files changed

Lines changed: 28 additions & 16 deletions

File tree

src/allotropy/parsers/constants.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,19 @@
1010
POSSIBLE_WELL_COUNTS = [1, 2, 4, 6, 8, 12, 24, 48, 72, 96, 384, 1536, 3456]
1111

1212

13-
def round_to_nearest_well_count(well_count: int) -> int | None:
14-
for possible_count in POSSIBLE_WELL_COUNTS:
13+
def round_to_nearest_well_count(
14+
well_count: int, possible_well_counts: list[int] | None = None
15+
) -> int | None:
16+
"""
17+
Round the well count to the nearest well count in the list of possible well counts. If a list
18+
of possible well counts is not provided, use the default list of possible well counts.
19+
If the well count is not in the list of possible well counts, return None.
20+
"""
21+
well_counts = (
22+
POSSIBLE_WELL_COUNTS if possible_well_counts is None else possible_well_counts
23+
)
24+
well_counts.sort()
25+
for possible_count in well_counts:
1526
if well_count > possible_count:
1627
continue
1728
return possible_count

src/allotropy/parsers/luminex_xponent/luminex_xponent_reader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,12 @@ def add_mandatory_columns(
227227
def _get_well_count(df: pd.DataFrame) -> int:
228228
# Count unique values in WELL LOCATION matching Excel-like cell ids: Letter(s) + Number(s)
229229
# Example matches: A1, B12, AA3
230+
accepted_well_counts = [96, 384]
230231
pattern = r"^[A-Za-z]+\d+$"
231232
values = df["WELL LOCATION"].astype(str).str.strip()
232233
matching = values[values.str.match(pattern)]
233234
unique_count = int(matching.str.upper().nunique())
234-
nearest = round_to_nearest_well_count(unique_count)
235+
nearest = round_to_nearest_well_count(unique_count, accepted_well_counts)
235236
return int(nearest or 0)
236237

237238
@classmethod

tests/parsers/luminex_intelliflex/testdata/luminex_intelliflex_single_dataset.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@
799799
],
800800
"container type": "well plate",
801801
"plate well count": {
802-
"value": 24.0,
802+
"value": 96.0,
803803
"unit": "#"
804804
}
805805
}
@@ -1601,7 +1601,7 @@
16011601
],
16021602
"container type": "well plate",
16031603
"plate well count": {
1604-
"value": 24.0,
1604+
"value": 96.0,
16051605
"unit": "#"
16061606
}
16071607
}
@@ -2403,7 +2403,7 @@
24032403
],
24042404
"container type": "well plate",
24052405
"plate well count": {
2406-
"value": 24.0,
2406+
"value": 96.0,
24072407
"unit": "#"
24082408
}
24092409
}
@@ -3205,7 +3205,7 @@
32053205
],
32063206
"container type": "well plate",
32073207
"plate well count": {
3208-
"value": 24.0,
3208+
"value": 96.0,
32093209
"unit": "#"
32103210
}
32113211
}
@@ -4007,7 +4007,7 @@
40074007
],
40084008
"container type": "well plate",
40094009
"plate well count": {
4010-
"value": 24.0,
4010+
"value": 96.0,
40114011
"unit": "#"
40124012
}
40134013
}
@@ -4809,7 +4809,7 @@
48094809
],
48104810
"container type": "well plate",
48114811
"plate well count": {
4812-
"value": 24.0,
4812+
"value": 96.0,
48134813
"unit": "#"
48144814
}
48154815
}
@@ -5611,7 +5611,7 @@
56115611
],
56125612
"container type": "well plate",
56135613
"plate well count": {
5614-
"value": 24.0,
5614+
"value": 96.0,
56155615
"unit": "#"
56165616
}
56175617
}
@@ -6413,7 +6413,7 @@
64136413
],
64146414
"container type": "well plate",
64156415
"plate well count": {
6416-
"value": 24.0,
6416+
"value": 96.0,
64176417
"unit": "#"
64186418
}
64196419
}
@@ -7215,7 +7215,7 @@
72157215
],
72167216
"container type": "well plate",
72177217
"plate well count": {
7218-
"value": 24.0,
7218+
"value": 96.0,
72197219
"unit": "#"
72207220
}
72217221
}
@@ -8017,7 +8017,7 @@
80178017
],
80188018
"container type": "well plate",
80198019
"plate well count": {
8020-
"value": 24.0,
8020+
"value": 96.0,
80218021
"unit": "#"
80228022
}
80238023
}
@@ -8819,7 +8819,7 @@
88198819
],
88208820
"container type": "well plate",
88218821
"plate well count": {
8822-
"value": 24.0,
8822+
"value": 96.0,
88238823
"unit": "#"
88248824
}
88258825
}
@@ -9621,7 +9621,7 @@
96219621
],
96229622
"container type": "well plate",
96239623
"plate well count": {
9624-
"value": 24.0,
9624+
"value": 96.0,
96259625
"unit": "#"
96269626
}
96279627
}
@@ -10423,7 +10423,7 @@
1042310423
],
1042410424
"container type": "well plate",
1042510425
"plate well count": {
10426-
"value": 24.0,
10426+
"value": 96.0,
1042710427
"unit": "#"
1042810428
}
1042910429
}

0 commit comments

Comments
 (0)