def test_update_existing_mapann(self): ns1, ns3, mids = self.create_mas() pks = ['a'] mgr = MapAnnotationManager() mgr.add_from_namespace_query(self.sf, ns1, pks) ma4 = MapAnnotationI() ma4 = MapAnnotationI() ma4.setNs(wrap(ns1)) ma4.setMapValue([NamedValue('a', '2'), NamedValue('b', '3'), ]) cma = CanonicalMapAnnotation(ma4, pks) # This should modify ma2 r = mgr.add(cma) assert r is cma cmas = mgr.get_map_annotations() assert len(cmas) == 2 rs = self.update.saveAndReturnArray([c.get_mapann() for c in cmas]) rs = sorted(rs, key=lambda x: unwrap(x.getId())) assert_equal_map_value(rs[0].getMapValue(), [NamedValue('a', '1')]) assert unwrap(rs[0].getNs()) == ns1 assert_equal_map_value(rs[1].getMapValue(), [ NamedValue('a', '2'), NamedValue('b', '3')]) assert unwrap(rs[1].getNs()) == ns1
def test_init_defaults_empty(self, ns): ma = MapAnnotationI(1) if ns is not None: ma.setNs(rstring(ns)) cma = CanonicalMapAnnotation(ma) assert cma.ma is ma expectedns = ns if ns else '' assert cma.ns == expectedns assert cma.kvpairs == [] assert cma.primary is None assert cma.parents == set()
def test_init_defaults_kvpairs(self, ns): ma = MapAnnotationI(1) ma.setMapValue([NamedValue('b', '2'), NamedValue('a', '1')]) if ns is not None: ma.setNs(rstring(ns)) cma = CanonicalMapAnnotation(ma) assert cma.ma is ma expectedns = ns if ns else '' assert cma.ns == expectedns assert cma.kvpairs == [('b', '2'), ('a', '1')] assert cma.primary is None assert cma.parents == set()
def test_init_primary_keys(self, ns, primary_keys): ma = MapAnnotationI(1) ma.setNs(rstring(ns)) ma.setMapValue([NamedValue('b', '2'), NamedValue('a', '1')]) cma = CanonicalMapAnnotation(ma, primary_keys=primary_keys) assert cma.ma is ma expectedns = ns if ns else '' assert cma.ns == expectedns assert cma.kvpairs == [('b', '2'), ('a', '1')] expectedpks = [('a', '1'), ('b', '2')][:len(primary_keys)] if primary_keys: expectedpri = (expectedns, frozenset(expectedpks)) else: expectedpri = None assert cma.primary == expectedpri assert cma.parents == set()
def create_map_annotation( targets, rowkvs, ns=omero.constants.namespaces.NSBULKANNOTATIONS): ma = MapAnnotationI() ma.setNs(rstring(ns)) mv = [] for k, vs in rowkvs: if not isinstance(vs, (tuple, list)): vs = [vs] mv.extend(NamedValue(k, str(v)) for v in vs) ma.setMapValue(mv) links = [] for target in targets: otype = target.ice_staticId().split('::')[-1] link = getattr(omero.model, '%sAnnotationLinkI' % otype)() link.setParent(target) link.setChild(ma) links.append(link) return links
def create_map_annotation(targets, rowkvs, ns=omero.constants.namespaces.NSBULKANNOTATIONS): ma = MapAnnotationI() ma.setNs(rstring(ns)) mv = [] for k, vs in rowkvs: if not isinstance(vs, (tuple, list)): vs = [vs] mv.extend(NamedValue(k, str(v)) for v in vs) ma.setMapValue(mv) links = [] for target in targets: otype = target.ice_staticId().split('::')[-1] link = getattr(omero.model, '%sAnnotationLinkI' % otype)() link.setParent(target) link.setChild(ma) links.append(link) return links
def create_mas(self): ns1 = self.uuid() ns3 = self.uuid() ma1 = MapAnnotationI() ma1.setNs(wrap(ns1)) ma1.setMapValue([NamedValue('a', '1')]) ma2 = MapAnnotationI() ma2.setNs(wrap(ns1)) ma2.setMapValue([NamedValue('a', '2')]) ma3 = MapAnnotationI() ma3.setNs(wrap(ns3)) ma3.setMapValue([NamedValue('a', '1')]) mids = self.update.saveAndReturnIds([ma1, ma2, ma3]) print ns1, ns3, mids return ns1, ns3, mids
def screen_metadata(client, file, object): query = client.sf.getQueryService() update = client.sf.getUpdateService() name, oid = object.split(":") do_update = False query = ( "select x from %s x join fetch x.annotationLinks xal " "join fetch xal.child where x.id = %d" ) obj = query.findByQuery(query % (name, long(oid)), None) ann = None for link in obj.copyAnnotationLinks(): if isinstance(link.child, MapAnnotationI): if ann is not None: raise Exception("2 maps!") ann = link.child print "Found map:", ann.id.val if ann is None: ann = MapAnnotationI() ann.setNs(rstring("openmicroscopy.org/omero/client/mapAnnotation")) ann.setMapValue(list()) obj.linkAnnotation(ann) do_update = True print "Creating new map" old = unwrap(obj.description) desc = "" values = dict() for line in input([file]): parts = line.strip().split("\t") key = parts[0] if len(parts) > 1: val = parts[1] else: val = None if key == "Study " + P_T: desc += P_T desc += "\n" desc += val desc += "\n\n" elif key == E_D: desc += E_D desc += "\n" desc += val elif key == P_M[0]: x, y = P_M values[y] = "%s http://www.ncbi.nlm.nih.gov/pubmed/%s" % (val, val) elif key == P_D[0]: x, y = P_D doi = val.split("dx.doi.org")[-1][1:] values[y] = "%s %s" % (doi, val) else: for x, y in (S_T, I_T, P_A): if key == x: values[y] = val.strip('"') old_values = dict() for x in ann.getMapValue(): old_values[x.name] = x for x, y in (S_T, I_T, P_A, P_M, P_D): if y not in old_values: ann.getMapValue().append(NamedValue(y, values[y])) do_update = True print "found new named value" elif old_values[y].value != values[y]: old_values[y].value = values[y] do_update = True print "changed named value" if old != desc: do_update = True obj.description = rstring(desc) else: print "descriptions match" if do_update: print "updating" update.saveObject(obj) print values
def screen_metadata(client, file, object): query = client.sf.getQueryService() update = client.sf.getUpdateService() name, oid = object.split(":") do_update = False query = ("select x from %s x join fetch x.annotationLinks xal " "join fetch xal.child where x.id = %d") obj = query.findByQuery(query % (name, long(oid)), None) ann = None for link in obj.copyAnnotationLinks(): if isinstance(link.child, MapAnnotationI): if ann is not None: raise Exception("2 maps!") ann = link.child print "Found map:", ann.id.val if ann is None: ann = MapAnnotationI() ann.setNs(rstring("openmicroscopy.org/omero/client/mapAnnotation")) ann.setMapValue(list()) obj.linkAnnotation(ann) do_update = True print "Creating new map" old = unwrap(obj.description) desc = "" values = dict() for line in input([file]): parts = line.strip().split("\t") key = parts[0] if len(parts) > 1: val = parts[1] else: val = None if key == "Study " + P_T: desc += P_T desc += "\n" desc += val desc += "\n\n" elif key == E_D: desc += E_D desc += "\n" desc += val elif key == P_M[0]: x, y = P_M values[y] = "%s http://www.ncbi.nlm.nih.gov/pubmed/%s" % (val, val) elif key == P_D[0]: x, y = P_D doi = val.split("dx.doi.org")[-1][1:] values[y] = "%s %s" % (doi, val) else: for x, y in (S_T, I_T, P_A): if key == x: values[y] = val.strip('"') old_values = dict() for x in ann.getMapValue(): old_values[x.name] = x for x, y in (S_T, I_T, P_A, P_M, P_D): if y not in old_values: ann.getMapValue().append(NamedValue(y, values[y])) do_update = True print "found new named value" elif old_values[y].value != values[y]: old_values[y].value = values[y] do_update = True print "changed named value" if old != desc: do_update = True obj.description = rstring(desc) else: print "descriptions match" if do_update: print "updating" update.saveObject(obj) print values