Commit 9a9bd6c6 by abonin

switch to the new cython interface to array.array

parent 6002fbaa
...@@ -5,6 +5,8 @@ Created on 6 Nov. 2009 ...@@ -5,6 +5,8 @@ Created on 6 Nov. 2009
''' '''
#@PydevCodeAnalysisIgnore #@PydevCodeAnalysisIgnore
from cpython cimport array
from obitools import BioSequence from obitools import BioSequence
from _lcs cimport * from _lcs cimport *
from _upperbond cimport * from _upperbond cimport *
...@@ -137,8 +139,6 @@ def lenlcs(seq1,seq2,double minimum=0.,bint normalized=False, int reference=ALIL ...@@ -137,8 +139,6 @@ def lenlcs(seq1,seq2,double minimum=0.,bint normalized=False, int reference=ALIL
cdef bytes se2=bytes(str(seq2)) cdef bytes se2=bytes(str(seq2))
cdef int l1 = len(seq1) cdef int l1 = len(seq1)
cdef int l2 = len(seq2) cdef int l2 = len(seq2)
cdef array.array[unsigned char] w1
cdef array.array[unsigned char] w2
cdef int o1 cdef int o1
cdef int o2 cdef int o2
cdef int wordcount cdef int wordcount
...@@ -146,11 +146,15 @@ def lenlcs(seq1,seq2,double minimum=0.,bint normalized=False, int reference=ALIL ...@@ -146,11 +146,15 @@ def lenlcs(seq1,seq2,double minimum=0.,bint normalized=False, int reference=ALIL
cdef bint possible cdef bint possible
cdef bint large cdef bint large
cdef array.array[uchar] w1
cdef array.array[uchar] w2
cdef char *s1 cdef char *s1
cdef char *s2 cdef char *s2
s1=se1 s1=se1
s2=se2 s2=se2
if min(l1,l2) < 8: if min(l1,l2) < 8:
lcsali = LCS() lcsali = LCS()
lcsali.seqA = seq1 lcsali.seqA = seq1
...@@ -163,7 +167,7 @@ def lenlcs(seq1,seq2,double minimum=0.,bint normalized=False, int reference=ALIL ...@@ -163,7 +167,7 @@ def lenlcs(seq1,seq2,double minimum=0.,bint normalized=False, int reference=ALIL
o1 = seq1.word4over o1 = seq1.word4over
else: else:
w1 = newtable() w1 = newtable()
o1 = buildTable(s1,w1._BYTES,&wordcount) o1 = buildTable(s1,w1.data.as_uchars,&wordcount)
if isinstance(seq1, BioSequence): if isinstance(seq1, BioSequence):
seq1.word4table=w1 seq1.word4table=w1
seq1.word4over=o1 seq1.word4over=o1
...@@ -172,13 +176,14 @@ def lenlcs(seq1,seq2,double minimum=0.,bint normalized=False, int reference=ALIL ...@@ -172,13 +176,14 @@ def lenlcs(seq1,seq2,double minimum=0.,bint normalized=False, int reference=ALIL
o2 = seq2.word4over o2 = seq2.word4over
else: else:
w2 = newtable() w2 = newtable()
o2 = buildTable(s2,w2._BYTES,&wordcount) o2 = buildTable(s2,w2.data.as_uchars,&wordcount)
if isinstance(seq2, BioSequence) : if isinstance(seq2, BioSequence) :
seq2.word4table=w2 seq2.word4table=w2
seq2.word4over=o2 seq2.word4over=o2
large = reference==ALILEN or reference==MAXLEN large = reference==ALILEN or reference==MAXLEN
possible = ispossible(l1, w1._BYTES, o1, possible = ispossible(l1, w1.data.as_uchars, o1,
l2, w2._BYTES, o2, l2, w2.data.as_uchars, o2,
minimum,normalized,large) minimum,normalized,large)
if possible: if possible:
lcs = fastLCSScore(s1,s2,NULL,&alilength) lcs = fastLCSScore(s1,s2,NULL,&alilength)
......
from array import array from cpython cimport array
cimport array
cdef extern from *: cdef extern from *:
ctypedef char* const_char_ptr "const char*" ctypedef char* const_char_ptr "const char*"
cdef import from "_upperbond.h": cdef import from "_upperbond.h":
int buildTable(const_char_ptr sequence, unsigned char *table, int *count) int buildTable(const_char_ptr sequence, unsigned char *table, int *count)
int compareTable(unsigned char *t1, int over1, unsigned char* t2, int over2) int compareTable(unsigned char *t1, int over1, unsigned char* t2, int over2)
...@@ -13,5 +12,5 @@ cdef import from "_upperbond.h": ...@@ -13,5 +12,5 @@ cdef import from "_upperbond.h":
bint ispossible(int len1, unsigned char *t1, int over1, bint ispossible(int len1, unsigned char *t1, int over1,
int len2, unsigned char* t2, int over2, int len2, unsigned char* t2, int over2,
double minimum, bint normalized, bint large) double minimum, bint normalized, bint large)
cdef array.array[unsigned char] newtable() cdef array.array[unsigned char] newtable()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment