Esempio n. 1
0
    alg = CompactAlignment()
    alg.read_file_object(args.infile, args.informat)

    #     if args.actions:
    #         print >>sys.stderr, "will perform the following actions: %s" %",".join(args.actions)
    #     else:
    #         print >>sys.stderr, "No actions will be taken. Input in %s will be written to output in %s." %(args.informat,args.outformat)

    if args.masksites:
        alg.mask_gapy_sites(args.masksites)

    if args.filterfragments:
        rem = []
        for k, v in alg.items():
            if len(v.seq) < args.filterfragments:
                rem.append(k)
        for k in rem:
            alg.pop(k, None)

    if args.rename:
        lines = [x for x in args.rename.readlines() if x != "\n"]
        namemap = dict(
            list(
                zip((x.strip() for i, x in enumerate(lines) if i % 2 == 0),
                    (x.strip() for i, x in enumerate(lines) if i % 2 == 1))))
        names = copy(list(alg.keys()))
        for k in names:
            alg[namemap[k]] = alg.pop(k)

    alg.write(args.outfile, args.outformat)
Esempio n. 2
0
    args = parser.parse_args()
    alg = CompactAlignment()
    alg.read_file_object(args.infile,args.informat)
    
#     if args.actions:
#         print >>sys.stderr, "will perform the following actions: %s" %",".join(args.actions)
#     else:
#         print >>sys.stderr, "No actions will be taken. Input in %s will be written to output in %s." %(args.informat,args.outformat)
    
    if args.masksites:
        alg.mask_gapy_sites(args.masksites)
        
    if args.filterfragments:
        rem = []
        for k, v in alg.iteritems():
            if len(v.seq) < args.filterfragments:
                rem.append(k)
        for k in rem:
            alg.pop(k, None)
        
    if args.rename:
        lines=filter(lambda x: x!="\n", args.rename.readlines())
        namemap=dict(zip((x.strip() for i,x in enumerate(lines) if i%2 == 0),
                         (x.strip() for i,x in enumerate(lines) if i%2 == 1)))
        names = copy(alg.keys())
        for k in names:
            alg[namemap[k]] = alg.pop(k)
            
    alg.write(args.outfile, args.outformat)