コード例 #1
0
    def test_init_defaults_duplicates(self):
        ma = MapAnnotationI(1)
        ma.setMapValue([NamedValue('a', '1'), NamedValue('a', '1')])

        with pytest.raises(ValueError) as excinfo:
            CanonicalMapAnnotation(ma)
        assert str(excinfo.value).startswith('Duplicate ')
コード例 #2
0
    def test_init_missing_primary_key(self):
        ma = MapAnnotationI(1)
        ma.setMapValue([NamedValue('b', '2')])

        with pytest.raises(MapAnnotationPrimaryKeyException) as excinfo:
            CanonicalMapAnnotation(ma, primary_keys=['a', 'b'])
        assert str(excinfo.value).startswith('Missing ')
コード例 #3
0
    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
コード例 #4
0
ファイル: test_gateway.py プロジェクト: olatarkowska/omero-py
    def test_map_annotation(self):
        """Tests MapAnnotationWrapper.getValue() returns unicode"""
        values = [(u'one', u'₹₹'), (u'two', u'¥¥')]
        obj = MapAnnotationI()
        data = [NamedValue(d[0], d[1]) for d in values]
        obj.setMapValue(data)

        map_ann = MockConnection(obj).getObject("Annotation", 1)
        assert map_ann.getValue() == values
コード例 #5
0
    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()
コード例 #6
0
    def create_cmas(self, pk2):
        ma1 = MapAnnotationI(1)
        ma1.setMapValue([NamedValue('a', '1')])
        cma1 = CanonicalMapAnnotation(ma1, primary_keys=['a'])
        cma1.add_parent('Parent', 1)

        ma2 = MapAnnotationI(2)
        ma2.setMapValue([NamedValue('b', '2'), NamedValue('a', '1')])
        cma2 = CanonicalMapAnnotation(ma2, primary_keys=[pk2])
        cma2.add_parent('Parent', 1)
        cma2.add_parent('Parent', 2)

        return cma1, cma2
コード例 #7
0
    def test_get_mapann(self):
        ma = MapAnnotationI(1)
        ma.setMapValue([NamedValue('a', '1')])
        cma = CanonicalMapAnnotation(ma, primary_keys=['a'])
        cma.add_parent('Parent', 1)
        cma.kvpairs.append(('b', '2'))
        newma = cma.get_mapann()

        assert newma is ma
        mv = newma.getMapValue()
        assert len(mv) == 2
        assert_equal_name_value(mv[0], NamedValue('a', '1'))
        assert_equal_name_value(mv[1], NamedValue('b', '2'))
コード例 #8
0
    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()
コード例 #9
0
    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
コード例 #10
0
    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
コード例 #11
0
    def test_merge(self, reverse):
        ma1 = MapAnnotationI(1)
        ma1.setMapValue([NamedValue('a', '1')])
        cma1 = CanonicalMapAnnotation(ma1, primary_keys=['a'])
        cma1.add_parent('Parent', 1)
        ma2 = MapAnnotationI(2)
        ma2.setMapValue([NamedValue('b', '2'), NamedValue('a', '1')])
        cma2 = CanonicalMapAnnotation(ma2, primary_keys=['b'])
        cma2.add_parent('Parent', 1)
        cma2.add_parent('Parent', 2)

        if reverse:
            cma2.merge(cma1)
            assert cma2.kvpairs == [('b', '2'), ('a', '1')]
            assert cma2.parents == set([('Parent', 1), ('Parent', 2)])
            assert cma2.primary == ('', frozenset([('b', '2')]))
        else:
            cma1.merge(cma2)
            assert cma1.kvpairs == [('a', '1'), ('b', '2')]
            assert cma1.parents == set([('Parent', 1), ('Parent', 2)])
            assert cma1.primary == ('', frozenset([('a', '1')]))
コード例 #12
0
    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
コード例 #13
0
ファイル: meta.py プロジェクト: IDR/idr-metadata
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
コード例 #14
0
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