Skip to content

Commit 8483aee

Browse files
committed
updated translate function to address #274
1 parent 3c95941 commit 8483aee

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

panaroo/prokka.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,34 @@
4747

4848
def get_trans_table(table):
4949
# swap to different codon table
50+
translation_table = bact_translation_table.copy()
51+
tb = generic_by_id[table]
5052
if table!=11:
5153
if table not in generic_by_id:
5254
raise RuntimeError("Invalid codon table! Must be available" +
5355
" as a generic table in BioPython")
54-
translation_table = bact_translation_table.copy()
55-
tb = generic_by_id[table]
5656
for codon in tb.forward_table:
57+
if 'U' in codon: continue
5758
ind = reduce_array[np.array(bytearray(codon.encode()), dtype=np.int8)]
5859
translation_table[ind[0], ind[1], ind[2]] = tb.forward_table[codon].encode('utf-8')
5960
for codon in tb.stop_codons:
61+
if 'U' in codon: continue
6062
ind = reduce_array[np.array(bytearray(codon.encode()), dtype=np.int8)]
6163
translation_table[ind[0], ind[1], ind[2]] = b'*'
62-
return(translation_table)
63-
else:
64-
return(bact_translation_table)
64+
65+
return([translation_table, set(tb.start_codons)])
6566

6667

6768
def translate(seq, translation_table):
6869
indices = reduce_array[np.array(bytearray(seq.encode()), dtype=np.int8)]
69-
70-
return translation_table[
70+
pseq = translation_table[0][
7171
indices[np.arange(0, len(seq), 3)], indices[np.arange(1, len(seq), 3)],
7272
indices[np.arange(2, len(seq), 3)]].tostring().decode('ascii')
73+
# Check for a different start codon.
74+
if seq[0:3] in translation_table[1]:
75+
return ('M' + pseq[1:])
76+
return(pseq)
77+
7378

7479
def create_temp_gff3(gff_file, fasta_file, temp_dir):
7580

0 commit comments

Comments
 (0)