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 @@ -70,6 +70,7 @@ class Analyte:
statistics: list[StatisticsDocument] | None = None
statistic_datum_role: TStatisticDatumRole | None = None
fluorescence: float | None = None
custom_info: dict[str, Any] | None = None


@dataclass(frozen=True)
Expand Down Expand Up @@ -253,42 +254,45 @@ def _get_measurement_document(
assay_bead_count=TQuantityValueNumber(value=measurement.assay_bead_count),
analyte_aggregate_document=AnalyteAggregateDocument(
analyte_document=[
AnalyteDocumentItem(
analyte_identifier=analyte.identifier,
analyte_name=analyte.name,
assay_bead_identifier=analyte.assay_bead_identifier,
assay_bead_count=TQuantityValueNumber(
value=analyte.assay_bead_count
),
fluorescence=quantity_or_none(
TQuantityValueRelativeFluorescenceUnit,
analyte.fluorescence,
has_statistic_datum_role=analyte.statistic_datum_role,
),
statistics_aggregate_document=(
StatisticsAggregateDocument(
statistics_document=[
StatisticsDocumentItem(
statistical_feature=statistic.statistical_feature,
statistic_dimension_aggregate_document=StatisticDimensionAggregateDocument(
statistic_dimension_document=[
StatisticDimensionDocumentItem(
statistical_value=TQuantityValueModel(
value=dimension.value,
unit=dimension.unit,
has_statistic_datum_role=dimension.statistic_datum_role,
),
)
for dimension in statistic.statistic_dimensions
]
),
)
for statistic in analyte.statistics
]
)
if analyte.statistics
else None
add_custom_information_document(
AnalyteDocumentItem(
analyte_identifier=analyte.identifier,
analyte_name=analyte.name,
assay_bead_identifier=analyte.assay_bead_identifier,
assay_bead_count=TQuantityValueNumber(
value=analyte.assay_bead_count
),
fluorescence=quantity_or_none(
TQuantityValueRelativeFluorescenceUnit,
analyte.fluorescence,
has_statistic_datum_role=analyte.statistic_datum_role,
),
statistics_aggregate_document=(
StatisticsAggregateDocument(
statistics_document=[
StatisticsDocumentItem(
statistical_feature=statistic.statistical_feature,
statistic_dimension_aggregate_document=StatisticDimensionAggregateDocument(
statistic_dimension_document=[
StatisticDimensionDocumentItem(
statistical_value=TQuantityValueModel(
value=dimension.value,
unit=dimension.unit,
has_statistic_datum_role=dimension.statistic_datum_role,
),
)
for dimension in statistic.statistic_dimensions
]
),
)
for statistic in analyte.statistics
]
)
if analyte.statistics
else None
),
),
custom_info_doc=analyte.custom_info,
)
for analyte in measurement.analytes
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def create_data(self, named_file_contents: NamedFileContents) -> Data:

samples_dict = SampleMetadata.create_samples(reader["Samples"])
# Only parse system-level metadata once, from the first well.
system_metadata = SystemMetadata.create(reader["Wells"][0])
wells = reader["Wells"].findall("Well")
system_metadata = SystemMetadata.create(wells[0])
plate_dimensions = reader["PlateDimensions"]
plate_well_count = plate_dimensions.get_attr("TotalWells")
plate_dimensions.get_unread()

return Data(
create_metadata(
Expand All @@ -44,12 +48,12 @@ def create_data(self, named_file_contents: NamedFileContents) -> Data:
well,
samples_dict[well.name],
system_metadata,
experimental_data_id=reader["NativeDocumentLocation"].text,
experiment_type=reader["Description"].text,
plate_well_count=int(
reader.get_attribute("PlateDimensions", "TotalWells")
),
experimental_data_id=reader[
"NativeDocumentLocation"
].get_text_or_none(),
experiment_type=reader["Description"].get_text_or_none(),
plate_well_count=int(plate_well_count),
)
for well in [Well.create(well_xml) for well_xml in reader["Wells"]]
for well in [Well.create(well_xml) for well_xml in wells]
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@
)
from allotropy.named_file_contents import NamedFileContents
from allotropy.parsers.biorad_bioplex_manager import constants
from allotropy.parsers.utils.strict_xml_element import StrictXmlElement


class BioradBioplexReader:
def __init__(self, named_file_contents: NamedFileContents) -> None:
contents = named_file_contents.contents.read()
# Ensure contents is bytes for StrictXmlElement.create_from_bytes()
if isinstance(contents, str):
contents = contents.encode("utf-8")
try:
xml_tree = Et.ElementTree(Et.fromstring(contents)) # noqa: S314
self.root = xml_tree.getroot()
self.children = {child.tag: child for child in self.root}
self.root = StrictXmlElement.create_from_bytes(contents)
# Create a mapping of child tags to StrictXmlElement objects
self.children = {}
for child_tag in constants.EXPECTED_TAGS:
child_element = self.root.find_or_none(child_tag)
if child_element is not None:
self.children[child_tag] = child_element
except Et.ParseError as err:
# Return all expected tags if XML parsing fails
msg = "Error parsing xml"
Expand All @@ -31,12 +39,12 @@ def _validate(self) -> None:
msg = f"Missing expected tags in xml: {missing_tags}"
raise AllotropeConversionError(msg)

def __getitem__(self, child_tag: str) -> Et.Element:
def __getitem__(self, child_tag: str) -> StrictXmlElement:
return get_key_or_error("child tag of root", child_tag, self.children)

def get_attribute(self, child_tag: str, attribute: str) -> str:
try:
return self[child_tag].attrib[attribute]
except KeyError as e:
msg = f"Unable to find '{attribute}' in {self[child_tag].attrib}"
return self[child_tag].get_attr(attribute)
except Exception as e:
msg = f"Unable to find '{attribute}' in {self[child_tag].element.attrib}"
raise AllotropeConversionError(msg) from e
Loading
Loading