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 @@ -241,8 +241,6 @@ def _create_measurement(
) -> Measurement | None:
if not result:
return None
# TODO: temp workaround for cal doc result
well_item._result = result

(
reporter_dye_data_cube,
Expand Down Expand Up @@ -332,6 +330,30 @@ def get_well_item_results(
)


def enrich_wells_with_results(
wells: list[Well],
results_data: dict[int, dict[str, Result]],
) -> list[Well]:
"""Return new Wells with results attached to well items via immutable copy.

This creates new WellItem instances with _result properly set at construction time
(via dataclasses.replace), avoiding mutation of the private field after creation.
"""
from dataclasses import replace

enriched_wells = []
for well in wells:
enriched_items = []
for well_item in well.items:
result = get_well_item_results(well_item, results_data)
if result:
enriched_items.append(replace(well_item, _result=result))
else:
enriched_items.append(well_item)
enriched_wells.append(replace(well, items=enriched_items))
return enriched_wells


def get_well_item_amp_data(
well_item: WellItem, amp_data: dict[int, dict[str, AmplificationData]]
) -> AmplificationData | None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
create_calculated_data,
create_measurement_groups,
create_metadata,
enrich_wells_with_results,
)
from allotropy.parsers.appbio_quantstudio.appbio_quantstudio_reader import (
AppBioQuantStudioReader,
Expand Down Expand Up @@ -41,8 +42,11 @@ def parse_data(
results_data, result_metadata = Result.create(reader, header.experiment_type)
melt_data = MeltCurveRawData.create(reader)

# Create immutable copies of wells with results attached
enriched_wells = enrich_wells_with_results(wells, results_data)

calculated_data_documents = iter_calculated_data_documents(
[well_item for well in wells for well_item in well.items],
[well_item for well in enriched_wells for well_item in well.items],
header.experiment_type,
result_metadata.reference_sample_description,
result_metadata.reference_dna_description,
Expand All @@ -52,7 +56,7 @@ def parse_data(
metadata=create_metadata(header, original_file_path),
measurement_groups=create_measurement_groups(
header,
wells,
enriched_wells,
amp_data,
multi_data,
results_data,
Expand Down
Loading