Attachment 'translate.py'

Download

   1 #!/usr/bin/env python
   2 import sys
   3 
   4 xlate={"ttt":"f","ttc":"f","tta":"l","ttg":"l","ctt":"l","ctc":"l","cta":"l","ctg":"l","att":"i","atc":"i","ata":"i","atg":"m","gtt":"v","gtc":"v","gta":"v","gtg":"v","tct":"s","tcc":"s","tca":"s","tcg":"s","cct":"p","ccc":"p","cca":"p","ccg":"p","act":"t","acc":"t","aca":"t","acg":"t","gct":"a","gcc":"a","gca":"a","gcg":"a","tat":"y","tac":"y","taa":"0","tag":"0","cat":"h","cac":"h","caa":"q","cag":"q","aat":"n","aac":"n","aaa":"k","aag":"k","gat":"d","gac":"d","gaa":"e","gag":"e","tgt":"c","tgc":"c","tga":"0","tgg":"w","cgt":"r","cgc":"r","cga":"r","cgg":"r","agt":"s","agc":"s","aga":"r","agg":"r","ggt":"g","ggc":"g","gga":"g","ggg":"g"}
   5 
   6 fsp=sys.argv[1]
   7 dna=file(fsp,"r").read()         # read the entire file into ram
   8 dna=dna.translate(None,"0123456789 \t\n\r").lower()
   9 out=file(fsp+".prot","w")
  10 
  11 for i in xrange(0,len(dna),3):
  12 	triplet=dna[i:i+3]
  13 	try: amino=xlate[triplet]
  14 	except:
  15 		print "Unknown triplet: ",triplet
  16 		sys.exit(1)
  17 	out.write(amino)
  18 
  19 out.write("\n")

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.