def main(import_md): # Load metadata to orchestrate import with open(import_md, 'r') as fp: batch_md = json.load(fp) import_user = batch_md['user'] import_group = batch_md['group'] file_metadata = batch_md['import_targets'] data_dir = Path(batch_md['server_path']) # Create user connection suconn = BlitzGateway(OMERO_USER, OMERO_PASS, host=OMERO_HOST, port=OMERO_PORT, secure=True) suconn.connect() conn = suconn.suConn(import_user, import_group, 2160000000) suconn.close() # Import targets from import.json for md in file_metadata: filename = md['filename'] file_path = data_dir / filename print(f'Preparing to import {str(file_path)}') imp_ctl = Importer(conn, file_path, md) imp_ctl.import_ln_s(OMERO_HOST, OMERO_PORT) print("import done") if imp_ctl.screen: print("it's a screen") imp_ctl.get_plate_ids() print(f"plate ids get! {str(imp_ctl.plate_ids[0])}") imp_ctl.organize_plates() print("plate organized") imp_ctl.annotate_plates() print("plate annotated") else: imp_ctl.get_image_ids() imp_ctl.organize_images() imp_ctl.annotate_images() conn.close() return
def connect_as_user(username): """Establish a connection to OMERO with a given user context. To establish a connection as a specific user without knowing their credential, a two-stage process is required: first the bsae connection is created with an admin user, then this existing connection is switched over to a (non-privileged) user account. Returns the connection in the user's context. """ # establish the base connection with an admin account su_conn = BlitzGateway(SU_USER, SU_PASS, host=HOST, port=PORT) if su_conn.connect() is False: raise RuntimeError('Connection to OMERO failed, check settings!') # now switch to the requested user conn = su_conn.suConn(username) if conn.connect() is False: raise RuntimeError('User switching in OMERO failed, check settings!') log.debug("Successfully connected to OMERO.") return conn
print kv if len(kv) == 2: data.append(kv) elif len(kv) == 1: data.append([kv[0], ""]) print "list data", data to_delete = [] for ann in obj.listAnnotations(ns=namespace): kv = ann.getValue() to_delete.append(ann.id) #for dataset in conn.getObjects("Dataset", ids): suconn = conn.suConn( owner ) #this line has been introduced to allow sysadmin to copy kvpairs on behalf of the owner's image map_ann = omero.gateway.MapAnnotationWrapper( suconn ) #this line tells that the connection to the Map annotation is done by sysadmin but with the name of the owner of the data map_ann.setNs(namespace) map_ann.setValue(data) map_ann.save() obj.linkAnnotation(map_ann) suconn.close( ) #this line is necessary to "close" also the connection as "other user" as the sysadmin is now concluding to operate on behalf of the owner of the image if len(to_delete) > 0: conn.deleteObjects('Annotation', to_delete) # Return some value(s).
def main(md_filepath, user_name, group, admin_user, server, port): # create connection and establish context password = getpass(f'Enter password for {admin_user}: ') su_conn = BlitzGateway(admin_user, password, host=server, port=port) su_conn.connect() conn = su_conn.suConn(user_name, group, 600000) su_conn.close() orphan_ids = get_image_ids(conn) # load and prepare metadata md = load_md(md_filepath) if 'filename' not in md.columns: logging.error('Metadata file missing filename column') return if 'dataset' not in md.columns: logging.error('Metadata file missing dataset column') return if 'project' not in md.columns: logging.error('Metadata file missing project column') return md_json = json.loads(md.to_json(orient='table', index=False)) # loop over metadata, move and annotate matching images processed_filenames = [] for row in md_json['data']: row.pop('OMERO_group', None) # No longer using this field project_name = str(row.pop('project')) dataset_name = str(row.pop('dataset')) filename = row.pop('filename') if filename not in processed_filenames: image_ids = filter_by_filename(conn, orphan_ids, filename) if len(image_ids) > 0: # move image into place, create projects/datasets as necessary project_id = set_or_create_project(conn, project_name) dataset_id = set_or_create_dataset(conn, project_id, dataset_name) link_images_to_dataset(conn, image_ids, dataset_id) print(f'Moved images:{image_ids} to dataset:{dataset_id}') # map annotations ns = CURRENT_MD_NS map_ann_id = multi_post_map_annotation(conn, "Image", image_ids, row, ns) print(f'Created annotation:{map_ann_id}' f' and linked to images:{image_ids}') processed_filenames.append(filename) else: print(f'Image with filename:{filename} not found in orphans') else: print(f'Already processed images with filename:{filename}') conn.close() print('Complete!')
# PASS = '******' # PASS = '******' SU_USER = "******" SU_PASS = "******" try: from localconfig import USER, SU_USER, SU_PASS, MANAGED_REPO except ImportError: print "Using hard-coded configuration values!" su_conn = BlitzGateway(SU_USER, SU_PASS, host=HOST, port=PORT) if su_conn.connect() is False: raise RuntimeError("Connection to OMERO failed, check settings!") conn = su_conn.suConn(USER) if conn.connect() is False: raise RuntimeError("User switching in OMERO failed, check settings!") su_conn = BlitzGateway(SU_USER, SU_PASS, host=HOST, port=PORT) su_conn.connect() conn = su_conn.suConn(USER) conn.connect() # projs = [ x for x in conn.listProjects() ] projs = [x for x in conn.listProjects(eid=conn.getUserId())] for proj in projs: print proj.getName() proj = projs[0]