예제 #1
0
 def setUp(self):
     self.nex = NexusReader()
     self.nex.read_string(
     """Begin data;
     Dimensions ntax=4 nchar=4;
     Format datatype=standard symbols="01" gap=-;
     Matrix
     Harry              1000
     Simon              0100
     Betty              0010
     Louise             0001
     ;""")
     self.nex = multistatise(self.nex)
예제 #2
0
 def test_regression_include_invisible_taxa(self):
     """Include taxa that have no entries"""
     data = """
     #NEXUS
     
     BEGIN DATA;
         DIMENSIONS  NTAX=15 NCHAR=7;
         FORMAT DATATYPE=STANDARD MISSING=? GAP=- INTERLEAVE=YES;
     MATRIX
     
     Gertrude                0000001
     Debbie                  0001000
     Zarathrustra            0000000
     Christie                0010000
     Benny                   0100000
     Bertha                  0100000
     Craig                   0010000
     Fannie-May              0000010
     Charles                 0010000
     Annik                   1000000
     Frank                   0000010
     Amber                   1000000
     Andreea                 1000000
     Edward                  0000100
     Donald                  0001000
     ;
     END;
     """
     
     nex = NexusReader()
     nex.read_string(data)
     msnex = multistatise(nex)
     
     for taxon,sites in msnex.data.matrix.items():
         if taxon[0] == 'Z':
             continue # will check later
         
         # first letter of taxa name is the expected character state
         assert taxon[0] == sites[0], "%s should be %s not %s" % (taxon, taxon[0], sites[0])
     # deal with completely missing taxa
     assert 'Zarathrustra' in msnex.data.matrix
     assert msnex.data.matrix['Zarathrustra'][0] == '?'
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)