def _test_parsing_context(self): """ Create a small csv file, use populate_metadata.py to parse and attach to Plate. Then query to check table has expected content. """ ctx = ParsingContext(self.client, self.plate, file=self.csvName) ctx.parse() ctx.write_to_omero() # Get file annotations anns = self.get_plate_annotations() # Only expect a single annotation which is a 'bulk annotation' assert len(anns) == 1 tableFileAnn = anns[0] assert unwrap(tableFileAnn.getNs()) == NSBULKANNOTATIONS fileid = tableFileAnn.file.id.val # Open table to check contents r = self.client.sf.sharedResources() t = r.openTable(OriginalFileI(fileid), None) cols = t.getHeaders() rows = t.getNumberOfRows() assert rows == self.rowCount * self.colCount for hit in range(rows): rowValues = [col.values[0] for col in t.read(range(len(cols)), hit, hit+1).columns] assert len(rowValues) == 4 if "a1" in rowValues: assert "Control" in rowValues elif "a2" in rowValues: assert "Treatment" in rowValues else: assert False, "Row does not contain 'a1' or 'a2'"
def testPopulateMetadataPlate(self): """ Create a small csv file, use populate_metadata.py to parse and attach to Plate. Then query to check table has expected content. """ csvName = "testCreate.csv" self.createCsv(csvName) rowCount = 1 colCount = 2 plate = self.createPlate(rowCount, colCount) ctx = ParsingContext(self.client, plate, csvName) ctx.parse() ctx.write_to_omero() # Delete local temp file os.remove(csvName) # Get file annotations query = """select p from Plate p left outer join fetch p.annotationLinks links left outer join fetch links.child 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' assert len(anns) == 1 tableFileAnn = anns[0] assert unwrap(tableFileAnn.getNs()) == NSBULKANNOTATIONS fileid = tableFileAnn.file.id.val # Open table to check contents r = self.client.sf.sharedResources() t = r.openTable(OriginalFileI(fileid), None) cols = t.getHeaders() rows = t.getNumberOfRows() assert rows == rowCount * colCount for hit in range(rows): rowValues = [ col.values[0] for col in t.read(range(len(cols)), hit, hit + 1).columns ] assert len(rowValues) == 4 if "a1" in rowValues: assert "Control" in rowValues elif "a2" in rowValues: assert "Treatment" in rowValues else: assert False, "Row does not contain 'a1' or 'a2'"
def testPopulateMetadataPlate(self): """ Create a small csv file, use populate_metadata.py to parse and attach to Plate. Then query to check table has expected content. """ csvName = "testCreate.csv" self.createCsv(csvName) rowCount = 1 colCount = 2 plate = self.createPlate(rowCount, colCount) ctx = ParsingContext(self.client, plate, csvName) ctx.parse() ctx.write_to_omero() # Delete local temp file os.remove(csvName) # Get file annotations query = """select p from Plate p left outer join fetch p.annotationLinks links left outer join fetch links.child 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' assert len(anns) == 1 tableFileAnn = anns[0] assert unwrap(tableFileAnn.getNs()) == NSBULKANNOTATIONS fileid = tableFileAnn.file.id.val # Open table to check contents r = self.client.sf.sharedResources() t = r.openTable(OriginalFileI(fileid), None) cols = t.getHeaders() rows = t.getNumberOfRows() assert rows == rowCount * colCount for hit in range(rows): rowValues = [col.values[0] for col in t.read(range(len(cols)), hit, hit+1).columns] assert len(rowValues) == 4 if "a1" in rowValues: assert "Control" in rowValues elif "a2" in rowValues: assert "Treatment" in rowValues else: assert False, "Row does not contain 'a1' or 'a2'"
def populate_data(self, csv, cfg): row_count = 1 col_count = 6 self.screen, self.plate = self.create_screen(row_count, col_count) ctx = ParsingContext(self.client, self.screen.proxy(), file=csv) ctx.parse() ctx.write_to_omero() # Get file annotations anns = self.get_screen_annotations() # Only expect a single annotation which is a 'bulk annotation' assert len(anns) == 1 table_file_ann = anns[0] assert unwrap(table_file_ann.getNs()) == NSBULKANNOTATIONS fileid = table_file_ann.file.id.val ctx = BulkToMapAnnotationContext( self.client, self.screen.proxy(), fileid=fileid, cfg=cfg) ctx.parse() ctx.write_to_omero()
def populate_data(self, csv, cfg): row_count = 1 col_count = 6 self.screen, self.plate = self.create_screen(row_count, col_count) ctx = ParsingContext(self.client, self.screen.proxy(), file=csv) ctx.parse() ctx.write_to_omero() # Get file annotations anns = self.get_screen_annotations() # Only expect a single annotation which is a 'bulk annotation' assert len(anns) == 1 table_file_ann = anns[0] assert unwrap(table_file_ann.getNs()) == NSBULKANNOTATIONS fileid = table_file_ann.file.id.val ctx = BulkToMapAnnotationContext( self.client, self.screen.proxy(), fileid=fileid, cfg=cfg) ctx.parse() ctx.write_to_omero()
def _test_parsing_context(self): """ Create a small csv file, use populate_metadata.py to parse and attach to Plate. Then query to check table has expected content. """ ctx = ParsingContext(self.client, self.plate, file=self.csvName) ctx.parse() ctx.write_to_omero() # Get file annotations anns = self.get_plate_annotations() # Only expect a single annotation which is a 'bulk annotation' assert len(anns) == 1 tableFileAnn = anns[0] assert unwrap(tableFileAnn.getNs()) == NSBULKANNOTATIONS fileid = tableFileAnn.file.id.val # Open table to check contents r = self.client.sf.sharedResources() t = r.openTable(OriginalFileI(fileid), None) cols = t.getHeaders() rows = t.getNumberOfRows() assert rows == self.rowCount * self.colCount for hit in range(rows): rowValues = [ col.values[0] for col in t.read(range(len(cols)), hit, hit + 1).columns ] assert len(rowValues) == 4 if "a1" in rowValues: assert "Control" in rowValues elif "a2" in rowValues: assert "Treatment" in rowValues else: assert False, "Row does not contain 'a1' or 'a2'"
# =================================================== orig_table_file = conn.getObject( "OriginalFile", attributes={'name': tablename}) # if name is unique savedTable = conn.c.sf.sharedResources().openTable(orig_table_file._obj) print "Opened table with row-count:", savedTable.getNumberOfRows() # Populate a table on a Plate from a csv file # =========================================== colNames = "Well, Well Type, Concentration\n" csvLines = [ colNames, "A1, Control, 0\n", "A2, Treatment, 5\n", "A3, Treatment, 10\n"] with open('data.csv', 'w') as csvData: csvData.writelines(csvLines) plate = conn.getObject("Plate", plateId) target_object = plate._obj client = conn.c ctx = ParsingContext(client, target_object, 'data.csv') ctx.parse() ctx.write_to_omero() os.remove('data.csv') # Close connection # ================ # When you are done, close the session to free up server resources. conn._closeSession()
# =================================================== orig_table_file = conn.getObject( "OriginalFile", attributes={'name': table_name}) # if name is unique saved_table = resources.openTable(orig_table_file._obj) print("Opened table with row-count:", saved_table.getNumberOfRows()) saved_table.close() # Populate a table on a Plate from a csv file # =========================================== col_names = "Well, Well Type, Concentration\n" csv_lines = [ col_names, "A1, Control, 0\n", "A2, Treatment, 5\n", "A3, Treatment, 10\n"] with open('data.csv', 'w') as csv_data: csv_data.writelines(csv_lines) plate = conn.getObject("Plate", plateId) target_object = plate._obj client = conn.c ctx = ParsingContext(client, target_object, 'data.csv') ctx.parse() ctx.write_to_omero() os.remove('data.csv') # Close connection # ================ # When you are done, close the session to free up server resources. conn.close()