Setting NA values is now handled properly for OBI_SEQ, OBI_STR and

OBI_QUAL columns
This commit is contained in:
Celine Mercier
2016-06-09 14:22:36 +02:00
parent fc3641d7ff
commit 2a1ea3ba3f
8 changed files with 143 additions and 125 deletions

View File

@ -58,26 +58,24 @@ cdef class OBIDMS_column_qual(OBIDMS_column):
cdef uint8_t* value_b
cdef int value_length
if value is None :
value_b = OBIQual_int_NA
value_length = 0
if obi_column_set_obiqual_int_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, OBIQual_int_NA, 0) < 0:
raise Exception("Problem setting a value in a column")
else :
value_length = len(value)
value_b = <uint8_t*> malloc(value_length * sizeof(uint8_t))
for i in range(value_length) :
value_b[i] = <uint8_t>value[i]
if obi_column_set_obiqual_int_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value_b, value_length) < 0:
raise Exception("Problem setting a value in a column")
if value is not None :
if obi_column_set_obiqual_int_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value_b, value_length) < 0:
raise Exception("Problem setting a value in a column")
free(value_b)
cpdef set_str_line(self, index_t line_nb, object value):
cdef bytes value_b
if value is None :
value_b = OBIQual_char_NA
if obi_column_set_obiqual_int_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, OBIQual_int_NA, 0) < 0:
raise Exception("Problem setting a value in a column")
else :
value_b = str2bytes(value)
if obi_column_set_obiqual_char_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value_b) < 0:
raise Exception("Problem setting a value in a column")
if obi_column_set_obiqual_char_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, str2bytes(value)) < 0:
raise Exception("Problem setting a value in a column")
# TODO

View File

@ -31,13 +31,12 @@ cdef class OBIDMS_column_seq(OBIDMS_column):
return result
cpdef set_line(self, index_t line_nb, object value):
cdef bytes value_b
if value is None :
value_b = OBISeq_NA
if obi_column_set_obiseq_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, OBISeq_NA) < 0:
raise Exception("Problem setting a value in a column")
else :
value_b = str2bytes(value)
if obi_column_set_obiseq_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value_b) < 0:
raise Exception("Problem setting a value in a column")
if obi_column_set_obiseq_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, str2bytes(value)) < 0:
raise Exception("Problem setting a value in a column")
# TODO choose alignment type (lcs or other) with supplementary argument
cpdef align(self,

View File

@ -26,13 +26,12 @@ cdef class OBIDMS_column_str(OBIDMS_column):
return result
cpdef set_line(self, index_t line_nb, object value):
cdef bytes value_b
if value is None :
value_b = OBIStr_NA
if obi_column_set_obistr_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, OBIStr_NA) < 0:
raise Exception("Problem setting a value in a column")
else :
value_b = str2bytes(value)
if obi_column_set_obistr_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value_b) < 0:
raise Exception("Problem setting a value in a column")
if obi_column_set_obistr_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, str2bytes(value)) < 0:
raise Exception("Problem setting a value in a column")
cdef class OBIDMS_column_multi_elts_str(OBIDMS_column_multi_elts):

View File

@ -4,35 +4,35 @@ from ._obidms cimport OBIView_line
cdef class OBI_Seq(dict) :
cdef str id
cdef str definition
cdef str sequence
cdef object id
cdef object definition
cdef object sequence
cpdef set_id(self, str id)
cpdef get_id(self)
cpdef set_definition(self, str definition)
cpdef get_definition(self)
cpdef get_sequence(self)
cpdef set_id(self, object id)
cpdef object get_id(self)
cpdef set_definition(self, object definition)
cpdef object get_definition(self)
cpdef object get_sequence(self)
cdef class OBI_Nuc_Seq(OBI_Seq) :
cdef object quality
#cpdef str reverse_complement(self)
cpdef set_sequence(self, str sequence)
#cpdef object reverse_complement(self)
cpdef set_sequence(self, object sequence)
cpdef set_quality(self, object quality)
cpdef get_quality(self)
cpdef object get_quality(self)
cdef class OBI_Nuc_Seq_Stored(OBIView_line) :
cpdef set_id(self, str id)
cpdef get_id(self)
cpdef set_definition(self, str definition)
cpdef get_definition(self)
cpdef set_sequence(self, str sequence)
cpdef get_sequence(self)
cpdef set_id(self, object id)
cpdef object get_id(self)
cpdef set_definition(self, object definition)
cpdef object get_definition(self)
cpdef set_sequence(self, object sequence)
cpdef object get_sequence(self)
cpdef set_quality(self, object quality)
cpdef get_quality(self)
cpdef get_str_quality(self)
cpdef object get_quality(self)
cpdef object get_str_quality(self)
# cpdef str reverse_complement(self)
# cpdef object reverse_complement(self)

View File

@ -9,20 +9,20 @@ from .capi.obiview cimport NUC_SEQUENCE_COLUMN, \
cdef class OBI_Seq(dict) :
def __init__(self, str id, str seq, str definition=None) :
def __init__(self, object id, object seq, object definition=None) :
self.set_id(id)
self.set_sequence(seq)
if definition is not None :
self.set_definition(definition)
cpdef set_id(self, str id) :
cpdef set_id(self, object id) :
self.id = id
self[bytes2str(ID_COLUMN)] = id
cpdef get_id(self) :
return self.id
cpdef set_definition(self, str definition) :
cpdef set_definition(self, object definition) :
self.definition = definition
self[bytes2str(DEFINITION_COLUMN)] = definition
@ -38,7 +38,7 @@ cdef class OBI_Seq(dict) :
cdef class OBI_Nuc_Seq(OBI_Seq) :
cpdef set_sequence(self, str sequence) :
cpdef set_sequence(self, object sequence) :
self.sequence = sequence
self[bytes2str(NUC_SEQUENCE_COLUMN)] = sequence
@ -57,34 +57,34 @@ cdef class OBI_Nuc_Seq_Stored(OBIView_line) :
# TODO store the str version of column name macros
cpdef set_id(self, str id) :
cpdef set_id(self, object id) :
self[bytes2str(ID_COLUMN)] = id
cpdef get_id(self) :
cpdef object get_id(self) :
return self[bytes2str(ID_COLUMN)]
cpdef set_definition(self, str definition) :
cpdef set_definition(self, object definition) :
self[bytes2str(DEFINITION_COLUMN)] = definition
cpdef get_definition(self) :
cpdef object get_definition(self) :
return self[bytes2str(DEFINITION_COLUMN)]
cpdef set_sequence(self, str sequence) :
cpdef set_sequence(self, object sequence) :
self[bytes2str(NUC_SEQUENCE_COLUMN)] = sequence
cpdef get_sequence(self) :
cpdef object get_sequence(self) :
return self[bytes2str(NUC_SEQUENCE_COLUMN)]
cpdef set_quality(self, object quality) :
if type(quality) == list :
if (type(quality) == list) or (quality is None) :
self[bytes2str(QUALITY_COLUMN)] = quality
else : # Quality is in str form
(((self.view).columns)[bytes2str(QUALITY_COLUMN)]).set_str_line(self.index, quality)
cpdef get_quality(self) :
cpdef object get_quality(self) :
return self[bytes2str(QUALITY_COLUMN)]
cpdef get_str_quality(self) :
cpdef object get_str_quality(self) :
return ((self.view).columns)[bytes2str(QUALITY_COLUMN)].get_str_line(self.index)
# def __str__(self) :