|
3 | 3 | from allotropy.allotrope.models.adm.multi_analyte_profiling.benchling._2024._09.multi_analyte_profiling import ( |
4 | 4 | AnalyteAggregateDocument, |
5 | 5 | AnalyteDocumentItem, |
| 6 | + CalculatedDataAggregateDocument, |
| 7 | + CalculatedDataDocumentItem, |
6 | 8 | CalibrationAggregateDocument, |
7 | 9 | CalibrationDocumentItem, |
| 10 | + DataSourceAggregateDocument, |
| 11 | + DataSourceDocumentItem, |
8 | 12 | DataSystemDocument, |
9 | 13 | DeviceControlAggregateDocument, |
10 | 14 | DeviceControlDocumentItem, |
|
17 | 21 | MultiAnalyteProfilingAggregateDocument, |
18 | 22 | MultiAnalyteProfilingDocumentItem, |
19 | 23 | SampleDocument, |
| 24 | + StatisticDimensionAggregateDocument, |
| 25 | + StatisticDimensionDocumentItem, |
| 26 | + StatisticsAggregateDocument, |
| 27 | + StatisticsDocumentItem, |
| 28 | + TQuantityValueModel, |
20 | 29 | ) |
21 | 30 | from allotropy.allotrope.models.shared.components.plate_reader import SampleRoleType |
22 | 31 | from allotropy.allotrope.models.shared.definitions.custom import ( |
|
28 | 37 | from allotropy.allotrope.models.shared.definitions.definitions import ( |
29 | 38 | TStatisticDatumRole, |
30 | 39 | ) |
| 40 | +from allotropy.allotrope.models.shared.definitions.units import Unitless |
31 | 41 | from allotropy.allotrope.schema_mappers.schema_mapper import SchemaMapper |
32 | 42 | from allotropy.constants import ASM_CONVERTER_VERSION |
| 43 | +from allotropy.parsers.utils.calculated_data_documents.definition import ( |
| 44 | + CalculatedDocument, |
| 45 | +) |
33 | 46 | from allotropy.parsers.utils.values import quantity_or_none |
34 | 47 |
|
35 | 48 |
|
| 49 | +@dataclass(frozen=True) |
| 50 | +class StatisticDimension: |
| 51 | + value: float |
| 52 | + unit: str |
| 53 | + statistic_datum_role: TStatisticDatumRole |
| 54 | + |
| 55 | + |
| 56 | +@dataclass(frozen=True) |
| 57 | +class StatisticsDocument: |
| 58 | + statistical_feature: str |
| 59 | + statistic_dimensions: list[StatisticDimension] |
| 60 | + |
| 61 | + |
36 | 62 | @dataclass(frozen=True) |
37 | 63 | class Analyte: |
38 | 64 | identifier: str |
39 | 65 | name: str |
40 | | - value: float |
41 | 66 | assay_bead_identifier: str |
42 | 67 | assay_bead_count: float |
43 | | - statistic_datum_role: TStatisticDatumRole | None |
| 68 | + statistics: list[StatisticsDocument] | None = None |
| 69 | + statistic_datum_role: TStatisticDatumRole | None = None |
| 70 | + fluorescence: float | None = None |
44 | 71 |
|
45 | 72 |
|
46 | 73 | @dataclass(frozen=True) |
@@ -115,6 +142,7 @@ class Metadata: |
115 | 142 | class Data: |
116 | 143 | metadata: Metadata |
117 | 144 | measurement_groups: list[MeasurementGroup] |
| 145 | + calculated_data: list[CalculatedDocument] | None = None |
118 | 146 |
|
119 | 147 |
|
120 | 148 | class Mapper(SchemaMapper[Data, Model]): |
@@ -146,6 +174,9 @@ def map_model(self, data: Data) -> Model: |
146 | 174 | self._get_technique_document(measurement_group, data.metadata) |
147 | 175 | for measurement_group in data.measurement_groups |
148 | 176 | ], |
| 177 | + calculated_data_aggregate_document=self._get_calculated_data_aggregate_document( |
| 178 | + data.calculated_data |
| 179 | + ), |
149 | 180 | ), |
150 | 181 | field_asm_manifest=self.MANIFEST, |
151 | 182 | ) |
@@ -208,9 +239,33 @@ def _get_measurement_document( |
208 | 239 | ), |
209 | 240 | fluorescence=quantity_or_none( |
210 | 241 | TQuantityValueRelativeFluorescenceUnit, |
211 | | - analyte.value, |
| 242 | + analyte.fluorescence, |
212 | 243 | has_statistic_datum_role=analyte.statistic_datum_role, |
213 | 244 | ), |
| 245 | + statistics_aggregate_document=( |
| 246 | + StatisticsAggregateDocument( |
| 247 | + statistics_document=[ |
| 248 | + StatisticsDocumentItem( |
| 249 | + statistical_feature=statistic.statistical_feature, |
| 250 | + statistic_dimension_aggregate_document=StatisticDimensionAggregateDocument( |
| 251 | + statistic_dimension_document=[ |
| 252 | + StatisticDimensionDocumentItem( |
| 253 | + statistical_value=TQuantityValueModel( |
| 254 | + value=dimension.value, |
| 255 | + unit=dimension.unit, |
| 256 | + has_statistic_datum_role=dimension.statistic_datum_role, |
| 257 | + ), |
| 258 | + ) |
| 259 | + for dimension in statistic.statistic_dimensions |
| 260 | + ] |
| 261 | + ), |
| 262 | + ) |
| 263 | + for statistic in analyte.statistics |
| 264 | + ] |
| 265 | + ) |
| 266 | + if analyte.statistics |
| 267 | + else None |
| 268 | + ), |
214 | 269 | ) |
215 | 270 | for analyte in measurement.analytes |
216 | 271 | ] |
@@ -261,3 +316,33 @@ def _get_error_aggregate_document( |
261 | 316 | for error in errors |
262 | 317 | ] |
263 | 318 | ) |
| 319 | + |
| 320 | + def _get_calculated_data_aggregate_document( |
| 321 | + self, calculated_data_items: list[CalculatedDocument] | None |
| 322 | + ) -> CalculatedDataAggregateDocument | None: |
| 323 | + if not calculated_data_items: |
| 324 | + return None |
| 325 | + |
| 326 | + return CalculatedDataAggregateDocument( |
| 327 | + calculated_data_document=[ |
| 328 | + CalculatedDataDocumentItem( |
| 329 | + calculated_data_identifier=calculated_data_item.uuid, |
| 330 | + calculated_data_name=calculated_data_item.name, |
| 331 | + calculation_description=calculated_data_item.description, |
| 332 | + calculated_result=TQuantityValueModel( |
| 333 | + value=calculated_data_item.value, |
| 334 | + unit=calculated_data_item.unit or Unitless.unit, |
| 335 | + ), |
| 336 | + data_source_aggregate_document=DataSourceAggregateDocument( |
| 337 | + data_source_document=[ |
| 338 | + DataSourceDocumentItem( |
| 339 | + data_source_identifier=item.reference.uuid, |
| 340 | + data_source_feature=item.feature, |
| 341 | + ) |
| 342 | + for item in calculated_data_item.data_sources |
| 343 | + ] |
| 344 | + ), |
| 345 | + ) |
| 346 | + for calculated_data_item in calculated_data_items |
| 347 | + ] |
| 348 | + ) |
0 commit comments