Skip to content

Commit

Permalink
perform checksum check as part of the app fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Jul 1, 2024
1 parent b77cd0c commit bfccab1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/depiction/persistence/imzml_read_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def summary(self, checksums: bool = True) -> str:
f"{mz_range_line}"
)

def print_summary(self, checksums: bool = True) -> None:
print(self.summary(checksums=checksums))
def print_summary(self, checksums: bool = True, file=None) -> None:
print(self.summary(checksums=checksums), file=file)

@cached_property
def pixel_size(self) -> PixelSize | None:
Expand Down
12 changes: 12 additions & 0 deletions src/depiction_targeted_preproc/app/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from loguru import logger

from depiction.misc.find_file_util import find_one_by_extension
from depiction.persistence import ImzmlReadFile
from depiction_targeted_preproc.pipeline.setup import setup_workdir
from depiction_targeted_preproc.pipeline_config.artifacts_mapping import ARTIFACT_FILES_MAPPING, get_result_files
from depiction_targeted_preproc.pipeline_config.model import (
Expand Down Expand Up @@ -42,6 +43,9 @@ def entrypoint(
if not workunit_yaml_file.exists():
raise RuntimeError(f"Workunit yaml file not found: {workunit_yaml_file}")

# Ensure the input file's checksum passes
check_imzml_file(ImzmlReadFile(input_imzml_file))

# Parse the params
params = parse_parameters(workunit_yaml_file)

Expand Down Expand Up @@ -77,6 +81,14 @@ def export_pipeline_params(work_dir: Path, output_dir: Path, sample_name: str) -
shutil.copy(work_dir / sample_name / "pipeline_params.yml", output_dir / sample_name / "pipeline_params.yml")


def check_imzml_file(imzml_file: ImzmlReadFile) -> None:
# TODO this is not very efficient, but is better than not checking the file at all
logger.info(f"Checking the integrity of the input file: {imzml_file.imzml_file}")
logger.info(imzml_file.summary())
if not imzml_file.is_checksum_valid:
raise RuntimeError(f"Checksum validation failed for the input file: {imzml_file.imzml_file}")


def zip_results(output_dir: Path, sample_name: str) -> None:
with ZipFile(output_dir / f"{sample_name}.zip", "w") as zipf:
for file in (output_dir / sample_name).rglob("*"):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/persistence/test_imzml_read_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_summary_when_continuous(self, method_reader) -> None:
def test_print_summary(self, mock_summary, mock_print) -> None:
self.mock_read_file.print_summary()
mock_summary.assert_called_once_with(checksums=True)
mock_print.assert_called_once_with(mock_summary.return_value)
mock_print.assert_called_once_with(mock_summary.return_value, file=None)

@patch.object(ImzmlReadFile, "reader")
def test_cached_properties(self, method_reader) -> None:
Expand Down

0 comments on commit bfccab1

Please sign in to comment.