Advertisement
Guest User

Untitled

a guest
Feb 29th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. import omero
  2. from omero.rtypes import rstring
  3. import omero.grid
  4. from omero.gateway import BlitzGateway
  5.  
  6. USERNAME = "will"
  7. PASSWORD = "ome"
  8. HOST = "localhost"
  9. PORT = 4064
  10.  
  11. plateId = 103
  12. conn = BlitzGateway(USERNAME, PASSWORD, host=HOST, port=PORT)
  13. conn.connect()
  14. tablename = "Channels_Min_Mex_Intensity"
  15.  
  16. # Go through all wells in Plate, adding row for each
  17. plate = conn.getObject("Plate", plateId)
  18. wellIds = []
  19. rowData = []
  20. chCount = 0
  21. for well in plate._listChildren():
  22. well = omero.gateway.WellWrapper(conn, well)
  23. image = well.getImage()
  24. if image is None:
  25. continue
  26. wellIds.append(well.id)
  27. chCount = image.getSizeC()
  28. row = []
  29. print "well, image", well.id, image.id
  30. for ch in image.getChannels():
  31. row.append(long(ch.getWindowMin()))
  32. row.append(long(ch.getWindowMax()))
  33. rowData.append(row)
  34.  
  35. print 'wellIds', wellIds
  36. print 'rowData', rowData
  37.  
  38.  
  39. # Now we know how many channels, we can make the table
  40. col1 = omero.grid.WellColumn('Well', '', [])
  41. columns = [col1]
  42. colNames = []
  43. for chIdx in range(chCount):
  44. for name in ['Ch%sMin' % chIdx, 'Ch%sMax' % chIdx]:
  45. colNames.append(name)
  46. columns.append(omero.grid.LongColumn(name, '', []))
  47.  
  48. table = conn.c.sf.sharedResources().newTable(1, tablename)
  49. table.initialize(columns)
  50.  
  51.  
  52. # Add Data from above
  53. data1 = omero.grid.WellColumn('Well', '', wellIds)
  54. data = [data1]
  55. for colIdx in range(len(rowData[0])):
  56. colData = [r[colIdx] for r in rowData]
  57. print "colData", len(colData)
  58. name = colNames[colIdx]
  59. data.append(omero.grid.LongColumn(name, '', colData))
  60.  
  61. print "Adding data: ", len(data)
  62. table.addData(data)
  63. table.close()
  64.  
  65. print "table closed..."
  66. orig_file = table.getOriginalFile()
  67. fileAnn = omero.model.FileAnnotationI()
  68. fileAnn.ns = rstring('openmicroscopy.org/omero/bulk_annotations')
  69. fileAnn.setFile(omero.model.OriginalFileI(orig_file.id.val, False))
  70. fileAnn = conn.getUpdateService().saveAndReturnObject(fileAnn)
  71. link = omero.model.PlateAnnotationLinkI()
  72. link.setParent(omero.model.PlateI(plateId, False))
  73. link.setChild(omero.model.FileAnnotationI(fileAnn.id.val, False))
  74.  
  75. print "save link..."
  76. conn.getUpdateService().saveAndReturnObject(link)
  77.  
  78. conn._closeSession()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement