Skip to content

Commit

Permalink
Refactoring and test coverage fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tkakar committed Jan 9, 2025
1 parent 2658d4f commit 629fa39
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/portal_visualization/builders/imaging_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Component as cm,
)

from ..utils import get_matches, group_by_file_name, get_conf_cells
from ..utils import get_matches, group_by_file_name, get_conf_cells, get_found_images
from ..paths import (IMAGE_PYRAMID_DIR, OFFSETS_DIR, SEQFISH_HYB_CYCLE_REGEX,
SEQFISH_FILE_REGEX, SEGMENTATION_SUPPORT_IMAGE_SUBDIR,
SEGMENTATION_SUBDIR)
Expand Down Expand Up @@ -90,7 +90,7 @@ def _add_segmentation_image(self, dataset):
found_images = get_found_images(self.seg_image_pyramid_regex, file_paths_found)
filtered_images = [img for img in found_images if SEGMENTATION_SUPPORT_IMAGE_SUBDIR not in img]

if not filtered_images:
if not filtered_images: # pragma: no cover
raise FileNotFoundError(f"Segmentation assay with uuid {self._uuid} has no matching files")

img_url, offsets_url = self._get_img_and_offset_url(filtered_images[0], self.seg_image_pyramid_regex)
Expand Down Expand Up @@ -293,13 +293,3 @@ def _get_pos_name(self, image_path):
return re.search(SEQFISH_FILE_REGEX, image_path)[0].split(".")[
0
]


def get_found_images(image_pyramid_regex, file_paths_found):
found_images = [
path for path in get_matches(
file_paths_found, image_pyramid_regex + r".*\.ome\.tiff?$",
)
if 'separate/' not in path
]
return found_images
10 changes: 10 additions & 0 deletions src/portal_visualization/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ def _get_cells_from_obj(vc_obj):
]


def get_found_images(image_pyramid_regex, file_paths_found):
found_images = [
path for path in get_matches(
file_paths_found, image_pyramid_regex + r".*\.ome\.tiff?$",
)
if 'separate/' not in path
]
return found_images


def files_from_response(response_json):
'''
>>> response_json = {'hits': {'hits': [
Expand Down
12 changes: 12 additions & 0 deletions test/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest
import zarr

from src.portal_visualization.utils import get_found_images
from src.portal_visualization.epic_factory import get_epic_builder
from src.portal_visualization.builders.base_builders import ConfCells
from src.portal_visualization.builder_factory import (
Expand Down Expand Up @@ -96,6 +97,17 @@ def test_has_visualization(has_vis_entity):
assert has_vis == has_visualization(entity, get_entity, parent, epic_uuid)


def test_get_found_images():
file_paths = [
"image_pyramid/sample.ome.tiff",
"image_pyramid/sample_separate/sample.ome.tiff",
]
regex = "image_pyramid"
result = get_found_images(regex, file_paths)
assert len(result) == 1
assert result[0] == "image_pyramid/sample.ome.tiff"


def mock_zarr_store(entity_path, mocker):
# Need to mock zarr.open to yield correct values for different scenarios
z = zarr.open()
Expand Down

0 comments on commit 629fa39

Please sign in to comment.