Skip to content

Commit 6da14ff

Browse files
committed
Modified logic use cubedata just if there is more than one data point
1 parent 033e2db commit 6da14ff

11 files changed

Lines changed: 5597 additions & 6929 deletions

src/allotropy/parsers/unchained_labs_lunatic_stunner/unchained_labs_lunatic_stunner_structure.py

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def _create_measurement(
148148
absorbance_errors.append(
149149
ErrorDocument(
150150
error=NOT_APPLICABLE,
151-
error_feature=f"{DEFAULT_DETECTION_TYPE.lower()}-{wavelength_column}",
151+
error_feature=f"{DEFAULT_DETECTION_TYPE.lower()}",
152152
)
153153
)
154154

@@ -164,8 +164,6 @@ def _create_measurement(
164164

165165
error_documents: list[ErrorDocument] = []
166166

167-
spectrum_data_cube = _get_spectrum_data_cube(well_plate_data, wavelength_columns)
168-
169167
concentration_factor = well_plate_data.get(float, "concentration factor (ng/ul)")
170168
application = header.get(str, "application")
171169
analytical_method_identifier = (
@@ -183,24 +181,25 @@ def _create_measurement(
183181
error_documents.extend(calculated_data_errors)
184182
error_documents.extend(absorbance_errors)
185183

186-
return Measurement(
187-
type_=MeasurementType.ULTRAVIOLET_ABSORBANCE_CUBE_SPECTRUM,
188-
device_type=DEVICE_TYPE,
189-
detection_type=detection_type,
190-
identifier=measurement_identifier,
191-
analytical_method_identifier=analytical_method_identifier,
192-
experimental_data_identifier=experimental_data_identifier,
193-
electronic_absorbance_reference_wavelength_setting=background_wavelength,
194-
sample_identifier=well_plate_data[str, "sample name"],
195-
location_identifier=well_plate_data[str, "plate position"],
196-
well_plate_identifier=well_plate_data.get(str, "plate id"),
197-
batch_identifier=well_plate_data.get(str, "sample group"),
198-
firmware_version=header.get(str, "client version"),
199-
number_of_averages=well_plate_data.get(float, "number of acquisitions"),
200-
integration_time=well_plate_data.get(float, "acquisition time (s)"),
201-
compartment_temperature=well_plate_data.get(float, "temperature (°c)"),
202-
spectrum_data_cube=spectrum_data_cube,
203-
sample_custom_info={
184+
measurement_dict = {
185+
"type_": MeasurementType.ULTRAVIOLET_ABSORBANCE_CUBE_SPECTRUM
186+
if len(wavelength_columns) > 1
187+
else MeasurementType.ULTRAVIOLET_ABSORBANCE,
188+
"device_type": DEVICE_TYPE,
189+
"detection_type": detection_type,
190+
"identifier": measurement_identifier,
191+
"analytical_method_identifier": analytical_method_identifier,
192+
"experimental_data_identifier": experimental_data_identifier,
193+
"electronic_absorbance_reference_wavelength_setting": background_wavelength,
194+
"sample_identifier": well_plate_data[str, "sample name"],
195+
"location_identifier": well_plate_data[str, "plate position"],
196+
"well_plate_identifier": well_plate_data.get(str, "plate id"),
197+
"batch_identifier": well_plate_data.get(str, "sample group"),
198+
"firmware_version": header.get(str, "client version"),
199+
"number_of_averages": well_plate_data.get(float, "number of acquisitions"),
200+
"integration_time": well_plate_data.get(float, "acquisition time (s)"),
201+
"compartment_temperature": well_plate_data.get(float, "temperature (°c)"),
202+
"sample_custom_info": {
204203
"plate type": header.get(str, "plate type")
205204
or well_plate_data.get(str, "plate type"),
206205
"nr of plates": header.get(str, "nr of plates"),
@@ -213,7 +212,7 @@ def _create_measurement(
213212
float, "molecular weight (kda)"
214213
),
215214
},
216-
device_control_custom_info={
215+
"device_control_custom_info": {
217216
"path length mode": well_plate_data.get(str, "path length mode"),
218217
"pump": well_plate_data.get(str, "pump"),
219218
"column": header.get(str, "column") or well_plate_data.get(str, "column"),
@@ -222,22 +221,22 @@ def _create_measurement(
222221
),
223222
"Acquisition filtering": well_plate_data.get(str, "acquisition filtering"),
224223
},
225-
error_document=error_documents,
226-
processed_data_document=ProcessedDataDocument(
224+
"error_document": error_documents,
225+
"processed_data_document": ProcessedDataDocument(
227226
identifier=random_uuid_str(),
228227
concentration_factor=concentration_factor,
229228
peak_list_custom_info=peak_data,
230229
)
231230
if concentration_factor is not None or peak_data
232231
else None,
233-
calc_docs_custom_info={
232+
"calc_docs_custom_info": {
234233
**calculated_data_values,
235234
**{
236235
"b22 linear fit": well_plate_data.get(str, "b22 linear fit"),
237236
"kd linear fit": well_plate_data.get(str, "kd linear fit"),
238237
},
239238
},
240-
measurement_custom_info={
239+
"measurement_custom_info": {
241240
"electronic_absorbance_reference_absorbance": background_absorbance,
242241
**_filter_empty_string_values(
243242
well_plate_data.get_unread(
@@ -265,7 +264,28 @@ def _create_measurement(
265264
)
266265
),
267266
},
268-
)
267+
}
268+
269+
extra_variables: dict[str, Any] = {}
270+
if len(wavelength_columns) > 1:
271+
spectrum_data_cube = _get_spectrum_data_cube(
272+
well_plate_data, wavelength_columns
273+
)
274+
extra_variables["spectrum_data_cube"] = spectrum_data_cube
275+
elif len(wavelength_columns) == 1:
276+
wavelength_match = WAVELENGTH_COLUMNS_RE.match(wavelength_columns[0])
277+
278+
wavelength, _ = wavelength_match.groups() if wavelength_match else ("", "")
279+
absorbance = well_plate_data.get(float, wavelength_columns[0])
280+
extra_variables["absorbance"] = (
281+
absorbance if absorbance is not None else NEGATIVE_ZERO
282+
)
283+
extra_variables["detector_wavelength_setting"] = float(wavelength)
284+
extra_variables["wavelength_identifier"] = wavelength_columns[0]
285+
286+
measurement_dict.update(extra_variables)
287+
288+
return Measurement(**measurement_dict) # type: ignore
269289

270290

271291
def _get_spectrum_data_cube(

0 commit comments

Comments
 (0)