From 6c1a3aff473797b274b9cffe337d5b8107a36498 Mon Sep 17 00:00:00 2001 From: mercierc Date: Wed, 21 Jul 2021 15:19:24 +1200 Subject: [PATCH] Fixed the handling of sample names that are numbers (forcing conversion) --- python/obitools3/dms/column/column.pyx | 7 ++++++- python/obitools3/dms/column/typed_column/str.pyx | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/python/obitools3/dms/column/column.pyx b/python/obitools3/dms/column/column.pyx index d3039d3..27a80ef 100755 --- a/python/obitools3/dms/column/column.pyx +++ b/python/obitools3/dms/column/column.pyx @@ -7,7 +7,8 @@ __OBIDMS_COLUMN_CLASS__ = {} from ..capi.obitypes cimport name_data_type, \ obitype_t, \ obiversion_t, \ - OBI_QUAL + OBI_QUAL, \ + OBI_STR from ..capi.obidms cimport obi_import_column @@ -128,6 +129,10 @@ cdef class Column(OBIWrapper) : else: 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 associated_column_name_b == b"": if column_name == QUALITY_COLUMN: diff --git a/python/obitools3/dms/column/typed_column/str.pyx b/python/obitools3/dms/column/typed_column/str.pyx index 09b0842..00ec0bc 100755 --- a/python/obitools3/dms/column/typed_column/str.pyx +++ b/python/obitools3/dms/column/typed_column/str.pyx @@ -74,6 +74,9 @@ cdef class Column_str(Column_idx): if value is None : value_b = OBIStr_NA 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_b = value_bytes @@ -137,6 +140,9 @@ cdef class Column_multi_elts_str(Column_multi_elts_idx): if value is None : value_b = OBIStr_NA 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_b = value_bytes @@ -206,6 +212,9 @@ cdef class Column_tuples_str(Column_idx): i = 0 for elt in value : 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) strcpy(array+i, elt_b) i = i + len(elt_b) + 1