Fixed the handling of sample names that are numbers (forcing conversion)

This commit is contained in:
mercierc
2021-07-21 15:19:24 +12:00
parent e2932b05f2
commit 6c1a3aff47
2 changed files with 15 additions and 1 deletions

View File

@ -7,7 +7,8 @@ __OBIDMS_COLUMN_CLASS__ = {}
from ..capi.obitypes cimport name_data_type, \ from ..capi.obitypes cimport name_data_type, \
obitype_t, \ obitype_t, \
obiversion_t, \ obiversion_t, \
OBI_QUAL OBI_QUAL, \
OBI_STR
from ..capi.obidms cimport obi_import_column from ..capi.obidms cimport obi_import_column
@ -128,6 +129,10 @@ cdef class Column(OBIWrapper) :
else: else:
elements_names_p = NULL elements_names_p = NULL
if column_name_b == b"SAMPLE" or column_name_b == b"sample":
# force str type
data_type = OBI_STR
if data_type == OBI_QUAL: if data_type == OBI_QUAL:
if associated_column_name_b == b"": if associated_column_name_b == b"":
if column_name == QUALITY_COLUMN: if column_name == QUALITY_COLUMN:

View File

@ -74,6 +74,9 @@ cdef class Column_str(Column_idx):
if value is None : if value is None :
value_b = <char*>OBIStr_NA value_b = <char*>OBIStr_NA
else : else :
if self.name == b'sample' or self.name == b'SAMPLE':
if type(value) == int:
value = str(value) # force sample ids to be str
value_bytes = tobytes(value) value_bytes = tobytes(value)
value_b = <char*>value_bytes value_b = <char*>value_bytes
@ -137,6 +140,9 @@ cdef class Column_multi_elts_str(Column_multi_elts_idx):
if value is None : if value is None :
value_b = <char*>OBIStr_NA value_b = <char*>OBIStr_NA
else : else :
if self.name == b'sample' or self.name == b'SAMPLE':
if type(value) == int:
value = str(value) # force sample ids to be str
value_bytes = tobytes(value) value_bytes = tobytes(value)
value_b = <char*>value_bytes value_b = <char*>value_bytes
@ -206,6 +212,9 @@ cdef class Column_tuples_str(Column_idx):
i = 0 i = 0
for elt in value : for elt in value :
if elt is not None and elt != '': if elt is not None and elt != '':
if self.name == b'sample' or self.name == b'SAMPLE':
if type(elt) == int:
elt = str(elt) # force sample ids to be str
elt_b = tobytes(elt) elt_b = tobytes(elt)
strcpy(array+i, <char*>elt_b) strcpy(array+i, <char*>elt_b)
i = i + len(elt_b) + 1 i = i + len(elt_b) + 1