Пример #1
0
def run(args):
    nexus = get_reader(args)

    if args.number:
        print_site_values(nexus)
        return 0

    if args.stats:
        print_character_stats(nexus)
        return 0

    const, unique, zeros, remove = [], [], [], []
    if args.constant:
        const = list(iter_constant_sites(nexus))
        if const:
            args.log.info("Constant Sites: %s" %
                          ",".join([str(i + 1) for i in const]))
    if args.unique:
        unique = list(iter_unique_sites(nexus))
        if unique:
            args.log.info("Unique Sites: %s" %
                          ",".join([str(i + 1) for i in unique]))
    if args.zeros:
        zeros = check_zeros(nexus)
        if zeros:
            args.log.info("Zero Sites: %s" %
                          ",".join([str(i + 1) for i in zeros]))
    if args.remove:
        args.log.info("Remove: %s" % ",".join([str(i) for i in args.remove]))
        remove = [i - 1
                  for i in args.remove]  # translate to zero-based indices.

    write_output(
        new_nexus_without_sites(nexus, set(const + unique + zeros + remove)),
        args)
Пример #2
0
def run(args):
    nexus_obj = get_reader(args, required_blocks=['data'])
    print(nexus_obj.filename)

    with Table(args, 'Taxon', 'Characters') as t:
        for taxon in sorted(nexus_obj.data.matrix):
            tally = collections.Counter()
            for site in nexus_obj.data.matrix[taxon]:
                tally.update([site])

            t.append([
                taxon,
                ", ".join(['%s x %s' % (k, tally[k]) for k in sorted(tally)])
            ])
Пример #3
0
def run(args):
    checkers = CHECKERS['base']
    if args.extra:
        checkers.extend(CHECKERS['extra'])
    if args.ascertainment:
        checkers.extend(CHECKERS['ascertainment'])

    with warnings.catch_warnings(record=True) as warned:
        warnings.simplefilter("always")
        nex = get_reader(args)

        if len(warned):
            print("Warnings encountered in reading nexus:")
            for w in warned:
                print("\t%s" % w)

    for checker in checkers:
        checker(nex).status()
Пример #4
0
def run(args):
    nexus = get_reader(args, required_blocks=['trees'])
    args.log.info("{0} trees found with {1} translated taxa".format(
        nexus.trees.ntrees, len(nexus.trees.translators)))

    if args.deltree:
        nexus = delete_trees(nexus, args.deltree, log=args.log)

    if args.resample:
        nexus = sample_trees(nexus, every_nth=args.resample, log=args.log)

    if args.random:
        nexus = sample_trees(nexus, num_trees=args.random, log=args.log)

    if args.removecomments:
        nexus = strip_comments_in_trees(nexus, log=args.log)

    if args.detranslate:
        nexus.trees.detranslate()

    write_output(nexus, args)
Пример #5
0
def test_get_reader(monkeypatch):
    monkeypatch.setattr(
        'sys.stdin', io.StringIO('#NEXUS\n\nbegin trees;\ntree t = ();\nend;'))
    with pytest.raises(ParserError):
        get_reader(argparse.Namespace(filename=None), required_blocks=['data'])
Пример #6
0
def run(args):
    write_output(shufflenexus(get_reader(args), args.numchars or False), args)
Пример #7
0
def run(args):
    print_character_stats(get_reader(args, required_blocks=['data']), args.site_index)
Пример #8
0
def run(args):
    printer = print_binary if args.type == 'binary' else print_tally
    printer(TALLY_TYPES[args.type](get_reader(args)))
Пример #9
0
def run(args):
    write_output(binarise(get_reader(args)), args)
Пример #10
0
def run(args):
    write_output(combine_nexuses(get_reader(args, many=True)), args)
Пример #11
0
def run(args):
    write_output(get_reader(args), args)
Пример #12
0
def run(args):
    nexuslist = [
        multistatise.multistatise(n) for n in get_reader(args, many=True)
    ]
    write_output(combine_nexuses(nexuslist), args)