Added possibility to specify the offset for encoding and decoding
sequence quality character strings
This commit is contained in:
@ -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=*)
|
||||
|
@ -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")
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user