Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class Measurement:
# Errors
errors: list[Error] | None = None

# Custom information
custom_info: dict[str, Any] | None = None
device_control_custom_info: dict[str, Any] | None = None


@dataclass(frozen=True)
class MeasurementGroup:
Expand Down Expand Up @@ -302,7 +306,7 @@ def _get_measurement_document_item(
metadata.sample_volume_setting,
),
),
None,
measurement.device_control_custom_info,
),
]
),
Expand Down Expand Up @@ -355,7 +359,7 @@ def _get_sample_document(self, measurement: Measurement) -> SampleDocument:
batch_identifier=measurement.batch_identifier,
description=measurement.description,
),
None,
measurement.custom_info,
)

def _create_analyte_document(self, analyte: Analyte) -> AnalyteDocument:
Expand Down
28 changes: 28 additions & 0 deletions src/allotropy/parsers/novabio_flex2/novabio_flex2_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from allotropy.parsers.utils.pandas import SeriesData
from allotropy.parsers.utils.uuids import random_uuid_str
from allotropy.parsers.utils.values import try_float_or_none
from allotropy.parsers.utils.warnings_tools import suppress_unused_keys_warning


@dataclass(frozen=True)
Expand Down Expand Up @@ -78,13 +79,26 @@ class Sample:
viable_cell_count: float | None = None
cell_type_processing_method: str | None = None
cell_density_dilution_factor: float | None = None
custom_info: dict[str, Any] | None = None
device_control_custom_info: dict[str, Any] | None = None

@classmethod
def create(cls, units: SeriesData, data: SeriesData) -> Sample:
cell_density_dilution = data.get(str, "Cell Density Dilution", "")
if cell_density_dilution:
cell_density_dilution = cell_density_dilution.split(":")[0]

unused_keys = {
"Sample Time",
"PCO2 @ Temp",
"PO2 @ Temp",
"pH @ Temp",
"Operator",
"Osm",
}
data.mark_read(unused_keys)
units.mark_read(unused_keys)

return Sample(
identifier=data[str, "Sample ID"],
sample_type=data[str, "Sample Type"],
Expand Down Expand Up @@ -122,6 +136,17 @@ def create(cls, units: SeriesData, data: SeriesData) -> Sample:
if cell_density_dilution
else None,
cell_density_dilution_factor=try_float_or_none(str(cell_density_dilution)),
device_control_custom_info=data.get_custom_keys(
{
"Sparging O2%",
"pH / Gas Flow Time",
"Vessel Pressure (psi)",
"Chemistry Flow Time",
"Valid Images",
"Cell Density Flow",
}
),
custom_info={**data.get_unread(), **units.get_unread()},
)


Expand Down Expand Up @@ -165,6 +190,7 @@ def parse_units(units: SeriesData) -> SeriesData:
return SeriesData(pd.Series(data))

@staticmethod
@suppress_unused_keys_warning
def parse_data(
raw_data: pd.DataFrame,
) -> tuple[SeriesData, list[SeriesData]]:
Expand Down Expand Up @@ -198,6 +224,8 @@ def _create_measurement(sample: Sample, **kwargs: Any) -> Measurement:
sample_identifier=sample.identifier,
description=sample.sample_type,
batch_identifier=sample.batch_identifier,
custom_info=sample.custom_info,
device_control_custom_info=sample.device_control_custom_info,
**kwargs,
)

Expand Down
27 changes: 27 additions & 0 deletions src/allotropy/parsers/utils/warnings_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import annotations

from collections.abc import Callable
import functools
import gc
import os
from typing import Any


def suppress_unused_keys_warning(func: Callable[..., Any]) -> Callable[..., Any]:
Comment thread
nathan-stender marked this conversation as resolved.
"""
Use when a class that warns for unread keys is created for a special one-off use that does not intend to read all keys, e.g.
to read a single value and return.
Not appropriate to use in the main use of the class where unread keys should be copied into custom data fields.
"""

@functools.wraps(func)
def _wrapper(*args: Any, **kwargs: Any) -> Any:
previous_warn_unused_keys = os.environ.pop("WARN_UNUSED_KEYS", None)
try:
return func(*args, **kwargs)
finally:
gc.collect()
if previous_warn_unused_keys is not None:
os.environ["WARN_UNUSED_KEYS"] = previous_warn_unused_keys

return _wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
"device control document": [
{
"device type": "solution-analyzer",
"detection type": "metabolite-detection"
"detection type": "metabolite-detection",
"custom information document": {
"Vessel Pressure (psi)": 0.0,
"Sparging O2%": 20.9,
"Chemistry Flow Time": 6.67,
"pH / Gas Flow Time": 3.65
}
}
]
},
Expand All @@ -19,7 +25,12 @@
"sample document": {
"sample identifier": "SMPL_1234",
"batch identifier": "BATCH_123",
"description": "Spent Media"
"description": "Spent Media",
"custom information document": {
"Vessel ID": "3L Bioreactor",
"Chemistry Dilution Ratio": "1:1",
"Cell Type": "Workhog"
}
},
"analyte aggregate document": {
"analyte document": [
Expand Down Expand Up @@ -94,7 +105,13 @@
"device control document": [
{
"device type": "solution-analyzer",
"detection type": "blood-gas-detection"
"detection type": "blood-gas-detection",
"custom information document": {
"Vessel Pressure (psi)": 0.0,
"Sparging O2%": 20.9,
"Chemistry Flow Time": 6.67,
"pH / Gas Flow Time": 3.65
}
}
]
},
Expand All @@ -103,7 +120,12 @@
"sample document": {
"sample identifier": "SMPL_1234",
"batch identifier": "BATCH_123",
"description": "Spent Media"
"description": "Spent Media",
"custom information document": {
"Vessel ID": "3L Bioreactor",
"Chemistry Dilution Ratio": "1:1",
"Cell Type": "Workhog"
}
},
"pO2": {
"value": 191.6,
Expand All @@ -127,7 +149,13 @@
"device control document": [
{
"device type": "solution-analyzer",
"detection type": "ph-detection"
"detection type": "ph-detection",
"custom information document": {
"Vessel Pressure (psi)": 0.0,
"Sparging O2%": 20.9,
"Chemistry Flow Time": 6.67,
"pH / Gas Flow Time": 3.65
}
}
]
},
Expand All @@ -136,7 +164,12 @@
"sample document": {
"sample identifier": "SMPL_1234",
"batch identifier": "BATCH_123",
"description": "Spent Media"
"description": "Spent Media",
"custom information document": {
"Vessel ID": "3L Bioreactor",
"Chemistry Dilution Ratio": "1:1",
"Cell Type": "Workhog"
}
},
"pH": {
"value": 7.4,
Expand All @@ -159,7 +192,7 @@
"file name": "SampleResults2022-06-28_142558.csv",
"UNC path": "tests/parsers/novabio_flex2/testdata/SampleResults2022-06-28_142558.csv",
"ASM converter name": "allotropy_novabio_flex2",
"ASM converter version": "0.1.79",
"ASM converter version": "0.1.105",
"software name": "NovaBio Flex"
},
"device system document": {
Expand Down
Loading
Loading