예제 #1
0
    def test_transform(self):
        headers, column_cfgs = self.get_complicated_headers()

        tr = KeyValueListTransformer(headers, None, column_cfgs)
        r = tr.transform(("3", "2", "4", "1a|1b", "x", "5", "6"))

        assert len(r) == 6
        assert r[0] == ("a1", ["1a", "1b"])
        assert r[1] == ("__a2", ["2"])
        assert r[2] == ("a3", ["3"])
        assert r[3] == ("a4", ["*-4-*"])
        assert r[4] == ("a5", ["5"])
        assert r[5] == ("a6", ["6"])
    def test_transform(self):
        headers, column_cfgs = self.get_complicated_headers()

        tr = KeyValueListTransformer(headers, None, column_cfgs)
        r = tr.transform(("3", "2", "4", "1a|1b", "x", "5", "6"))

        assert len(r) == 6
        assert r[0] == ("a1", ["1a", "1b"])
        assert r[1] == ("__a2", ["2"])
        assert r[2] == ("a3", ["3"])
        assert r[3] == ("a4", ["*-4-*"])
        assert r[4] == ("a5", ["5"])
        assert r[5] == ("a6", ["6"])
예제 #3
0
    def test_transform(self):
        headers = ["a2", "a4", "a3", "a1"]
        output_configs = [
            (expected(name="a1", split="|"), 3),
            (expected(name="a2", visible=False), 0),
            (expected(name="a4", clientvalue="*-{{ value }}-*"), 1),
        ]

        tr = KeyValueListTransformer(headers, output_configs)
        r = tr.transform(("2", "4", "x", "1a|1b"))

        assert len(r) == 3
        assert r[0] == ("a1", ["1a", "1b"])
        assert r[1] == ("__a2", ["2"])
        assert r[2] == ("a4", ["*-4-*"])
예제 #4
0
    def populate(self, table):
        def idcolumn_to_omeroclass(col):
            clsname = re.search('::(\w+)Column$', col.ice_staticId()).group(1)
            return getattr(omero.model, '%sI' % clsname)

        nrows = table.getNumberOfRows()
        data = table.readCoordinates(range(nrows))

        # Don't create annotations on higher-level objects
        # idcoltypes = set(HeaderResolver.screen_keys.values())
        idcoltypes = set((ImageColumn, WellColumn))
        idcols = []
        for n in xrange(len(data.columns)):
            col = data.columns[n]
            if col.__class__ in idcoltypes:
                omeroclass = idcolumn_to_omeroclass(col)
                idcols.append((omeroclass, n))

        headers = [c.name for c in data.columns]
        if self.default_cfg or self.column_cfgs:
            tr = KeyValueListTransformer(headers, self.default_cfg,
                                         self.column_cfgs)
        else:
            tr = KeyValueListPassThrough(headers)

        mas = []
        for row in izip(*(c.values for c in data.columns)):
            rowkvs = tr.transform(row)
            targets = []
            for omerotype, n in idcols:
                if row[n] > 0:
                    obj = omerotype(row[n], False)
                    # Josh: disabling to prevent duplication in UI
                    # targets.append(obj)
                    targets.extend(self._get_additional_targets(obj))
                else:
                    log.warn("Invalid Id:%d found in row %s", row[n], row)
            if targets:
                malinks = self.create_map_annotation(targets, rowkvs)
                log.debug('Map:\n\t' + ('\n\t'.join(
                    "%s=%s" % (v.name, v.value)
                    for v in malinks[0].getChild().getMapValue())))
                log.debug('Targets:\n\t' + ('\n\t'.join(
                    "%s:%d" % (t.ice_staticId().split('::')[-1], t.id._val)
                    for t in targets)))
                mas.extend(malinks)

        self.mapannotations = mas
    def populate(self, table):
        def idcolumn_to_omeroclass(col):
            clsname = re.search('::(\w+)Column$', col.ice_staticId()).group(1)
            return getattr(omero.model, '%sI' % clsname)

        nrows = table.getNumberOfRows()
        data = table.readCoordinates(range(nrows))

        # Don't create annotations on higher-level objects
        # idcoltypes = set(HeaderResolver.screen_keys.values())
        idcoltypes = set((ImageColumn, WellColumn))
        idcols = []
        for n in xrange(len(data.columns)):
            col = data.columns[n]
            if col.__class__ in idcoltypes:
                omeroclass = idcolumn_to_omeroclass(col)
                idcols.append((omeroclass, n))

        headers = [c.name for c in data.columns]
        if self.default_cfg or self.column_cfgs:
            tr = KeyValueListTransformer(
                headers, self.default_cfg, self.column_cfgs)
        else:
            tr = KeyValueListPassThrough(headers)

        mas = []
        for row in izip(*(c.values for c in data.columns)):
            rowkvs = tr.transform(row)
            targets = []
            for omerotype, n in idcols:
                if row[n] > 0:
                    obj = omerotype(row[n], False)
                    # Josh: disabling to prevent duplication in UI
                    # targets.append(obj)
                    targets.extend(self._get_additional_targets(obj))
                else:
                    log.warn("Invalid Id:%d found in row %s", row[n], row)
            if targets:
                malinks = self.create_map_annotation(targets, rowkvs)
                log.debug('Map:\n\t' + ('\n\t'.join("%s=%s" % (
                    v.name, v.value) for v in
                    malinks[0].getChild().getMapValue())))
                log.debug('Targets:\n\t' + ('\n\t'.join("%s:%d" % (
                    t.ice_staticId().split('::')[-1], t.id._val)
                    for t in targets)))
                mas.extend(malinks)

        self.mapannotations = mas
예제 #6
0
    def test_init_col(self):
        headers = ["a1"]
        tr = KeyValueListTransformer(headers, None, [{
            "name": "a1",
            "visible": False
        }])
        assert tr.default_cfg == expected()

        assert len(tr.output_configs) == 1
        assert tr.output_configs[0] == (expected(name="a1", visible=False), 0)
예제 #7
0
    def test_init_col_ordered_unordered(self):
        headers = ["a2", "a1"]
        tr = KeyValueListTransformer(headers, None, [{
            "name": "a2",
            "visible": False
        }, {
            "name": "a1",
            "position": 1
        }])
        assert tr.default_cfg == expected()

        assert len(tr.output_configs) == 2
        assert tr.output_configs[0] == (expected(name="a1", position=1), 1)
        assert tr.output_configs[1] == (expected(name="a2", visible=False), 0)
예제 #8
0
    def test_init_col_complicated_order(self):
        headers, column_cfgs = self.get_complicated_headers()
        tr = KeyValueListTransformer(headers, None, column_cfgs)
        assert tr.default_cfg == expected()

        assert len(tr.output_configs) == 6
        assert tr.output_configs[0] == (expected(name="a1",
                                                 position=1,
                                                 split="|"), 3)
        assert tr.output_configs[1] == (expected(name="a2", visible=False), 1)
        assert tr.output_configs[2] == (expected(name="a3"), 0)
        assert tr.output_configs[3] == (expected(
            name="a4", position=4, clientvalue="*-{{ value }}-*"), 2)
        assert tr.output_configs[4] == (expected(name="a5"), 5)
        assert tr.output_configs[5] == (expected(name="a6"), 6)
예제 #9
0
    def test_init_col_unincluded(self):
        headers = ["a2", "a1"]
        tr = KeyValueListTransformer(headers, {
            "include": False,
            "includeclient": False
        }, [{
            "name": "a2",
            "include": True
        }])
        assert tr.default_cfg == expected(include=False, includeclient=False)

        assert len(tr.output_configs) == 1
        assert tr.output_configs[0] == (expected(name="a2",
                                                 include=True,
                                                 includeclient=False), 0)
예제 #10
0
 def test_transformj2(self):
     cfg = expected(name="a1", clientvalue="http://{{ value | urlencode }}")
     assert KeyValueListTransformer.transform1("a b",
                                               cfg) == ("a1",
                                                        ["http://a%20b"])
예제 #11
0
 def test_transform1(self, inout):
     cfg = expected(name="a1", **inout[1])
     assert KeyValueListTransformer.transform1(inout[0], cfg) == inout[2]
예제 #12
0
 def test_transform1_clientname(self):
     cfg = expected(name="a1", clientname="a / 1")
     assert KeyValueListTransformer.transform1("ab, c",
                                               cfg) == ("a / 1", ["ab, c"])
 def test_transform1(self, inout):
     cfg = expected(name="a1", **inout[1])
     assert KeyValueListTransformer.transform1(inout[0], cfg) == inout[2]
 def test_transform1_clientname(self):
     cfg = expected(name="a1", clientname="a / 1")
     assert KeyValueListTransformer.transform1("ab, c", cfg) == (
         "a / 1", ["ab, c"])