コード例 #1
0
ファイル: test_tree.py プロジェクト: sbesson/omero-web
    def test_marshal_plate(self, mock_conn, owner_permissions):
        row = [rlong(1), rstring("name"), rlong(1), owner_permissions, 2]
        expected = {
            "id": 1,
            "ownerId": 1,
            "name": "name",
            "permsCss":
            "canEdit canAnnotate canLink canDelete canChgrp isOwned",
            "childCount": 2,
        }

        marshaled = _marshal_plate(mock_conn, row)
        assert marshaled == expected
コード例 #2
0
    def test_marshal_plate(self, mock_conn, owner_permissions):
        row = [rlong(1L), rstring('name'), rlong(1L), owner_permissions, 2]
        expected = {
            'id': 1L,
            'ownerId': 1L,
            'name': 'name',
            'permsCss':
            'canEdit canAnnotate canLink canDelete isOwned canChgrp',
            'childCount': 2
        }

        marshaled = _marshal_plate(mock_conn, row)
        assert marshaled == expected
コード例 #3
0
ファイル: tree.py プロジェクト: sbesson/omero-mapr
def marshal_plates(conn,
                   screen_id,
                   mapann_value,
                   query=False,
                   mapann_ns=[],
                   mapann_names=[],
                   group_id=-1,
                   experimenter_id=-1,
                   page=1,
                   limit=settings.PAGE):
    ''' Marshals plates

        @param conn OMERO gateway.
        @type conn L{omero.gateway.BlitzGateway}
        @param screen_id The Screen ID to filter by.
        @type screen_id L{long}
        @param mapann_value The Map annotation value to filter by.
        @type mapann_value L{string}
        @param query Flag allowing to search for value patters.
        @type query L{boolean}
        @param mapann_ns The Map annotation namespace to filter by.
        @type mapann_ns L{string}
        @param mapann_names The Map annotation names to filter by.
        @type mapann_names L{string}
        @param group_id The Group ID to filter by or -1 for all groups,
        defaults to -1
        @type group_id L{long}
        @param experimenter_id The Experimenter (user) ID to filter by
        or -1 for all experimenters
        @type experimenter_id L{long}
        @param page Page number of results to get. `None` or 0 for no paging
        defaults to 1
        @type page L{long}
        @param limit The limit of results per page to get
        defaults to the value set in settings.PAGE
        @type page L{long}
    '''

    plates = []

    # early exit
    if screen_id is None or not isinstance(screen_id, long):
        return plates

    params, where_clause = _set_parameters(mapann_ns=mapann_ns,
                                           mapann_names=mapann_names,
                                           query=query,
                                           mapann_value=mapann_value,
                                           params=None,
                                           experimenter_id=experimenter_id,
                                           page=page,
                                           limit=limit)

    params.addLong("sid", screen_id)
    where_clause.append('screen.id = :sid')

    service_opts = deepcopy(conn.SERVICE_OPTS)

    # Set the desired group context
    if group_id is None:
        group_id = -1
    service_opts.setOmeroGroup(group_id)

    qs = conn.getQueryService()

    # TODO: Joining wellsample should be enough since wells are annotated
    # with the same annotations as images. In the future if that changes,
    # query has to be restored to:
    # -     count(distinct i.id) as childCount)
    # - from ImageAnnotationLink ial join ial.child a join a.mapValue mv
    # -     join ial.parent i join i.wellSamples ws join ws.well w
    # -     join w.plate plate join plate.screenLinks sl join sl.parent screen
    q = """
        select new map(mv.value as value,
            plate.id as id,
            plate.name as name,
            plate.details.owner.id as ownerId,
            plate as plate_details_permissions,
            count(distinct ws.id) as childCount)
        from WellAnnotationLink wal join wal.child a join a.mapValue mv
            join wal.parent w join w.wellSamples ws
            join w.plate plate join plate.screenLinks sl
            join sl.parent screen
        where %s
        group by plate.id, plate.name, mv.value
        order by lower(plate.name), plate.id, mv.value
        """ % (" and ".join(where_clause))

    logger.debug("HQL QUERY: %s\nPARAMS: %r" % (q, params))
    for e in qs.projection(q, params, service_opts):
        e = unwrap(e)
        v = e[0]['value']
        e = [
            e[0]['id'], e[0]['name'], e[0]['ownerId'],
            e[0]['plate_details_permissions'], e[0]['childCount']
        ]
        mp = _marshal_plate(conn, e[0:5])
        extra = {'extra': {'node': 'plate'}}
        if mapann_value is not None:
            extra['extra']['value'] = v
        mp.update(extra)
        plates.append(mp)

    return plates
コード例 #4
0
ファイル: tree.py プロジェクト: sbesson/omero-mapr
def marshal_datasets(conn,
                     project_id,
                     mapann_value,
                     query=False,
                     mapann_ns=[],
                     mapann_names=[],
                     group_id=-1,
                     experimenter_id=-1,
                     page=1,
                     limit=settings.PAGE):
    ''' Marshals plates

        @param conn OMERO gateway.
        @type conn L{omero.gateway.BlitzGateway}
        @param project_id The Project ID to filter by.
        @type project_id L{long}
        @param mapann_value The Map annotation value to filter by.
        @type mapann_value L{string}
        @param query Flag allowing to search for value patters.
        @type query L{boolean}
        @param mapann_ns The Map annotation namespace to filter by.
        @type mapann_ns L{string}
        @param mapann_names The Map annotation names to filter by.
        @type mapann_names L{string}
        @param group_id The Group ID to filter by or -1 for all groups,
        defaults to -1
        @type group_id L{long}
        @param experimenter_id The Experimenter (user) ID to filter by
        or -1 for all experimenters
        @type experimenter_id L{long}
        @param page Page number of results to get. `None` or 0 for no paging
        defaults to 1
        @type page L{long}
        @param limit The limit of results per page to get
        defaults to the value set in settings.PAGE
        @type page L{long}
    '''
    datasets = []

    # early exit
    if project_id is None or not isinstance(project_id, long):
        return datasets

    params, where_clause = _set_parameters(mapann_ns=mapann_ns,
                                           mapann_names=mapann_names,
                                           query=query,
                                           mapann_value=mapann_value,
                                           params=None,
                                           experimenter_id=experimenter_id,
                                           page=page,
                                           limit=limit)

    params.addLong("pid", project_id)
    where_clause.append('project.id = :pid')

    service_opts = deepcopy(conn.SERVICE_OPTS)

    # Set the desired group context
    if group_id is None:
        group_id = -1
    service_opts.setOmeroGroup(group_id)

    qs = conn.getQueryService()
    q = """
        select new map(mv.value as value,
            dataset.id as id,
            dataset.name as name,
            dataset.details.owner.id as ownerId,
            dataset as dataset_details_permissions,
            count(distinct i.id) as childCount)
        from ImageAnnotationLink ial join ial.child a join a.mapValue mv
            join ial.parent i join i.datasetLinks dil
            join dil.parent dataset join dataset.projectLinks pl
            join pl.parent project
        where %s
        group by dataset.id, dataset.name, mv.value
        order by lower(dataset.name), dataset.id, mv.value
        """ % (" and ".join(where_clause))

    logger.debug("HQL QUERY: %s\nPARAMS: %r" % (q, params))
    for e in qs.projection(q, params, service_opts):
        e = unwrap(e)
        v = e[0]['value']
        e = [
            e[0]['id'], e[0]['name'], e[0]['ownerId'],
            e[0]['dataset_details_permissions'], e[0]['childCount']
        ]
        mp = _marshal_plate(conn, e[0:5])
        extra = {'extra': {'node': 'dataset'}}
        if mapann_value is not None:
            extra['extra']['value'] = v
        mp.update(extra)
        datasets.append(mp)

    return datasets
コード例 #5
0
ファイル: test_tree.py プロジェクト: kok26th/openmicroscopy
        }

        marshaled = _marshal_dataset(mock_conn, row)
        assert marshaled == expected

    def test_marshal_plate(self, mock_conn, owner_permissions):
        row = [rlong(1L), rstring("name"), rlong(1L), owner_permissions, 2]
        expected = {
            "id": 1L,
            "ownerId": 1L,
            "name": "name",
            "permsCss": "canEdit canAnnotate canLink canDelete isOwned canChgrp",
            "childCount": 2,
        }

        marshaled = _marshal_plate(mock_conn, row)
        assert marshaled == expected

    def test_marshal_plate_not_owner(self, mock_conn, owner_permissions):
        row = [rlong(1L), rstring("name"), rlong(2L), owner_permissions, 2]
        expected = {
            "id": 1L,
            "ownerId": 2L,
            "name": "name",
            "permsCss": "canEdit canAnnotate canLink canDelete",
            "childCount": 2,
        }

        marshaled = _marshal_plate(mock_conn, row)
        print marshaled
        print expected
コード例 #6
0
def marshal_plates(conn, screen_id,
                   mapann_value, query=False,
                   mapann_ns=[], mapann_names=[],
                   group_id=-1, experimenter_id=-1,
                   page=1, limit=settings.PAGE):

    ''' Marshals plates

        @param conn OMERO gateway.
        @type conn L{omero.gateway.BlitzGateway}
        @param screen_id The Screen ID to filter by.
        @type screen_id L{long}
        @param mapann_value The Map annotation value to filter by.
        @type mapann_value L{string}
        @param query Flag allowing to search for value patters.
        @type query L{boolean}
        @param mapann_ns The Map annotation namespace to filter by.
        @type mapann_ns L{string}
        @param mapann_names The Map annotation names to filter by.
        @type mapann_names L{string}
        @param group_id The Group ID to filter by or -1 for all groups,
        defaults to -1
        @type group_id L{long}
        @param experimenter_id The Experimenter (user) ID to filter by
        or -1 for all experimenters
        @type experimenter_id L{long}
        @param page Page number of results to get. `None` or 0 for no paging
        defaults to 1
        @type page L{long}
        @param limit The limit of results per page to get
        defaults to the value set in settings.PAGE
        @type page L{long}
    '''

    plates = []

    # early exit
    if screen_id is None or not isinstance(screen_id, long):
        return plates

    params, where_clause = _set_parameters(
        mapann_ns=mapann_ns, mapann_names=mapann_names,
        query=query, mapann_value=mapann_value,
        params=None, experimenter_id=experimenter_id,
        page=page, limit=limit)

    params.addLong("sid", screen_id)
    where_clause.append('screen.id = :sid')

    service_opts = deepcopy(conn.SERVICE_OPTS)

    # Set the desired group context
    if group_id is None:
        group_id = -1
    service_opts.setOmeroGroup(group_id)

    qs = conn.getQueryService()

    # TODO: Joining wellsample should be enough since wells are annotated
    # with the same annotations as images. In the future if that changes,
    # query has to be restored to:
    # -     count(distinct i.id) as childCount)
    # - from ImageAnnotationLink ial join ial.child a join a.mapValue mv
    # -     join ial.parent i join i.wellSamples ws join ws.well w
    # -     join w.plate plate join plate.screenLinks sl join sl.parent screen
    q = """
        select new map(mv.value as value,
            plate.id as id,
            plate.name as name,
            plate.details.owner.id as ownerId,
            plate as plate_details_permissions,
            count(distinct ws.id) as childCount)
        from WellAnnotationLink wal join wal.child a join a.mapValue mv
            join wal.parent w join w.wellSamples ws
            join w.plate plate join plate.screenLinks sl
            join sl.parent screen
        where %s
        group by plate.id, plate.name, mv.value
        order by lower(plate.name), plate.id, mv.value
        """ % (" and ".join(where_clause))

    logger.debug("HQL QUERY: %s\nPARAMS: %r" % (q, params))
    for e in qs.projection(q, params, service_opts):
        e = unwrap(e)
        v = e[0]['value']
        e = [e[0]['id'],
             e[0]['name'],
             e[0]['ownerId'],
             e[0]['plate_details_permissions'],
             e[0]['childCount']]
        mp = _marshal_plate(conn, e[0:5])
        extra = {'extra': {'node': 'plate'}}
        if mapann_value is not None:
            extra['extra']['value'] = v
        mp.update(extra)
        plates.append(mp)

    return plates
コード例 #7
0
def marshal_datasets(conn, project_id,
                     mapann_value, query=False,
                     mapann_ns=[], mapann_names=[],
                     group_id=-1, experimenter_id=-1,
                     page=1, limit=settings.PAGE):

    ''' Marshals plates

        @param conn OMERO gateway.
        @type conn L{omero.gateway.BlitzGateway}
        @param project_id The Project ID to filter by.
        @type project_id L{long}
        @param mapann_value The Map annotation value to filter by.
        @type mapann_value L{string}
        @param query Flag allowing to search for value patters.
        @type query L{boolean}
        @param mapann_ns The Map annotation namespace to filter by.
        @type mapann_ns L{string}
        @param mapann_names The Map annotation names to filter by.
        @type mapann_names L{string}
        @param group_id The Group ID to filter by or -1 for all groups,
        defaults to -1
        @type group_id L{long}
        @param experimenter_id The Experimenter (user) ID to filter by
        or -1 for all experimenters
        @type experimenter_id L{long}
        @param page Page number of results to get. `None` or 0 for no paging
        defaults to 1
        @type page L{long}
        @param limit The limit of results per page to get
        defaults to the value set in settings.PAGE
        @type page L{long}
    '''
    datasets = []

    # early exit
    if project_id is None or not isinstance(project_id, long):
        return datasets

    params, where_clause = _set_parameters(
        mapann_ns=mapann_ns, mapann_names=mapann_names,
        query=query, mapann_value=mapann_value,
        params=None, experimenter_id=experimenter_id,
        page=page, limit=limit)

    params.addLong("pid", project_id)
    where_clause.append('project.id = :pid')

    service_opts = deepcopy(conn.SERVICE_OPTS)

    # Set the desired group context
    if group_id is None:
        group_id = -1
    service_opts.setOmeroGroup(group_id)

    qs = conn.getQueryService()
    q = """
        select new map(mv.value as value,
            dataset.id as id,
            dataset.name as name,
            dataset.details.owner.id as ownerId,
            dataset as dataset_details_permissions,
            count(distinct i.id) as childCount)
        from ImageAnnotationLink ial join ial.child a join a.mapValue mv
            join ial.parent i join i.datasetLinks dil
            join dil.parent dataset join dataset.projectLinks pl
            join pl.parent project
        where %s
        group by dataset.id, dataset.name, mv.value
        order by lower(dataset.name), dataset.id, mv.value
        """ % (" and ".join(where_clause))

    logger.debug("HQL QUERY: %s\nPARAMS: %r" % (q, params))
    for e in qs.projection(q, params, service_opts):
        e = unwrap(e)
        v = e[0]['value']
        e = [e[0]['id'],
             e[0]['name'],
             e[0]['ownerId'],
             e[0]['dataset_details_permissions'],
             e[0]['childCount']]
        mp = _marshal_plate(conn, e[0:5])
        extra = {'extra': {'node': 'dataset'}}
        if mapann_value is not None:
            extra['extra']['value'] = v
        mp.update(extra)
        datasets.append(mp)

    return datasets
コード例 #8
0
ファイル: tree.py プロジェクト: IDR/omero-mapr
def marshal_plates(conn,
                   screen_id,
                   mapann_value,
                   mapann_ns=[],
                   mapann_names=[],
                   group_id=-1,
                   experimenter_id=-1,
                   page=1,
                   limit=settings.PAGE):
    ''' Marshals plates

        @param conn OMERO gateway.
        @type conn L{omero.gateway.BlitzGateway}
        @param screen_id The Screen ID to filter by.
        @type screen_id L{long}
        @param mapann_value The Map annotation value to filter by.
        @type mapann_value L{string}
        @param mapann_names The Map annotation names to filter by.
        @type mapann_names L{string}
        @param group_id The Group ID to filter by or -1 for all groups,
        defaults to -1
        @type group_id L{long}
        @param experimenter_id The Experimenter (user) ID to filter by
        or -1 for all experimenters
        @type experimenter_id L{long}
        @param page Page number of results to get. `None` or 0 for no paging
        defaults to 1
        @type page L{long}
        @param limit The limit of results per page to get
        defaults to the value set in settings.PAGE
        @type page L{long}
    '''
    plates = []
    params, where_clause = _set_parameters(mapann_ns=mapann_ns,
                                           mapann_names=mapann_names,
                                           mapann_query=None,
                                           mapann_value=mapann_value,
                                           params=None,
                                           experimenter_id=experimenter_id,
                                           page=page,
                                           limit=limit)

    params.addLong("sid", screen_id)
    where_clause.append('screen.id = :sid')

    service_opts = deepcopy(conn.SERVICE_OPTS)

    # Set the desired group context
    if group_id is None:
        group_id = -1
    service_opts.setOmeroGroup(group_id)

    qs = conn.getQueryService()
    q = """
        select new map(plate.id as id,
               plate.name as name,
               plate.details.owner.id as ownerId,
               plate as plate_details_permissions,
               count(distinct i.id) as childCount)
        from ImageAnnotationLink ial join ial.child a join a.mapValue mv
             join ial.parent i join i.wellSamples ws join ws.well w
             join w.plate plate join plate.screenLinks sl join
             sl.parent screen
        where %s
        group by plate.id, plate.name
        order by lower(plate.name), plate.id
        """ % (" and ".join(where_clause))

    logger.debug("HQL QUERY: %s\nPARAMS: %r" % (q, params))
    for e in qs.projection(q, params, service_opts):
        e = unwrap(e)
        e = [
            e[0]["id"], e[0]["name"], e[0]["ownerId"],
            e[0]["plate_details_permissions"], e[0]["childCount"]
        ]
        mp = _marshal_plate(conn, e[0:5])
        mp.update({'extra': {'value': mapann_value, 'node': 'plate'}})
        plates.append(mp)

    return plates