|
47 | 47 |
|
48 | 48 | def get_trans_table(table): |
49 | 49 | # swap to different codon table |
| 50 | + translation_table = bact_translation_table.copy() |
| 51 | + tb = generic_by_id[table] |
50 | 52 | if table!=11: |
51 | 53 | if table not in generic_by_id: |
52 | 54 | raise RuntimeError("Invalid codon table! Must be available" + |
53 | 55 | " as a generic table in BioPython") |
54 | | - translation_table = bact_translation_table.copy() |
55 | | - tb = generic_by_id[table] |
56 | 56 | for codon in tb.forward_table: |
| 57 | + if 'U' in codon: continue |
57 | 58 | ind = reduce_array[np.array(bytearray(codon.encode()), dtype=np.int8)] |
58 | 59 | translation_table[ind[0], ind[1], ind[2]] = tb.forward_table[codon].encode('utf-8') |
59 | 60 | for codon in tb.stop_codons: |
| 61 | + if 'U' in codon: continue |
60 | 62 | ind = reduce_array[np.array(bytearray(codon.encode()), dtype=np.int8)] |
61 | 63 | 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)]) |
65 | 66 |
|
66 | 67 |
|
67 | 68 | def translate(seq, translation_table): |
68 | 69 | indices = reduce_array[np.array(bytearray(seq.encode()), dtype=np.int8)] |
69 | | - |
70 | | - return translation_table[ |
| 70 | + pseq = translation_table[0][ |
71 | 71 | indices[np.arange(0, len(seq), 3)], indices[np.arange(1, len(seq), 3)], |
72 | 72 | 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 | + |
73 | 78 |
|
74 | 79 | def create_temp_gff3(gff_file, fasta_file, temp_dir): |
75 | 80 |
|
|
0 commit comments