Cython: fasta writer
This commit is contained in:
@ -4,7 +4,7 @@ from cython.view cimport array as cvarray
|
|||||||
|
|
||||||
cdef class FastaFormat:
|
cdef class FastaFormat:
|
||||||
|
|
||||||
cdef HeaderFormat headerFormater
|
cdef HeaderFormat headerFormatter
|
||||||
|
|
||||||
cdef size_t sequenceBufferLength
|
cdef size_t sequenceBufferLength
|
||||||
cdef char* sequenceBuffer
|
cdef char* sequenceBuffer
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
|
#cython: language_level=3
|
||||||
|
|
||||||
cimport cython
|
cimport cython
|
||||||
|
from obitools3.dms.capi.obiview cimport NUC_SEQUENCE_COLUMN
|
||||||
|
from obitools3.utils cimport bytes2str
|
||||||
|
|
||||||
|
|
||||||
cdef class FastaFormat:
|
cdef class FastaFormat:
|
||||||
|
|
||||||
def __init__(self, list tags=[], bint printNAKeys=False):
|
def __init__(self, list tags=[], bint printNAKeys=False):
|
||||||
self.headerFormater = HeaderFormat(True,
|
self.headerFormatter = HeaderFormat("fasta",
|
||||||
tags,
|
tags,
|
||||||
printNAKeys)
|
printNAKeys)
|
||||||
|
|
||||||
@cython.boundscheck(False)
|
@cython.boundscheck(False)
|
||||||
def __call__(self, dict data):
|
def __call__(self, object data):
|
||||||
cdef bytes brawseq = data['sequence']
|
cdef bytes brawseq = data[NUC_SEQUENCE_COLUMN]
|
||||||
cdef size_t lseq = len(brawseq)
|
cdef size_t lseq = len(brawseq)
|
||||||
cdef size_t k=0
|
cdef size_t k = 0
|
||||||
cdef list lines = []
|
cdef list lines = []
|
||||||
|
|
||||||
for k in range(0,lseq,60):
|
for k in range(0,lseq,60):
|
||||||
@ -19,12 +24,5 @@ cdef class FastaFormat:
|
|||||||
|
|
||||||
brawseq = b'\n'.join(lines)
|
brawseq = b'\n'.join(lines)
|
||||||
|
|
||||||
return "%s\n%s" % (self.headerFormater(data),bytes2str(brawseq))
|
return bytes2str(self.headerFormatter(data) + b"\n" + brawseq)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user