# Misc functions # ------------------------------------ # ------------------------------------ # Classes # ------------------------------------ # ------------------------------------ # Main # ------------------------------------ if __name__=="__main__": # Get parameters args=argParser() fh = IO.mopen(args.ofname,'w') genome=FastaFile(args.genome) for i,item in enumerate(IO.BioReader(args.ifname,args.ftype)): try: strand = item.strand except: strand = "+" seq=item.getSeq(genome) if len(seq)>0: print >> fh, '>'+(item.id!="NONAME" and item.id or "item_"+str(i)) if args.linelength: seq = seq.formatSeq(args.linelength) if args.case=='u': seq=seq.upper() elif args.case=='l': seq=seq.lower() print >> fh, seq
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)
# ------------------------------------ # Main # ------------------------------------ if __name__=="__main__": args = argParser() fh = IO.mopen(args.ofname, 'w') # Parse chromosome region if args.region: m = re.search("(\S+):(\S*)-(\S*):(\S*)",args.region) chrom, start, end, strand = m.groups() else: chrom = args.chrom start = args.start end = args.end strand= args.strand if not chrom: raise ValueError("chromosome name is required.") start = int(start) if start else None end = int(end) if end else None strand = strand if strand in ["+","-","."] else "+" # Get seq from Fasta file fa = FastaFile(args.ifname) seq = fa.getSeq(chrom,start,end,strand) fa.close() # Print result print >>fh, ">{0}:{1}-{2}:{3}".format(chrom, start and start or "", end and end or "", strand) print >>fh, seq.formatSeq() IO.mclose(fh)
# Misc functions # ------------------------------------ # ------------------------------------ # Classes # ------------------------------------ # ------------------------------------ # Main # ------------------------------------ if __name__ == "__main__": # Get parameters args = argParser() fh = IO.mopen(args.ofname, 'w') genome = FastaFile(args.genome) for i, item in enumerate(IO.BioReader(args.ifname, args.ftype)): try: strand = item.strand except: strand = "+" seq = item.getSeq(genome) if len(seq) > 0: print >> fh, '>' + (item.id != "NONAME" and item.id or "item_" + str(i)) if args.linelength: seq = seq.formatSeq(args.linelength) if args.case == 'u': seq = seq.upper() elif args.case == 'l': seq = seq.lower()
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)