Created
May 8, 2019 12:30
-
-
Save will-moore/d7909d029c929cf0cd569af8bea1c841 to your computer and use it in GitHub Desktop.
This file contains 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
import omero | |
from omero.gateway import BlitzGateway | |
# See https://www.openmicroscopy.org/community/posting.php?mode=reply&f=6&t=8736 | |
idr_client = omero.client(host="idr.openmicroscopy.org", port=4064) | |
idr_client.createSession('public', 'public') | |
conn = BlitzGateway(client_obj=idr_client) | |
# Use search service - NB: not currently working on IDR | |
# result = conn.searchObjects(["Project", "Screen"], "Organism: Homo sapiens") | |
# print result | |
def _escape_chars_like(query): | |
escape_chars = { | |
"%": "\%", | |
"_": "\_", | |
} | |
for k, v in escape_chars.items(): | |
query = query.replace(k, v) | |
return query | |
# Use query Service (like OMERO.mapr)... | |
query_service = conn.getQueryService() | |
params = omero.sys.ParametersI() | |
# Will match e.g. "Homo Sapiens" | |
# Use leading and trailing %% wildcard | |
params.addString('value', "%%%s%%" % _escape_chars_like("sapi")) | |
params.addString('name', 'Organism') | |
query = """select pal.parent from | |
ProjectAnnotationLink pal | |
join pal.child a | |
join a.mapValue mv | |
where mv.value like :value and mv.name = :name | |
""" | |
result = query_service.findAllByQuery(query, params, conn.SERVICE_OPTS) | |
for p in result: | |
print "ID", p.id.val, p.name.val | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment