def well_images(request, conn=None, **kwargs): # check for mandatory parameter id well_id = request.GET.get("id", None) if well_id is None: return JsonResponse({"error": "No well id provided."}) try: query_service = conn.getQueryService() # set well id params = ParametersI() params.add("well_id", rlong(long(well_id))) # get total count first count = query_service.projection( "select count(distinct ws.id) from WellSample ws " + "where ws.well.id = :well_id", params, ) results = {"data": [], "meta": {"totalCount": count[0][0].val}} # set offset and limit filter = omero.sys.Filter() filter.offset = rint(request.GET.get("offset", 0)) filter.limit = rint(request.GET.get("limit", 10)) params.theFilter = filter # fire off query images = query_service.findAllByQuery( "select ws.image from WellSample ws " + "where ws.well.id = :well_id order by well_index", params) # we need only image id and name for our purposes for img in images: img_ret = {"@id": img.getId().getValue()} if img.getName() is not None: img_ret["Name"] = img.getName().getValue() results["data"].append(img_ret) return JsonResponse(results) except Exception as get_well_images_exception: return JsonResponse({"error": repr(get_well_images_exception)})
plates = q.findAll("Plate", filter) if len(plates) == 0: print "No plates" sys.exit(0) else: import random example_plate = random.choice(plates) print "Loading wells for Plate %s (%s)" % ( example_plate.getId().getValue(), example_plate.getName().getValue()) # An example of true paging filter.limit = rint(12) params = ParametersI() params.addId(example_plate.getId().getValue()) params.theFilter = filter offset = 0 while True: wells = q.findAllByQuery(LOAD_WELLS, params) if len(wells) == 0: break else: offset += len(wells) params.theFilter.offset = rint(offset) for well in wells: id = well.getId().getValue() row = well.getRow().getValue() col = well.getColumn().getValue()
from omero_sys_ParametersI import ParametersI # Temporary c = omero.client() s = c.createSession() q = s.getQueryService() GET_IMAGES_WITH_PLATES = "select i from Image i join i.wellSamples ws join ws.well w" " join w.plate p" # Inner joins GET_PLATE_FROM_IMAGE_ID = ( "select p from Plate p join p.wells w join w.wellSamples ws" " join ws.image i where i.id = :id" ) filter = omero.sys.Filter() filter.limit = rint(100) filter.offset = rint(0) params = ParametersI() params.theFilter = filter images = q.findAllByQuery(GET_IMAGES_WITH_PLATES, params) print "Found %s images" % len(images) for image in images: params = ParametersI() params.addId(image.getId().getValue()) # Multiple plates per image will through an exception plate = q.findByQuery(GET_PLATE_FROM_IMAGE_ID, params) print "Image %s belongs to Plate %s (%s)" % ( image.getId().getValue(), plate.getId().getValue(), plate.getName().getValue(), )