| 1 |
# cython: language_level=3 |
| 2 |
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t |
| 3 |
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t |
| 4 |
from libc.stdlib cimport malloc, calloc, realloc, free |
| 5 |
from libc.string cimport memcpy, memcmp, strncpy, strlen, strdup |
| 6 |
from libc.stdio cimport FILE, printf |
| 7 |
cimport cython |
| 8 |
|
| 9 |
from cpython cimport array |
| 10 |
from pysam.libchtslib cimport faidx_t, kstring_t, BGZF |
| 11 |
|
| 12 |
# These functions are put here and not in chtslib.pxd in order |
| 13 |
# to avoid warnings for unused functions. |
| 14 |
cdef extern from "pysam_stream.h" nogil: |
| 15 |
|
| 16 |
ctypedef struct kstream_t: |
| 17 |
pass |
| 18 |
|
| 19 |
ctypedef struct kseq_t: |
| 20 |
kstring_t name |
| 21 |
kstring_t comment |
| 22 |
kstring_t seq |
| 23 |
kstring_t qual |
| 24 |
|
| 25 |
kseq_t *kseq_init(BGZF *) |
| 26 |
int kseq_read(kseq_t *) |
| 27 |
void kseq_destroy(kseq_t *) |
| 28 |
kstream_t *ks_init(BGZF *) |
| 29 |
void ks_destroy(kstream_t *) |
| 30 |
|
| 31 |
# Retrieve characters from stream until delimiter |
| 32 |
# is reached placing results in str. |
| 33 |
int ks_getuntil(kstream_t *, |
| 34 |
int delimiter, |
| 35 |
kstring_t * str, |
| 36 |
int * dret) |
| 37 |
|
| 38 |
cdef class FastaFile: |
| 39 |
cdef bint is_remote |
| 40 |
cdef object _filename, _references, _lengths, reference2length |
| 41 |
cdef faidx_t* fastafile |
| 42 |
cdef char* _fetch(self, char* reference, |
| 43 |
int start, int end, int* length) except? NULL |
| 44 |
|
| 45 |
|
| 46 |
cdef class FastqProxy: |
| 47 |
cdef kseq_t * _delegate |
| 48 |
cdef cython.str to_string(self) |
| 49 |
cdef cython.str tostring(self) |
| 50 |
cpdef array.array get_quality_array(self, int offset=*) |
| 51 |
|
| 52 |
|
| 53 |
cdef class FastxRecord: |
| 54 |
""" |
| 55 |
Python container for pysam.libcfaidx.FastqProxy with persistence. |
| 56 |
""" |
| 57 |
cdef public str comment, quality, sequence, name |
| 58 |
cdef cython.str to_string(self) |
| 59 |
cdef cython.str tostring(self) |
| 60 |
cpdef array.array get_quality_array(self, int offset=*) |
| 61 |
|
| 62 |
cdef class FastxFile: |
| 63 |
cdef object _filename |
| 64 |
cdef BGZF * fastqfile |
| 65 |
cdef kseq_t * entry |
| 66 |
cdef bint persist |
| 67 |
cdef bint is_remote |
| 68 |
|
| 69 |
cdef kseq_t * getCurrent(self) |
| 70 |
cdef int cnext(self) |
| 71 |
|
| 72 |
|
| 73 |
# Compatibility Layer for pysam 0.8.1 |
| 74 |
cdef class FastqFile(FastxFile): |
| 75 |
pass |
| 76 |
|
| 77 |
|
| 78 |
# Compatibility Layer for pysam < 0.8 |
| 79 |
cdef class Fastafile(FastaFile): |
| 80 |
pass |
| 81 |
|