Skip to content

Commit bd20cfa

Browse files
authored
Merge pull request #43 from joshmoore/fix-42-rois
2 parents 5ae9bf5 + 0735f3f commit bd20cfa

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ repos:
3434
- --autofix
3535

3636
- repo: https://github.com/PyCQA/flake8
37-
rev: 4.0.1
37+
rev: 7.2.0
3838
hooks:
3939
- id: flake8
4040
additional_dependencies: [
4141
flake8-blind-except,
4242
flake8-builtins,
4343
flake8-rst-docstrings,
44-
flake8-logging-format,
44+
# flake8-logging-format,
4545
]
4646
args: [
4747
# default black line length is 88

src/omero_rdf/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ def handle(self, data: Data) -> URIRef:
394394
Returns the id for the data object itself
395395
"""
396396
# TODO: Add quad representation as an option
397-
output: Triple
398397

399398
str_id = data.get("@id")
400399
if not str_id:
@@ -674,15 +673,18 @@ def descend(
674673
elif isinstance(target, Image):
675674
img = self._lookup(gateway, "Image", target.id)
676675
imgid = handler(img)
677-
pixid = handler(img.getPrimaryPixels())
678-
handler.emit((pixid, DCTERMS.isPartOf, imgid))
679-
handler.emit((imgid, DCTERMS.hasPart, pixid))
676+
if img.getPrimaryPixels() is not None:
677+
pixid = handler(img.getPrimaryPixels())
678+
handler.emit((pixid, DCTERMS.isPartOf, imgid))
679+
handler.emit((imgid, DCTERMS.hasPart, pixid))
680680
for annotation in img.listAnnotations(None):
681681
img._loadAnnotationLinks()
682682
annid = handler(annotation)
683683
handler.emit((annid, DCTERMS.isPartOf, imgid))
684684
for roi in self._get_rois(gateway, img):
685-
handler(roi)
685+
roiid = handler(roi)
686+
handler.emit((roiid, DCTERMS.isPartOf, pixid))
687+
handler.emit((pixid, DCTERMS.hasPart, roiid))
686688
return imgid
687689

688690
else:

test/integration/clitest/test_rdf.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
from omero.testlib.cli import CLITest
2323
from omero_rdf import RdfControl
24+
from omero.model import RoiI
25+
26+
from rdflib import Graph, Namespace, RDF
27+
from rdflib.namespace import DCTERMS
2428

2529

2630
class TestRdf(CLITest):
@@ -41,3 +45,34 @@ def test_rdf(self, capfd):
4145
self.args += [obj_arg]
4246
out = self.rdf(capfd)
4347
assert out
48+
49+
def test_rois(self, capfd):
50+
51+
update = self.client.sf.getUpdateService()
52+
53+
# Setup a test image with a roi
54+
pix = self.create_pixels()
55+
img = pix.image
56+
roi = RoiI()
57+
img.addRoi(roi)
58+
img = update.saveAndReturnObject(img)
59+
60+
# Export the test image
61+
object_type = "Image"
62+
obj_arg = f"{object_type}:{img.id.val}"
63+
self.args += ["-Fturtle", obj_arg]
64+
out = self.rdf(capfd)
65+
66+
# Check that it contains the roi linked to the image (issue#42)
67+
g = Graph()
68+
g.parse(data=out, format="ttl")
69+
70+
xml = Namespace("http://www.openmicroscopy.org/Schemas/OME/2016-06#")
71+
72+
found = False
73+
for s, p, o in g.triples((None, DCTERMS.isPartOf, None)):
74+
print(s, p, o)
75+
if (s, RDF.type, xml.ROI) in g and (o, RDF.type, xml.Pixels) in g:
76+
found = True
77+
78+
assert found, "no link between pixels and ROI:" + g.serialize()

0 commit comments

Comments
 (0)