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
1 change: 1 addition & 0 deletions src/allotropy/allotrope/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"=": "_EQUALS_",
"@": "_AT_",
"'": "_QUOTE_",
"*": "_ASTERISK_",
",": "_COMMA_",
"&": "_AMPERSAND_",
# NOTE: this MUST be at the end, or it will break other key replacements.
Expand Down
13 changes: 13 additions & 0 deletions src/allotropy/allotrope/models/shared/definitions/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
PartsPerBillion,
PartsPerMillion,
Percent,
PerMolarPerCentimeter,
PerMolarPerSecond,
PerSecond,
PH,
Expand Down Expand Up @@ -610,6 +611,18 @@ class TNullableQuantityValuePartsPerMillion(PartsPerMillion, TNullableQuantityVa
pass


@dataclass(frozen=True, kw_only=True)
class TQuantityValuePerMolarPerCentimeter(PerMolarPerCentimeter, TQuantityValue):
pass


@dataclass(frozen=True, kw_only=True)
class TNullableQuantityValuePerMolarPerCentimeter(
PerMolarPerCentimeter, TNullableQuantityValue
):
pass


@dataclass(frozen=True, kw_only=True)
class TQuantityValuePerMolarPerSecond(PerMolarPerSecond, TQuantityValue):
pass
Expand Down
5 changes: 5 additions & 0 deletions src/allotropy/allotrope/models/shared/definitions/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ class PartsPerMillion(HasUnit):
unit: str = "ppm"


@dataclass(frozen=True, kw_only=True)
class PerMolarPerCentimeter(HasUnit):
unit: str = "M-1cm-1"


@dataclass(frozen=True, kw_only=True)
class PerMolarPerSecond(HasUnit):
unit: str = "M-1s-1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
UltravioletAbsorbanceSpectrumDetectionMeasurementDocumentItems,
)
from allotropy.allotrope.models.shared.definitions.custom import (
TQuantityValueKiloDalton,
TQuantityValueMicroliter,
TQuantityValueMilliAbsorbanceUnit,
TQuantityValueNanogramPerMicroliter,
TQuantityValueNanometer,
TQuantityValuePerMolarPerCentimeter,
TQuantityValueRelativeFluorescenceUnit,
TQuantityValueUnitless,
)
Expand Down Expand Up @@ -77,6 +80,7 @@ class ProcessedDataFeature:
class ProcessedData:
features: list[ProcessedDataFeature]
identifier: str | None = None
custom_info: dict[str, Any] | None = None


@dataclass
Expand All @@ -102,6 +106,8 @@ class Measurement:
original_sample_concentration_unit: str | None = None
baseline_absorbance: float | None = None
electronic_absorbance_reference_wavelength_setting: float | None = None
cursor_position: float | None = None
cursor_absorbance: float | None = None

# Measurements
absorbance: JsonFloat | None = None
Expand Down Expand Up @@ -269,6 +275,14 @@ def _get_ultraviolet_absorbance_measurement_document(
TQuantityValueMilliAbsorbanceUnit,
measurement.baseline_absorbance,
),
"340 raw": quantity_or_none(
TQuantityValueMilliAbsorbanceUnit,
(measurement.custom_info or {}).get("340 raw"),
),
"Cursor Abs.": quantity_or_none(
TQuantityValueMilliAbsorbanceUnit,
measurement.cursor_absorbance,
),
}
return add_custom_information_document(doc, custom_info_doc)

Expand Down Expand Up @@ -341,6 +355,9 @@ def _get_device_control_custom_document(
"dilution factor": quantity_or_none(
TQuantityValueUnitless, measurement.dilution_factor_setting
),
"Cursor Pos.": quantity_or_none(
TQuantityValueNanometer, measurement.cursor_position
),
}
return (measurement.device_control_custom_info or {}) | custom_info

Expand All @@ -363,14 +380,19 @@ def _get_sample_document(self, measurement: Measurement) -> SampleDocument:
measurement.sample_custom_info["last read standards"]
)

sample_custom_info = measurement.sample_custom_info or {}
Comment thread
joshua-benchling marked this conversation as resolved.
sample_custom_info["Mol. Wt. kda"] = quantity_or_none(
TQuantityValueKiloDalton, sample_custom_info.get("Mol. Wt. kda")
)

