Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add unread keys to custom information document #672

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions src/allotropy/allotrope/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@


DICT_KEY_TO_MODEL_KEY_REPLACEMENTS = {
".": "_POINT_",
"-": "_DASH_",
"°": "_DEG_",
"/": "_SLASH_",
"\\": "_BSLASH_",
"(": "_OPAREN_",
")": "_CPAREN_",
"%": "_PERCENT_",
# NOTE: this MUST be at the end, or it will break other key replacements.
" ": "_",
}
Expand All @@ -108,6 +110,8 @@
def add_custom_information_document(
model: ModelClass, custom_info_doc: Any
) -> ModelClass:
if not custom_info_doc:
return model

if isinstance(custom_info_doc, dict):
custom_info_doc = structure_custom_information_document(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Callable
from dataclasses import dataclass
from typing import TypeVar
from typing import Any, TypeVar

from allotropy.allotrope.converter import add_custom_information_document
from allotropy.allotrope.models.adm.pcr.benchling._2023._09.qpcr import (
Expand Down Expand Up @@ -101,14 +101,6 @@ class ProcessedData:
normalized_reporter_result: float | None = None
baseline_corrected_reporter_result: float | None = None

# Metadata
comments: str | None = None
highsd: str | None = None
noamp: str | None = None
expfail: str | None = None
tholdfail: str | None = None
prfdrop: str | None = None

data_cubes: list[DataCube] | None = None


Expand Down Expand Up @@ -138,13 +130,7 @@ class Measurement:
processed_data: ProcessedData | None = None
data_cubes: list[DataCube] | None = None

# Custom metadata
well_identifier: int | None = None
omit: bool | None = None
sample_color: str | None = None
biogroup_name: str | None = None
biogroup_color: str | None = None
target_color: str | None = None
custom_info: dict[str, Any] | None = None


@dataclass
Expand All @@ -170,6 +156,7 @@ class Metadata:
software_name: str | None = None
software_version: str | None = None
product_manufacturer: str | None = None
custom_info: dict[str, Any] | None = None


@dataclass
Expand Down Expand Up @@ -218,17 +205,20 @@ def _get_technique_document(
) -> QPCRDocumentItem:
return QPCRDocumentItem(
analyst=measurement_group.analyst,
measurement_aggregate_document=MeasurementAggregateDocument(
experimental_data_identifier=measurement_group.experimental_data_identifier,
experiment_type=metadata.experiment_type,
container_type=metadata.container_type,
plate_well_count=TQuantityValueNumber(
value=measurement_group.plate_well_count
measurement_aggregate_document=add_custom_information_document(
MeasurementAggregateDocument(
experimental_data_identifier=measurement_group.experimental_data_identifier,
experiment_type=metadata.experiment_type,
container_type=metadata.container_type,
plate_well_count=TQuantityValueNumber(
value=measurement_group.plate_well_count
),
measurement_document=[
self._get_measurement_document_item(measurement, metadata)
for measurement in measurement_group.measurements
],
),
measurement_document=[
self._get_measurement_document_item(measurement, metadata)
for measurement in measurement_group.measurements
],
metadata.custom_info,
),
)

Expand All @@ -237,9 +227,6 @@ def _get_measurement_document_item(
measurement: Measurement,
metadata: Metadata,
) -> MeasurementDocumentItem:
custom_doc = {
"omit": measurement.omit,
}
measurement_doc = MeasurementDocumentItem(
measurement_identifier=measurement.identifier,
measurement_time=self.get_date_time(measurement.timestamp),
Expand Down Expand Up @@ -275,82 +262,65 @@ def _get_measurement_document_item(
MeltingCurveDataCube, "melting curve", measurement.data_cubes
),
)
return add_custom_information_document(measurement_doc, custom_doc)
return add_custom_information_document(measurement_doc, measurement.custom_info)

def _get_sample_document(self, measurement: Measurement) -> SampleDocument:
custom_doc = {
"well identifier": measurement.well_identifier,
"sample color": measurement.sample_color,
"biogroup name": measurement.biogroup_name,
"biogroup color": measurement.biogroup_color,
"target color": measurement.target_color,
}
sample_doc = SampleDocument(
return SampleDocument(
sample_identifier=measurement.sample_identifier,
sample_role_type=measurement.sample_role_type,
well_location_identifier=measurement.well_location_identifier,
well_plate_identifier=measurement.well_plate_identifier,
)
return add_custom_information_document(sample_doc, custom_doc)

def _get_processed_data_aggregate_document(
self, data: ProcessedData | None
) -> ProcessedDataAggregateDocument | None:
if not data:
return None

return ProcessedDataAggregateDocument(
processed_data_document=[
add_custom_information_document(
ProcessedDataDocumentItem(
data_processing_document=DataProcessingDocument(
automatic_cycle_threshold_enabled_setting=data.automatic_cycle_threshold_enabled_setting,
cycle_threshold_value_setting=TQuantityValueUnitless(
value=data.cycle_threshold_value_setting,
),
automatic_baseline_determination_enabled_setting=data.automatic_baseline_determination_enabled_setting,
genotyping_determination_method_setting=quantity_or_none(
TQuantityValueUnitless,
data.genotyping_determination_method_setting,
),
baseline_determination_start_cycle_setting=quantity_or_none(
TQuantityValueNumber,
data.baseline_determination_start_cycle_setting,
),
baseline_determination_end_cycle_setting=quantity_or_none(
TQuantityValueNumber,
data.baseline_determination_end_cycle_setting,
),
),
cycle_threshold_result=TNullableQuantityValueUnitless(
value=data.cycle_threshold_result,
),
normalized_reporter_result=quantity_or_none(
TQuantityValueUnitless, data.normalized_reporter_result
ProcessedDataDocumentItem(
data_processing_document=DataProcessingDocument(
automatic_cycle_threshold_enabled_setting=data.automatic_cycle_threshold_enabled_setting,
cycle_threshold_value_setting=TQuantityValueUnitless(
value=data.cycle_threshold_value_setting,
),
baseline_corrected_reporter_result=quantity_or_none(
automatic_baseline_determination_enabled_setting=data.automatic_baseline_determination_enabled_setting,
genotyping_determination_method_setting=quantity_or_none(
TQuantityValueUnitless,
data.baseline_corrected_reporter_result,
data.genotyping_determination_method_setting,
),
genotyping_determination_result=data.genotyping_determination_result,
normalized_reporter_data_cube=self._get_data_cube(
NormalizedReporterDataCube,
"normalized reporter",
data.data_cubes,
baseline_determination_start_cycle_setting=quantity_or_none(
TQuantityValueNumber,
data.baseline_determination_start_cycle_setting,
),
baseline_corrected_reporter_data_cube=self._get_data_cube(
BaselineCorrectedReporterDataCube,
"baseline corrected reporter",
data.data_cubes,
baseline_determination_end_cycle_setting=quantity_or_none(
TQuantityValueNumber,
data.baseline_determination_end_cycle_setting,
),
),
custom_info_doc={
"comments": data.comments,
"highsd": data.highsd,
"noamp": data.noamp,
"expfail": data.expfail,
"tholdfail": data.tholdfail,
"prfdrop": data.prfdrop,
},
cycle_threshold_result=TNullableQuantityValueUnitless(
value=data.cycle_threshold_result,
),
normalized_reporter_result=quantity_or_none(
TQuantityValueUnitless, data.normalized_reporter_result
),
baseline_corrected_reporter_result=quantity_or_none(
TQuantityValueUnitless,
data.baseline_corrected_reporter_result,
),
genotyping_determination_result=data.genotyping_determination_result,
normalized_reporter_data_cube=self._get_data_cube(
NormalizedReporterDataCube,
"normalized reporter",
data.data_cubes,
),
baseline_corrected_reporter_data_cube=self._get_data_cube(
BaselineCorrectedReporterDataCube,
"baseline corrected reporter",
data.data_cubes,
),
)
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ def _create_processed_data(
cycle_threshold_result=result.cycle_threshold_result,
normalized_reporter_result=result.normalized_reporter_result,
baseline_corrected_reporter_result=result.baseline_corrected_reporter_result,
comments=result.comments,
highsd=result.highsd,
noamp=result.noamp,
expfail=result.expfail,
tholdfail=result.tholdfail,
prfdrop=result.prfdrop,
data_cubes=_create_processed_data_cubes(amplification_data),
)

Expand Down Expand Up @@ -187,24 +181,23 @@ def _create_measurement(
sample_identifier=well_item.sample_identifier,
sample_role_type=well_item.sample_role_type,
well_location_identifier=well_item.well_location_identifier,
well_identifier=well_item.identifier,
well_plate_identifier=header.barcode,
omit=result.omit,
sample_color=well_item.sample_color,
biogroup_name=well_item.biogroup_name,
biogroup_color=well_item.biogroup_color,
target_color=well_item.target_color,
total_cycle_number_setting=amplification_data.total_cycle_number_setting,
pcr_detection_chemistry=header.pcr_detection_chemistry,
reporter_dye_setting=well_item.reporter_dye_setting,
quencher_dye_setting=well_item.quencher_dye_setting,
passive_reference_dye_setting=header.passive_reference_dye_setting,
processed_data=_create_processed_data(amplification_data, result),
custom_info=(well_item.extra_data or {})
| (result.extra_data or {})
| {"well identifier": well_item.identifier},
data_cubes=data_cubes,
)


def create_metadata(header: Header, file_name: str) -> Metadata:
def create_metadata(
header: Header, results_metadata: ResultMetadata, file_name: str
) -> Metadata:
return Metadata(
device_identifier=header.device_identifier,
device_type=constants.DEVICE_TYPE,
Expand All @@ -218,6 +211,7 @@ def create_metadata(header: Header, file_name: str) -> Metadata:
measurement_method_identifier=header.measurement_method_identifier,
experiment_type=header.experiment_type,
container_type=constants.CONTAINER_TYPE,
custom_info=header.extra_data | results_metadata.extra_data,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def create_data(self, named_file_contents: NamedFileContents) -> Data:
)

return Data(
metadata=create_metadata(header, named_file_contents.original_file_name),
metadata=create_metadata(
header, results_metadata, named_file_contents.original_file_name
),
measurement_groups=create_measurement_groups(
header, wells, amp_data, multi_data, results_data, melt_data
),
Expand Down
Loading
Loading