Пример #1
0
def get_images(gateway, datasets, orphaned=True):
    """Return all image ids and image names for provided dataset ids"""
    browse = gateway.getFacility(BrowseFacility)
    experimenter = gateway.getLoggedInUser()
    ctx = SecurityContext(experimenter.getGroupId())
    images = []
    for dataset_id in datasets:
        ids = ArrayList(1)
        ids.add(Long(dataset_id))
        j = browse.getImagesForDatasets(ctx, ids).iterator()
        while j.hasNext():
            image = j.next()
            images.append({
                'Image Id': String.valueOf(image.getId()),
                'Image Name': image.getName(),
                'Dataset Id': dataset_id,
                'Dataset Name': datasets[dataset_id],
            })
    if orphaned:
        orphans = browse.getOrphanedImages(
            ctx, ctx.getExperimenter())  # need to pass user id (long)
        for image in orphans:
            images.append({
                'Image Id': String.valueOf(image.getId()),
                'Image Name': image.getName(),
                'Dataset Id': -1,
                'Dataset Name': '<Orphaned>',
            })
    return images
Пример #2
0
def uploadImage(path, gateway):
    
    user = gateway.getLoggedInUser()
        ctx = SecurityContext(user.getGroupId())
        sessionKey = gateway.getSessionId(user)
        
        config = ImportConfig()
        
        config.email.set("")
        config.sendFiles.set('true')
        config.sendReport.set('false')
        config.contOnError.set('false')
        config.debug.set('false')
        config.hostname.set(HOST)
        config.sessionKey.set(sessionKey)
        config.targetClass.set("omero.model.Dataset")
        config.targetId.set(datasetId)
        
        loci.common.DebugTools.enableLogging("DEBUG")
        
        store = config.createStore()
        reader = OMEROWrapper(config)
        
        library = ImportLibrary(store,reader)
        errorHandler = ErrorHandler(config)
        
        library.addObserver(LoggingImportMonitor())
        candidates = ImportCandidates (reader, path, errorHandler)
        reader.setMetadataOptions(DefaultMetadataOptions(MetadataLevel.ALL))
        success = library.importCandidates(config, candidates)
        return success
Пример #3
0
def upload_image(gateway, path, host, dataset_id):

    user = gateway.getLoggedInUser()
    ctx = SecurityContext(user.getGroupId())
    session_key = gateway.getSessionId(user)
    
    str2d = Array.newInstance(String,[1])
    str2d[0] = path
    
    config = ImportConfig()

    config.email.set("")
    config.sendFiles.set('true')
    config.sendReport.set('false')
    config.contOnError.set('false')
    config.debug.set('false')
    config.hostname.set(host)
    config.sessionKey.set(session_key)
    config.targetClass.set("omero.model.Dataset")
    config.targetId.set(dataset_id)

    loci.common.DebugTools.enableLogging("DEBUG")

    store = config.createStore()
    reader = OMEROWrapper(config)

    library = ImportLibrary(store,reader)
    error_handler = ErrorHandler(config)

    library.addObserver(LoggingImportMonitor())
    candidates = ImportCandidates(reader, str2d, error_handler)
    reader.setMetadataOptions(DefaultMetadataOptions(MetadataLevel.ALL))
    print('Importing image: ' + str2d[0])
    success = library.importCandidates(config, candidates)
    return success
Пример #4
0
def create_table(gatway):
    currentGroupId = gateway.getLoggedInUser().getGroupId()
    ctx = SecurityContext(currentGroupId)

    fac = gateway.getFacility(TablesFacility)
    table_name = "TablesDemo:%s" % str(random.randint(1, 1000))
    col1 = omero.grid.LongColumn('Uid', 'testLong', [])
    col2 = omero.grid.StringColumn('MyStringColumnInit', '', 64, [])
    columns = [col1, col2]

    resources = gateway.getSharedResources(ctx)
    repository_id = resources.repositories().descriptions[0].getId().getValue()
    table = resources.newTable(repository_id, table_name)
    table.initialize(columns)

    # Add data to the table
    ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    strings = [
        "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
        "ten"
    ]
    data1 = omero.grid.LongColumn('Uid', 'test Long', ids)
    data2 = omero.grid.StringColumn('MyStringColumn', '', 64, strings)
    data = [data1, data2]
    table.addData(data)
    table.close()

    return table
Пример #5
0
def download_image(gateway, image_id, path):
    "Download the files composing the image"

    transfer = gateway.getFacility(TransferFacility)
    user = gateway.getLoggedInUser()
    ctx = SecurityContext(user.getGroupId())
    return transfer.downloadImage(ctx, path, Long(image_id))
Пример #6
0
def _get_images_browser(gateway, dataset_id, group_id):
    browse = gateway.getFacility(BrowseFacility)
    user = gateway.getLoggedInUser()
    ctx = SecurityContext(group_id)
    ids = ArrayList(1)
    val = Long(dataset_id)
    ids.add(val)
    images = browse.getImagesForDatasets(ctx, ids)
    return images.iterator()
Пример #7
0
def getImageIds(gateway, datasetId):
    
    browse = gateway.getFacility(BrowseFacility)
        user = gateway.getLoggedInUser()
        ctx = SecurityContext(user.getGroupId())
        ids = ArrayList(1)
        val = Long(datasetId)
        ids.add(val)
        images = browse.getImagesForDatasets(ctx, ids)
        j = images.iterator()
        imageIds = []
        while j.hasNext():
            image = j.next()
                imageIds.append(String.valueOf(image.getId()))
Пример #8
0
def get_groups(gateway):
    """Retrieves the groups for the user"""
    currentGroupId = gateway.getLoggedInUser().getGroupId()
    ctx = SecurityContext(currentGroupId)
    adminService = gateway.getAdminService(ctx, True)
    uid = adminService.lookupExperimenter(username)
    groups = []
    for g in sorted(adminService.getMemberOfGroupIds(uid)):
        groupname = str(adminService.getGroup(g).getName().getValue())
        groups.append({
            'Id': g,
            'Name': groupname,
        })
        if g == currentGroupId:
            currentGroup = groupname
    return groups, currentGroup
Пример #9
0
def add_image_tag(gateway, tag_text, image_id, description=None):
    """Adds a tag to an image"""
    data_manager = gateway.getFacility(DataManagerFacility)
    user = gateway.getLoggedInUser()
    ctx = SecurityContext(user.getGroupId())

    # Arrange the data
    tag_data = TagAnnotationData(tag_text)
    if description:
        tag_data.setTagDescription(description)

    # Link the data to the image
    link = ImageAnnotationLinkI()
    link.setChild(tag_data.asAnnotation())
    link.setParent(ImageI(image_id, False))

    return data_manager.saveAndReturnObject(ctx, link)
Пример #10
0
def get_image_ids(gateway, dataset_id):
	"""Return all image ids for given dataset"""
	browse = gateway.getFacility(BrowseFacility)
	experimenter = gateway.getLoggedInUser()
	ctx = SecurityContext(experimenter.getGroupId())
	images = []
	ids = ArrayList(1)
	ids.add(Long(dataset_id))
	j = browse.getImagesForDatasets(ctx, ids).iterator()
	while j.hasNext():
	    image = j.next()
	    images.append({
	        'Image Id': String.valueOf(image.getId()),
	        'Image Name': image.getName(),
	        'Dataset Id': dataset_id,
	    })
	return images
