Skip to content

Instantly share code, notes, and snippets.

@will-moore
Created November 1, 2012 22:10
Show Gist options
  • Save will-moore/3997000 to your computer and use it in GitHub Desktop.
Save will-moore/3997000 to your computer and use it in GitHub Desktop.
OMERO script to rename Image Channels
import omero.scripts as scripts
from omero.gateway import BlitzGateway
from omero.rtypes import rstring, rlong
def renameChannels(conn, parameterMap):
updateService = conn.getUpdateService()
channel_names = parameterMap["Channel_Names"].split(",")
channel_names = [ name.strip() for name in channel_names]
ids = parameterMap["IDs"]
images = []
if parameterMap["Data_Type"] == "Dataset":
for ds in conn.getObjects("Dataset", ids):
images.extend( list(ds.listChildren()) )
else:
images = list( conn.getObjects("Image", ids) )
for image in images:
for n, c in zip(channel_names, image.getChannels()):
lc = c._obj.getLogicalChannel() # returns omero.model.LogicalChannelI
lc.setName(rstring(n))
updateService.saveObject(lc)
if __name__ == "__main__":
dataTypes = [rstring('Dataset'),rstring('Image')]
client = scripts.client('Rename_Channels.py', """Rename image Channels""",
scripts.String("Data_Type", optional=False, grouping="1",
description="Use all the images in specified 'Datasets' or choose individual 'Images'.",
values=dataTypes, default="Image"),
scripts.List("IDs", optional=False, grouping="2",
description="List of Dataset IDs or Image IDs to combine.").ofType(rlong(0)),
scripts.String("Channel_Names", optional=False, grouping="3",
description="Add Channel names separated by commas. E.g. 'DAPI, FITC, Red'")
)
try:
session = client.getSession()
# process the list of args above.
parameterMap = {}
for key in client.getInputKeys():
if client.getInput(key):
parameterMap[key] = client.getInput(key).getValue()
print parameterMap
conn = BlitzGateway(client_obj=client)
# renameChannels...
renameChannels(conn, parameterMap)
client.setOutput("Message", rstring("Channels Renamed!"))
finally:
client.closeSession()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment