Exemplo n.º 1
0
def get_script(request, script_name, conn):
    """Return a JS function to filter images by various params."""
    dataset_id = request.GET.get('dataset')
    plate_id = request.GET.get('plate')
    field_id = request.GET.get('field')
    image_ids = request.GET.getlist('image')
    if plate_id and field_id:
        img_ids = get_image_ids(conn, plate_id, field_id)
    elif dataset_id:
        objects = conn.getObjects('Image', opts={'dataset': dataset_id})
        img_ids = [i.id for i in objects]
    else:
        img_ids = [long(i) for i in image_ids]
    query_service = conn.getQueryService()

    if script_name == "ROI_count":
        # Want to get ROI count for images in plate

        # Get ROI counts
        params = ParametersI()
        params.addIds(img_ids)
        query = "select roi.image.id, count(roi.id) from Roi roi "\
                "where roi.image.id in (:ids) group by roi.image"
        p = query_service.projection(query, params, conn.SERVICE_OPTS)
        roi_counts = {}
        for i in p:
            roi_counts[i[0].val] = i[1].val
        min_count = min(roi_counts.values())
        max_count = max(roi_counts.values())

        # Return a JS function that will be passed an object
        # e.g. {'type': 'Image', 'id': 1}
        # and should return true or false
        f = """(function filter(data, params) {
            var roi_counts = %s;
            if (isNaN(params.count) || params.count == '') return true;
            if (params.operator === '=')
                return roi_counts[data.id] == params.count;
            if (params.operator === '<')
                return roi_counts[data.id] < params.count;
            if (params.operator === '>')
                return roi_counts[data.id] > params.count;
        })
        """ % json.dumps(roi_counts)

        filter_params = [
            {'name': 'operator',
             'type': 'text',
             'values': ['>', '=', '<'],
             'default': '>'},
            {'name': 'count',
             'type': 'number',
             'default': '',
             'title': '%s-%s' % (min_count, max_count)}
        ]
        return JsonResponse(
            {
                'f': f,
                'params': filter_params,
            })
Exemplo n.º 2
0
def get_data(request, data_name, conn):
    """Return data for images in a Project, Dataset or Plate."""
    project_id = request.GET.get('project')
    dataset_id = request.GET.get('dataset')
    plate_id = request.GET.get('plate')
    field_id = request.GET.get('field')
    if project_id:
        img_ids = get_project_image_ids(conn, project_id)
    elif dataset_id:
        objects = conn.getObjects('Image', opts={'dataset': dataset_id})
        img_ids = [i.id for i in objects]
    elif plate_id and field_id:
        img_ids = get_image_ids(conn, plate_id, field_id)
    else:
        img_ids = request.GET.getlist('image')
    query_service = conn.getQueryService()

    if data_name == "ROI_stats_max_size":
        if plate_id:
            ns = "roi.pixel.intensities.summary"
            return get_image_map_annotations(conn, plate_id, 0, ns,
                                             "Max Points")

    if data_name == "ROI_count":
        # Want to get ROI count for images
        params = ParametersI()
        # Include "-1" so that if we have no Image IDs that the query does
        # not fail.  It will not match anything.
        params.addIds([-1] + img_ids)
        query = "select roi.image.id, count(roi.id) from Roi roi "\
                "where roi.image.id in (:ids) group by roi.image"
        p = query_service.projection(query, params, conn.SERVICE_OPTS)
        roi_counts = {}
        for i in img_ids:
            # Add placeholder 0 for all images
            roi_counts[i] = 0
        for i in p:
            roi_counts[i[0].val] = i[1].val
        return roi_counts

    if data_name == "sizeT":
        # Want to get sizeT for images
        params = ParametersI()
        # Include "-1" so that if we have no Image IDs that the query does
        # not fail.  It will not match anything.
        params.addIds([-1] + img_ids)
        query = "select pixels.image.id, pixels.sizeT from Pixels pixels "\
                "where pixels.image.id in (:ids)"
        p = query_service.projection(query, params, conn.SERVICE_OPTS)
        size_t = {}
        for i in p:
            size_t[i[0].val] = i[1].val
        return size_t
Exemplo n.º 3
0
def get_data(request, data_name, conn):
    """Return data for images in a Dataset or Plate."""
    dataset_id = request.GET.get('dataset')
    plate_id = request.GET.get('plate')
    field_id = request.GET.get('field')
    if plate_id and field_id:
        img_ids = get_image_ids(conn, plate_id, field_id)
    elif dataset_id:
        objects = conn.getObjects('Image', opts={'dataset': dataset_id})
        img_ids = [i.id for i in objects]
    query_service = conn.getQueryService()

    if data_name == "ROI_stats_max_size":
        if plate_id:
            ns = "roi.pixel.intensities.summary"
            return get_image_map_annotations(conn, plate_id, 0, ns,
                                             "Max Points")

    if data_name == "ROI_count":
        # Want to get ROI count for images
        params = ParametersI()
        params.addIds(img_ids)
        query = "select roi.image.id, count(roi.id) from Roi roi "\
                "where roi.image.id in (:ids) group by roi.image"
        p = query_service.projection(query, params, conn.SERVICE_OPTS)
        roi_counts = {}
        for i in p:
            roi_counts[i[0].val] = i[1].val
        return roi_counts

    if data_name == "sizeT":
        # Want to get sizeT for images
        params = ParametersI()
        params.addIds(img_ids)
        query = "select pixels.image.id, pixels.sizeT from Pixels pixels "\
                "where pixels.image.id in (:ids)"
        p = query_service.projection(query, params, conn.SERVICE_OPTS)
        size_t = {}
        for i in p:
            size_t[i[0].val] = i[1].val
        return size_t
Exemplo n.º 4
0
def get_image_map_annotations(conn, plate_id, field_id, ns, key=None):
    """Get image IDs for images in Plate"""
    conn.SERVICE_OPTS.setOmeroGroup('-1')
    query_service = conn.getQueryService()
    iids = get_image_ids(conn, plate_id, field_id)
    params = ParametersI()
    params.addIds(iids)
    query = """select oal from ImageAnnotationLink as oal
            join fetch oal.details.owner
            left outer join fetch oal.child as ch
            left outer join fetch oal.parent as pa
            where pa.id in (:ids)
            and ch.ns='%s'""" % ns
    links = query_service.findAllByQuery(query, params, conn.SERVICE_OPTS)
    if key is None:
        return links
    map_values = {}
    for l in links:
        for kv in l.child.getMapValue():
            if key == kv.name:
                map_values[l.parent.id.val] = long(kv.value)
    return map_values