Example #1
0
def test_combine_missing(nex1, nex3):
    newnex = combine_nexuses(nex1, nex3)
    print(newnex.data)
    assert newnex.data['0.1']['Harry'] == '1'
    assert newnex.data['0.1']['Simon'] == '2'
    assert newnex.data['2.1']['Betty'] == '3'
    assert newnex.data['2.1']['Boris'] == '4'
    def test_combine_with_character_labels(self):
        n1 = NexusReader()
        n1.read_string(
            """
            BEGIN DATA;
                DIMENSIONS NTAX=3 NCHAR=3;
                FORMAT DATATYPE=STANDARD MISSING=0 GAP=-  SYMBOLS="123";
                CHARSTATELABELS
                    1 char1,
                    2 char2,
                    3 char3
            ;
            MATRIX
            Tax1         123
            Tax2         123
            Tax3         123
            ;
            """
        )
        n2 = NexusReader()
        n2.read_string(
            """
            BEGIN DATA;
                DIMENSIONS NTAX=3 NCHAR=3;
                FORMAT DATATYPE=STANDARD MISSING=0 GAP=-  SYMBOLS="456";
                CHARSTATELABELS
                    1 char1,
                    2 char2,
                    3 char3
            ;
            MATRIX
            Tax1         456
            Tax2         456
            Tax3         456
            ;
            """
        )
        newnex = combine_nexuses([n1, n2])
        assert re.search(r"""\bNTAX=3\b""", newnex.write())
        assert re.search(r"""\bNCHAR=6\b""", newnex.write())
        assert re.search(r'\sSYMBOLS="123456"[\s;]', newnex.write())

        for tax in [1, 2, 3]:
            assert re.search(r"""\bTax%d\s+123456\b""" % tax, newnex.write())

        counter = 1
        for nex_id in [1, 2]:
            for char_id in [1, 2, 3]:
                assert re.search(
                    r"""\b%d\s+%d.char%d\b""" % (counter, nex_id, char_id),
                    newnex.write(charblock=True)
                )
                counter += 1
Example #3
0
def test_combine():
    nex1 = NexusReader.from_string("""Begin trees;
            tree 1 = (a,b,c);
        end;""")
    nex2 = NexusReader.from_string("""Begin trees;
            tree 2 = (b,a,c);
            tree 3 = (b,c,a);
        end;""")

    newnex = combine_nexuses([nex1, nex2])
    assert len(newnex.trees) == 3
    assert newnex.trees[0] == "tree 1 = (a,b,c);"
    assert newnex.trees[1] == "tree 2 = (b,a,c);"
    assert newnex.trees[2] == "tree 3 = (b,c,a);"
Example #4
0
    def test_combine_with_character_labels(self):
        n1 = NexusReader()
        n1.read_string("""
            BEGIN DATA;
                DIMENSIONS NTAX=3 NCHAR=3;
                FORMAT DATATYPE=STANDARD MISSING=0 GAP=-  SYMBOLS="123";
                CHARSTATELABELS
                    1 char1,
                    2 char2,
                    3 char3
            ;
            MATRIX
            Tax1         123
            Tax2         123
            Tax3         123
            ;
            """)
        n2 = NexusReader()
        n2.read_string("""
            BEGIN DATA;
                DIMENSIONS NTAX=3 NCHAR=3;
                FORMAT DATATYPE=STANDARD MISSING=0 GAP=-  SYMBOLS="456";
                CHARSTATELABELS
                    1 char1,
                    2 char2,
                    3 char3
            ;
            MATRIX
            Tax1         456
            Tax2         456
            Tax3         456
            ;
            """)
        newnex = combine_nexuses([n1, n2])
        assert re.search(r"""\bNTAX=3\b""", newnex.write())
        assert re.search(r"""\bNCHAR=6\b""", newnex.write())
        assert re.search(r'\sSYMBOLS="123456"[\s;]', newnex.write())

        for tax in [1, 2, 3]:
            assert re.search(r"""\bTax%d\s+123456\b""" % tax, newnex.write())

        counter = 1
        for nex_id in [1, 2]:
            for char_id in [1, 2, 3]:
                assert re.search(
                    r"""\b%d\s+%d.char%d\b""" % (counter, nex_id, char_id),
                    newnex.write(charblock=True))
                counter += 1
