|
| 1 | +from omero.gateway import BlitzGateway |
| 2 | +from omero.gateway import BlitzObjectWrapper |
| 3 | +from omero.model import ExternalInfoI, ImageI |
| 4 | +from omero.rtypes import rstring, rlong |
| 5 | +from omero_sys_ParametersI import ParametersI |
| 6 | +from omero.model import Image |
| 7 | +from omero.model import Plate |
| 8 | +from omero.model import Screen |
| 9 | +from omero.model import Dataset |
| 10 | +from omero.model import Project |
| 11 | + |
| 12 | + |
| 13 | +def get_path(conn: BlitzGateway, image_id: int) -> str: |
| 14 | + params = ParametersI() |
| 15 | + params.addId(image_id) |
| 16 | + query = """ |
| 17 | + select fs from Fileset as fs |
| 18 | + join fetch fs.images as image |
| 19 | + left outer join fetch fs.usedFiles as usedFile |
| 20 | + join fetch usedFile.originalFile as f |
| 21 | + join fetch f.hasher where image.id = :id |
| 22 | + """ |
| 23 | + fs = conn.getQueryService().findByQuery(query, params) |
| 24 | + res = fs._getUsedFiles()[0]._clientPath._val |
| 25 | + return res |
| 26 | + |
| 27 | + |
| 28 | +def set_external_info(img: ImageI, path: str) -> ImageI: |
| 29 | + info = ExternalInfoI() |
| 30 | + info.entityType = rstring("com.glencoesoftware.ngff:multiscales") |
| 31 | + info.entityId = rlong(3) |
| 32 | + info.lsid = rstring(path) |
| 33 | + img.details.externalInfo = info |
| 34 | + return img |
| 35 | + |
| 36 | + |
| 37 | +def _lookup(conn: BlitzGateway, type: str, oid: int) -> BlitzObjectWrapper: |
| 38 | + conn.SERVICE_OPTS.setOmeroGroup("-1") |
| 39 | + obj = conn.getObject(type, oid) |
| 40 | + if not obj: |
| 41 | + raise ValueError(f"No such {type}: {oid}") |
| 42 | + return obj |
| 43 | + |
| 44 | + |
| 45 | +def get_images(conn: BlitzGateway, object): |
| 46 | + if isinstance(object, list): |
| 47 | + for x in object: |
| 48 | + yield from get_images(conn, x) |
| 49 | + elif isinstance(object, Screen): |
| 50 | + scr = _lookup(conn, "Screen", object.id) |
| 51 | + for plate in scr.listChildren(): |
| 52 | + yield from get_images(conn, plate._obj) |
| 53 | + elif isinstance(object, Plate): |
| 54 | + plt = _lookup(conn, "Plate", object.id) |
| 55 | + for well in plt.listChildren(): |
| 56 | + for idx in range(0, well.countWellSample()): |
| 57 | + img = well.getImage(idx) |
| 58 | + yield img |
| 59 | + elif isinstance(object, Project): |
| 60 | + prj = _lookup(conn, "Project", object.id) |
| 61 | + for ds in prj.listChildren(): |
| 62 | + yield from get_images(conn, ds._obj) |
| 63 | + elif isinstance(object, Dataset): |
| 64 | + ds = _lookup(conn, "Dataset", object.id) |
| 65 | + for img in ds.listChildren(): |
| 66 | + yield img |
| 67 | + elif isinstance(object, Image): |
| 68 | + img = _lookup(conn, "Image", object.id) |
| 69 | + yield img |
| 70 | + else: |
| 71 | + raise ValueError(f"Unsupported type: {object.__class__.__name__}") |
0 commit comments