From 11032ec90baac36e7fb0ec5f3aa394b14b7089b6 Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Wed, 17 Oct 2018 11:24:44 +0200 Subject: [PATCH] Cython: Sequence objects: Quality strings are now returned as bytes instead of str --- .../dms/column/typed_column/qual.pxd | 10 +++++----- .../dms/column/typed_column/qual.pyx | 20 +++++++++---------- python/obitools3/dms/obiseq.pyx | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/python/obitools3/dms/column/typed_column/qual.pxd b/python/obitools3/dms/column/typed_column/qual.pxd index 1381517..3b8a20e 100644 --- a/python/obitools3/dms/column/typed_column/qual.pxd +++ b/python/obitools3/dms/column/typed_column/qual.pxd @@ -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=*) \ No newline at end of file diff --git a/python/obitools3/dms/column/typed_column/qual.pyx b/python/obitools3/dms/column/typed_column/qual.pyx index cbc6d03..4af9e34 100644 --- a/python/obitools3/dms/column/typed_column/qual.pyx +++ b/python/obitools3/dms/column/typed_column/qual.pyx @@ -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 diff --git a/python/obitools3/dms/obiseq.pyx b/python/obitools3/dms/obiseq.pyx index 655f100..c7bbbec 100644 --- a/python/obitools3/dms/obiseq.pyx +++ b/python/obitools3/dms/obiseq.pyx @@ -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