Skip to content

Instantly share code, notes, and snippets.

@ximenesuk
Last active October 6, 2015 19:17
Show Gist options
  • Save ximenesuk/3040561 to your computer and use it in GitHub Desktop.
Save ximenesuk/3040561 to your computer and use it in GitHub Desktop.
Create a set of realistic users, groups, projects, datasets and tags for movie making.
from omero.gateway import BlitzGateway
import omero
from omero.rtypes import rstring
from omero_model_ProjectI import ProjectI
from omero_model_DatasetI import DatasetI
from omero_model_ProjectDatasetLinkI import ProjectDatasetLinkI
from omero_model_ExperimenterI import ExperimenterI
from omero_model_ExperimenterGroupI import ExperimenterGroupI
from omero_model_PermissionsI import PermissionsI
from omero_model_TagAnnotationI import TagAnnotationI
from omero_model_AnnotationAnnotationLinkI import AnnotationAnnotationLinkI
rootpassw = "omero"
# set to actual host before use
host='localhost'
conn = BlitzGateway('root', rootpassw, host=host)
conn.connect()
admin = conn.getAdminService()
uuid = admin.getEventContext().sessionUuid
uuid = "" # for real
#uuid = "_" # for testing the script itself
userpassw = "ome"
passw = rstring(userpassw)
emailsuff = "@example.com"
# Define some groups, users, projects, datasets and tags.
groups = {
"g1" : {"name":"Nevis Group (Private)", "perms":"rw----"},
"g2" : {"name":"Nevis Group (Collab)", "perms":"rwra--"},
"g3" : {"name":"Skye Lab", "perms":"rw----"},
"g4" : {"name":"Skye Teaching Lab", "perms":"rwr---"}
}
users = {
"u1" : {"name":"ben", "first":"Ben", "last":"Nevis", "groups":["g1","g2"], "owner":["g1","g2"], "admin":True},
"u2" : {"name":"isla", "first":"Isla", "last":"Skye", "groups":["g3","g4"], "owner":["g3","g4"], "admin":False},
"u3" : {"name":"glen", "first":"Glen", "last":"Coe", "groups":["g1","g2","g4"], "owner":[], "admin":False},
"u4" : {"name":"eileen", "first":"Eileen", "last":"Donan", "groups":["g1","g2","g4"], "owner":[], "admin":False},
"u5" : {"name":"benj", "first":"Ben", "last":"Becula", "groups":["g3","g4"], "owner":["g4"], "admin":False},
"u6" : {"name":"kay", "first":"Kay", "last":"Prath", "groups":["g3","g4"], "owner":[], "admin":False},
"u7" : {"name":"kyle", "first":"Kyle", "last":"Lochalsh", "groups":["g3"], "owner":[], "admin":False}
}
projects = {
"p1" : {"name":"Analysis MCAK - GFP - MCAK cell line", "user":"u1", "group":"g1",
"datasets":["201126 - siCTL_LPM_M_total", "201126 - siHP1b_LPM_M_total", "201226 - siHP1a_LPM_M_total"]},
"p2" : {"name":"Analysis_siAllKyotoWT_M", "user":"u1", "group":"g2",
"datasets":["siAll_Exp1_LPM_M"]},
"p3" : {"name":"Bod1", "user":"u2", "group":"g3",
"datasets":["080506_ColdStable","2010-12-21_Bod1_cul3_KLHL22"]},
"p4" : {"name":"DYRK1A_fragments", "user":"u2", "group":"g3",
"datasets":["090120", "090121", "090122"]},
"p5" : {"name":"Embryos", "user":"u3", "group":"g1",
"datasets":[]},
"p6" : {"name":"Flp-ln cell lines", "user":"u3", "group":"g2",
"datasets":["101024-GFP-MCAK_drugs", "101026-sirna"]},
"p7" : {"name":"Centrosomes", "user":"u4", "group":"g1",
"datasets":["Fig 2", "Fig 3", "Fig 4"]},
"p8" : {"name":"Cilia and Centrosomes 201108088", "user":"u4", "group":"g1",
"datasets":["Fig 4"]},
"p9" : {"name":"Disease", "user":"u5", "group":"g3",
"datasets":["201102142-Fig 1", "201102142-Fig 4", "201102142-Fig 6"]},
"p10" : {"name":"Structural analysis reveals features of the spindle checkpoint kinase", "user":"u5", "group":"g3",
"datasets":["201110013-Figure 1", "201110013-Figure 4", "201110013-Figure 6", "201110013-Figure 8"]},
"p11" : {"name":"Timelapse", "user":"u6", "group":"g3",
"datasets":["200908150-Figure 1", "200908150-Figure 5", "200908150-Figure 6", ]},
"p12" : {"name":"Term 1", "user":"u5", "group":"g4",
"datasets":["Week 1", "Week 3", "Week 5", ]},
"p13" : {"name":"Term 2", "user":"u5", "group":"g4",
"datasets":["Week 1", "Week 3", "Week 5", ]},
"p14" : {"name":"Term 3", "user":"u5", "group":"g4",
"datasets":["Week 1", "Week 3", "Week 5", ]},
"p15" : {"name":"Publications", "user":"u1", "group":"g2",
"datasets":["JCB 2010", "Nature 2011", "Cell 2012"]},
"p16" : {"name":"Analysis MCAK - GFP - MCAK cell line", "user":"u5", "group":"g3",
"datasets":["201126 - siCTL_LPM_M_total", "201126 - siHP1b_LPM_M_total", "201226 - siHP1a_LPM_M_total"]},
"p17" : {"name":"Analysis_siAllKyotoWT_M", "user":"u5", "group":"g3",
"datasets":["siAll_Exp1_LPM_M"]}
}
datasets = {
"d1" : {"name":"Importin-beta negatively regulates multiple aspects of mitosis", "user":"u4", "group":"g1"},
"d2" : {"name":"Importin-beta negatively regulates multiple aspects of mitosis", "user":"u6", "group":"g3"}
}
tagsets = {
"t1" : {"user":"u1", "group":"g1", "tagset":"Phases", "tags":["G2phase","Sphase","Interphase","Prometaphase","Metaphase","Anaphase","Telophase","G1phase"]},
"t2" : {"user":"u1", "group":"g1", "tagset":None, "tags":["Mitosis","Meiosis","Cytokinesis","Postmitotic"]},
"t3" : {"user":"u1", "group":"g2", "tagset":"Category", "tags":["Primary","Secondary","Junk"]},
"t4" : {"user":"u2", "group":"g3", "tagset":None, "tags":["Sphase","Interphase","Prometaphase","Metaphase","Anaphase","Telophase"]},
"t5" : {"user":"u2", "group":"g3", "tagset":"Phases", "tags":["Mitosis","Meiosis","Cytokinesis","Postmitotic"]},
"t6" : {"user":"u5", "group":"g4", "tagset":"Assignment", "tags":["1","2","3","5","6"]}
}
# existing groups
userGroup = admin.lookupGroup("user") # all users need to be in 'user' group to do anything!
systemGroup = admin.lookupGroup("system") # admin users need to be in 'system' group
####################
# Create groups
####################
for gr in groups.values():
group = ExperimenterGroupI()
group.name = rstring(gr["name"] + uuid)
group.details.permissions = PermissionsI(gr["perms"])
gr["id"] = admin.createGroup(group)
gr["group"] = admin.getGroup(gr["id"])
####################
# Create users
####################
for usr in users.values():
# Create an experimenter object
user = ExperimenterI()
user.omeName = rstring(usr["name"] + uuid)
user.firstName = rstring(usr["first"])
user.lastName = rstring(usr["last"])
user.email = rstring(usr["name"] + emailsuff)
# Set default to first group
default = groups[usr["groups"][0]]["group"]
# Create list of groups
glist = [userGroup]
for gr in usr["groups"]:
glist.append(groups[gr]["group"])
if usr["admin"]:
glist.append(systemGroup)
# Create experimenter
usr["id"] = admin.createExperimenterWithPassword(user, passw, default, glist)
usr["user"] = admin.getExperimenter(usr["id"])
# Make owner
for o in usr["owner"]:
admin.setGroupOwner(groups[o]["group"], usr["user"])
conn.seppuku()
####################
# Create P/Ds
####################
for proj in projects.values():
conn = BlitzGateway(users[proj["user"]]["name"] + uuid, userpassw, host=host)
conn.connect()
update = conn.getUpdateService()
project = ProjectI()
project.setName(rstring(proj["name"] + uuid))
project = update.saveAndReturnObject(project,{'omero.group':str(groups[proj["group"]]["id"])})
links = []
for dset in proj["datasets"]:
dataset = DatasetI()
dataset.setName(rstring(dset + uuid))
dataset = update.saveAndReturnObject(dataset,{'omero.group':str(groups[proj["group"]]["id"])})
l = ProjectDatasetLinkI()
l.setChild(dataset)
l.setParent(project)
links.append(l)
if links:
update.saveAndReturnArray(links,{'omero.group':str(groups[proj["group"]]["id"])})
conn.seppuku()
####################
# Create Datasets
####################
for dset in datasets.values():
conn = BlitzGateway(users[dset["user"]]["name"] + uuid, userpassw, host=host)
conn.connect()
update = conn.getUpdateService()
dataset = DatasetI()
dataset.setName(rstring(dset["name"] + uuid))
dataset = update.saveAndReturnObject(dataset,{'omero.group':str(groups[dset["group"]]["id"])})
conn.seppuku()
####################
# Create Tags
####################
for tset in tagsets.values():
conn = BlitzGateway(users[tset["user"]]["name"] + uuid, userpassw, host=host)
conn.connect()
update = conn.getUpdateService()
tagList = []
for name in tset["tags"]:
tag = TagAnnotationI()
tag.setTextValue(rstring(name + uuid))
tagList.append(tag)
tagList = update.saveAndReturnArray(tagList,{'omero.group':str(groups[tset["group"]]["id"])})
if tset["tagset"]:
tag = TagAnnotationI()
tag.setTextValue(rstring(tset["tagset"] + uuid))
tag.setNs(rstring(omero.constants.metadata.NSINSIGHTTAGSET))
tag = update.saveAndReturnObject(tag,{'omero.group':str(groups[tset["group"]]["id"])})
links = []
for child in tagList:
l = AnnotationAnnotationLinkI()
l.setChild(child)
l.setParent(tag)
links.append(l)
update.saveAndReturnArray(links,{'omero.group':str(groups[tset["group"]]["id"])})
conn.seppuku()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment