comparison tools/align_back_trans/align_back_trans.py @ 1:ec202446408a draft

Uploaded v0.0.4, fixed an error message.
author peterjc
date Wed, 04 Jun 2014 08:42:23 -0400
parents 0c24e4e2177d
children 9fbf29a8c12b
comparison
equal deleted inserted replaced
0:0c24e4e2177d 1:ec202446408a
26 from Bio import SeqIO 26 from Bio import SeqIO
27 from Bio import AlignIO 27 from Bio import AlignIO
28 from Bio.Data.CodonTable import ambiguous_generic_by_id 28 from Bio.Data.CodonTable import ambiguous_generic_by_id
29 29
30 if "-v" in sys.argv or "--version" in sys.argv: 30 if "-v" in sys.argv or "--version" in sys.argv:
31 print "v0.0.3" 31 print "v0.0.4"
32 sys.exit(0) 32 sys.exit(0)
33 33
34 def stop_err(msg, error_level=1): 34 def stop_err(msg, error_level=1):
35 """Print error message to stdout and quit with given error level.""" 35 """Print error message to stdout and quit with given error level."""
36 sys.stderr.write("%s\n" % msg) 36 sys.stderr.write("%s\n" % msg)
38 38
39 def check_trans(identifier, nuc, prot, table): 39 def check_trans(identifier, nuc, prot, table):
40 """Returns nucleotide sequence if works (can remove trailing stop)""" 40 """Returns nucleotide sequence if works (can remove trailing stop)"""
41 if len(nuc) % 3: 41 if len(nuc) % 3:
42 stop_err("Nucleotide sequence for %s is length %i (not a multiple of three)" 42 stop_err("Nucleotide sequence for %s is length %i (not a multiple of three)"
43 % (identifier, nuc)) 43 % (identifier, len(nuc)))
44 44
45 p = str(prot).upper().replace("*", "X") 45 p = str(prot).upper().replace("*", "X")
46 t = str(nuc.translate(table)).upper().replace("*", "X") 46 t = str(nuc.translate(table)).upper().replace("*", "X")
47 if len(t) == len(p) + 1: 47 if len(t) == len(p) + 1:
48 if str(nuc)[-3:].upper() in ambiguous_generic_by_id[table].stop_codons: 48 if str(nuc)[-3:].upper() in ambiguous_generic_by_id[table].stop_codons: