def marshal_images(conn, parent, parent_id, mapann_value, query=False, mapann_ns=[], mapann_names=[], load_pixels=False, group_id=-1, experimenter_id=-1, page=1, date=False, thumb_version=False, limit=settings.PAGE): ''' Marshals images @param conn OMERO gateway. @type conn L{omero.gateway.BlitzGateway} @param plate_id The Plate ID to filter by. @type plate_id L{long} @param mapann_value The Map annotation value to filter by. @type mapann_value L{string} @param query Flag allowing to search for value patters. @type query L{boolean} @param mapann_ns The Map annotation namespace to filter by. @type mapann_ns L{string} @param mapann_names The Map annotation names to filter by. @type mapann_names L{string} @param load_pixels Whether to load the X,Y,Z dimensions @type load_pixels Boolean @param group_id The Group ID to filter by or -1 for all groups, defaults to -1 @type group_id L{long} @param experimenter_id The Experimenter (user) ID to filter by or -1 for all experimenters @type experimenter_id L{long} @param page Page number of results to get. `None` or 0 for no paging defaults to 1 @type page L{long} @param limit The limit of results per page to get defaults to the value set in settings.PAGE @type page L{long} ''' images = [] # early exit if (parent_id is None or not isinstance(parent_id, long)) or not parent: return images params, where_clause = _set_parameters(mapann_ns=mapann_ns, mapann_names=mapann_names, query=query, mapann_value=mapann_value, params=None, experimenter_id=experimenter_id, page=page, limit=limit) service_opts = deepcopy(conn.SERVICE_OPTS) # Set the desired group context if group_id is None: group_id = -1 service_opts.setOmeroGroup(group_id) from_join_clauses = [] qs = conn.getQueryService() extra_values = [] if load_pixels: extra_values.append(""" , pix.sizeX as sizeX, pix.sizeY as sizeY, pix.sizeZ as sizeZ """) if date: extra_values.append(""", image.details.creationEvent.time as date, image.acquisitionDate as acqDate """) q = """ select new map(image.id as id, image.name as name, image.details.owner.id as ownerId, image as image_details_permissions, image.fileset.id as filesetId %s) from Image image """ % "".join(extra_values) if load_pixels: # We use 'left outer join', since we still want images if no pixels q += ' left outer join image.pixels pix ' q += """ where image.id in ( """ if parent == 'plate': from_join_clauses.append(""" ImageAnnotationLink ial join ial.child a join a.mapValue mv join ial.parent image join image.wellSamples ws join ws.well well join well.plate plate """) params.addLong("pid", parent_id) where_clause.append('plate.id = :pid') if parent == 'dataset': from_join_clauses.append(""" ImageAnnotationLink ial join ial.child a join a.mapValue mv join ial.parent image join image.datasetLinks dil join dil.parent dataset """) params.addLong("did", parent_id) where_clause.append('dataset.id = :did') q += """ %s %s order by lower(image.name)) """ % (' select image.id from ' + ' '.join(from_join_clauses), build_clause(where_clause, 'where', 'and')) logger.debug("HQL QUERY: %s\nPARAMS: %r" % (q, params)) for e in qs.projection(q, params, service_opts): e = unwrap(e)[0] d = [ e["id"], e["name"], e["ownerId"], e["image_details_permissions"], e["filesetId"] ] kwargs = {'conn': conn, 'row': d[0:5]} if load_pixels: d = [e["sizeX"], e["sizeY"], e["sizeZ"]] kwargs['row_pixels'] = d if date: kwargs['acqDate'] = e['acqDate'] kwargs['date'] = e['date'] im = _marshal_image(**kwargs) images.append(im) # Load thumbnails separately # We want version of most recent thumbnail (max thumbId) owned by user if thumb_version and len(images) > 0: user_id = conn.getUserId() iids = [i['id'] for i in images] params = omero.sys.ParametersI() params.addIds(iids) params.add('thumbOwner', wrap(user_id)) q = """select image.id, thumbs.version from Image image join image.pixels pix join pix.thumbnails thumbs where image.id in (:ids) and thumbs.id = ( select max(t.id) from Thumbnail t where t.pixels = pix.id and t.details.owner.id = :thumbOwner ) """ thumb_versions = {} logger.debug("HQL QUERY: %s\nPARAMS: %r" % (q, params)) for t in qs.projection(q, params, service_opts): iid, tv = unwrap(t) thumb_versions[iid] = tv # For all images, set thumb version if we have it... for i in images: if i['id'] in thumb_versions: i['thumbVersion'] = thumb_versions[i['id']] return images
def _marshal_image(conn, row, tags_on_images): image = tree._marshal_image(conn, row[0:5]) image['clientPath'] = unwrap(row[5]) image['tags'] = tags_on_images.get(image['id']) or [] return image
def marshal_images(conn, parent, parent_id, mapann_value, query=False, mapann_ns=[], mapann_names=[], load_pixels=False, group_id=-1, experimenter_id=-1, page=1, date=False, thumb_version=False, limit=settings.PAGE): ''' Marshals images @param conn OMERO gateway. @type conn L{omero.gateway.BlitzGateway} @param plate_id The Plate ID to filter by. @type plate_id L{long} @param mapann_value The Map annotation value to filter by. @type mapann_value L{string} @param query Flag allowing to search for value patters. @type query L{boolean} @param mapann_ns The Map annotation namespace to filter by. @type mapann_ns L{string} @param mapann_names The Map annotation names to filter by. @type mapann_names L{string} @param load_pixels Whether to load the X,Y,Z dimensions @type load_pixels Boolean @param group_id The Group ID to filter by or -1 for all groups, defaults to -1 @type group_id L{long} @param experimenter_id The Experimenter (user) ID to filter by or -1 for all experimenters @type experimenter_id L{long} @param page Page number of results to get. `None` or 0 for no paging defaults to 1 @type page L{long} @param limit The limit of results per page to get defaults to the value set in settings.PAGE @type page L{long} ''' images = [] # early exit if (parent_id is None or not isinstance(parent_id, long)) or not parent: return images params, where_clause = _set_parameters( mapann_ns=mapann_ns, mapann_names=mapann_names, query=query, mapann_value=mapann_value, params=None, experimenter_id=experimenter_id, page=page, limit=limit) service_opts = deepcopy(conn.SERVICE_OPTS) # Set the desired group context if group_id is None: group_id = -1 service_opts.setOmeroGroup(group_id) from_join_clauses = [] qs = conn.getQueryService() extra_values = [] if load_pixels: extra_values.append(""" , pix.sizeX as sizeX, pix.sizeY as sizeY, pix.sizeZ as sizeZ """) if date: extra_values.append(""", image.details.creationEvent.time as date, image.acquisitionDate as acqDate """) q = """ select new map(image.id as id, image.name as name, image.details.owner.id as ownerId, image as image_details_permissions, image.fileset.id as filesetId %s) from Image image """ % "".join(extra_values) if load_pixels: # We use 'left outer join', since we still want images if no pixels q += ' left outer join image.pixels pix ' q += """ where image.id in ( """ if parent == 'plate': from_join_clauses.append(""" ImageAnnotationLink ial join ial.child a join a.mapValue mv join ial.parent image join image.wellSamples ws join ws.well well join well.plate plate """) params.addLong("pid", parent_id) where_clause.append('plate.id = :pid') if parent == 'dataset': from_join_clauses.append(""" ImageAnnotationLink ial join ial.child a join a.mapValue mv join ial.parent image join image.datasetLinks dil join dil.parent dataset """) params.addLong("did", parent_id) where_clause.append('dataset.id = :did') q += """ %s %s order by lower(image.name)) """ % (' select image.id from ' + ' '.join(from_join_clauses), build_clause(where_clause, 'where', 'and')) logger.debug("HQL QUERY: %s\nPARAMS: %r" % (q, params)) for e in qs.projection(q, params, service_opts): e = unwrap(e)[0] d = [e["id"], e["name"], e["ownerId"], e["image_details_permissions"], e["filesetId"]] kwargs = {'conn': conn, 'row': d[0:5]} if load_pixels: d = [e["sizeX"], e["sizeY"], e["sizeZ"]] kwargs['row_pixels'] = d if date: kwargs['acqDate'] = e['acqDate'] kwargs['date'] = e['date'] im = _marshal_image(**kwargs) images.append(im) # Load thumbnails separately # We want version of most recent thumbnail (max thumbId) owned by user if thumb_version and len(images) > 0: user_id = conn.getUserId() iids = [i['id'] for i in images] params = omero.sys.ParametersI() params.addIds(iids) params.add('thumbOwner', wrap(user_id)) q = """select image.id, thumbs.version from Image image join image.pixels pix join pix.thumbnails thumbs where image.id in (:ids) and thumbs.id = ( select max(t.id) from Thumbnail t where t.pixels = pix.id and t.details.owner.id = :thumbOwner ) """ thumb_versions = {} logger.debug("HQL QUERY: %s\nPARAMS: %r" % (q, params)) for t in qs.projection(q, params, service_opts): iid, tv = unwrap(t) thumb_versions[iid] = tv # For all images, set thumb version if we have it... for i in images: if i['id'] in thumb_versions: i['thumbVersion'] = thumb_versions[i['id']] return images