Пример #1
0
def nex():
    res = NexusReader.from_string("""
        Begin data;
        Dimensions ntax=3 nchar=2;
        Format datatype=standard symbols="01" gap=-;
        Charstatelabels
            1 char1, 2 char2;
        Matrix
        Maori               14
        Dutch               25
        Latin               36
        ;""")
    return binarise(res)
Пример #2
0
 def setUp(self):
     self.nex = NexusReader()
     self.nex.read_string("""
     Begin data;
     Dimensions ntax=3 nchar=2;
     Format datatype=standard symbols="01" gap=-;
     Charstatelabels
         1 char1, 2 char2;
     Matrix
     Maori               14
     Dutch               25
     Latin               36
     ;""")
     self.nex = binarise(self.nex)
Пример #3
0
 def setUp(self):
     self.nex = NexusReader()
     self.nex.read_string("""
     Begin data;
     Dimensions ntax=3 nchar=2;
     Format datatype=standard symbols="01" gap=-;
     Charstatelabels
         1 char1, 2 char2;
     Matrix
     Maori               14
     Dutch               25
     Latin               36
     ;""")
     self.nex = binarise(self.nex)
Пример #4
0
def test_to_binary_alphabetical():
    """Test Nexus -> Binary: alphabetical states"""
    nex = binarise(
        NexusReader.from_string("""
        #NEXUS
        BEGIN DATA;
            DIMENSIONS NTAX=5 NCHAR=2;
            FORMAT MISSING=? GAP=- SYMBOLS="ABCDE";
            CHARSTATELABELS
            1 ALL,
            2 ASHES
        ;
        MATRIX
        Mehri        AB
        Geto         AB
        Walani       A-
        Hebrew       A(C,D)
        Soqotri      BC
        ;
        END;
        """))
    nexus = nex.make_nexus(charblock=True, interleave=False)

    assert re.search(r"\s+NCHAR=5;", nexus)

    assert re.search(r"1\s+ALL_A,", nexus)
    assert re.search(r"2\s+ALL_B,", nexus)
    assert re.search(r"3\s+ASHES_B,", nexus)
    assert re.search(r"4\s+ASHES_C,", nexus)
    assert re.search(r"5\s+ASHES_D", nexus)

    assert re.search(r"Geto\s+10100", nexus)
    assert re.search(r"Hebrew\s+10011", nexus)
    assert re.search(r"Mehri\s+10100", nexus)
    assert re.search(r"Soqotri\s+01010", nexus)
    assert re.search(r"Walani\s+10000", nexus)
#!/usr/bin/env python
import sys
from nexus import NexusReader, VERSION
from nexus.tools.binarise import binarise

__author__ = 'Simon Greenhill <*****@*****.**>'
__doc__ = """nexus_multistate2binary - python-nexus tools v%(version)s

Converts multistate nexuses to binary present/absent form.
""" % {
    'version': VERSION,
}

if __name__ == '__main__':
    #set up command-line options
    from optparse import OptionParser
    parser = OptionParser(usage="usage: %prog old.nex new.nex")
    options, args = parser.parse_args()

    try:
        nexusname = args[0]
        newnexusname = args[1]
    except IndexError:
        print(__doc__)
        print("Author: %s\n" % __author__)
        parser.print_help()
        sys.exit()

    new = binarise(NexusReader(nexusname))
    new.write_to_file(newnexusname)
if __name__ == '__main__':
    #set up command-line options
    from optparse import OptionParser
    parser = OptionParser(usage="usage: %prog old.nex new.nex")
    parser.add_option("-1", "--onefile", dest="onefile",
            action="store_true", default=False,
            help="One nexus file for each multistate character")
    options, args = parser.parse_args()

    try:
        nexusname = args[0]
        newnexusname = args[1]
    except IndexError:
        print(__doc__)
        print("Author: %s\n" % __author__)
        parser.print_help()
        sys.exit()
        
    new = binarise(NexusReader(nexusname), one_nexus_per_block=options.onefile)
    if isinstance(new, NexusWriter):
        new.write_to_file(newnexusname)
    elif len(new) > 1:
        newnexusname, ext = os.path.splitext(newnexusname)
        for nex in new:
            nex.write_to_file("%s-%s%s" %
                (newnexusname, nex.clean(nex.characters[0]), ext)
            )


Пример #7
0
def run(args):
    write_output(binarise(get_reader(args)), args)