예제 #1
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
if __name__ == '__main__':
    from optparse import OptionParser
    parser = OptionParser(
        usage="usage: %prog [-o output.nex] nex1.nex nex2.nex ... nexN.nex"
    )
    parser.add_option("-o", "--output", dest="output",
            action="store", default=None, type="string",
            help="output nexus file")
    options, nexuslist = parser.parse_args()

    if len(nexuslist) < 1:
        print(__doc__)
        parser.print_help()
        sys.exit()

    if options.output is not None:
        outfile = options.output
    else:
        outfile = 'multistate.nex'

    nexuslist2 = []
    for nfile in nexuslist:
        n = NexusReader(nfile)
        n = multistatise(n)
        nexuslist2.append(n)

    out = combine_nexuses(nexuslist2)

    out.write_to_file(outfile, charblock=True, interleave=False)
    print("Written to %s" % outfile)
    parser = OptionParser(
        usage="usage: %prog [-o output.nex] nex1.nex nex2.nex ... nexN.nex")
    parser.add_option("-o",
                      "--output",
                      dest="output",
                      action="store",
                      default=None,
                      type="string",
                      help="output nexus file")
    options, nexuslist = parser.parse_args()

    if len(nexuslist) < 1:
        print __doc__
        parser.print_help()
        sys.exit()

    if options.output is not None:
        outfile = options.output
    else:
        outfile = 'multistate.nex'

    nexuslist2 = []
    for nfile in nexuslist:
        n = NexusReader(nfile)
        n = multistatise(n)
        nexuslist2.append(n)

    out = combine_nexuses(nexuslist2)

    out.write_to_file(outfile, charblock=True, interleave=False)
    print("Written to %s" % outfile)
예제 #4
0
def run(args):
    write_output(combine_nexuses(get_reader(args, many=True)), args)
예제 #5
0
 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())
예제 #6
0
 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())
예제 #7
0
 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'
예제 #8
0
 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())
예제 #9
0
 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'
예제 #10
0
def run(args):
    nexuslist = [
        multistatise.multistatise(n) for n in get_reader(args, many=True)
    ]
    write_output(combine_nexuses(nexuslist), args)