1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
Description: Avoid runtime typecasting of bytearray to bytes
Author: James Addison <jay@jp-hosting.net>
Bug-Debian: https://bugs.debian.org/1098613
---
--- python-sqt-0.8.0.orig/sqt/_helpers.pyx
+++ python-sqt-0.8.0/sqt/_helpers.pyx
@@ -402,10 +402,13 @@ def hamming_distance(unicode s, unicode
# Lookup table that maps nucleotides to their 2-bit representation
# and everything else to 255.
-cdef bytearray _nt_trans = bytearray([255]*256)
-for frm, to in zip(b'ACGTacgt', b'\x00\x01\x02\x03\x00\x01\x02\x03'):
- _nt_trans[frm] = to
+def _make_nt_trans():
+ table = bytearray([255]*256)
+ for frm, to in zip(b'ACGTacgt', b'\x00\x01\x02\x03\x00\x01\x02\x03'):
+ table[frm] = to
+ return bytes(table)
+cdef bytes _nt_trans = _make_nt_trans()
# Lookup table that maps 6-bit encoded codons to amino acids
def _make_codon_array(stop_aa='*'):
@@ -414,9 +417,9 @@ def _make_codon_array(stop_aa='*'):
b = codon.encode().translate(_nt_trans)
index = b[0] * 16 + b[1] * 4 + b[2]
triples[index] = ord(aa)
- return triples
+ return bytes(triples)
-cdef bytearray _codon_array = _make_codon_array()
+cdef bytes _codon_array = _make_codon_array()
def nt_to_aa(s: str):
@@ -433,8 +436,8 @@ def nt_to_aa(s: str):
cdef int j = 0
cdef int v = 0
cdef unsigned char nt0, nt1, nt2
- cdef char* nt_trans_ptr = <bytes>_nt_trans
- cdef char* codon_array_ptr = <bytes>_codon_array
+ cdef char* nt_trans_ptr = _nt_trans
+ cdef char* codon_array_ptr = _codon_array
cdef bytes s_bytes = s.encode()
cdef char* b = s_bytes
cdef bytearray result = bytearray([0]*((len(s)+2)//3))
|