Skip to content

Commit ef6130e

Browse files
feat: ChemoMetec Nucleoview - add support for tab separated files (#1015)
Co-authored-by: Nathan Stender <nathan.stender@benchling.com>
1 parent c2ddbba commit ef6130e

4 files changed

Lines changed: 125 additions & 4 deletions

File tree

src/allotropy/parsers/chemometec_nucleoview/nucleoview_reader.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from io import StringIO
2+
13
import pandas as pd
24

35
from allotropy.exceptions import AllotropeConversionError, AllotropeParsingError
@@ -10,9 +12,29 @@ class NucleoviewReader:
1012

1113
@classmethod
1214
def read(cls, contents: IOType) -> pd.DataFrame:
13-
df = read_csv(
14-
contents, sep="[;,]+", engine="python", skipinitialspace=True, index_col=0
15-
)
15+
content = contents.read()
16+
content_str = content.decode("UTF-8") if isinstance(content, bytes) else content
17+
separators = [":\t", "[;,]+"]
18+
last_error = None
19+
20+
for sep in separators:
21+
try:
22+
df = read_csv(
23+
StringIO(content_str),
24+
sep=sep,
25+
engine="python",
26+
skipinitialspace=True,
27+
index_col=0,
28+
)
29+
if df.shape[1] >= 1:
30+
break
31+
except AllotropeParsingError as e:
32+
last_error = e
33+
continue
34+
else:
35+
if last_error:
36+
raise last_error
37+
1638
try:
1739
df = df[:-1].dropna(axis="index", how="all").T
1840
except KeyError as e:

src/allotropy/parsers/chemometec_nucleoview/nucleoview_structure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def _converted_value_or_none(key: str) -> float | None:
107107
Measurement(
108108
measurement_identifier=random_uuid_str(),
109109
timestamp=timestamp or DEFAULT_EPOCH_TIMESTAMP,
110-
sample_identifier=data[str, "Image"].split("-")[3],
110+
sample_identifier=data.get(str, "Sample ID")
111+
or data[str, "Image"].split("-")[3],
111112
cell_density_dilution_factor=data.get(float, "Multiplication factor"),
112113
viability=data[float, "Viability (%)"],
113114
# Cell counts are measured in cells/mL, but reported in millions of cells/mL
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Source ID: 99999999-00009
2+
Time (UTC): 1999-09-99 09:49:29
3+
Sample ID: 1111_viability count new 99x_pass 99
4+
Protocol: Count & Viability; 1.49
5+
Software version: 9.9.9.99
6+
Secure Mode status: Enable
7+
Signed by:
8+
Sample Media: Via2-Cassette
9+
User: gih
10+
Operator: gih
11+
Instrument: S/N:99999999999
12+
Tags:
13+
Comments:
14+
Total (cells/ml): 1.12E+06
15+
Live (cells/ml): 9.28E+05
16+
Dead (cells/ml): 1.90E+05
17+
Viability (%): 83.0
18+
Diameter (um): 9.7
19+
Aggregates (%): 0.0
20+
Debris Index: 50
21+
Dilution Factor: 10
22+
Status: OK
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"$asm.manifest": "http://purl.allotrope.org/manifests/cell-counting/REC/2024/09/cell-counting.manifest",
3+
"cell counting aggregate document": {
4+
"cell counting document": [
5+
{
6+
"measurement aggregate document": {
7+
"measurement document": [
8+
{
9+
"device control aggregate document": {
10+
"device control document": [
11+
{
12+
"device type": "dark field imager (cell counter)",
13+
"detection type": "dark field"
14+
}
15+
]
16+
},
17+
"measurement identifier": "CHEMOMETEC_NUCLEOVIEW_TEST_ID_0",
18+
"measurement time": "1970-01-01T00:00:00+00:00",
19+
"processed data aggregate document": {
20+
"processed data document": [
21+
{
22+
"viability (cell counter)": {
23+
"value": 83.0,
24+
"unit": "%"
25+
},
26+
"viable cell density (cell counter)": {
27+
"value": 0.928,
28+
"unit": "10^6 cells/mL"
29+
},
30+
"total cell density (cell counter)": {
31+
"value": 1.12,
32+
"unit": "10^6 cells/mL"
33+
},
34+
"dead cell density (cell counter)": {
35+
"value": 0.19,
36+
"unit": "10^6 cells/mL"
37+
}
38+
}
39+
]
40+
},
41+
"sample document": {
42+
"sample identifier": "1111_viability count new 99x_pass 99"
43+
},
44+
"custom information document": {
45+
"User": "gih",
46+
"Secure Mode status": "Enable",
47+
"Sample Media": "Via2-Cassette",
48+
"Software version": "9.9.9.99",
49+
"Time (UTC)": "1999-09-99 09:49:29",
50+
"Debris Index": 50.0,
51+
"Instrument": "S/N:99999999999",
52+
"Protocol": "Count & Viability; 1.49",
53+
"Aggregates (%)": 0.0,
54+
"Dilution Factor": 10.0,
55+
"Diameter (um)": 9.7
56+
}
57+
}
58+
]
59+
},
60+
"analyst": "gih"
61+
}
62+
],
63+
"data system document": {
64+
"ASM file identifier": "chemometec_nucleoview_example08.json",
65+
"data system instance identifier": "N/A",
66+
"file name": "chemometec_nucleoview_example08.csv",
67+
"UNC path": "tests/parsers/chemometec_nucleoview/testdata/chemometec_nucleoview_example08.csv",
68+
"ASM converter name": "allotropy_chemometec_nucleoview",
69+
"ASM converter version": "0.1.93",
70+
"software name": "NucleoView"
71+
},
72+
"device system document": {
73+
"model number": "NucleoCounter NC-200"
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)