Cython: Sequence objects: Quality strings are now returned as bytes

instead of str
This commit is contained in:
Celine Mercier
2018-10-17 11:24:44 +02:00
parent 8a9ba8b0a8
commit 11032ec90b
3 changed files with 17 additions and 17 deletions

View File

@ -10,17 +10,17 @@ from ..column_idx cimport Column_idx, \
cdef class Column_qual(Column_idx) :
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_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) :
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_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_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=*)

View File

@ -29,7 +29,7 @@ from libc.stdlib cimport malloc, free
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):
@ -67,7 +67,7 @@ cdef class Column_qual(Column_idx):
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
cdef char* value
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")
if value == OBIQual_char_NA :
result = None
else : # TODO discuss
result = bytes2str(value)
else :
result = value
free(value)
return result
@ -99,7 +99,7 @@ cdef class Column_qual(Column_idx):
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
cdef bytes value_b
if value is None :
@ -134,7 +134,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts_idx):
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
cdef char* value
cdef object result
@ -147,7 +147,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts_idx):
if value == OBIQual_char_NA :
result = None
else :
result = bytes2str(value) # TODO return bytes?
result = value
free(value)
return result
@ -184,7 +184,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts_idx):
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
cdef char* value
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)
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 :
value_in_result = bytes2str(value)
value_in_result = value
free(value)
result[elements_names[i]] = value_in_result
if all_NA :
@ -240,7 +240,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts_idx):
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
cdef bytes value_b
cdef bytes elt_name

View File

@ -363,9 +363,9 @@ cdef class Nuc_Seq_Stored(Seq_Stored) :
# quality character string property getter
# WARNING: default offset used
@property
def quality_str(self):
def quality_bytes(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:
return None