#format python """ReverseComplement using BioPython """ import sys from Bio import Fasta dictDnaComp = {'A':'T', 'T':'A', 'G':'C', 'C':'G'} def main(infilename, outfilename): try: infile = open(infilename, 'r') outfile = open(outfilename, 'w') except: print "Error: unable to open file" sys.exit() parser = Fasta.RecordParser() iterator = Fasta.Iterator(infile, parser) while 1: curRecord = iterator.next() if curRecord is None: break curRecord.sequence = convert(curRecord.sequence) outfile.write(str(curRecord)) def convert(aSeq): newSeq = '' for index in range(len(aSeq)-1, -1, -1): newSeq += dictDnaComp[aSeq[index]] return newSeq if __name__ == '__main__': ifile, ofile = sys.argv[1:3] main(ifile, ofile)