Skip to content

Commit e705eb6

Browse files
fix: Handle multiple spaces in Raw Data line for BMG MARS parser (#1243)
## Summary BMG PHERAstar CSV exports can write the `Raw Data` header with more than one space before the filter parenthesis (e.g. `Raw Data (450)` with two spaces). The parser's regexes required exactly one literal space, so parsing failed with: ``` AllotropeConversionError: Raw Data line not found in input file. ``` This relaxes the whitespace to `\s+` in the search regex and all four `FILTER_FORMATS` patterns in `bmg_mars_structure.py`. ## Changes - `bmg_mars_structure.py`: `Raw Data \(` → `Raw Data\s+\(` in the search regex and all filter format patterns. - Added regression test data: `PHERAstar output file.CSV` (a real double-space export) and its generated expected `.json`. ## Testing - All 8 `bmg_mars` tests pass. - `hatch run lint` (ruff, black, mypy) clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 42970b7 commit e705eb6

3 files changed

Lines changed: 3980 additions & 5 deletions

File tree

src/allotropy/parsers/bmg_mars/bmg_mars_structure.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ class Header:
7171

7272
FILTER_FORMATS: ClassVar[dict[str, tuple[str, FilterHandler]]] = {
7373
"Raw Data (Ex/Em)": (
74-
r"Raw Data \((\d+\.?\d*)/(\d+\.?\d*)\)",
74+
r"Raw Data\s+\((\d+\.?\d*)/(\d+\.?\d*)\)",
7575
lambda m: (float(m.group(2)), float(m.group(1))),
7676
),
7777
"Raw Data (Ex Em)": (
78-
r"Raw Data \((\d+\.?\d*) (\d+\.?\d*)\)",
78+
r"Raw Data\s+\((\d+\.?\d*) (\d+\.?\d*)\)",
7979
lambda m: (float(m.group(2)), float(m.group(1))),
8080
),
8181
"Raw Data (Em)": (
82-
r"Raw Data \((\d+\.?\d*)\)",
82+
r"Raw Data\s+\((\d+\.?\d*)\)",
8383
lambda m: (float(m.group(1)), None),
8484
),
8585
"Raw Data (No filter)": (
86-
r"Raw Data \(No filter\)",
86+
r"Raw Data\s+\(No filter\)",
8787
lambda _: (None, None),
8888
),
8989
}
@@ -100,7 +100,7 @@ def create(data: SeriesData, header_content: str) -> Header:
100100

101101
# Get wavelengths from RawData line
102102
raw_data_line = assert_not_none(
103-
re.search(r"Raw Data \(.*?\)", header_content),
103+
re.search(r"Raw Data\s+\(.*?\)", header_content),
104104
msg="Raw Data line not found in input file.",
105105
).group(0)
106106

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
User: USER,Path: C:\Program Files (x86)\BMG\PHERAstar\User\Data,Test run no.: 65
2+
Test name: dsRNA ELISA,Date: 6/18/2026,Time: 3:56:48 PM
3+
4+
ID1: 20260618 dsRNA _PLATE_01_18Jun26,
5+
Absorbance
6+
7+
Raw Data (450)
8+
9+
,1,2,3,4,5,6,7,8,9,10,11,12,
10+
A,1.691,1.557,1.583,0.596,0.336,0.221,0.162,0.091,0.098,0.086,0.213,1.641
11+
B,1.016,0.986,0.953,0.479,0.321,0.199,0.135,0.094,0.1,0.087,0.126,1.194
12+
C,0.561,0.503,0.503,0.07,0.082,0.078,0.084,0.094,0.101,0.08,0.13,1.637
13+
D,0.342,0.272,0.28,0.072,0.083,0.165,0.181,0.074,0.091,0.076,0.094,1.171
14+
E,0.184,0.16,0.165,0.069,0.07,0.142,0.078,0.079,0.089,0.081,0.098,1.361
15+
F,0.119,0.113,0.122,0.076,0.074,0.082,0.08,0.084,0.096,0.083,0.091,0.914
16+
G,0.086,0.093,0.097,0.098,0.073,0.086,0.086,0.086,0.087,0.085,0.094,1.4
17+
H,0.069,0.076,0.074,0.074,0.077,0.091,0.086,0.096,0.094,0.087,0.088,0.884
18+

0 commit comments

Comments
 (0)