Пример #11
0
def get_projects_datasets(gateway):
    """Retrieves the projects and datasets for the user"""
    results = []
    proj_dict = {}
    ds_dict = {}
    groupid = gateway.getLoggedInUser().getGroupId()
    ctx = SecurityContext(groupid)
    containerService = gateway.getPojosService(ctx)

    # Read datasets in all projects
    projects = containerService.loadContainerHierarchy(
        "Project", None,
        None)  # allowed: 'Project", "Dataset", "Screen", "Plate"
    for p in projects:  # omero.model.ProjectI
        p_id = p.getId().getValue()
        p_name = p.getName().getValue()
        proj_dict[p_id] = p_name
        for d in p.linkedDatasetList():
            ds_id = d.getId().getValue()
            ds_name = d.getName().getValue()
            results.append({
                'Project Id': p_id,
                'Project Name': p_name,
                'Dataset Id': ds_id,
                'Dataset Name': ds_name,
                'Group Id': groupid,
            })
            ds_dict[ds_id] = ds_name

    # read datasets not linked to any project
    ds_in_proj = [p['Dataset Id'] for p in results]
    ds = containerService.loadContainerHierarchy("Dataset", None, None)
    for d in ds:  # omero.model.ProjectI
        ds_id = d.getId().getValue()
        ds_name = d.getName().getValue()
        if ds_id not in ds_in_proj:
            ds_dict[ds_id] = ds_name
            results.append({
                'Project Id': '--',
                'Project Name': '--',
                'Dataset Id': ds_id,
                'Dataset Name': ds_name,
                'Group Id': groupid,
            })
    return results, proj_dict, ds_dict
Пример #12
0
def _add_table(gateway, table_parameters, table_data, table_name, target):
    """Appends a table to a target object"""
    # Verify consistency of tables
    if len(table_parameters) != len(table_data):
        raise Exception('Table parameters and data do not have the same length')

    columns = []
    for i in range(len(table_parameters)):
        columns.append(TableDataColumn(table_parameters[i][0],
                                       i,
                                       table_parameters[i][1]))
        if len(table_parameters[i]) == 3:
            columns[-1].setDescription(table_parameters[i][2])

    table = TableData(columns, table_data)

    facility = gateway.getFacility(TablesFacility)
    user = gateway.getLoggedInUser()
    ctx = SecurityContext(user.getGroupId())

    facility.addTable(ctx, target, table_name, table)
Пример #13
0
def _get_available_tables(gateway, target):
    facility = gateway.getFacility(TablesFacility)
    user = gateway.getLoggedInUser()
    ctx = SecurityContext(user.getGroupId())

    return facility.getAvailableTables(ctx, target)
Пример #14
0
def _data_manager_generator(gateway, group_id):
    data_manager = gateway.getFacility(DataManagerFacility)
    user = gateway.getLoggedInUser()
    ctx = SecurityContext(group_id)

    return data_manager, ctx
Пример #15
0
    # use the appropriate target DataObject and attach the MapAnnotationData object to it
    if target_type == "Project":
        target_obj = ProjectData(ProjectI(target_id, False))
    elif target_type == "Dataset":
        target_obj = DatasetData(DatasetI(target_id, False))
    elif target_type == "Image":
        target_obj = browse.getImage(ctx, long(target_id))

    table_facility = gateway.getFacility(TablesFacility)
    table_facility.addTable(ctx, target_obj, "Table_from_Fiji", table_data)


# Main code
gateway = connect(group_id, username, password, server, port)
currentGroupId = gateway.getLoggedInUser().getGroupId()
ctx = SecurityContext(currentGroupId)

# 1. Create a Omero Table obkect, upload, and link it to target object
table = create_table(gateway)
link_table_to_object(gateway, table, target_id, target_type)

# 2. Create a ImageJ ResultsTable, convert it into Omero table object, upload and link it to target object
imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif")
IJ.run(imp, "8-bit", "")
# white might be required depending on the version of Fiji
IJ.run(imp, "Auto Threshold", "method=MaxEntropy stack")
IJ.run(imp, "Analyze Particles...",
       "size=10-Infinity pixel display clear add stack")
IJ.run(
    "Set Measurements...", "area mean standard modal min centroid center \
        perimeter bounding fit shape feret's integrated median skewness \