Skip to content

Commit

Permalink
updated translate function to address #274
Browse files Browse the repository at this point in the history
  • Loading branch information
gtonkinhill committed Apr 2, 2024
1 parent 3c95941 commit 8483aee
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions panaroo/prokka.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,34 @@

def get_trans_table(table):
# swap to different codon table
translation_table = bact_translation_table.copy()
tb = generic_by_id[table]
if table!=11:
if table not in generic_by_id:
raise RuntimeError("Invalid codon table! Must be available" +
" as a generic table in BioPython")
translation_table = bact_translation_table.copy()
tb = generic_by_id[table]
for codon in tb.forward_table:
if 'U' in codon: continue
ind = reduce_array[np.array(bytearray(codon.encode()), dtype=np.int8)]
translation_table[ind[0], ind[1], ind[2]] = tb.forward_table[codon].encode('utf-8')
for codon in tb.stop_codons:
if 'U' in codon: continue
ind = reduce_array[np.array(bytearray(codon.encode()), dtype=np.int8)]
translation_table[ind[0], ind[1], ind[2]] = b'*'
return(translation_table)
else:
return(bact_translation_table)

return([translation_table, set(tb.start_codons)])


def translate(seq, translation_table):
indices = reduce_array[np.array(bytearray(seq.encode()), dtype=np.int8)]

return translation_table[
pseq = translation_table[0][
indices[np.arange(0, len(seq), 3)], indices[np.arange(1, len(seq), 3)],
indices[np.arange(2, len(seq), 3)]].tostring().decode('ascii')
# Check for a different start codon.
if seq[0:3] in translation_table[1]:
return ('M' + pseq[1:])
return(pseq)


def create_temp_gff3(gff_file, fasta_file, temp_dir):

Expand Down

0 comments on commit 8483aee

Please sign in to comment.