def createSynthetic(self): """ Create a image with archived files (i.e. pre-FS) """ from omero.sys import ParametersI # Produce an FS image as our template orig_img = self.importMIF(name="reimport", sizeX=16, sizeY=16, with_companion=True) orig_img = orig_img[0] orig_pix = self.query.findByQuery( "select p from Pixels p where p.image.id = :id", ParametersI().addId(orig_img.id.val)) orig_fs = self.query.findByQuery( "select f from Image i join i.fileset f where i.id = :id", ParametersI().addId(orig_img.id.val)) try: new_img, new_pix = self.duplicateMIF(orig_img) self.copyPixels(orig_pix, new_pix) self.copyFiles(orig_img, new_img, new_pix) return new_img finally: self.delete("/Fileset", orig_fs)
def import_pyramid_pre_fs(self, tmpdir): name = "test&sizeX=4000&sizeY=4000.fake" fakefile = tmpdir.join(name) fakefile.write('') pixels = self.import_image(filename=str(fakefile), skip="checksum")[0] id = long(float(pixels)) # wait for the pyramid to be generated self.wait_for_pyramid(id) query_service = self.client.sf.getQueryService() pixels_service = self.client.sf.getPixelsService() orig_pix = query_service.findByQuery( "select p from Pixels p where p.id = :id", ParametersI().addId(id)) orig_fs = query_service.findByQuery( "select f from Image i join i.fileset f where i.id = :id", ParametersI().addId(orig_pix.image.id.val)) try: new_img = pixels_service.copyAndResizeImage( orig_pix.image.id.val, rint(4000), rint(4000), rint(1), rint(1), [0], None, True).val pix_id = unwrap( query_service.projection( "select p.id from Image i join i.pixels p where i.id = :id", ParametersI().addId(new_img)))[0][0] # This won't work but it but we then have a pyramid without fileset self.copyPixels(orig_pix, PixelsI(pix_id, False)) except omero.InternalException: print "Cannot copy pixels for image %s" % orig_pix.image.id.val finally: self.delete([orig_fs]) return pix_id
def get_data(request, data_name, conn): """Return data for images in a Project, Dataset or Plate.""" project_id = request.GET.get('project') dataset_id = request.GET.get('dataset') plate_id = request.GET.get('plate') field_id = request.GET.get('field') if project_id: img_ids = get_project_image_ids(conn, project_id) elif dataset_id: objects = conn.getObjects('Image', opts={'dataset': dataset_id}) img_ids = [i.id for i in objects] elif plate_id and field_id: img_ids = get_image_ids(conn, plate_id, field_id) else: img_ids = request.GET.getlist('image') query_service = conn.getQueryService() if data_name == "ROI_stats_max_size": if plate_id: ns = "roi.pixel.intensities.summary" return get_image_map_annotations(conn, plate_id, 0, ns, "Max Points") if data_name == "ROI_count": # Want to get ROI count for images params = ParametersI() # Include "-1" so that if we have no Image IDs that the query does # not fail. It will not match anything. params.addIds([-1] + img_ids) query = "select roi.image.id, count(roi.id) from Roi roi "\ "where roi.image.id in (:ids) group by roi.image" p = query_service.projection(query, params, conn.SERVICE_OPTS) roi_counts = {} for i in img_ids: # Add placeholder 0 for all images roi_counts[i] = 0 for i in p: roi_counts[i[0].val] = i[1].val return roi_counts if data_name == "sizeT": # Want to get sizeT for images params = ParametersI() # Include "-1" so that if we have no Image IDs that the query does # not fail. It will not match anything. params.addIds([-1] + img_ids) query = "select pixels.image.id, pixels.sizeT from Pixels pixels "\ "where pixels.image.id in (:ids)" p = query_service.projection(query, params, conn.SERVICE_OPTS) size_t = {} for i in p: size_t[i[0].val] = i[1].val return size_t
def index_projects(es, index, client, project_ids): session = client.getSession() query_service = session.getQueryService() for project_id in project_ids: log.info('Processing Project:%d' % project_id) params = ParametersI() params.addId(project_id) t0 = time.time() project = query_service.findByQuery( QUERY_PROJECT, params, {'omero.group': '-1'} ) log.info( 'Loaded Project:%d (%dms)' % ( project_id, (time.time() - t0) * 1000 ) ) if project is None: log.warn('Project:%d has no Datasets or Images!' % project_id) continue t0 = time.time() document = ProjectDocument(client, project) log.info( 'Created document from Project:%d (%dms)' % ( project_id, (time.time() - t0) * 1000 ) ) if es is None: print document for image_document in document.image_documents: print image_document continue logging.info('Using Elasticsearch index: %s' % index) t0 = time.time() result = es.index( index=index, doc_type='project', id=project_id, body=json.dumps(document.document) ) log.info( 'Index complete: %r (%dms)' % ( result, (time.time() - t0) * 1000 ) ) t0 = time.time() result = helpers.bulk( es, image_document_index_actions(document, index) ) log.info( 'Index complete: %r (%dms)' % ( result, (time.time() - t0) * 1000 ) )
def testTiles(self): from omero.model import PixelsI from omero.sys import ParametersI from omero.util.tiles import RPSTileLoop from omero.util.tiles import TileLoopIteration from numpy import fromfunction sizeX = 4096 sizeY = 4096 sizeZ = 1 sizeC = 1 sizeT = 1 tileWidth = 1024 tileHeight = 1024 imageName = "testStitchBig4K-1Ktiles" description = None tile_max = float(255) pixelsService = self.client.sf.getPixelsService() queryService = self.client.sf.getQueryService() query = "from PixelsType as p where p.value='int8'" pixelsType = queryService.findByQuery(query, None) channelList = range(sizeC) iId = pixelsService.createImage(sizeX, sizeY, sizeZ, sizeT, channelList, pixelsType, imageName, description) image = queryService.findByQuery( "select i from Image i join fetch i.pixels where i.id = :id", ParametersI().addId(iId)) pid = image.getPrimaryPixels().getId().getValue() def f(x, y): """ create some fake pixel data tile (2D numpy array) """ return (x * y) / (1 + x + y) def mktile(w, h): tile = fromfunction(f, (w, h)) tile = tile.astype(int) tile[tile > tile_max] = tile_max return list(tile.flatten()) tile = fromfunction(f, (tileWidth, tileHeight)).astype(int) tile_min = float(tile.min()) tile_max = min(tile_max, float(tile.max())) class Iteration(TileLoopIteration): def run(self, data, z, c, t, x, y, tileWidth, tileHeight, tileCount): tile2d = mktile(tileWidth, tileHeight) data.setTile(tile2d, z, c, t, x, y, tileWidth, tileHeight) loop = RPSTileLoop(self.client.sf, PixelsI(pid, False)) loop.forEachTile(256, 256, Iteration()) c = 0 pixelsService.setChannelGlobalMinMax(pid, c, tile_min, tile_max)
def find_images(self): session = self.client.getSession() query_service = session.getQueryService() dataset_ids = [v.id.val for v in self.project.linkedDatasetList()] image_counts_per_dataset = self.get_image_counts_per_dataset( query_service) for dataset_id in dataset_ids: if image_counts_per_dataset.get(dataset_id, 0) < 1: log.info( 'Skipping Dataset:%d Project:%d, contains no Images!' % (dataset_id, self.project.id.val)) continue offset = 0 count = limit = 100 params = ParametersI().addId(dataset_id).page(offset, limit) while count == limit: t0 = time.time() images = query_service.findAllByQuery(QUERY_IMAGES, params, {'omero.group': '-1'}) log.info('Found %d Images in Dataset:%d Project:%d (%dms)' % (len(images), dataset_id, self.project.id.val, (time.time() - t0) * 1000)) count = len(images) offset += count params.page(offset, limit) for image in images: yield image
def well_annotations(request, screen, conn=None, **kwargs): """ Return Annotations on child Wells. JSON format same as for webclient/api/annotations/?type=map """ ann_type = request.GET.get('type', None) # get wells in Screen queryService = conn.getQueryService() params = ParametersI() params.addId(screen) query = """select well.id from Well as well join well.plate plate join plate.screenLinks screenLinks where screenLinks.parent.id=:id """ result = queryService.projection(query, params, conn.SERVICE_OPTS) iids = [r[0].val for r in result] anns, exps = marshal_annotations(conn, well_ids=iids, ann_type=ann_type, limit=100000) return JsonResponse({'annotations': anns, 'experimenters': exps})
def archivedFiles(self, img_obj): return \ self.client.sf.getQueryService().findAllByQuery(( "select o from Image i join i.pixels p " "join p.pixelsFileMaps m join m.parent o " "where i.id = :id"), ParametersI().addId(img_obj.id.val))
def get_perms(conn, object_type, object_id, object_owner_id, object_group_id, cache): # Attempt to get permissions which have previously been recorded for this # group depending on if the object is owned or not perms = cache.get((object_group_id.val, object_owner_id.val)) # If no cache, query an object to get the permissions for this group and # object ownership if perms is None: params = ParametersI() params.addId(object_id) q = ''' select obj from %s obj where obj.id = :id ''' % object_type qs = conn.getQueryService() obj = qs.projection(q, params, conn.SERVICE_OPTS)[0][0].val perms_obj = obj.details.permissions # To be compatible with parse_permissions_css, convert the required # fields to a dictionary restrictions = ('canEdit', 'canAnnotate', 'canLink', 'canDelete') perms = {} for r in restrictions: if getattr(perms_obj, r)(): perms[r] = True # Cache the result cache[(object_group_id.val, object_owner_id.val)] = perms return perms
def hql_query(self, query, params=None): ''' Execute the given HQL query and return the results. Optionally accepts a parameters object. For conveniance, will unwrap the OMERO types ''' # Connect if not already connected if self.conn is None: self.connect() if params is None: params = ParametersI() # Set OMERO Group to -1 to query across all available data self.conn.SERVICE_OPTS.setOmeroGroup(-1) # Get the Query Service qs = self.conn.getQueryService() # Execute the query rows = qs.projection(query, params, self.conn.SERVICE_OPTS) # Unwrap the query results unwrapped_rows = [] for row in rows: unwrapped_row=[] for column in row: if column is None: unwrapped_row.append(None) else: unwrapped_row.append(column.val) unwrapped_rows.append(unwrapped_row) return unwrapped_rows
def test_remove_pyramids_check_thumbnails(self, tmpdir, capsys): """Test check that the thumbnail is correctly created""" name = "big&sizeX=3500&sizeY=3500&little=false.fake" img_id = self.import_pyramid(tmpdir, name) query_service = self.client.sf.getQueryService() pix = query_service.findByQuery( "select p from Pixels p where p.image.id = :id", ParametersI().addId(img_id)) tb = self.client.sf.createThumbnailStore() id = pix.id.val thumb_hash = None try: thumbs = tb.getThumbnailByLongestSideSet(rint(64), [id], {'omero.group': '-1'}) assert len(thumbs) == 1 thumb_hash = self.calculate_sha1(thumbs[id]) # remove the pyramid and the thumbnail self.args += ["--endian=big"] self.cli.invoke(self.args, strict=True) out, err = capsys.readouterr() thumbs = tb.getThumbnailByLongestSideSet(rint(64), [id], {'omero.group': '-1'}) assert len(thumbs) == 1 # The clock should be returned during the pyramid generation digest = self.calculate_sha1(thumbs[id]) assert digest != thumb_hash # The pyramid generation has now been triggered. self.wait_for_pyramid(id) thumbs = tb.getThumbnailByLongestSideSet(rint(64), [id], {'omero.group': '-1'}) digest = self.calculate_sha1(thumbs[id]) # The thumbnail should now be back assert digest == thumb_hash finally: tb.close()
def datasets(request, project, conn=None, **kwargs): """Return {dataset: {name: Dataset, id:1}, image: {id: 2}}.""" queryService = conn.getQueryService() params = ParametersI() params.addId(project) query = """select d from Dataset as d join fetch d.imageLinks imageLinks join fetch imageLinks.child join fetch d.projectLinks projectLinks where projectLinks.parent.id=:id """ result = queryService.findAllByQuery(query, params, conn.SERVICE_OPTS) data = [] for d in result: for link in d.copyImageLinks(): data.append({ 'dataset': { 'id': d.id.val, 'name': d.name.val }, 'image': { 'id': link.child.id.val } }) return JsonResponse({'data': data})
def image_annotations(request, project, conn=None, **kwargs): """ Return Annotations on child Images. JSON format same as for webclient/api/annotations/?type=map """ ann_type = request.GET.get('type', None) # get images in Project queryService = conn.getQueryService() params = ParametersI() params.addId(project) query = """select image.id from Image as image join image.datasetLinks datasetLinks join datasetLinks.parent as dataset join dataset.projectLinks projectLinks where projectLinks.parent.id=:id """ result = queryService.projection(query, params, conn.SERVICE_OPTS) iids = [r[0].val for r in result] anns, exps = marshal_annotations(conn, image_ids=iids, ann_type=ann_type, limit=100000) return JsonResponse({'annotations': anns, 'experimenters': exps})
def get_script(request, script_name, conn): """Return a JS function to filter images by various params.""" dataset_id = request.GET.get('dataset') plate_id = request.GET.get('plate') field_id = request.GET.get('field') image_ids = request.GET.getlist('image') if plate_id and field_id: img_ids = get_image_ids(conn, plate_id, field_id) elif dataset_id: objects = conn.getObjects('Image', opts={'dataset': dataset_id}) img_ids = [i.id for i in objects] else: img_ids = [long(i) for i in image_ids] query_service = conn.getQueryService() if script_name == "ROI_count": # Want to get ROI count for images in plate # Get ROI counts params = ParametersI() params.addIds(img_ids) query = "select roi.image.id, count(roi.id) from Roi roi "\ "where roi.image.id in (:ids) group by roi.image" p = query_service.projection(query, params, conn.SERVICE_OPTS) roi_counts = {} for i in p: roi_counts[i[0].val] = i[1].val min_count = min(roi_counts.values()) max_count = max(roi_counts.values()) # Return a JS function that will be passed an object # e.g. {'type': 'Image', 'id': 1} # and should return true or false f = """(function filter(data, params) { var roi_counts = %s; if (isNaN(params.count) || params.count == '') return true; if (params.operator === '=') return roi_counts[data.id] == params.count; if (params.operator === '<') return roi_counts[data.id] < params.count; if (params.operator === '>') return roi_counts[data.id] > params.count; }) """ % json.dumps(roi_counts) filter_params = [ {'name': 'operator', 'type': 'text', 'values': ['>', '=', '<'], 'default': '>'}, {'name': 'count', 'type': 'number', 'default': '', 'title': '%s-%s' % (min_count, max_count)} ] return JsonResponse( { 'f': f, 'params': filter_params, })
def get_logfile(query, fid): from omero.sys import ParametersI q = ("select o from FilesetJobLink l " "join l.parent as fs join l.child as j " "join j.originalFileLinks l2 join l2.child as o " "where fs.id = :id and " "o.mimetype = 'application/omero-log-file'") return query.findByQuery(q, ParametersI().addId(fid))
def index_screens(es, index, client, screen_ids): session = client.getSession() query_service = session.getQueryService() for screen_id in screen_ids: log.info('Processing Screen:%d' % screen_id) params = ParametersI() params.addId(screen_id) t0 = time.time() plates = query_service.findAllByQuery( QUERY_PLATES, params, {'omero.group': '-1'} ) log.info( 'Loaded %d Plates from Screen:%d (%dms)' % ( len(plates), screen_id, (time.time() - t0) * 1000 ) ) for plate in plates: plate_id = plate.id.val t0 = time.time() document = PlateDocument(client, plate) log.info( 'Created document from Plate:%d (%dms)' % ( plate_id, (time.time() - t0) * 1000 ) ) if es is None: print document for well_document in document.well_documents: print well_document continue logging.info('Using Elasticsearch index: %s' % index) t0 = time.time() result = es.index( index=index, doc_type='plate', id=plate_id, body=json.dumps(document.document) ) log.info( 'Index complete: %r (%dms)' % ( result, (time.time() - t0) * 1000 ) ) t0 = time.time() result = helpers.bulk( es, well_document_index_actions(document, index) ) log.info( 'Index complete: %r (%dms)' % ( result, (time.time() - t0) * 1000 ) )
def get_image_counts_per_dataset(self, query_service): params = ParametersI() params.addId(self.project.id.val) t0 = time.time() image_counts = dict([ (r[0].val, r[1].val) for r in query_service.projection( QUERY_IMAGE_COUNTS, params, {'omero.group': '-1'}) ]) log.info('Image counts: %s (%dms)' % (pformat(image_counts, indent=2), (time.time() - t0) * 1000)) return image_counts
def get_well_ids(conn, plate_id): """Get well IDs for Plate""" conn.SERVICE_OPTS.setOmeroGroup('-1') query_service = conn.getQueryService() params = ParametersI() params.addId(plate_id) query = "select well.id "\ "from Well well "\ "where well.plate.id = :id" p = query_service.projection(query, params, conn.SERVICE_OPTS) return [i[0].val for i in p]
def get_data(request, data_name, conn): """Return data for images in a Dataset or Plate.""" dataset_id = request.GET.get('dataset') plate_id = request.GET.get('plate') field_id = request.GET.get('field') if plate_id and field_id: img_ids = get_image_ids(conn, plate_id, field_id) elif dataset_id: objects = conn.getObjects('Image', opts={'dataset': dataset_id}) img_ids = [i.id for i in objects] query_service = conn.getQueryService() if data_name == "ROI_stats_max_size": if plate_id: ns = "roi.pixel.intensities.summary" return get_image_map_annotations(conn, plate_id, 0, ns, "Max Points") if data_name == "ROI_count": # Want to get ROI count for images params = ParametersI() params.addIds(img_ids) query = "select roi.image.id, count(roi.id) from Roi roi "\ "where roi.image.id in (:ids) group by roi.image" p = query_service.projection(query, params, conn.SERVICE_OPTS) roi_counts = {} for i in p: roi_counts[i[0].val] = i[1].val return roi_counts if data_name == "sizeT": # Want to get sizeT for images params = ParametersI() params.addIds(img_ids) query = "select pixels.image.id, pixels.sizeT from Pixels pixels "\ "where pixels.image.id in (:ids)" p = query_service.projection(query, params, conn.SERVICE_OPTS) size_t = {} for i in p: size_t[i[0].val] = i[1].val return size_t
def test_rename_annotation(self): ns = NSFSRENAME mrepo = self.client.getManagedRepository() orig_img = self.import_fake_file(with_companion=True) orig_fs = self.get_fileset(orig_img) new_dir = prep_directory(self.client, mrepo) self.assert_rename(orig_fs, new_dir) ann = self.query.projection( ("select a.id from FilesetAnnotationLink l " "join l.child as a where l.parent.id = :id " "and a.ns = :ns"), ParametersI().addId(orig_fs.id).addString("ns", ns)) assert ann
def run(): """ """ data_types = [rstring("Plate")] client = scripts.client( "Unlink_Images.py", "Unlink Images from a given Plate", scripts.String("Data_Type", optional=False, grouping="1", description="The data type you want to work with.", values=data_types, default="Plate"), scripts.List("IDs", optional=False, grouping="2", description="List of Plate IDs").ofType(rlong(0)), version="0.1", authors=["Chris Allan"], institutions=["Glencoe Software Inc."], contact="*****@*****.**", ) try: script_params = {} for key in client.getInputKeys(): if client.getInput(key): script_params[key] = client.getInput(key, unwrap=True) session = client.getSession() update_service = session.getUpdateService() query_service = session.getQueryService() count = 0 for plate_id in script_params["IDs"]: params = ParametersI() params.addId(plate_id) plate = query_service.findByQuery( "SELECT p from Plate AS p " "LEFT JOIN FETCH p.wells as w " "LEFT JOIN FETCH w.wellSamples as ws " "WHERE p.id = :id", params) for well in plate.copyWells(): count += well.sizeOfWellSamples() well.clearWellSamples() update_service.saveObject(plate) client.setOutput("Message", rstring( "Unlinking of %d Image(s) successful." % count)) finally: client.closeSession()
def get_project_image_ids(conn, project_id): """Get image IDs for images in Project""" conn.SERVICE_OPTS.setOmeroGroup('-1') query_service = conn.getQueryService() params = ParametersI() params.addId(project_id) query = "select link "\ "from DatasetImageLink link "\ "join fetch link.parent dataset "\ "join fetch dataset.projectLinks plink "\ "where plink.parent.id = :id " p = query_service.projection(query, params, conn.SERVICE_OPTS) img_ids = [i[0].val.child.id.val for i in p] return img_ids
def get_dataset_image_ids(conn, dataset_id): """Get image IDs for images in Dataset""" conn.SERVICE_OPTS.setOmeroGroup('-1') query_service = conn.getQueryService() params = ParametersI() params.addId(dataset_id) query = "select img.id "\ "from DatasetImageLink link "\ "join link.child as img "\ "where link.parent.id = :id" p = query_service.projection(query, params, conn.SERVICE_OPTS) img_ids = [i[0].val for i in p] return img_ids
def duplicateMIF(self, orig_img): """ Use copyAndResizeImage to create a "synthetic" image (one without a fileset) """ new_img = self.pixels.copyAndResizeImage( orig_img.id.val, rint(16), rint(16), rint(1), rint(1), [0], None, True).val pix_id = unwrap(self.query.projection( "select p.id from Image i join i.pixels p where i.id = :id", ParametersI().addId(new_img)))[0][0] new_img = ImageI(new_img, False) new_pix = PixelsI(pix_id, False) return new_img, new_pix
def testConvertSynthetic(self): """ Convert a pre-FS file to FS using a README.txt as the first in the list. """ readme_path = create_path() readme_path.write_text( """ This file has been inserted into the fileset in order to prevent import. It can be safely deleted. """) readme_obj = self.client.upload(str(readme_path), name="README.txt") new_img = self.createSynthetic() binaries = self.imageBinaries(new_img.id.val) self.assertManageImageBinaries(binaries) files = self.archivedFiles(new_img) files.insert(0, readme_obj) proc = self.startUpload(files) handle = self.uploadFileset(proc, files) try: fs = handle.getRequest().activity.parent self.linkImageToFileset(new_img, fs) fs = self.client.sf.getQueryService().findByQuery(( "select fs from Fileset fs " "join fetch fs.usedFiles " "where fs.id = :id"), ParametersI().addId(fs.id.val)) used = fs.copyUsedFiles() fs.clearUsedFiles() for idx in range(1, 3): # omit readme fs.addFilesetEntry(used[idx]) used[idx].originalFile.unload() self.client.sf.getUpdateService().saveObject(fs) for file in files: self.delete("OriginalFile", file) binaries = self.imageBinaries(new_img.id.val) self.assertManageImageBinaries(binaries, lenArchived=0) finally: handle.close() binaries = self.imageBinaries( new_img.id.val, togglePixels=True) self.assertManageImageBinaries( binaries, lenArchived=0, pixelsPresent=False)
def list_microscopes(request, conn=None, **kwargs): params = ParametersI() params.addString('ns', wrap(JSON_FILEANN_NS)) # q = """select new map(obj.id as id, # obj.description as desc, # o.firstName as firstName, # o.lastName as lastName, # e.time as time, # f.name as name, # obj as obj_details_permissions) # from FileAnnotation obj # join obj.details.owner as o # join obj.details.creationEvent as e # join obj.file.details as p # join obj.file as f where obj.ns=:ns""" q = """select obj from FileAnnotation obj join obj.details.owner as o join obj.details.creationEvent as e join obj.file.details as p join obj.file as f where obj.ns=:ns""" qs = conn.getQueryService() # file_anns = qs.projection(q, params, conn.SERVICE_OPTS) file_annotations = qs.findAllByQuery(q, params, conn.SERVICE_OPTS) rsp = [] for file_ann in file_annotations: print('fa', file_ann) fa_wrapper = FileAnnotationWrapper(conn, file_ann) file_wrapper = fa_wrapper.getFile() print('file_wrapper', file_wrapper) file_data = b"".join(list(file_wrapper.getFileInChunks())) print('file_data', file_data) json_data = json.loads(file_data.decode("utf-8")) # date = datetime.fromtimestamp(unwrap(fa['time'])/1000) # first_name = unwrap(file_ann) # last_name = unwrap(fa['lastName']) fig_file = { 'id': file_ann.id.val, # 'name': unwrap(fa['name']), # 'description': unwrap(fa['desc']), # 'ownerFullName': "%s %s" % (first_name, last_name), # 'creationDate': time.mktime(date.timetuple()), # 'canEdit': fa['obj_details_permissions'].get('canEdit'), 'microscope': json_data } rsp.append(fig_file) return JsonResponse({'data': rsp})
def import_pyramid(self, tmpdir, name=None, thumb=False): if name is None: name = "test&sizeX=4000&sizeY=4000.fake" fakefile = tmpdir.join(name) fakefile.write('') pixels = self.import_image(filename=str(fakefile), skip="checksum")[0] id = long(float(pixels)) assert id >= 0 # wait for the pyramid to be generated self.wait_for_pyramid(id) query_service = self.client.sf.getQueryService() pix = query_service.findByQuery( "select p from Pixels p where p.id = :id", ParametersI().addId(id)) return pix.image.id.val
def get_image_ids(conn, plate_id, field_id=0): """Get image IDs for images in Plate""" conn.SERVICE_OPTS.setOmeroGroup('-1') query_service = conn.getQueryService() params = ParametersI() params.addId(plate_id) params.add('wsidx', rint(field_id)) query = "select img.id "\ "from Well well "\ "join well.wellSamples ws "\ "join ws.image img "\ "where well.plate.id = :id "\ "and index(ws) = :wsidx" p = query_service.projection(query, params, conn.SERVICE_OPTS) img_ids = [i[0].val for i in p] return img_ids
def get_data(request, data_name, conn): """Return table data for images in a Plate.""" plate_id = request.GET.get('plate') field_id = request.GET.get('field') # dict of well_id: img_id img_ids = get_well_image_ids(conn, plate_id, field_id) print 'img_ids', img_ids query_service = conn.getQueryService() if data_name.startswith("Table_"): column_name = data_name.replace("Table_", "") # Load table and get data for named column params = ParametersI() params.addId(plate_id) query = """select oal from PlateAnnotationLink as oal left outer join fetch oal.child as ch left outer join oal.parent as pa where pa.id=:id and ch.ns='%s'""" % NSBULKANNOTATIONS links = query_service.findAllByQuery(query, params, conn.SERVICE_OPTS) shared_resources = conn.getSharedResources() # Just use the first Table we find # TODO: handle multiple tables!? file_id = links[0].child.file.id.val table = shared_resources.openTable(OriginalFileI(file_id), conn.SERVICE_OPTS) headers = table.getHeaders() column_names = [col.name for col in headers] col_index = column_names.index(column_name) rows = table.getNumberOfRows() # Load first column 'Well' & named column col_data = table.read([0, col_index], 0, rows).columns table_data = {} well_ids = col_data[0].values values = col_data[1].values for well_id, value in zip(well_ids, values): print 'well_id', well_id, value img_id = img_ids[well_id] table_data[img_id] = value return table_data
def annotation_ids_by_field(conn, value="CMPO_0000077", key="Phenotype Term Accession", ns="openmicroscopy.org/omero/bulk_annotations"): """ Return a list of IDs for map annotations with the given namespace that have a key=value pair matching the given parameters. """ from omero.rtypes import unwrap from omero.sys import ParametersI params = ParametersI() params.addString("value", value) params.addString("key", key) params.addString("ns", ns) q = ("select a.id from MapAnnotation a join a.mapValue as mv " "where a.ns = :ns and mv.name = :key and mv.value = :value") return unwrap(conn.getQueryService().projection(q, params))[0]