Created
April 25, 2018 08:16
-
-
Save will-moore/43a7a1440ca43dcaca1b3f3195769836 to your computer and use it in GitHub Desktop.
Grabs a bunch of map annotations from IDR to populate a local OMERO with test data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import omero | |
| from omero.gateway import BlitzGateway | |
| from omero.sys import ParametersI | |
| from omero.rtypes import rint | |
| import requests | |
| USERNAME = "username" | |
| PASSWORD = "secret" | |
| conn = BlitzGateway(USERNAME, PASSWORD, host="localhost", port=4064) | |
| conn.connect() | |
| idr_well_ids = [67137, 67066, 67069, 67070, 67073, 67074, 67075, 67077, 67079, 67080, 67081, 67082, 67084, 67085, 67086, 67089, 67090, 67093, 67094, 67095, 67096, 67097, 67098, 67099, 67105, 67106, 67109, 67110, 67111, 67112, 67113, 67114, 67115, 67116, 67117, 67118, 67119, 67120, 67123, 67124, 67125, 67126, 67127, 67128, 67132, 67133, 67134, 67135, 67138, 67140, 67141, 67143, 67144, 67146, 67147, 67148, 67150, 67154, 67155, 67156] | |
| session = requests.Session() | |
| base_url = "http://idr.openmicroscopy.org/webclient/api/annotations/?type=map" | |
| ns = "openmicroscopy.org/mapr/gene" | |
| # dataset_image_ids = [4406, 4407, 4415, 4416, 4417, 4418, 72484, 72489, 72497, 73397, 73398, 73399, 73400, 73842] | |
| def get_well_image_ids(conn, plate_id, field_id=0): | |
| """Get list of [wellId, imageId] for Plate""" | |
| # conn.SERVICE_OPTS.setOmeroGroup('-1') | |
| query_service = conn.getQueryService() | |
| params = ParametersI() | |
| params.addId(plate_id) | |
| params.add('wsidx', rint(field_id)) | |
| query = "select well.id, img.id "\ | |
| "from Well well "\ | |
| "join well.wellSamples ws "\ | |
| "join ws.image img "\ | |
| "where well.plate.id = :id "\ | |
| "and index(ws) = :wsidx" | |
| p = query_service.projection(query, params, conn.SERVICE_OPTS) | |
| img_ids = [] | |
| for i in p: | |
| well_id = i[0].val | |
| img_id = i[1].val | |
| img_ids.append([well_id, img_id]) | |
| return img_ids | |
| well_img_ids = get_well_image_ids(conn, 103, 0) | |
| print well_img_ids | |
| for idr_id, well_img_id in zip(idr_well_ids, well_img_ids): | |
| url = base_url + "&well=%s" % idr_id | |
| map_anns = session.get(url).json()['annotations'] | |
| for ann in map_anns: | |
| if ann['ns'] == ns: | |
| key_value_data = ann['values'] | |
| map_ann = omero.gateway.MapAnnotationWrapper(conn) | |
| map_ann.setValue(key_value_data) | |
| map_ann.setNs(ns) | |
| map_ann.save() | |
| w = conn.getObject('Well', well_img_id[0]) | |
| w.linkAnnotation(map_ann) | |
| i = conn.getObject('Image', well_img_id[1]) | |
| i.linkAnnotation(map_ann) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment