def omero_table_file(self, user1, table_data): """Create a new OMERO Table and returns the original file ID.""" client = user1[0] col_types, col_names, rows = table_data columns = [] for col_type, name in zip(col_types, col_names): if col_type == StringColumn: columns.append(StringColumn(name, '', 64, [])) else: columns.append(col_type(name, '', [])) tablename = "omero_table_test:%s" % str(random()) table = client.sf.sharedResources().newTable(1, tablename) table.initialize(columns) table.setMetadata("test", rstring("value")) table.setMetadata("my_number", rint(100)) data = [] for col_type, name, idx in zip(col_types, col_names, range(len(col_names))): col_data = [row[idx] for row in rows] if col_type == StringColumn: data.append(StringColumn(name, '', 64, col_data)) else: data.append(col_type(name, '', col_data)) table.addData(data) orig_file = table.getOriginalFile() table.close() return orig_file.id.val
def create_columns_plate(self): columns = list() for i, header_as_lower in enumerate(self.headers_as_lower): name = self.headers[i] try: column = self.plate_keys[header_as_lower](name, '', list()) except KeyError: column = StringColumn(name, '', self.DEFAULT_COLUMN_SIZE, list()) columns.append(column) for column in columns: if column.__class__ is PlateColumn: columns.append(StringColumn(PLATE_NAME_COLUMN, '', self.DEFAULT_COLUMN_SIZE, list())) if column.__class__ is WellColumn: columns.append(StringColumn(WELL_NAME_COLUMN, '', self.DEFAULT_COLUMN_SIZE, list())) return columns
def create_columns_plate(self): columns = list() for i, header_as_lower in enumerate(self.headers_as_lower): name = self.headers[i] try: column = self.plate_keys[header_as_lower](name, '', list()) except KeyError: column = StringColumn(name, '', self.DEFAULT_COLUMN_SIZE, list()) columns.append(column) return columns
def plate_well_table(itest, well_grid_factory, update_service, conn): """ Returns a new OMERO Plate, linked Wells, linked WellSamples, and linked Images populated by an L{omeroweb.testlib.IWebTest} instance. """ plate = PlateI() plate.name = rstring(itest.uuid()) # Well A1 has one WellSample plate.addWell(well_grid_factory({(0, 0): 1})[0]) plate = update_service.saveAndReturnObject(plate) col1 = WellColumn('Well', '', []) col2 = StringColumn('TestColumn', '', 64, []) columns = [col1, col2] tablename = "plate_well_table_test:%s" % str(random()) table = conn.c.sf.sharedResources().newTable(1, tablename) table.initialize(columns) wellIds = [w.id.val for w in plate.copyWells()] print("WellIds", wellIds) data1 = WellColumn('Well', '', wellIds) data2 = StringColumn('TestColumn', '', 64, ["foobar"]) data = [data1, data2] table.addData(data) orig_file = table.getOriginalFile() table.close() fileAnn = FileAnnotationI() fileAnn.ns = rstring('openmicroscopy.org/omero/bulk_annotations') fileAnn.setFile(OriginalFileI(orig_file.id.val, False)) fileAnn = conn.getUpdateService().saveAndReturnObject(fileAnn) link = PlateAnnotationLinkI() link.setParent(PlateI(plate.id.val, False)) link.setChild(FileAnnotationI(fileAnn.id.val, False)) update_service.saveAndReturnObject(link) return plate, wellIds
def create_columns_plate(self): columns = list() for i, header_as_lower in enumerate(self.headers_as_lower): name = self.headers[i] description = "" if "%%" in name: name, description = name.split("%%", 1) name = name.strip() # description is key=value. Convert to json if "=" in description: k, v = description.split("=", 1) k = k.strip() description = json.dumps({k: v.strip()}) # HDF5 does not allow / in column names name = name.replace('/', '\\') try: column = self.plate_keys[header_as_lower](name, description, list()) except KeyError: column = StringColumn(name, description, self.DEFAULT_COLUMN_SIZE, list()) columns.append(column) for column in columns: if column.__class__ is PlateColumn: columns.append( StringColumn(PLATE_NAME_COLUMN, '', self.DEFAULT_COLUMN_SIZE, list())) if column.__class__ is WellColumn: columns.append( StringColumn(WELL_NAME_COLUMN, '', self.DEFAULT_COLUMN_SIZE, list())) if column.__class__ is ImageColumn: columns.append( StringColumn(IMAGE_NAME_COLUMN, '', self.DEFAULT_COLUMN_SIZE, list())) self.columns_sanity_check(columns) return columns
def testTableRead(self, gatewaywrapper): gatewaywrapper.loginAsAuthor() # we are Author pr = gatewaywrapper.getTestProject() assert pr is not None sr = gatewaywrapper.gateway.getSharedResources() name = 'bulk_annotations' table = sr.newTable(1, name) data = [StringColumn('col1', '', 2, ['A1', 'B1', 'C1'])] original_file = table.getOriginalFile() assert table is not None table.initialize(data) table.addData(data) file_annotation = omero.gateway.FileAnnotationWrapper( gatewaywrapper.gateway) file_annotation.setNs('openmicroscopy.org/omero/bulk_annotations') file_annotation.setDescription(name) file_annotation.setFile(original_file) pr.linkAnnotation(file_annotation) # table created, can we read it back? pr = gatewaywrapper.getTestProject() assert pr is not None file_annotation = pr.getAnnotation( ns='openmicroscopy.org/omero/bulk_annotations') assert file_annotation is not None table = sr.openTable(file_annotation._obj.file) assert table is not None # now as Admin gatewaywrapper.loginAsAdmin() sr = gatewaywrapper.gateway.getSharedResources() gatewaywrapper.gateway.SERVICE_OPTS.setOmeroGroup('-1') pr = gatewaywrapper.getTestProject() assert pr is not None file_annotation = pr.getAnnotation( ns='openmicroscopy.org/omero/bulk_annotations') assert file_annotation is not None table = sr.openTable( file_annotation._obj.file, gatewaywrapper.gateway.SERVICE_OPTS) assert table is not None
def testTableRead(self): # we are Author pr = self.getTestProject() self.assertNotEqual(pr, None) sr = self.gateway.getSharedResources() name = 'bulk_annotations' table = sr.newTable(1, name) data = [StringColumn('col1', '', 1, ['A1', 'B1', 'C1'])] original_file = table.getOriginalFile() self.assertNotEqual(table, None) table.initialize(data) table.addData(data) file_annotation = omero.gateway.FileAnnotationWrapper(self.gateway) file_annotation.setNs('openmicroscopy.org/omero/bulk_annotations') file_annotation.setDescription(name) file_annotation.setFile(original_file) pr.linkAnnotation(file_annotation) # table created, can we read it back? pr = self.getTestProject() self.assertNotEqual(pr, None) file_annotation = pr.getAnnotation( ns='openmicroscopy.org/omero/bulk_annotations') self.assertNotEqual(file_annotation, None) table = sr.openTable(file_annotation._obj.file) self.assertNotEqual(table, None) # now as Admin self.loginAsAdmin() sr = self.gateway.getSharedResources() self.gateway.SERVICE_OPTS.setOmeroGroup('-1') pr = self.getTestProject() self.assertNotEqual(pr, None) file_annotation = pr.getAnnotation( ns='openmicroscopy.org/omero/bulk_annotations') self.assertNotEqual(file_annotation, None) table = sr.openTable(file_annotation._obj.file, self.gateway.SERVICE_OPTS) self.assertNotEqual(table, None)
def parse(self): provider = self.original_file_provider data = provider.get_original_file_data(self.original_file) try: rows = list(csv.reader(data, delimiter=",")) finally: data.close() columns = [ ImageColumn("Image", "", list()), RoiColumn("ROI", "", list()), StringColumn("Type", "", 12, list()), ] for row in rows[1:]: wellnumber = self.well_name_to_number(row[0]) image = self.analysis_ctx.\ image_from_wellnumber(wellnumber) # TODO: what to do with the field?! # field = int(row[1]) # image = images[field] roi = RoiI() shape = PointI() shape.cx = rdouble(float(row[2])) shape.cy = rdouble(float(row[3])) shape.textValue = rstring(row[4]) roi.addShape(shape) roi.image = image.proxy() rid = self.update_service\ .saveAndReturnIds([roi])[0] columns[0].values.append(image.id.val) columns[1].values.append(rid) columns[2].values.append(row[4]) return MeasurementParsingResult([columns])