Cython: Sequence objects: Quality strings are now returned as bytes
instead of str
This commit is contained in:
@ -10,17 +10,17 @@ from ..column_idx cimport Column_idx, \
|
|||||||
cdef class Column_qual(Column_idx) :
|
cdef class Column_qual(Column_idx) :
|
||||||
|
|
||||||
cpdef object get_line(self, index_t line_nb)
|
cpdef object get_line(self, index_t line_nb)
|
||||||
cpdef object get_str_line(self, index_t line_nb, int offset=*)
|
cpdef object get_bytes_line(self, index_t line_nb, int offset=*)
|
||||||
cpdef set_line(self, index_t line_nb, object value)
|
cpdef set_line(self, index_t line_nb, object value)
|
||||||
cpdef set_str_line(self, index_t line_nb, object value, int offset=*)
|
cpdef set_bytes_line(self, index_t line_nb, object value, int offset=*)
|
||||||
|
|
||||||
|
|
||||||
cdef class Column_multi_elts_qual(Column_multi_elts_idx) :
|
cdef class Column_multi_elts_qual(Column_multi_elts_idx) :
|
||||||
|
|
||||||
cpdef object get_item(self, index_t line_nb, object elt_id)
|
cpdef object get_item(self, index_t line_nb, object elt_id)
|
||||||
cpdef object get_str_item(self, index_t line_nb, object elt_id, int offset=*)
|
cpdef object get_bytes_item(self, index_t line_nb, object elt_id, int offset=*)
|
||||||
cpdef object get_line(self, index_t line_nb)
|
cpdef object get_line(self, index_t line_nb)
|
||||||
cpdef object get_str_line(self, index_t line_nb, int offset=*)
|
cpdef object get_bytes_line(self, index_t line_nb, int offset=*)
|
||||||
cpdef set_item(self, index_t line_nb, object elt_id, object value)
|
cpdef set_item(self, index_t line_nb, object elt_id, object value)
|
||||||
cpdef set_str_item(self, index_t line_nb, object elt_id, object value, int offset=*)
|
cpdef set_bytes_item(self, index_t line_nb, object elt_id, object value, int offset=*)
|
||||||
|
|
@ -29,7 +29,7 @@ from libc.stdlib cimport malloc, free
|
|||||||
from libc.stdint cimport uint8_t
|
from libc.stdint cimport uint8_t
|
||||||
|
|
||||||
|
|
||||||
# TODO detect type of value and call set_item_str if str or bytes
|
# TODO detect type of value and call set_item_str if str or bytes?
|
||||||
|
|
||||||
cdef class Column_qual(Column_idx):
|
cdef class Column_qual(Column_idx):
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ cdef class Column_qual(Column_idx):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
cpdef object get_str_line(self, index_t line_nb, int offset=-1):
|
cpdef object get_bytes_line(self, index_t line_nb, int offset=-1):
|
||||||
global obi_errno
|
global obi_errno
|
||||||
cdef char* value
|
cdef char* value
|
||||||
cdef object result
|
cdef object result
|
||||||
@ -76,8 +76,8 @@ cdef class Column_qual(Column_idx):
|
|||||||
obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column")
|
obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column")
|
||||||
if value == OBIQual_char_NA :
|
if value == OBIQual_char_NA :
|
||||||
result = None
|
result = None
|
||||||
else : # TODO discuss
|
else :
|
||||||
result = bytes2str(value)
|
result = value
|
||||||
free(value)
|
free(value)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ cdef class Column_qual(Column_idx):
|
|||||||
free(value_b)
|
free(value_b)
|
||||||
|
|
||||||
|
|
||||||
cpdef set_str_line(self, index_t line_nb, object value, int offset=-1):
|
cpdef set_bytes_line(self, index_t line_nb, object value, int offset=-1):
|
||||||
global obi_errno
|
global obi_errno
|
||||||
cdef bytes value_b
|
cdef bytes value_b
|
||||||
if value is None :
|
if value is None :
|
||||||
@ -134,7 +134,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts_idx):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
cpdef object get_str_item(self, index_t line_nb, object elt_id, int offset=-1):
|
cpdef object get_bytes_item(self, index_t line_nb, object elt_id, int offset=-1):
|
||||||
global obi_errno
|
global obi_errno
|
||||||
cdef char* value
|
cdef char* value
|
||||||
cdef object result
|
cdef object result
|
||||||
@ -147,7 +147,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts_idx):
|
|||||||
if value == OBIQual_char_NA :
|
if value == OBIQual_char_NA :
|
||||||
result = None
|
result = None
|
||||||
else :
|
else :
|
||||||
result = bytes2str(value) # TODO return bytes?
|
result = value
|
||||||
free(value)
|
free(value)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts_idx):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
cpdef object get_str_line(self, index_t line_nb, int offset=-1) :
|
cpdef object get_bytes_line(self, index_t line_nb, int offset=-1) :
|
||||||
global obi_errno
|
global obi_errno
|
||||||
cdef char* value
|
cdef char* value
|
||||||
cdef object value_in_result
|
cdef object value_in_result
|
||||||
@ -203,7 +203,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts_idx):
|
|||||||
value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i, offset)
|
value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i, offset)
|
||||||
obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column")
|
obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column")
|
||||||
if value != OBIQual_char_NA :
|
if value != OBIQual_char_NA :
|
||||||
value_in_result = bytes2str(value)
|
value_in_result = value
|
||||||
free(value)
|
free(value)
|
||||||
result[elements_names[i]] = value_in_result
|
result[elements_names[i]] = value_in_result
|
||||||
if all_NA :
|
if all_NA :
|
||||||
@ -240,7 +240,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts_idx):
|
|||||||
free(value_b)
|
free(value_b)
|
||||||
|
|
||||||
|
|
||||||
cpdef set_str_item(self, index_t line_nb, object elt_id, object value, int offset=-1):
|
cpdef set_bytes_item(self, index_t line_nb, object elt_id, object value, int offset=-1):
|
||||||
global obi_errno
|
global obi_errno
|
||||||
cdef bytes value_b
|
cdef bytes value_b
|
||||||
cdef bytes elt_name
|
cdef bytes elt_name
|
||||||
|
@ -363,9 +363,9 @@ cdef class Nuc_Seq_Stored(Seq_Stored) :
|
|||||||
# quality character string property getter
|
# quality character string property getter
|
||||||
# WARNING: default offset used
|
# WARNING: default offset used
|
||||||
@property
|
@property
|
||||||
def quality_str(self):
|
def quality_bytes(self):
|
||||||
if QUALITY_COLUMN in self:
|
if QUALITY_COLUMN in self:
|
||||||
return self._view.get_column(QUALITY_COLUMN).get_str_line(self._index)
|
return self._view.get_column(QUALITY_COLUMN).get_bytes_line(self._index)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user