From ad618c29dc7b467c74948b75eef64d0749e0f71e Mon Sep 17 00:00:00 2001 From: Andy Sweet Date: Thu, 14 Dec 2023 17:08:56 -0800 Subject: [PATCH] Update usage of GraphQL client to match new schema (#20) This bumps the minimum required version of `cryoet-data-portal` to v2 that includes changes to the underlying GraphQL schema. It also changes the readers and widgets to adapt to the corresponding API changes, so that tomograms and points annotations are read correctly when they are available. --- setup.cfg | 2 +- src/napari_cryoet_data_portal/_open_widget.py | 10 +++++++++- src/napari_cryoet_data_portal/_reader.py | 11 ++++++++++- src/napari_cryoet_data_portal/_sample_data.py | 2 +- src/napari_cryoet_data_portal/_tests/conftest.py | 2 +- src/napari_cryoet_data_portal/_tests/test_reader.py | 5 ++--- 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/setup.cfg b/setup.cfg index 64ab1b8..2628041 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,7 @@ project_urls = [options] packages = find: install_requires = - cryoet_data_portal + cryoet_data_portal>=2 fsspec[http,s3] npe2 numpy diff --git a/src/napari_cryoet_data_portal/_open_widget.py b/src/napari_cryoet_data_portal/_open_widget.py index 3a2564d..0f43f48 100644 --- a/src/napari_cryoet_data_portal/_open_widget.py +++ b/src/napari_cryoet_data_portal/_open_widget.py @@ -165,7 +165,15 @@ def _loadTomogram( ) for annotation in annotations: - yield read_annotation(annotation, tomogram=tomogram) + point_paths = tuple( + f.https_path + for f in annotation.files + if f.shape_type == "Point" + ) + if len(point_paths) > 0: + yield read_annotation(annotation, tomogram=tomogram) + else: + logger.warn("Found no points annotations. Skipping.") def _onLayerLoaded(self, layer_data: FullLayerData) -> None: logger.debug("OpenWidget._onLayerLoaded") diff --git a/src/napari_cryoet_data_portal/_reader.py b/src/napari_cryoet_data_portal/_reader.py index a5fb55a..86cb318 100644 --- a/src/napari_cryoet_data_portal/_reader.py +++ b/src/napari_cryoet_data_portal/_reader.py @@ -8,6 +8,8 @@ from npe2.types import FullLayerData, PathOrPaths, ReaderFunction from cryoet_data_portal import Annotation, Tomogram +from napari_cryoet_data_portal._logging import logger + OBJECT_COLOR = { "ribosome": "red", @@ -195,7 +197,14 @@ def read_annotation(annotation: Annotation, *, tomogram: Optional[Tomogram] = No >>> data, attrs, _ = read_annotation(annotation) >>> points = Points(data, **attrs) """ - data, attributes, layer_type = read_points_annotations_ndjson(annotation.https_annotations_path) + point_paths = tuple( + f.https_path + for f in annotation.files + if f.shape_type == "Point" + ) + if len(point_paths) > 1: + logger.warn("Found more than one points annotation. Using the first.") + data, attributes, layer_type = read_points_annotations_ndjson(point_paths[0]) name = annotation.object_name if tomogram is None: attributes["name"] = name diff --git a/src/napari_cryoet_data_portal/_sample_data.py b/src/napari_cryoet_data_portal/_sample_data.py index 9ab4dae..adb8934 100644 --- a/src/napari_cryoet_data_portal/_sample_data.py +++ b/src/napari_cryoet_data_portal/_sample_data.py @@ -23,7 +23,7 @@ def tomogram_10000_ts_027() -> List[FullLayerData]: def _read_tomogram_from_10000(name: str) -> List[FullLayerData]: client = Client() - tomogram_spacing_url = f"https://files.cryoetdataportal.cziscience.com/10000/{name}/Tomograms/VoxelSpacing13.48/" + tomogram_spacing_url = f"https://files.cryoetdataportal.cziscience.com/10000/{name}/Tomograms/VoxelSpacing13.480/" tomogram_spacing = next(TomogramVoxelSpacing.find(client, [TomogramVoxelSpacing.https_prefix == tomogram_spacing_url])) tomogram: Tomogram = next(tomogram_spacing.tomograms) diff --git a/src/napari_cryoet_data_portal/_tests/conftest.py b/src/napari_cryoet_data_portal/_tests/conftest.py index d979be1..debfb84 100644 --- a/src/napari_cryoet_data_portal/_tests/conftest.py +++ b/src/napari_cryoet_data_portal/_tests/conftest.py @@ -15,4 +15,4 @@ def dataset(client: Client) -> Dataset: @pytest.fixture() def tomogram(client: Client) -> Tomogram: - return next(Tomogram.find(client, [Tomogram.name == 'TS_026'])) \ No newline at end of file + return next(Tomogram.find(client, [Tomogram.name == 'TS_026', Tomogram.https_omezarr_dir.like("%13.480%")])) \ No newline at end of file diff --git a/src/napari_cryoet_data_portal/_tests/test_reader.py b/src/napari_cryoet_data_portal/_tests/test_reader.py index dbfaf1b..2657253 100644 --- a/src/napari_cryoet_data_portal/_tests/test_reader.py +++ b/src/napari_cryoet_data_portal/_tests/test_reader.py @@ -2,7 +2,6 @@ from napari import Viewer from napari.layers import Points -from cryoet_data_portal import Annotation, Client from napari_cryoet_data_portal import ( read_points_annotations_ndjson, @@ -10,8 +9,8 @@ ) CLOUDFRONT_URI = "https://files.cryoetdataportal.cziscience.com" -TOMOGRAM_DIR = f"{CLOUDFRONT_URI}/10000/TS_026/Tomograms/VoxelSpacing13.48" -ANNOTATION_FILE = f"{TOMOGRAM_DIR}/Annotations/sara_goetz-ribosome-1.0.ndjson" +TOMOGRAM_DIR = f"{CLOUDFRONT_URI}/10000/TS_026/Tomograms/VoxelSpacing13.480" +ANNOTATION_FILE = f"{TOMOGRAM_DIR}/Annotations/101-cytosolic_ribosome-1.0_point.ndjson" def test_read_tomogram_ome_zarr():