Last active
May 3, 2018 12:10
-
-
Save rgozim/9fe75d75bd888a050511795205a7cf9b to your computer and use it in GitHub Desktop.
This file contains 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 = "root" | |
PASSWORD = "omero" | |
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] | |
imageIds = range(1, 780) | |
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 imageIds | |
for idr_id, img_id in zip(idr_well_ids, imageIds): | |
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', img_id) | |
i.linkAnnotation(map_ann) |
This file contains 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