Write MIHCSME metadata to Excel file.
All sheets are always written, even if empty, so the file can be used as
a template. The AssayConditions sheet uses default column headers when no
conditions are present.
:param metadata: MIHCSMEMetadata object to export
:param output_path: Path to output Excel file, or a file-like object (e.g., BytesIO)
Source code in src/mihcsme_py/writer.py
| def write_metadata_to_excel(
metadata: MIHCSMEMetadata, output_path: Union[Path, BinaryIO]
) -> None:
"""
Write MIHCSME metadata to Excel file.
All sheets are always written, even if empty, so the file can be used as
a template. The AssayConditions sheet uses default column headers when no
conditions are present.
:param metadata: MIHCSMEMetadata object to export
:param output_path: Path to output Excel file, or a file-like object (e.g., BytesIO)
"""
wb = Workbook()
# Remove default sheet
if "Sheet" in wb.sheetnames:
wb.remove(wb["Sheet"])
# Write Investigation Information (always)
groups = metadata.investigation_information.groups if metadata.investigation_information else {}
_write_grouped_sheet(
wb,
"InvestigationInformation",
groups,
header_comment="# Investigation Information - Metadata about the overall investigation"
)
# Write Study Information (always)
groups = metadata.study_information.groups if metadata.study_information else {}
_write_grouped_sheet(
wb,
"StudyInformation",
groups,
header_comment="# Study Information - Metadata about the study design"
)
# Write Assay Information (always)
groups = metadata.assay_information.groups if metadata.assay_information else {}
_write_grouped_sheet(
wb,
"AssayInformation",
groups,
header_comment="# Assay Information - Metadata about the assay protocol"
)
# Write Assay Conditions (always)
_write_assay_conditions(wb, metadata.assay_conditions)
# Write Reference Sheets
for ref_sheet in metadata.reference_sheets:
_write_reference_sheet(wb, ref_sheet.name, ref_sheet.data)
# Save workbook
wb.save(output_path)
|