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)
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)]) ])
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()
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)
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'])
def run(args): write_output(shufflenexus(get_reader(args), args.numchars or False), args)
def run(args): print_character_stats(get_reader(args, required_blocks=['data']), args.site_index)
def run(args): printer = print_binary if args.type == 'binary' else print_tally printer(TALLY_TYPES[args.type](get_reader(args)))
def run(args): write_output(binarise(get_reader(args)), args)
def run(args): write_output(combine_nexuses(get_reader(args, many=True)), args)
def run(args): write_output(get_reader(args), args)
def run(args): nexuslist = [ multistatise.multistatise(n) for n in get_reader(args, many=True) ] write_output(combine_nexuses(nexuslist), args)