Skip to content

Instantly share code, notes, and snippets.

@will-moore
Last active August 6, 2019 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save will-moore/31c25fdbfc4dafebe245 to your computer and use it in GitHub Desktop.
Save will-moore/31c25fdbfc4dafebe245 to your computer and use it in GitHub Desktop.
Python script for to generate an OMERO.table on a Plate from channel min/max values
import omero
from omero.rtypes import rstring
import omero.grid
from omero.gateway import BlitzGateway
USERNAME = "will"
PASSWORD = "ome"
HOST = "localhost"
PORT = 4064
screenId = 4304
conn = BlitzGateway(USERNAME, PASSWORD, host=HOST, port=PORT)
conn.connect()
tablename = "Channels_Min_Mex_Intensity"
# Go through all wells in all Plates, adding row for each
screen = conn.getObject("Screen", screenId)
wellIds = []
rowData = []
chCount = 1
for plate in screen.listChildren():
print plate.name
for well in plate._listChildren():
well = omero.gateway.WellWrapper(conn, well)
image = well.getImage()
if image is None:
continue
wellIds.append(well.id)
# chCount = image.getSizeC()
row = []
print "well, image", well.id, image.id
for ch in image.getChannels():
row.append(long(ch.getWindowMin()))
row.append(long(ch.getWindowMax()))
rowData.append(row)
print 'wellIds', wellIds
print 'rowData', rowData
# Now we know how many channels, we can make the table
col1 = omero.grid.WellColumn('Well', '', [])
columns = [col1]
colNames = []
for chIdx in range(chCount):
for name in ['Ch%sMin' % chIdx, 'Ch%sMax' % chIdx]:
colNames.append(name)
columns.append(omero.grid.LongColumn(name, '', []))
table = conn.c.sf.sharedResources().newTable(1, tablename)
table.initialize(columns)
# Add Data from above
data1 = omero.grid.WellColumn('Well', '', wellIds)
data = [data1]
for colIdx in range(chCount * 2):
colData = [r[colIdx] for r in rowData]
print "colData", len(colData)
name = colNames[colIdx]
data.append(omero.grid.LongColumn(name, '', colData))
print "Adding data: ", len(data)
table.addData(data)
orig_file = table.getOriginalFile()
table.close()
print "table closed..."
fileAnn = omero.model.FileAnnotationI()
fileAnn.ns = rstring('openmicroscopy.org/omero/bulk_annotations')
fileAnn.setFile(omero.model.OriginalFileI(orig_file.id.val, False))
fileAnn = conn.getUpdateService().saveAndReturnObject(fileAnn)
link = omero.model.ScreenAnnotationLinkI()
link.setParent(omero.model.ScreenI(screenId, False))
link.setChild(omero.model.FileAnnotationI(fileAnn.id.val, False))
print "save link..."
conn.getUpdateService().saveAndReturnObject(link)
conn._closeSession()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment