def run(password, target, host, port): for user_number in range(1, 51): username = "******" % user_number print(username) conn = BlitzGateway(username, password, host=host, port=port) try: conn.connect() ds = conn.getObject("Dataset", attributes={'name': target}, opts={'owner': conn.getUserId()}) if ds is None: print("No dataset with name %s found" % target) continue print("Dataset", ds.getId()) conn.setChannelNames("Dataset", [ds.getId()], { 1: "H2B", 2: "nuclear lamina" }) except Exception as exc: print("Error while changing the channel names: %s" % str(exc)) finally: # Close connection for each user when done conn.close()
def run(username, password, project_id, host, port): conn = BlitzGateway(username, password, host=host, port=port) try: conn.connect() project = conn.getObject("Project", project_id) for dataset in project.listChildren(): print("\n\nDataset", dataset.id, dataset.name) for image in dataset.listChildren(): print("Image", image.id, image.name) ann = image.getAnnotation(NAMESPACE) if ann is None: print(" No annotation found") continue keys = ann.getValue() values = [kv[1] for kv in keys if kv[0] == MAP_KEY] if len(values) == 0: print(" No Key-Value found for key:", MAP_KEY) channels = values[0].split("; ") print("Channels", channels) name_dict = {} for c, ch_name in enumerate(channels): name_dict[c + 1] = ch_name.split(":")[1] conn.setChannelNames("Image", [image.id], name_dict, channelCount=None) except Exception as exc: print("Error while changing names: %s" % str(exc)) finally: conn.close()
def run(args): username = args.username password = args.password project_id = args.project_id host = args.server port = args.port use_stain = args.use_stain add_map_anns = args.add_map_anns token_index = 0 if use_stain else 1 conn = BlitzGateway(username, password, host=host, port=port) try: conn.connect() project = conn.getObject("Project", project_id) for dataset in project.listChildren(): print("\n\nDataset", dataset.id, dataset.name) for image in dataset.listChildren(): print("Image", image.id, image.name) ann = image.getAnnotation(NAMESPACE) if ann is None: print(" No annotation found") continue keys = ann.getValue() values = [kv[1] for kv in keys if kv[0] == MAP_KEY] if len(values) == 0: print(" No Key-Value found for key:", MAP_KEY) channels = values[0].split("; ") print("Channels", channels) name_dict = {} key_value_pairs = [] for c, ch_name in enumerate(channels): tokens = ch_name.split(":") if add_map_anns and len(tokens) > 1: key_value_pairs.extend( [["Ch%s_Stain" % c, tokens[0]], ["Ch%s_Label" % c, tokens[1]]] ) if len(tokens) > token_index: label = tokens[token_index] else: label = ch_name name_dict[c + 1] = label conn.setChannelNames("Image", [image.id], name_dict, channelCount=None) if len(key_value_pairs) > 0: create_map_ann(conn, image, key_value_pairs) except Exception as exc: print("Error while changing names: %s" % str(exc)) finally: conn.close()
conn.connect() NAMESPACE = "openmicroscopy.org/omero/bulk_annotations" MAP_KEY = "Channels" # TO BE MODIFIED project_id = 4501 project = conn.getObject("Project", project_id) for dataset in project.listChildren(): print "\n\nDataset", dataset.id, dataset.name for image in dataset.listChildren(): print "Image", image.id, image.name ann = image.getAnnotation(NAMESPACE) if ann is None: print " No annotation found" continue key_values = ann.getValue() channels_value = [kv[1] for kv in key_values if kv[0] == MAP_KEY] if len(channels_value) == 0: print " No Key-Value found for key:", MAP_KEY channels = channels_value[0].split("; ") print "Channels", channels name_dict = {} for c, ch_name in enumerate(channels): name_dict[c + 1] = ch_name.split(":")[1] conn.setChannelNames("Image", [image.id], name_dict, channelCount=None)
ch1 = channel_name elif channel_info.strip().startswith("Ch2"): ch2 = channel_name elif channel_info.strip().startswith("Ch3"): ch3 = channel_name if not (ch1 and ch2 and ch3): print("Channel name missing for row {}".format(index)) channel_names[key] = {1: ch1, 2: ch2, 3: ch3} conn = BlitzGateway(os.environ.get('OMERO_USER', 'xxx'), os.environ.get('OMERO_PASSWORD', 'xxx'), host=host, port=port) conn.connect() screen = conn.getObject("Screen", sys.argv[2]) for pl in screen.listChildren(): n_fields = pl.getNumberOfFields() for well in pl.listChildren(): print("Processing {} - {}".format(pl.getName(), well.getWellPos())) for field in range(n_fields[0], n_fields[1] + 1): ws = well.getWellSample(field) key = "{},{}".format(pl.getName(), well.getWellPos()) if ws and ws.getImage() and key in channel_names: img = well.getImage() conn.setChannelNames("Image", [img.getId()], channel_names[key], channelCount=None) conn.close()