Skip to content

Instantly share code, notes, and snippets.

@will-moore
Created July 25, 2014 11:16
Show Gist options
  • Save will-moore/e5fe45145fbfc5494127 to your computer and use it in GitHub Desktop.
Save will-moore/e5fe45145fbfc5494127 to your computer and use it in GitHub Desktop.
Examples of using the OMERO BlitzGateway search API following updates in 5.0.3.
from omero.gateway import BlitzGateway
from datetime import datetime
import time
conn = BlitzGateway('will', 'ome', host="localhost")
conn.connect()
print "\n----> Simple Search: "
for i in conn.searchObjects(["Image"], "tiff"):
print i.OMERO_CLASS, i.getName()
# Create some dates to search between
fromDate = datetime(2014, 7, 1, 0, 0)
todayDate = datetime.now()
fromTime = time.mktime(fromDate.timetuple())*1000
todayTime = time.mktime(todayDate.timetuple())*1000
dateRange = [fromTime, todayTime]
print "\n----> Created from: ", fromDate
# All objects have a creation date / import date
for i in conn.searchObjects(["Dataset", "Image"], "tiff", created=dateRange):
print i.OMERO_CLASS, i.getName()
print "\n----> Acquired from:", fromDate
# Use the Acquisition Date for Images that have it (otherwise will default to creation date)
for i in conn.searchObjects(["Dataset", "Image"], "tiff", created=dateRange, useAcquisitionDate=True):
print i.OMERO_CLASS, i.getName()
print "\n----> Searching Fields:"
# E.g. 'name', 'description', 'annotation', 'file.name', 'file.format', 'file.contents', 'file.path'
# See https://www.openmicroscopy.org/site/support/omero5/developers/Modules/Search.html for full details
for i in conn.searchObjects(["Dataset", "Image"], "tiff", fields=["file.contents"]):
print i.OMERO_CLASS, i.getName()
print "\n----> Searching within groups / users:"
# By default, search applies only to the 'current' group and All users
# To seach a specific group/owner, use group/owner Id
# To search across all Groups use '-1'
myUserId = conn.getUserId()
for i in conn.searchObjects(["Dataset", "Image"], "tiff", searchGroup=-1, ownedBy=myUserId):
print i.OMERO_CLASS, i.getName()
print "\n----> Pagination: page 1"
# default batchSize is 1000
for i in conn.searchObjects(["Image"], "tiff", batchSize=10):
print i.OMERO_CLASS, i.getName()
print "\n----> Pagination: page 2"
# page index is 0-based
for i in conn.searchObjects(["Image"], "tiff", batchSize=10, page=1):
print i.OMERO_CLASS, i.getName()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment