Cython: fastq formatter
This commit is contained in:
10
python/obitools3/format/fastq.pxd
Normal file
10
python/obitools3/format/fastq.pxd
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from ..utils cimport bytes2str
|
||||||
|
from .header cimport HeaderFormat
|
||||||
|
from cython.view cimport array as cvarray
|
||||||
|
|
||||||
|
cdef class FastqFormat:
|
||||||
|
|
||||||
|
cdef HeaderFormat headerFormatter
|
||||||
|
|
||||||
|
cdef size_t sequenceBufferLength
|
||||||
|
cdef char* sequenceBuffer
|
32
python/obitools3/format/fastq.pyx
Normal file
32
python/obitools3/format/fastq.pyx
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#cython: language_level=3
|
||||||
|
|
||||||
|
cimport cython
|
||||||
|
from obitools3.dms.capi.obiview cimport NUC_SEQUENCE_COLUMN
|
||||||
|
from obitools3.utils cimport bytes2str, str2bytes, tobytes
|
||||||
|
|
||||||
|
|
||||||
|
# TODO quality offset option
|
||||||
|
cdef class FastqFormat:
|
||||||
|
|
||||||
|
def __init__(self, list tags=[], bint printNAKeys=False):
|
||||||
|
self.headerFormatter = HeaderFormat("fastq",
|
||||||
|
tags,
|
||||||
|
printNAKeys)
|
||||||
|
|
||||||
|
@cython.boundscheck(False)
|
||||||
|
def __call__(self, object data):
|
||||||
|
|
||||||
|
cdef bytes quality
|
||||||
|
|
||||||
|
if hasattr(data, "quality_str"):
|
||||||
|
quality = str2bytes(data.quality_str) # TODO quality_bytes property
|
||||||
|
elif hasattr(data, "quality"):
|
||||||
|
quality = tobytes(data.quality)
|
||||||
|
else:
|
||||||
|
raise AttributeError("No quality when exporting to fastq") # TODO discuss
|
||||||
|
|
||||||
|
return bytes2str(self.headerFormatter(data) +
|
||||||
|
b"\n" +
|
||||||
|
data[NUC_SEQUENCE_COLUMN] +
|
||||||
|
b"\n+\n" +
|
||||||
|
quality)
|
Reference in New Issue
Block a user