Created
April 27, 2016 10:53
-
-
Save will-moore/1f8994a12ad9a5608bf7b0b435d86dbc to your computer and use it in GitHub Desktop.
Simple python script for adding Custom Annotations to an object in OMERO
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 | |
conn = BlitzGateway("ben", "ome", host='localhost', port=4064) | |
conn.connect() | |
conn.SERVICE_OPTS.setOmeroGroup('-1') | |
update = conn.getUpdateService() | |
projectId = 1 | |
project = conn.getObject("Project", projectId) | |
groupId = project.getDetails().group.id.val | |
print groupId | |
conn.SERVICE_OPTS.setOmeroGroup(groupId) | |
def linkAnnotation(ann): | |
link = omero.model.ProjectAnnotationLinkI() | |
link.parent = omero.model.ProjectI(projectId, False) | |
link.child = ann | |
update.saveObject(link, conn.SERVICE_OPTS) | |
keyValueData = [["Drug Name", "Monastrol"], | |
["Concentration", "5 mg/ml"]] | |
mapAnn = omero.gateway.MapAnnotationWrapper(conn) | |
mapAnn.setNs("test.custom.map.ann.namespace") | |
mapAnn.setValue(keyValueData) | |
# mapAnn.save() | |
linkAnnotation(mapAnn._obj) | |
l = omero.model.LongAnnotationI() | |
l.longValue = omero.rtypes.rlong(987) | |
linkAnnotation(l) | |
l = omero.model.BooleanAnnotationI() | |
l.boolValue = omero.rtypes.rbool(True) | |
linkAnnotation(l) | |
l = omero.model.XmlAnnotationI() | |
l.textValue = omero.rtypes.rstring("<test>Is this valid xml</test>") | |
linkAnnotation(l) | |
l = omero.model.DoubleAnnotationI() | |
l.doubleValue = omero.rtypes.rdouble(12345678900000) | |
l.ns = omero.rtypes.rstring("really.really.big.number") | |
linkAnnotation(l) | |
l = omero.model.TermAnnotationI() | |
l.termValue = omero.rtypes.rstring("Metaphase") | |
l.ns = omero.rtypes.rstring("does.anyone.use.term.annotation") | |
linkAnnotation(l) | |
l = omero.model.TimestampAnnotationI() | |
l.timeValue = omero.rtypes.rtime(56348734) | |
linkAnnotation(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment