示例#1
0
文件: runtests.py 项目: flu-crew/smot
    def test_sampleContext(self):
        self.assertEqual(
            alg.sampleContext(
                alg.factorByField(
                    sp.p_tree.parse("(B|a,(A|b,C|b,E|b),D|c);").tree, field=2),
                keep=[],
                maxTips=1,
            ),
            sp.Node(kids=[
                sp.Node(label="B|a", factor="a"),
                sp.Node(label="A|b", factor="b"),
                sp.Node(label="D|c", factor="c"),
            ]),
        )

        self.assertEqual(
            alg.sampleContext(
                alg.factorByField(
                    sp.p_tree.parse("(B|a,(A|b,C|b,E|b),D|c);").tree, field=2),
                keep=[],
                maxTips=2,
            ),
            sp.Node(kids=[
                sp.Node(label="B|a", factor="a"),
                sp.Node(kids=[
                    sp.Node(label="A|b", factor="b"),
                    sp.Node(label="C|b", factor="b"),
                ]),
                sp.Node(label="D|c", factor="c"),
            ]),
        )
示例#2
0
文件: runtests.py 项目: flu-crew/smot
 def test_node(self):
     self.assertEqual(
         sp.p_node.parse("(A[foo=boo,bar=baz]:0.42)Root"),
         sp.Node(
             kids=[
                 sp.Node(label="A",
                         form={
                             "foo": "boo",
                             "bar": "baz"
                         },
                         length=0.42)
             ],
             label="Root",
         ),
     )
示例#3
0
文件: runtests.py 项目: flu-crew/smot
 def test_newick(self):
     self.assertEqual(
         sp.p_tree.parse("(A[foo=boo]:0.42)Root;").tree,
         sp.Node(
             kids=[sp.Node(label="A", form={"foo": "boo"}, length=0.42)],
             label="Root",
         ),
     )
     self.assertEqual(
         sp.p_tree.parse("(B,(A,C,E),D);").tree,
         sp.Node(kids=[
             sp.Node(label="B"),
             sp.Node(kids=[
                 sp.Node(label="A"),
                 sp.Node(label="C"),
                 sp.Node(label="E"),
             ]),
             sp.Node(label="D"),
         ]),
     )
示例#4
0
文件: runtests.py 项目: flu-crew/smot
    def test_treemap(self):
        def _lower(x):
            if x.label:
                x.label = x.label.lower()
            return x

        self.assertEqual(
            alg.treemap(sp.p_tree.parse("(B,(A,C,E),D);").tree, _lower),
            sp.Node(kids=[
                sp.Node(label="b"),
                sp.Node(kids=[
                    sp.Node(label="a"),
                    sp.Node(label="c"),
                    sp.Node(label="e"),
                ]),
                sp.Node(label="d"),
            ]),
        )
示例#5
0
文件: runtests.py 项目: flu-crew/smot
    def test_factorByLabel(self):
        def _fun(name):
            try:
                return name.split("|")[1]
            except:
                return None

        self.assertEqual(
            alg.factorByLabel(
                sp.p_tree.parse("(B|a,(A|b,C|b,E|b),D|c);").tree, _fun),
            sp.Node(kids=[
                sp.Node(label="B|a", factor="a"),
                sp.Node(kids=[
                    sp.Node(label="A|b", factor="b"),
                    sp.Node(label="C|b", factor="b"),
                    sp.Node(label="E|b", factor="b"),
                ]),
                sp.Node(label="D|c", factor="c"),
            ]),
        )
示例#6
0
文件: runtests.py 项目: flu-crew/smot
 def test_leaf(self):
     self.assertEqual(
         sp.p_leaf.parse("A[foo=boo]:0.42"),
         sp.Node(label="A", form={"foo": "boo"}, length=0.42),
     )