|
|
@ -3,6 +3,7 @@ |
|
|
|
Parsing the csv result files from Sensovations Sensospot image analysis. |
|
|
|
Parsing the csv result files from Sensovations Sensospot image analysis. |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import logging |
|
|
|
import pathlib |
|
|
|
import pathlib |
|
|
|
from datetime import datetime |
|
|
|
from datetime import datetime |
|
|
|
from typing import Optional, Union |
|
|
|
from typing import Optional, Union |
|
|
@ -12,6 +13,8 @@ from defusedxml import ElementTree |
|
|
|
|
|
|
|
|
|
|
|
from . import columns, parameters |
|
|
|
from . import columns, parameters |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger("sensospot_parser") |
|
|
|
|
|
|
|
|
|
|
|
PathLike = Union[str, pathlib.Path] |
|
|
|
PathLike = Union[str, pathlib.Path] |
|
|
|
|
|
|
|
|
|
|
|
RESULT_TAG_TYPES = { |
|
|
|
RESULT_TAG_TYPES = { |
|
|
@ -153,9 +156,11 @@ def parse_xml_file(xml_file: PathLike) -> pandas.DataFrame: |
|
|
|
Raises: |
|
|
|
Raises: |
|
|
|
ValueError if the xml file could not be parsed |
|
|
|
ValueError if the xml file could not be parsed |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
logger.info(f"Parsing xml results file {xml_file}") |
|
|
|
xml_file = pathlib.Path(xml_file) |
|
|
|
xml_file = pathlib.Path(xml_file) |
|
|
|
if not xml_file.is_file(): |
|
|
|
if not xml_file.is_file(): |
|
|
|
msg = "Xml file does not exist" |
|
|
|
msg = "Xml file does not exist" |
|
|
|
|
|
|
|
logger.debug(f"{msg}: {xml_file}") |
|
|
|
raise ValueError(msg) |
|
|
|
raise ValueError(msg) |
|
|
|
|
|
|
|
|
|
|
|
target = ParserTarget() |
|
|
|
target = ParserTarget() |
|
|
@ -165,11 +170,13 @@ def parse_xml_file(xml_file: PathLike) -> pandas.DataFrame: |
|
|
|
parser.feed(xml_file.read_text()) |
|
|
|
parser.feed(xml_file.read_text()) |
|
|
|
except (IndexError, KeyError, ValueError, TypeError) as e: |
|
|
|
except (IndexError, KeyError, ValueError, TypeError) as e: |
|
|
|
msg = "Malformed data in xml file" |
|
|
|
msg = "Malformed data in xml file" |
|
|
|
|
|
|
|
logger.warning(f"{msg} {xml_file}") |
|
|
|
raise ValueError(msg) from e |
|
|
|
raise ValueError(msg) from e |
|
|
|
|
|
|
|
|
|
|
|
data_frame = pandas.DataFrame(data=target.collected).reset_index() |
|
|
|
data_frame = pandas.DataFrame(data=target.collected).reset_index() |
|
|
|
if data_frame.empty: |
|
|
|
if data_frame.empty: |
|
|
|
msg = "Could not parse assay results xml file" |
|
|
|
msg = "Could not parse assay results xml file" |
|
|
|
|
|
|
|
logger.warning(f"{msg} {xml_file}") |
|
|
|
raise ValueError(msg) |
|
|
|
raise ValueError(msg) |
|
|
|
|
|
|
|
|
|
|
|
return columns._cleanup_data_columns(data_frame) |
|
|
|
return columns._cleanup_data_columns(data_frame) |
|
|
@ -191,6 +198,7 @@ def parse_xml_folder(folder: PathLike) -> pandas.DataFrame: |
|
|
|
xml_file = _find_result_xml_file(folder) |
|
|
|
xml_file = _find_result_xml_file(folder) |
|
|
|
if xml_file is None: |
|
|
|
if xml_file is None: |
|
|
|
msg = "Could not find assay results xml file" |
|
|
|
msg = "Could not find assay results xml file" |
|
|
|
|
|
|
|
logger.debug(f"{msg} in folder {folder}") |
|
|
|
raise ValueError(msg) |
|
|
|
raise ValueError(msg) |
|
|
|
data_frame = parse_xml_file(xml_file) |
|
|
|
data_frame = parse_xml_file(xml_file) |
|
|
|
data_frame = parameters.add_measurement_parameters(data_frame, folder) |
|
|
|
data_frame = parameters.add_measurement_parameters(data_frame, folder) |
|
|
|