def write_to_omero(self): sf = self.client.getSession() group = str(self.value_resolver.target_object.details.group.id.val) sr = sf.sharedResources() update_service = sf.getUpdateService() name = 'bulk_annotations' table = sr.newTable(1, name, {'omero.group': group}) if table is None: raise MetadataError( "Unable to create table: %s" % name) original_file = table.getOriginalFile() log.info('Created new table OriginalFile:%d' % original_file.id.val) table.initialize(self.columns) log.info('Table initialized with %d columns.' % (len(self.columns))) table.addData(self.columns) log.info('Added data column data.') table.close() file_annotation = FileAnnotationI() file_annotation.ns = \ rstring('openmicroscopy.org/omero/bulk_annotations') file_annotation.description = rstring(name) file_annotation.file = OriginalFileI(original_file.id.val, False) link = self.create_annotation_link() link.parent = self.target_object link.child = file_annotation update_service.saveObject(link, {'omero.group': group})
def testPopulateRoisPlate(self): """ Create a small csv file, use populate_roi.py to parse and attach to Plate. Then query to check table has expected content. """ csvName = self.createCsv(colNames="Well,Field,X,Y,Type", rowData=("A1,0,15,15,Test", )) rowCount = 1 colCount = 1 plate = self.createPlate(rowCount, colCount) # As opposed to the ParsingContext, here we are expected # to link the file ourselves ofile = self.client.upload(csvName).proxy() ann = FileAnnotationI() ann.file = ofile link = PlateAnnotationLinkI() link.parent = plate.proxy() link.child = ann link = self.client.sf.getUpdateService()\ .saveAndReturnObject(link) # End linking factory = PlateAnalysisCtxFactory(self.client.sf) factory.implementations = (MockPlateAnalysisCtx, ) ctx = factory.get_analysis_ctx(plate.id.val) assert 1 == ctx.get_measurement_count() meas = ctx.get_measurement_ctx(0) meas.parse_and_populate() # Get file annotations query = """select p from Plate p left outer join fetch p.annotationLinks links left outer join fetch links.child as ann left outer join fetch ann.file as file where p.id=%s""" % plate.id.val qs = self.client.sf.getQueryService() plate = qs.findByQuery(query, None) anns = plate.linkedAnnotationList() # Only expect a single annotation which is a 'bulk annotation' # the other is the original CSV assert len(anns) == 2 files = dict([(a.ns.val, a.file.id.val) for a in anns if a.ns]) fileid = files[NSMEASUREMENT] # Open table to check contents r = self.client.sf.sharedResources() t = r.openTable(OriginalFileI(fileid), None) cols = t.getHeaders() rows = t.getNumberOfRows() assert rows == 1 data = t.read(range(len(cols)), 0, 1) imag = data.columns[0].values[0] rois = self.client.sf.getRoiService() anns = rois.getRoiMeasurements(imag, RoiOptions()) assert anns
def test_file_annotation(self): """Tests AnnotationWrapper methods return strings""" file_name = u'₩€_file_$$' f = OriginalFileI() f.name = rstring(file_name) obj = FileAnnotationI() obj.file = f file_ann = MockConnection(obj).getObject("Annotation", 1) assert file_ann.getFileName() == file_name.encode('utf8')
def testPopulateRoisPlate(self): """ Create a small csv file, use populate_roi.py to parse and attach to Plate. Then query to check table has expected content. """ csvName = self.createCsv( colNames="Well,Field,X,Y,Type", rowData=("A1,0,15,15,Test",)) rowCount = 1 colCount = 1 plate = self.createPlate(rowCount, colCount) # As opposed to the ParsingContext, here we are expected # to link the file ourselves ofile = self.client.upload(csvName).proxy() ann = FileAnnotationI() ann.file = ofile link = PlateAnnotationLinkI() link.parent = plate.proxy() link.child = ann link = self.client.sf.getUpdateService()\ .saveAndReturnObject(link) # End linking factory = PlateAnalysisCtxFactory(self.client.sf) factory.implementations = (MockPlateAnalysisCtx,) ctx = factory.get_analysis_ctx(plate.id.val) assert 1 == ctx.get_measurement_count() meas = ctx.get_measurement_ctx(0) meas.parse_and_populate() # Get file annotations query = """select p from Plate p left outer join fetch p.annotationLinks links left outer join fetch links.child as ann left outer join fetch ann.file as file where p.id=%s""" % plate.id.val qs = self.client.sf.getQueryService() plate = qs.findByQuery(query, None) anns = plate.linkedAnnotationList() # Only expect a single annotation which is a 'bulk annotation' # the other is the original CSV assert len(anns) == 2 files = dict( [(a.ns.val, a.file.id.val) for a in anns if a.ns]) fileid = files[NSMEASUREMENT] # Open table to check contents r = self.client.sf.sharedResources() t = r.openTable(OriginalFileI(fileid), None) cols = t.getHeaders() rows = t.getNumberOfRows() assert rows == 1 data = t.read(range(len(cols)), 0, 1) imag = data.columns[0].values[0] rois = self.client.sf.getRoiService() anns = rois.getRoiMeasurements(imag, RoiOptions()) assert anns