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,8 +58,8 @@ 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))
@ -67,16 +67,14 @@ cdef class OBIDMS_column_qual(OBIDMS_column):
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 :
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:
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")

View File

@ -31,12 +31,11 @@ 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:
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

View File

@ -26,12 +26,11 @@ 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:
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")

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) :

View File

@ -33,18 +33,21 @@ int obi_column_set_obiqual_char_with_elt_idx(OBIDMS_column_p column, index_t lin
int i;
int ret_value;
// TODO NA
if (value == OBIQual_char_NA)
{
ret_value = obi_column_set_obiqual_int_with_elt_idx(column, line_nb, element_idx, OBIQual_int_NA, 0);
}
else
{
int_value_length = strlen(value);
int_value = (uint8_t*) malloc(int_value_length * sizeof(uint8_t));
// Convert in uint8_t array to index in that format
for (i=0; i<int_value_length; i++)
int_value[i] = ((uint8_t)(value[i])) - QUALITY_ASCII_BASE;
ret_value = obi_column_set_obiqual_int_with_elt_idx(column, line_nb, element_idx, int_value, int_value_length);
free(int_value);
}
return ret_value;
}
@ -58,8 +61,12 @@ int obi_column_set_obiqual_int_with_elt_idx(OBIDMS_column_p column, index_t line
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
return -1;
// TODO NA
if (value == OBIQual_int_NA)
{
idx = OBIIdx_NA;
}
else
{
// Add the value in the indexer
idx = obi_index_uint8(column->indexer, value, value_length);
if (idx == -1) // An error occurred
@ -84,6 +91,8 @@ int obi_column_set_obiqual_int_with_elt_idx(OBIDMS_column_p column, index_t line
else
return -1;
}
}
// Add the value's index in the column
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;
@ -100,7 +109,9 @@ char* obi_column_get_obiqual_char_with_elt_idx(OBIDMS_column_p column, index_t l
int_value = obi_column_get_obiqual_int_with_elt_idx(column, line_nb, element_idx, &int_value_length);
// TODO NA
// Check NA
if (int_value == OBIQual_int_NA)
return OBIQual_char_NA;
value = (char*) malloc((int_value_length + 1) * sizeof(char));

View File

@ -32,8 +32,12 @@ int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
return -1;
// TODO NA
if (value == OBISeq_NA)
{
idx = OBIIdx_NA;
}
else
{
// Add the value in the indexer
idx = obi_index_dna_seq(column->indexer, value);
if (idx == -1) // An error occurred
@ -58,6 +62,8 @@ int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
else
return -1;
}
}
// Add the value's index in the column
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;

View File

@ -32,8 +32,12 @@ int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
return -1;
// TODO NA
if (value == OBIStr_NA)
{
idx = OBIIdx_NA;
}
else
{
// Add the value in the indexer
idx = obi_index_char_str(column->indexer, value);
if (idx == -1) // An error occurred
@ -58,6 +62,7 @@ int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
else
return -1;
}
}
// Add the value's index in the column
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;