Exemplo n.º 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)
Exemplo n.º 2
0
 except IndexError:
     newnexusname = None
     
 
 nexus = NexusReader(nexusname)
 newnexus = None
 
 if options.number:
     if newnexusname is not None:
         print_site_values(nexus, newnexusname)
     else:
         print_site_values(nexus)
         
 elif options.constant:
     const = find_constant_sites(nexus)
     newnexus = new_nexus_without_sites(nexus, const)
     print("Constant Sites: %s" % ",".join([str(i) for i in const]))
 elif options.unique:
     unique = find_unique_sites(nexus)
     newnexus = new_nexus_without_sites(nexus, unique)
     print("Unique Sites: %s" % ",".join([str(i) for i in unique]))
 elif options.stats:
     d = print_character_stats(nexus)
     
 else:
     exit()
     
 # check for saving
 if newnexus is not None and newnexusname is not None:
     newnexus.write_to_file(newnexusname)
     print("New nexus written to %s" % newnexusname)
 def test_remove_sites_list(self):
     nexus = NexusReader(os.path.join(EXAMPLE_DIR, 'example.nex'))
     nexus = new_nexus_without_sites(nexus, [1])
     assert len(nexus.data) == 1
Exemplo n.º 4
0
        newnexusname = args[1]
    except IndexError:
        newnexusname = None

    nexus = NexusReader(nexusname)
    newnexus = None

    if options.number:
        if newnexusname is not None:
            print_site_values(nexus, newnexusname)
        else:
            print_site_values(nexus)

    elif options.constant:
        const = find_constant_sites(nexus)
        newnexus = new_nexus_without_sites(nexus, const)
        print("Constant Sites: %s" % ",".join([str(i) for i in const]))
    elif options.unique:
        unique = find_unique_sites(nexus)
        newnexus = new_nexus_without_sites(nexus, unique)
        print("Unique Sites: %s" % ",".join([str(i) for i in unique]))
    elif options.stats:
        d = print_character_stats(nexus)

    else:
        exit()

    # check for saving
    if newnexus is not None and newnexusname is not None:
        newnexus.write_to_file(newnexusname)
        print("New nexus written to %s" % newnexusname)
 def test_remove_sites_1(self):
     nexus = NexusReader(os.path.join(EXAMPLE_DIR, 'example.nex'))
     nexus = new_nexus_without_sites(nexus, [1])
     assert len(nexus.data) == 1
    if options.number:
        print_site_values(nexus)
        exit()
    
    if options.stats:
        print_character_stats(nexus)
        exit()
        
    const, unique, zeros, remove = [], [], [], []
    if options.constant:
        const = find_constant_sites(nexus)
        print("Constant Sites: %s" % ",".join([str(i) for i in const]))
    if options.unique:
        unique = find_unique_sites(nexus)
        print("Unique Sites: %s" % ",".join([str(i) for i in unique]))
    if options.zeros:
        zeros = check_zeros(nexus)
        print("Zero Sites: %s" % ",".join([str(i) for i in zeros]))
    if options.remove:
        remove = [int(i) for i in parse_deltree(options.remove)]
        print("Remove: %s" % ",".join([str(i) for i in zeros]))
        
    newnexus = new_nexus_without_sites(nexus, set(const + unique + zeros + remove))
    
    # check for saving
    if newnexus is not None and newnexusname is not None:
        newnexus.write_to_file(newnexusname)
        print("New nexus written to %s" % newnexusname)


Exemplo n.º 7
0
    newnexus = None

    if options.number:
        print_site_values(nexus)
        exit()
    
    if options.stats:
        print_character_stats(nexus)
        exit()
        
    const, unique, zeros, remove = [], [], [], []
    if options.constant:
        const = find_constant_sites(nexus)
        print("Constant Sites: %s" % ",".join([str(i) for i in const]))
    if options.unique:
        unique = find_unique_sites(nexus)
        print("Unique Sites: %s" % ",".join([str(i) for i in unique]))
    if options.zeros:
        zeros = check_zeros(nexus)
        print("Zero Sites: %s" % ",".join([str(i) for i in zeros]))
    if options.remove:
        remove = [int(i) for i in parse_deltree(options.remove)]
        print("Remove: %s" % ",".join([str(i) for i in zeros]))
        
    newnexus = new_nexus_without_sites(nexus, set(const + unique + zeros + remove))
    
    # check for saving
    if newnexus is not None and newnexusname is not None:
        newnexus.write_to_file(newnexusname)
        print("New nexus written to %s" % newnexusname)
def test_remove_sites_set(nex):
    nexus = new_nexus_without_sites(nex, set([1]))
    assert len(nexus.data) == 1
def test_remove_sites_list(nex):
    nexus = new_nexus_without_sites(nex, [1])
    assert len(nexus.data) == 1