sys.exit(p.print_help()) args = p.parse_args() return args # ------------------------------------ # Classes # ------------------------------------ # ------------------------------------ # Main # ------------------------------------ if __name__=="__main__": # Get parameters args=argParser() fh = IO.mopen(args.ofname, 'w') lastbed = Bed("chr1\t0\t0") cnt = 0 # count of unique items for item in IO.BioReader(args.ifname,args.ftype): if item.chrom == lastbed.chrom and item.start == lastbed.start and item.stop == lastbed.stop: if args.names == 'c': lastbed.id += ";"+item.id else: if lastbed.stop !=0: cnt += 1 if args.names == 'n': lastbed.id = str(cnt) elif args.names == 'p': lastbed.id = args.prefix+"_"+str(cnt) print >> fh, lastbed
required=False, help='Output file name. Default is "stdout".') if len(sys.argv) == 1: sys.exit(p.print_help()) args = p.parse_args() return args # ------------------------------------ # Classes # ------------------------------------ # ------------------------------------ # Main # ------------------------------------ if __name__ == "__main__": args = argParser() fh = IO.mopen(args.ofname, 'w') # Fasta file fa = FastaFile(args.ifname) f = IO.mopen(args.names) for faid in f: faid = faid.rstrip() seq = fa.getSeq(faid) print >> fh, ">" + faid print >> fh, seq.formatSeq() fa.close() IO.mclose(f) IO.mclose(fh)
args = p.parse_args() return args # ------------------------------------ # Classes # ------------------------------------ # ------------------------------------ # Main # ------------------------------------ if __name__ == "__main__": # Get parameters args = argParser() fh = IO.mopen(args.ofname, 'w') lastbed = Bed("chr1\t0\t0") cnt = 0 # count of unique items for item in IO.BioReader(args.ifname, args.ftype): if item.chrom == lastbed.chrom and item.start == lastbed.start and item.stop == lastbed.stop: if args.names == 'c': lastbed.id += ";" + item.id else: if lastbed.stop != 0: cnt += 1 if args.names == 'n': lastbed.id = str(cnt) elif args.names == 'p': lastbed.id = args.prefix + "_" + str(cnt) print >> fh, lastbed
p.add_argument("-n","--names",dest='names',type=str,metavar="names.lst",required=True,help='A file with sequence names. Can be "stdin".') p.add_argument("-o","--output",dest='ofname',type=str, default="stdout", metavar="output.fa",required=False,help='Output file name. Default is "stdout".') if len(sys.argv)==1: sys.exit(p.print_help()) args = p.parse_args() return args # ------------------------------------ # Classes # ------------------------------------ # ------------------------------------ # Main # ------------------------------------ if __name__=="__main__": args = argParser() fh = IO.mopen(args.ofname, 'w') # Fasta file fa = FastaFile(args.ifname) f = IO.mopen(args.names) for faid in f: faid=faid.rstrip() seq=fa.getSeq(faid) print >> fh, ">"+faid print >> fh, seq.formatSeq() fa.close() IO.mclose(f) IO.mclose(fh)