From 15d383fa8b56202d9e7a08e8138981fbac3e59cf Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Thu, 27 Jul 2017 19:24:41 +0200 Subject: [PATCH] Added possibility to specify the offset for encoding and decoding sequence quality character strings --- .../dms/column/typed_column/qual.pxd | 18 +++++----- .../dms/column/typed_column/qual.pyx | 34 +++++++++++-------- src/obidmscolumn_qual.c | 22 +++++++----- src/obidmscolumn_qual.h | 18 +++++++--- src/obiview.c | 32 ++++++++--------- src/obiview.h | 32 ++++++++++++----- 6 files changed, 95 insertions(+), 61 deletions(-) diff --git a/python/obitools3/dms/column/typed_column/qual.pxd b/python/obitools3/dms/column/typed_column/qual.pxd index f9cbba4..1381517 100644 --- a/python/obitools3/dms/column/typed_column/qual.pxd +++ b/python/obitools3/dms/column/typed_column/qual.pxd @@ -3,24 +3,24 @@ from ...capi.obitypes cimport index_t -from ..column cimport Column, \ - Column_multi_elts +from ..column_idx cimport Column_idx, \ + Column_multi_elts_idx -cdef class Column_qual(Column) : +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) + cpdef object get_str_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) + cpdef set_str_line(self, index_t line_nb, object value, int offset=*) -cdef class Column_multi_elts_qual(Column_multi_elts) : +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) + cpdef object get_str_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) + cpdef object get_str_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) + cpdef set_str_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 070127c..3ff8ad3 100644 --- a/python/obitools3/dms/column/typed_column/qual.pyx +++ b/python/obitools3/dms/column/typed_column/qual.pyx @@ -6,6 +6,8 @@ from ..column cimport register_column_class from ...view.view cimport View +from ..column cimport Column + from obitools3.utils cimport tobytes, bytes2str, \ obi_errno_to_exception @@ -28,7 +30,9 @@ from libc.stdint cimport uint8_t from libc.stdlib cimport malloc -cdef class Column_qual(Column): +# TODO detect type of value and call set_item_str if str or bytes + +cdef class Column_qual(Column_idx): @staticmethod def new(View view, @@ -59,12 +63,12 @@ cdef class Column_qual(Column): return result - cpdef object get_str_line(self, index_t line_nb): + cpdef object get_str_line(self, index_t line_nb, int offset=-1): global obi_errno cdef char* value cdef object result cdef int i - value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0) + value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, offset) 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 @@ -91,19 +95,19 @@ cdef class Column_qual(Column): free(value_b) - cpdef set_str_line(self, index_t line_nb, object value): + cpdef set_str_line(self, index_t line_nb, object value, int offset=-1): global obi_errno cdef bytes value_b if value is None : - if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, OBIQual_char_NA) < 0: + if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, OBIQual_char_NA, offset) < 0: obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") else : value_b = tobytes(value) - if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b) < 0: + if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b, offset) < 0: obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") -cdef class Column_multi_elts_qual(Column_multi_elts): +cdef class Column_multi_elts_qual(Column_multi_elts_idx): cpdef object get_item(self, index_t line_nb, object elt_id): global obi_errno @@ -126,15 +130,15 @@ cdef class Column_multi_elts_qual(Column_multi_elts): return result - cpdef object get_str_item(self, index_t line_nb, object elt_id): + cpdef object get_str_item(self, index_t line_nb, object elt_id, int offset=-1): global obi_errno cdef char* value cdef object result if type(elt_id) == int : - value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id) + value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, offset) else : elt_name = tobytes(elt_id) - value = obi_get_qual_char_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name) + value = obi_get_qual_char_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, offset) obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") if value == OBIQual_char_NA : result = None @@ -176,7 +180,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts): return result - cpdef object get_str_line(self, index_t line_nb) : + cpdef object get_str_line(self, index_t line_nb, int offset=-1) : global obi_errno cdef char* value cdef object value_in_result @@ -192,7 +196,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts): column_p = self.pointer() elements_names = self.elements_names for i in range(self.nb_elements_per_line) : - value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i) + 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) @@ -232,7 +236,7 @@ cdef class Column_multi_elts_qual(Column_multi_elts): free(value_b) - cpdef set_str_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=-1): global obi_errno cdef bytes value_b cdef bytes elt_name @@ -243,11 +247,11 @@ cdef class Column_multi_elts_qual(Column_multi_elts): value_b = tobytes(value) if type(elt_id) == int : - if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value_b) < 0 : + if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value_b, offset) < 0 : obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") else : elt_name = tobytes(elt_id) - if obi_set_qual_char_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value_b) < 0: + if obi_set_qual_char_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value_b, offset) < 0: obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") diff --git a/src/obidmscolumn_qual.c b/src/obidmscolumn_qual.c index 7faf04e..1197d7c 100644 --- a/src/obidmscolumn_qual.c +++ b/src/obidmscolumn_qual.c @@ -26,13 +26,16 @@ * **********************************************************************/ -int obi_column_set_obiqual_char_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value) +int obi_column_set_obiqual_char_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value, int offset) { uint8_t* int_value; int int_value_length; int i; int ret_value; + if (offset == -1) + offset = QUALITY_ASCII_BASE; + // Check NA value if (value == OBIQual_char_NA) { @@ -45,7 +48,7 @@ int obi_column_set_obiqual_char_with_elt_idx(OBIDMS_column_p column, index_t lin // Convert in uint8_t array to index in that format for (i=0; i