return add_custom_information_document(
SampleDocument(
sample_identifier=measurement.sample_identifier,
batch_identifier=measurement.batch_identifier,
location_identifier=measurement.location_identifier,
well_plate_identifier=measurement.well_plate_identifier,
),
(measurement.sample_custom_info or {}) | custom_info_doc,
sample_custom_info | custom_info_doc,
)

def _get_processed_data_aggregate_document(
Expand All @@ -379,14 +401,38 @@ def _get_processed_data_aggregate_document(
if not data:
return None

# Build custom info for processed data with proper TQuantityValue wrappers
processed_data_custom_info = {}
if data.custom_info:
processed_data_custom_info = {
"E1%": quantity_or_none(
TQuantityValueUnitless, data.custom_info.get("E1%")
),
"ext. coeff x10e3": quantity_or_none(
TQuantityValuePerMolarPerCentimeter,
data.custom_info.get("ext. coeff x10e3"),
),
"ext.c.": quantity_or_none(
TQuantityValuePerMolarPerCentimeter,
data.custom_info.get("ext.c. (l/(mol*cm))"),
),
"conc. factor": quantity_or_none(
TQuantityValueNanogramPerMicroliter,
data.custom_info.get("conc. factor (ng/ul)"),
),
}

return ProcessedDataAggregateDocument(
processed_data_document=[
ProcessedDataDocumentItem(
# TODO(nstender): figure out how to limit possible classes from get_quantity_class for typing.
mass_concentration=quantity_or_none(
get_quantity_class(feature.unit), feature.result # type: ignore[arg-type]
add_custom_information_document(
ProcessedDataDocumentItem(
# TODO(nstender): figure out how to limit possible classes from get_quantity_class for typing.
mass_concentration=quantity_or_none(
get_quantity_class(feature.unit), feature.result # type: ignore[arg-type]
),
processed_data_identifier=data.identifier,
),
processed_data_identifier=data.identifier,
processed_data_custom_info,
)
for feature in data.features
]
Expand Down
20 changes: 20 additions & 0 deletions src/allotropy/allotrope/schemas/shared/definitions/custom.json
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,26 @@
}
]
},
"tQuantityValuePerMolarPerCentimeter": {
"allOf": [
{
"$ref": "#/$defs/tQuantityValue"
},
{
"$ref": "#/$defs/PerMolarPerCentimeter"
}
]
},
"tNullableQuantityValuePerMolarPerCentimeter": {
"allOf": [
{
"$ref": "#/$defs/tNullableQuantityValue"
},
{
"$ref": "#/$defs/PerMolarPerCentimeter"
}
]
},
"tQuantityValuePerMolarPerSecond": {
"allOf": [
{
Expand Down
12 changes: 12 additions & 0 deletions src/allotropy/allotrope/schemas/shared/definitions/units.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,18 @@
"unit"
]
},
"PerMolarPerCentimeter": {
"properties": {
"unit": {
"type": "string",
"const": "M-1cm-1",
"$asm.unit-iri": "http://purl.allotrope.org/ontology/qudt-ext/unit#PerMolarPerCentimeter"
}
},
"required": [
"unit"
]
},
"PerMolarPerSecond": {
"properties": {
"unit": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ def create(data: SeriesData) -> SpectroscopyRow:
)
unit = data.get(str, "units")

# Read fields for Data Processing Document custom info
processed_data_custom_info = {
"E1%": data.get(float, "e 1%"),
"ext. coeff x10e3": data.get(float, "ext. coeff x10e3"),
"ext.c. (l/(mol*cm))": data.get(float, "ext.c. (l/(mol*cm))"),
"conc. factor (ng/ul)": data.get(float, "conc. factor (ng/ul)"),
}

measurements: list[Measurement] = []
for wavelength, absorbance in absorbances.items():
if absorbance is None:
Expand All @@ -190,11 +198,30 @@ def create(data: SeriesData) -> SpectroscopyRow:
unit=unit,
)
],
custom_info=processed_data_custom_info or None,
)
if mass_concentration_capture_wavelength == wavelength
and mass_concentration
and unit
else None,
cursor_position=data.get(float, "cursor pos."),
cursor_absorbance=data.get(float, "cursor abs."),
sample_custom_info={
"Mol. Wt. kda": data.get(float, "mol. wt. kda"),
},
custom_info=data.get_unread(
skip={
Comment thread
joshua-benchling marked this conversation as resolved.
"date",
"time",
"user id",
"formula value 1",
"formula name 1",
"formula 1",
"260/230",
"260/280",
"m.w. (g/mol)",
}
),
)
)

Expand Down
Loading
Loading