Example #5
0
 def test_combine_missing_generated_formatline(self):
     newnex = combine_nexuses([self.nex1, self.nex3]).write()
     assert re.search(r"""\bNTAX=4\b""", newnex)
     assert re.search(r"""\bNCHAR=2\b""", newnex)
     assert re.search(r'\sSYMBOLS="12345"[\s;]', newnex)
Example #6
0
 def test_combine_missing_generated_matrix(self):
     newnex = combine_nexuses([self.nex1, self.nex3]).write()
     assert re.search(r"""\bSimon\s+25\b""", newnex)
     assert re.search(r"""\bHarry\s+1\\?\b""", newnex)
     assert re.search(r"""\bBetty\s+\?3\b""", newnex)
     assert re.search(r"""\bBoris\s+\?4\b""", newnex)
Example #7
0
 def test_combine_missing(self):
     newnex = combine_nexuses([self.nex1, self.nex3])
     assert newnex.data['0.1']['Harry'] == '1'
     assert newnex.data['0.1']['Simon'] == '2'
     assert newnex.data['2.1']['Betty'] == '3'
     assert newnex.data['2.1']['Boris'] == '4'
Example #8
0
 def test_combine_simple_generated_matrix(self):
     newnex = combine_nexuses([self.nex1, self.nex2]).write()
     assert re.search(r"""\bSimon\s+24\b""", newnex)
     assert re.search(r"""\bHarry\s+13\b""", newnex)
Example #9
0
 def test_combine_simple(self):
     newnex = combine_nexuses([self.nex1, self.nex2])
     assert newnex.data['0.1']['Harry'] == '1'
     assert newnex.data['0.1']['Simon'] == '2'
     assert newnex.data['2.1']['Harry'] == '3'
     assert newnex.data['2.1']['Simon'] == '4'
 def test_combine_missing_generated_formatline(self):
     newnex = combine_nexuses([self.nex1, self.nex3])
     assert re.search(r"""\bNTAX=4\b""", newnex.write())
     assert re.search(r"""\bNCHAR=2\b""", newnex.write())
     assert re.search(r'\sSYMBOLS="12345"[\s;]', newnex.write())
 def test_combine_missing_generated_matrix(self):
     newnex = combine_nexuses([self.nex1, self.nex3])
     assert re.search(r"""\bSimon\s+25\b""", newnex.write())
     assert re.search(r"""\bHarry\s+1\\?\b""", newnex.write())
     assert re.search(r"""\bBetty\s+\?3\b""", newnex.write())
     assert re.search(r"""\bBoris\s+\?4\b""", newnex.write())
 def test_combine_missing(self):
     newnex = combine_nexuses([self.nex1, self.nex3])
     assert newnex.data['1.1']['Harry'] == '1'
     assert newnex.data['1.1']['Simon'] == '2'
     assert newnex.data['2.1']['Betty'] == '3'
     assert newnex.data['2.1']['Boris'] == '4'
 def test_combine_simple_generated_matrix(self):
     newnex = combine_nexuses([self.nex1, self.nex2])
     assert re.search(r"""\bSimon\s+24\b""", newnex.write())
     assert re.search(r"""\bHarry\s+13\b""", newnex.write())
 def test_combine_simple(self):
     newnex = combine_nexuses([self.nex1, self.nex2])
     assert newnex.data['1.1']['Harry'] == '1'
     assert newnex.data['1.1']['Simon'] == '2'
     assert newnex.data['2.1']['Harry'] == '3'
     assert newnex.data['2.1']['Simon'] == '4'
Example #15
0
def test_combine_iterated(nex1):
    res = combine_nexuses(combine_nexuses(nex1))
    assert res
Example #16
0
def test_combine_simple_generated_formatline(nex1, nex2):
    newnex = combine_nexuses([nex1, nex2]).write()
    assert re.search(r"""\bNTAX=2\b""", newnex)
    assert re.search(r"""\bNCHAR=2\b""", newnex)
    assert re.search(r'\sSYMBOLS="1234"[\s;]', newnex)