Skip to content

Commit

Permalink
Update usage of GraphQL client to match new schema (#20)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andy-sweet authored Dec 15, 2023
1 parent 966a523 commit ad618c2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ project_urls =
[options]
packages = find:
install_requires =
cryoet_data_portal
cryoet_data_portal>=2
fsspec[http,s3]
npe2
numpy
Expand Down
10 changes: 9 additions & 1 deletion src/napari_cryoet_data_portal/_open_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 10 additions & 1 deletion src/napari_cryoet_data_portal/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/napari_cryoet_data_portal/_sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/napari_cryoet_data_portal/_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
return next(Tomogram.find(client, [Tomogram.name == 'TS_026', Tomogram.https_omezarr_dir.like("%13.480%")]))
5 changes: 2 additions & 3 deletions src/napari_cryoet_data_portal/_tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

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,
read_tomogram_ome_zarr,
)

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():
Expand Down

0 comments on commit ad618c2

Please sign in to comment.