-
Notifications
You must be signed in to change notification settings - Fork 35
Add more opts support for getObjects('Annotation') #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
will-moore
wants to merge
12
commits into
ome:master
Choose a base branch
from
will-moore:getObjects_Annotations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c86f8e2
Start to add more opts support for getObjects('Annotation')
will-moore 16dc35a
Merge remote-tracking branch 'origin/master' into getObjects_Annotations
will-moore 4d6c32e
Support parent_type and parent_ids for getObjects('Annotation')
will-moore 559eb61
Support ns for getObjects('Annotation')
will-moore 4c1ee1d
load File for FileAnnotations
will-moore b0e6410
Always try to load annotation.File
will-moore 367e22e
Remove special handling of 'rating' annotation
will-moore 97c30cc
Fix docstring
will-moore 9a2ce90
raise AttributeError for invalid ann_type
will-moore 513ce54
Use conn.getObject('TagAnnotation'...) to load Tags
will-moore 2ce949c
Add XmlAnnotationWrapper to KNOWN_WRAPPERS
will-moore d16cce3
getObject('Annotation') parent_type case insensitive
will-moore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3377,7 +3377,7 @@ def buildQuery(self, obj_type, ids=None, params=None, attributes=None, | |
| wrapper = KNOWN_WRAPPERS.get(obj_type.lower(), None) | ||
| if wrapper is None: | ||
| raise KeyError( | ||
| "obj_type of %s not supported by getOjbects(). " | ||
| "obj_type of %s not supported by getObjects(). " | ||
| "E.g. use 'Image' etc" % obj_type) | ||
| else: | ||
| raise AttributeError( | ||
|
|
@@ -5134,6 +5134,7 @@ class AnnotationWrapper (BlitzObjectWrapper): | |
| # E.g. DoubleAnnotationI : DoubleAnnotationWrapper | ||
| registry = {} | ||
| OMERO_TYPE = None | ||
| OMERO_CLASS = "Annotation" | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| """ | ||
|
|
@@ -5164,13 +5165,49 @@ def _getQueryString(cls, opts=None): | |
| Returns a tuple of (query, clauses, params). | ||
|
|
||
| :param opts: Dictionary of optional parameters. | ||
| NB: No options supported for this class. | ||
| parent_type: (optional) "Project", "Dataset", "Image" etc | ||
| parent_ids: (optional) list of IDs for the parent type | ||
| ns: (optional) namespace string to filter by | ||
| :return: Tuple of string, list, ParametersI | ||
| """ | ||
| query = ("select obj from Annotation obj " | ||
|
|
||
| query, clauses, params = super( | ||
| AnnotationWrapper, cls)._getQueryString(opts) | ||
| if opts is None: | ||
| opts = {} | ||
|
|
||
| fetch_file = "" | ||
| if cls.OMERO_CLASS in ("Annotation", "FileAnnotation"): | ||
| fetch_file = "left outer join fetch obj.file as file" | ||
|
|
||
| query = (f"select obj from {cls.OMERO_CLASS} obj " | ||
| f"{fetch_file} " | ||
| "join fetch obj.details.owner as owner " | ||
| "join fetch obj.details.creationEvent") | ||
| return query, [], omero.sys.ParametersI() | ||
|
|
||
| # We want to make parent_type case-insensitive... | ||
| if 'parent_type' in opts: | ||
| # Title case works for most objects... | ||
| obj_type = opts['parent_type'].title() | ||
| # Handle special cases for certain annotatable object types | ||
| for otype in ["ExperimenterGroup", "LightPath", "LightSource", | ||
| "OriginalFile", "PlaneInfo", "PlateAcquisition"]: | ||
| if obj_type == otype.title(): | ||
| obj_type = otype | ||
| ids_clause = "" | ||
| if 'parent_ids' in opts: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the real-world use case associated with specifying |
||
| ids_clause = f"and link.parent.id in (:parent_ids)" | ||
| params.add("parent_ids", rlist([rlong(i) for i in opts['parent_ids']])) | ||
|
|
||
| clause = f"""exists (from {obj_type}AnnotationLink as link | ||
| where link.child.id = obj.id {ids_clause})""" | ||
| clauses.append(clause) | ||
|
|
||
| if 'ns' in opts: | ||
| clauses.append("obj.ns=:ns") | ||
| params.add("ns", rstring(opts['ns'])) | ||
|
|
||
| return (query, clauses, params) | ||
|
|
||
| @classmethod | ||
| def _register(cls, regklass): | ||
|
|
@@ -5315,29 +5352,14 @@ class FileAnnotationWrapper (AnnotationWrapper, OmeroRestrictionWrapper): | |
| """ | ||
|
|
||
| OMERO_TYPE = FileAnnotationI | ||
| OMERO_CLASS = "FileAnnotation" | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super(FileAnnotationWrapper, self).__init__(*args, **kwargs) | ||
| self._file = None | ||
|
|
||
| _attrs = ('file|OriginalFileWrapper',) | ||
|
|
||
| @classmethod | ||
| def _getQueryString(cls, opts=None): | ||
| """ | ||
| Used for building queries in generic methods such as | ||
| getObjects("FileAnnotation"). | ||
| Returns a tuple of (query, clauses, params). | ||
|
|
||
| :param opts: Dictionary of optional parameters. | ||
| NB: No options supported for this class. | ||
| :return: Tuple of string, list, ParametersI | ||
| """ | ||
| query = ("select obj from FileAnnotation obj " | ||
| "join fetch obj.details.owner as owner " | ||
| "join fetch obj.details.creationEvent join fetch obj.file") | ||
| return query, [], omero.sys.ParametersI() | ||
|
|
||
| def getValue(self): | ||
| """ Not implemented """ | ||
| pass | ||
|
|
@@ -5519,22 +5541,7 @@ class TimestampAnnotationWrapper (AnnotationWrapper): | |
| """ | ||
|
|
||
| OMERO_TYPE = TimestampAnnotationI | ||
|
|
||
| @classmethod | ||
| def _getQueryString(cls, opts=None): | ||
| """ | ||
| Used for building queries in generic methods such as | ||
| getObjects("TimestampAnnotation"). | ||
| Returns a tuple of (query, clauses, params). | ||
|
|
||
| :param opts: Dictionary of optional parameters. | ||
| NB: No options supported for this class. | ||
| :return: Tuple of string, list, ParametersI | ||
| """ | ||
| query = ("select obj from TimestampAnnotation obj " | ||
| "join fetch obj.details.owner as owner " | ||
| "join fetch obj.details.creationEvent") | ||
| return query, [], omero.sys.ParametersI() | ||
| OMERO_CLASS = "TimestampAnnotation" | ||
|
|
||
| def getValue(self): | ||
| """ | ||
|
|
@@ -5574,22 +5581,7 @@ class BooleanAnnotationWrapper (AnnotationWrapper): | |
| """ | ||
|
|
||
| OMERO_TYPE = BooleanAnnotationI | ||
|
|
||
| @classmethod | ||
| def _getQueryString(cls, opts=None): | ||
| """ | ||
| Used for building queries in generic methods such as | ||
| getObjects("BooleanAnnotation"). | ||
| Returns a tuple of (query, clauses, params). | ||
|
|
||
| :param opts: Dictionary of optional parameters. | ||
| NB: No options supported for this class. | ||
| :return: Tuple of string, list, ParametersI | ||
| """ | ||
| query = ("select obj from BooleanAnnotation obj " | ||
| "join fetch obj.details.owner as owner " | ||
| "join fetch obj.details.creationEvent") | ||
| return query, [], omero.sys.ParametersI() | ||
| OMERO_CLASS = "BooleanAnnotation" | ||
|
|
||
| def getValue(self): | ||
| """ | ||
|
|
@@ -5617,10 +5609,11 @@ def setValue(self, val): | |
|
|
||
| class TagAnnotationWrapper (AnnotationWrapper): | ||
| """ | ||
| omero_model_BooleanAnnotationI class wrapper extends AnnotationWrapper. | ||
| omero_model_TagAnnotationI class wrapper extends AnnotationWrapper. | ||
| """ | ||
|
|
||
| OMERO_TYPE = TagAnnotationI | ||
| OMERO_CLASS = "TagAnnotation" | ||
|
|
||
| def countTagsInTagset(self): | ||
| # temp solution waiting for #5785 | ||
|
|
@@ -5667,22 +5660,6 @@ def listParents(self, withlinks=True): | |
| self._conn, l.parent, l)) | ||
| return rv | ||
|
|
||
| @classmethod | ||
| def _getQueryString(cls, opts=None): | ||
| """ | ||
| Used for building queries in generic methods such as | ||
| getObjects("TagAnnotation"). | ||
| Returns a tuple of (query, clauses, params). | ||
|
|
||
| :param opts: Dictionary of optional parameters. | ||
| NB: No options supported for this class. | ||
| :return: Tuple of string, list, ParametersI | ||
| """ | ||
| query = ("select obj from TagAnnotation obj " | ||
| "join fetch obj.details.owner as owner " | ||
| "join fetch obj.details.creationEvent") | ||
| return query, [], omero.sys.ParametersI() | ||
|
|
||
| def getValue(self): | ||
| """ | ||
| Gets the value of the Tag | ||
|
|
@@ -5714,22 +5691,7 @@ class CommentAnnotationWrapper (AnnotationWrapper): | |
| """ | ||
|
|
||
| OMERO_TYPE = CommentAnnotationI | ||
|
|
||
| @classmethod | ||
| def _getQueryString(cls, opts=None): | ||
| """ | ||
| Used for building queries in generic methods such as | ||
| getObjects("CommentAnnotation"). | ||
| Returns a tuple of (query, clauses, params). | ||
|
|
||
| :param opts: Dictionary of optional parameters. | ||
| NB: No options supported for this class. | ||
| :return: Tuple of string, list, ParametersI | ||
| """ | ||
| query = ("select obj from CommentAnnotation obj " | ||
| "join fetch obj.details.owner as owner " | ||
| "join fetch obj.details.creationEvent") | ||
| return query, [], omero.sys.ParametersI() | ||
| OMERO_CLASS = "CommentAnnotation" | ||
|
|
||
| def getValue(self): | ||
| """ | ||
|
|
@@ -5760,22 +5722,7 @@ class LongAnnotationWrapper (AnnotationWrapper): | |
| omero_model_LongAnnotationI class wrapper extends AnnotationWrapper. | ||
| """ | ||
| OMERO_TYPE = LongAnnotationI | ||
|
|
||
| @classmethod | ||
| def _getQueryString(cls, opts=None): | ||
| """ | ||
| Used for building queries in generic methods such as | ||
| getObjects("LongAnnotation"). | ||
| Returns a tuple of (query, clauses, params). | ||
|
|
||
| :param opts: Dictionary of optional parameters. | ||
| NB: No options supported for this class. | ||
| :return: Tuple of string, list, ParametersI | ||
| """ | ||
| query = ("select obj from LongAnnotation obj " | ||
| "join fetch obj.details.owner as owner " | ||
| "join fetch obj.details.creationEvent") | ||
| return query, [], omero.sys.ParametersI() | ||
| OMERO_CLASS = "LongAnnotation" | ||
|
|
||
| def getValue(self): | ||
| """ | ||
|
|
@@ -5807,22 +5754,7 @@ class DoubleAnnotationWrapper (AnnotationWrapper): | |
| omero_model_DoubleAnnotationI class wrapper extends AnnotationWrapper. | ||
| """ | ||
| OMERO_TYPE = DoubleAnnotationI | ||
|
|
||
| @classmethod | ||
| def _getQueryString(cls, opts=None): | ||
| """ | ||
| Used for building queries in generic methods such as | ||
| getObjects("DoubleAnnotation"). | ||
| Returns a tuple of (query, clauses, params). | ||
|
|
||
| :param opts: Dictionary of optional parameters. | ||
| NB: No options supported for this class. | ||
| :return: Tuple of string, list, ParametersI | ||
| """ | ||
| query = ("select obj from DoubleAnnotation obj " | ||
| "join fetch obj.details.owner as owner " | ||
| "join fetch obj.details.creationEvent") | ||
| return query, [], omero.sys.ParametersI() | ||
| OMERO_CLASS = "DoubleAnnotation" | ||
|
|
||
| def getValue(self): | ||
| """ | ||
|
|
@@ -5855,22 +5787,7 @@ class TermAnnotationWrapper (AnnotationWrapper): | |
| only in 4.2+ | ||
| """ | ||
| OMERO_TYPE = TermAnnotationI | ||
|
|
||
| @classmethod | ||
| def _getQueryString(cls, opts=None): | ||
| """ | ||
| Used for building queries in generic methods such as | ||
| getObjects("TermAnnotation"). | ||
| Returns a tuple of (query, clauses, params). | ||
|
|
||
| :param opts: Dictionary of optional parameters. | ||
| NB: No options supported for this class. | ||
| :return: Tuple of string, list, ParametersI | ||
| """ | ||
| query = ("select obj from TermAnnotation obj " | ||
| "join fetch obj.details.owner as owner " | ||
| "join fetch obj.details.creationEvent") | ||
| return query, [], omero.sys.ParametersI() | ||
| OMERO_CLASS = "TermAnnotation" | ||
|
|
||
| def getValue(self): | ||
| """ | ||
|
|
@@ -5902,6 +5819,7 @@ class XmlAnnotationWrapper (CommentAnnotationWrapper): | |
| omero_model_XmlAnnotationI class wrapper extends CommentAnnotationWrapper. | ||
| """ | ||
| OMERO_TYPE = XmlAnnotationI | ||
| OMERO_CLASS = "XmlAnnotation" | ||
|
|
||
| AnnotationWrapper._register(XmlAnnotationWrapper) | ||
|
|
||
|
|
@@ -5914,23 +5832,7 @@ class MapAnnotationWrapper (AnnotationWrapper): | |
| omero_model_MapAnnotationI class wrapper. | ||
| """ | ||
| OMERO_TYPE = MapAnnotationI | ||
|
|
||
| @classmethod | ||
| def _getQueryString(cls, opts=None): | ||
| """ | ||
| Used for building queries in generic methods such as | ||
| getObjects("MapAnnotation"). | ||
| Returns a tuple of (query, clauses, params). | ||
|
|
||
| :param opts: Dictionary of optional parameters. | ||
| NB: No options supported for this class. | ||
| :return: Tuple of string, list, ParametersI | ||
| """ | ||
|
|
||
| query = ("select obj from MapAnnotation obj " | ||
| "join fetch obj.details.owner as owner " | ||
| "join fetch obj.details.creationEvent") | ||
| return query, [], omero.sys.ParametersI() | ||
| OMERO_CLASS = "MapAnnotation" | ||
|
|
||
| def getValue(self): | ||
| """ | ||
|
|
@@ -11139,6 +11041,7 @@ def refreshWrappers(): | |
| "termannotation": TermAnnotationWrapper, | ||
| "timestampannotation": TimestampAnnotationWrapper, | ||
| "mapannotation": MapAnnotationWrapper, | ||
| "xmlannotation": XmlAnnotationWrapper, | ||
| # allows for getObjects("Annotation", ids) | ||
| "annotation": AnnotationWrapper._wrap}) | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this utility to a separate utility method for transforming lower-case strings into case-sensitive object types with associated unit tests ?
I see a few places in the gateway that can use it. There might be use cases elsewhere in OMERO.py.