diff --git a/python/obitools3/obidms/_obidms.cfiles b/python/obitools3/obidms/_obidms.cfiles index bf37301..c87f58d 100644 --- a/python/obitools3/obidms/_obidms.cfiles +++ b/python/obitools3/obidms/_obidms.cfiles @@ -8,6 +8,8 @@ ../../../src/dna_seq_indexer.c ../../../src/encode.h ../../../src/encode.c +../../../src/hashtable.h +../../../src/hashtable.c ../../../src/murmurhash2.h ../../../src/murmurhash2.c ../../../src/obi_align.h diff --git a/python/obitools3/obidms/_obidms.pxd b/python/obitools3/obidms/_obidms.pxd index 908c9e3..e334c6d 100644 --- a/python/obitools3/obidms/_obidms.pxd +++ b/python/obitools3/obidms/_obidms.pxd @@ -18,7 +18,6 @@ cdef class OBIDMS_column: cdef index_t nb_elements_per_line cdef list elements_names - cpdef update_pointer(self) cpdef list get_elements_names(self) cpdef str get_data_type(self) cpdef index_t get_nb_lines_used(self) @@ -52,14 +51,19 @@ cdef class OBIView: cpdef add_column(self, str column_name, obiversion_t version_number=*, + str alias=*, str type=*, index_t nb_lines=*, index_t nb_elements_per_line=*, list elements_names=*, str indexer_name=*, + str associated_column_name=*, + obiversion_t associated_column_version=*, str comments=*, bint create=* ) + cpdef change_column_alias(self, str current_alias, str new_alias) + cpdef update_column_pointers(self) cpdef select_line(self, index_t line_nb) cpdef select_lines(self, list line_selection) cpdef save_and_close(self) diff --git a/python/obitools3/obidms/_obidms.pyx b/python/obitools3/obidms/_obidms.pyx index 2b516e7..c5903da 100644 --- a/python/obitools3/obidms/_obidms.pyx +++ b/python/obitools3/obidms/_obidms.pyx @@ -55,7 +55,7 @@ from ._obidmscolumn_seq cimport OBIDMS_column_seq, \ from .capi.obiview cimport Obiview_p, \ Obiview_infos_p, \ - Column_reference_p, \ + Alias_column_pair_p, \ obi_new_view_nuc_seqs, \ obi_new_view, \ obi_new_view_cloned_from_name, \ @@ -65,7 +65,7 @@ from .capi.obiview cimport Obiview_p, \ obi_open_view, \ obi_view_delete_column, \ obi_view_add_column, \ - obi_view_get_column, \ + obi_view_create_column_alias, \ obi_view_get_column, \ obi_view_get_pointer_on_column_in_view, \ obi_select_line, \ @@ -124,9 +124,6 @@ cdef class OBIDMS_column : for line_nb in range(lines_used): yield self.get_line(line_nb) - cpdef update_pointer(self): - self.pointer = obi_view_get_pointer_on_column_in_view(self.view.pointer, str2bytes(self.column_name)) - cpdef list get_elements_names(self): return self.elements_names @@ -297,58 +294,57 @@ cdef class OBIView : for i in range(view.infos.column_count) : column_p = (view.columns)[i] header = (column_p).header - col_name = bytes2str(header.name) + col_name = bytes2str(view.infos.column_references[i].alias) subclass = OBIDMS_column.get_subclass_type(column_p) self.columns[col_name] = subclass(self, col_name) - + def __repr__(self) : cdef str s - s = str(self.name) + ", " + str(self.comments) + ", " + str(self.pointer.infos.line_count) + " lines\n" + s = str(self.name) + "\n" + str(self.comments) + "\n" + str(self.pointer.infos.line_count) + " lines\n" for column_name in self.columns : - s = s + self.columns[column_name].__repr__() + '\n' + s = s + column_name + ": " + self.columns[column_name].__repr__() + '\n' return s cpdef delete_column(self, str column_name) : - - cdef int i - cdef Obiview_p view_p - cdef OBIDMS_column column - cdef OBIDMS_column_p column_p - cdef OBIDMS_column_header_p header + cdef str column_n - - view = self.pointer - - if obi_view_delete_column(view_p, str2bytes(column_name)) < 0 : + + if obi_view_delete_column(self.pointer, str2bytes(column_name)) < 0 : raise Exception("Problem deleting a column from a view") - # Update the dictionaries of column pointers and column objects, and update pointers in column objects (make function?): + # Update the dictionary of column objects: (self.columns).pop(column_name) - - for column_n in self.columns : - (self.columns[column_n]).update_pointer() + self.update_column_pointers() cpdef add_column(self, str column_name, obiversion_t version_number=-1, + str alias='', str type='', index_t nb_lines=0, index_t nb_elements_per_line=1, list elements_names=None, str indexer_name="", + str associated_column_name="", + obiversion_t associated_column_version=-1, str comments="", bint create=True ) : - cdef bytes column_name_b - cdef bytes elements_names_b - cdef object subclass + cdef bytes column_name_b + cdef bytes elements_names_b + cdef object subclass cdef OBIDMS_column_p column_p column_name_b = str2bytes(column_name) + if alias == '' : + alias = column_name + alias_b = column_name_b + else : + alias_b = str2bytes(alias) if nb_elements_per_line > 1 : elements_names_b = str2bytes(';'.join(elements_names)) @@ -372,20 +368,37 @@ cdef class OBIView : data_type = OBI_SEQ else : raise Exception("Invalid provided data type") - - if (obi_view_add_column(self.pointer, column_name_b, version_number, # TODO should return pointer on column? + + if (obi_view_add_column(self.pointer, column_name_b, version_number, alias_b, # TODO should return pointer on column? data_type, nb_lines, nb_elements_per_line, elements_names_b, str2bytes(indexer_name), + str2bytes(associated_column_name), associated_column_version, str2bytes(comments), create) < 0) : raise Exception("Problem adding a column in a view") # Get the column pointer - column_p = obi_view_get_column(self.pointer, column_name_b) + column_p = obi_view_get_column(self.pointer, alias_b) # Open and store the subclass subclass = OBIDMS_column.get_subclass_type(column_p) - (self.columns)[column_name] = subclass(self, column_name) - + (self.columns)[alias] = subclass(self, alias) + + + cpdef change_column_alias(self, str current_alias, str new_alias): + if (obi_view_create_column_alias(self.pointer, str2bytes(current_alias), str2bytes(new_alias)) < 0) : + raise Exception("Problem changing a column alias") + # Update the dictionaries of column column objects + self.columns[new_alias] = self.columns[current_alias] + (self.columns).pop(current_alias) + + + cpdef update_column_pointers(self): + cdef str column_n + cdef OBIDMS_column column + for column_n in self.columns : + column = self.columns[column_n] + column.pointer = obi_view_get_pointer_on_column_in_view(self.pointer, str2bytes(column_n)) + cpdef save_and_close(self) : if (obi_save_and_close_view(self.pointer) < 0) : @@ -493,7 +506,7 @@ cdef class OBIView_NUC_SEQS(OBIView): for i in range(view.infos.column_count) : column_p = (view.columns)[i] header = (column_p).header - col_name = bytes2str(header.name) + col_name = bytes2str(view.infos.column_references[i].alias) subclass = OBIDMS_column.get_subclass_type(column_p) self.columns[col_name] = subclass(self, col_name) @@ -553,7 +566,7 @@ cdef class OBIView_line : (((self.view).columns)[column_name]).set_line(self.index, value) def __contains__(self, str column_name): - return (column_name in self.view) + return (column_name in self.view.columns) def __repr__(self): cdef dict line @@ -623,7 +636,7 @@ cdef class OBIDMS : cdef Obiview_infos_p view_infos_p cdef dict view_infos_d - cdef Column_reference_p column_refs + cdef Alias_column_pair_p column_refs cdef int i, j cdef str column_name @@ -643,11 +656,12 @@ cdef class OBIDMS : view_infos_d["line_selection"]["column_name"] = bytes2str((view_infos_p.line_selection).column_name) view_infos_d["line_selection"]["version"] = (view_infos_p.line_selection).version view_infos_d["column_references"] = {} - column_refs = view_infos_p.column_references + column_references = view_infos_p.column_references for j in range(view_infos_d["column_count"]) : - column_name = bytes2str((column_refs[j]).column_name) + column_name = bytes2str((column_references[j]).alias) view_infos_d["column_references"][column_name] = {} - view_infos_d["column_references"][column_name]["version"] = column_refs[j].version + view_infos_d["column_references"][column_name]["original_name"] = bytes2str((column_references[j]).column_refs.column_name) + view_infos_d["column_references"][column_name]["version"] = (column_references[j]).column_refs.version obi_view_unmap_file(self.pointer, view_infos_p) diff --git a/python/obitools3/obidms/_obidmscolumn_bool.cfiles b/python/obitools3/obidms/_obidmscolumn_bool.cfiles index bf37301..c87f58d 100644 --- a/python/obitools3/obidms/_obidmscolumn_bool.cfiles +++ b/python/obitools3/obidms/_obidmscolumn_bool.cfiles @@ -8,6 +8,8 @@ ../../../src/dna_seq_indexer.c ../../../src/encode.h ../../../src/encode.c +../../../src/hashtable.h +../../../src/hashtable.c ../../../src/murmurhash2.h ../../../src/murmurhash2.c ../../../src/obi_align.h diff --git a/python/obitools3/obidms/_obidmscolumn_bool.pyx b/python/obitools3/obidms/_obidmscolumn_bool.pyx index fcef66c..12fa15b 100644 --- a/python/obitools3/obidms/_obidmscolumn_bool.pyx +++ b/python/obitools3/obidms/_obidmscolumn_bool.pyx @@ -1,9 +1,9 @@ #cython: language_level=3 -from .capi.obiview cimport obi_column_get_obibool_with_elt_name_in_view, \ - obi_column_get_obibool_with_elt_idx_in_view, \ - obi_column_set_obibool_with_elt_name_in_view, \ - obi_column_set_obibool_with_elt_idx_in_view +from .capi.obiview cimport obi_get_bool_with_elt_name_and_col_p_in_view, \ + obi_get_bool_with_elt_idx_and_col_p_in_view, \ + obi_set_bool_with_elt_name_and_col_p_in_view, \ + obi_set_bool_with_elt_idx_and_col_p_in_view from .capi.obierrno cimport obi_errno from .capi.obitypes cimport OBIBool_NA, obibool_t @@ -17,7 +17,7 @@ cdef class OBIDMS_column_bool(OBIDMS_column): cpdef object get_line(self, index_t line_nb): cdef obibool_t value cdef object result - value = obi_column_get_obibool_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) + value = obi_get_bool_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIBool_NA : @@ -29,7 +29,7 @@ cdef class OBIDMS_column_bool(OBIDMS_column): cpdef set_line(self, index_t line_nb, object value): if value is None : value = OBIBool_NA - if obi_column_set_obibool_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value) < 0: + if obi_set_bool_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value) < 0: raise Exception("Problem setting a value in a column") @@ -38,7 +38,7 @@ cdef class OBIDMS_column_multi_elts_bool(OBIDMS_column_multi_elts): cpdef object get_item(self, index_t line_nb, str element_name): cdef obibool_t value cdef object result - value = obi_column_get_obibool_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) + value = obi_get_bool_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) if obi_errno > 0 : raise IndexError(line_nb, element_name) if value == OBIBool_NA : @@ -56,7 +56,7 @@ cdef class OBIDMS_column_multi_elts_bool(OBIDMS_column_multi_elts): result = {} all_NA = True for i in range(self.nb_elements_per_line) : - value = obi_column_get_obibool_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) + value = obi_get_bool_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIBool_NA : @@ -73,5 +73,5 @@ cdef class OBIDMS_column_multi_elts_bool(OBIDMS_column_multi_elts): cpdef set_item(self, index_t line_nb, str element_name, object value): if value is None : value = OBIBool_NA - if obi_column_set_obibool_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value) < 0: + if obi_set_bool_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value) < 0: raise Exception("Problem setting a value in a column") diff --git a/python/obitools3/obidms/_obidmscolumn_char.cfiles b/python/obitools3/obidms/_obidmscolumn_char.cfiles index bf37301..c87f58d 100644 --- a/python/obitools3/obidms/_obidmscolumn_char.cfiles +++ b/python/obitools3/obidms/_obidmscolumn_char.cfiles @@ -8,6 +8,8 @@ ../../../src/dna_seq_indexer.c ../../../src/encode.h ../../../src/encode.c +../../../src/hashtable.h +../../../src/hashtable.c ../../../src/murmurhash2.h ../../../src/murmurhash2.c ../../../src/obi_align.h diff --git a/python/obitools3/obidms/_obidmscolumn_char.pyx b/python/obitools3/obidms/_obidmscolumn_char.pyx index 080885d..231f0fe 100644 --- a/python/obitools3/obidms/_obidmscolumn_char.pyx +++ b/python/obitools3/obidms/_obidmscolumn_char.pyx @@ -1,9 +1,9 @@ #cython: language_level=3 -from .capi.obiview cimport obi_column_get_obichar_with_elt_name_in_view, \ - obi_column_get_obichar_with_elt_idx_in_view, \ - obi_column_set_obichar_with_elt_name_in_view, \ - obi_column_set_obichar_with_elt_idx_in_view +from .capi.obiview cimport obi_get_char_with_elt_name_and_col_p_in_view, \ + obi_get_char_with_elt_idx_and_col_p_in_view, \ + obi_set_char_with_elt_name_and_col_p_in_view, \ + obi_set_char_with_elt_idx_and_col_p_in_view from .capi.obierrno cimport obi_errno from .capi.obitypes cimport OBIChar_NA, obichar_t @@ -15,7 +15,7 @@ cdef class OBIDMS_column_char(OBIDMS_column): cpdef object get_line(self, index_t line_nb): cdef obichar_t value cdef object result - value = obi_column_get_obichar_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) + value = obi_get_char_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIChar_NA : @@ -27,7 +27,7 @@ cdef class OBIDMS_column_char(OBIDMS_column): cpdef set_line(self, index_t line_nb, object value): if value is None : value = OBIChar_NA - if obi_column_set_obichar_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, str2bytes(value)[0]) < 0: + if obi_set_char_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, str2bytes(value)[0]) < 0: raise Exception("Problem setting a value in a column") @@ -36,7 +36,7 @@ cdef class OBIDMS_column_multi_elts_char(OBIDMS_column_multi_elts): cpdef object get_item(self, index_t line_nb, str element_name): cdef obichar_t value cdef object result - value = obi_column_get_obichar_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) + value = obi_get_char_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) if obi_errno > 0 : raise IndexError(line_nb, element_name) if value == OBIChar_NA : @@ -54,7 +54,7 @@ cdef class OBIDMS_column_multi_elts_char(OBIDMS_column_multi_elts): result = {} all_NA = True for i in range(self.nb_elements_per_line) : - value = obi_column_get_obichar_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) + value = obi_get_char_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIChar_NA : @@ -71,6 +71,6 @@ cdef class OBIDMS_column_multi_elts_char(OBIDMS_column_multi_elts): cpdef set_item(self, index_t line_nb, str element_name, object value): if value is None : value = OBIChar_NA - if obi_column_set_obichar_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), str2bytes(value)[0]) < 0: + if obi_set_char_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), str2bytes(value)[0]) < 0: raise Exception("Problem setting a value in a column") diff --git a/python/obitools3/obidms/_obidmscolumn_float.cfiles b/python/obitools3/obidms/_obidmscolumn_float.cfiles index bf37301..c87f58d 100644 --- a/python/obitools3/obidms/_obidmscolumn_float.cfiles +++ b/python/obitools3/obidms/_obidmscolumn_float.cfiles @@ -8,6 +8,8 @@ ../../../src/dna_seq_indexer.c ../../../src/encode.h ../../../src/encode.c +../../../src/hashtable.h +../../../src/hashtable.c ../../../src/murmurhash2.h ../../../src/murmurhash2.c ../../../src/obi_align.h diff --git a/python/obitools3/obidms/_obidmscolumn_float.pyx b/python/obitools3/obidms/_obidmscolumn_float.pyx index 1bd325e..b1c1df2 100644 --- a/python/obitools3/obidms/_obidmscolumn_float.pyx +++ b/python/obitools3/obidms/_obidmscolumn_float.pyx @@ -1,9 +1,9 @@ #cython: language_level=3 -from .capi.obiview cimport obi_column_get_obifloat_with_elt_name_in_view, \ - obi_column_get_obifloat_with_elt_idx_in_view, \ - obi_column_set_obifloat_with_elt_name_in_view, \ - obi_column_set_obifloat_with_elt_idx_in_view +from .capi.obiview cimport obi_get_float_with_elt_name_and_col_p_in_view, \ + obi_get_float_with_elt_idx_and_col_p_in_view, \ + obi_set_float_with_elt_name_and_col_p_in_view, \ + obi_set_float_with_elt_idx_and_col_p_in_view from .capi.obierrno cimport obi_errno from .capi.obitypes cimport OBIFloat_NA, obifloat_t @@ -15,7 +15,7 @@ cdef class OBIDMS_column_float(OBIDMS_column): cpdef object get_line(self, index_t line_nb): cdef obifloat_t value cdef object result - value = obi_column_get_obifloat_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) + value = obi_get_float_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIFloat_NA : @@ -27,7 +27,7 @@ cdef class OBIDMS_column_float(OBIDMS_column): cpdef set_line(self, index_t line_nb, object value): if value is None : value = OBIFloat_NA - if obi_column_set_obifloat_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value) < 0: + if obi_set_float_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value) < 0: raise Exception("Problem setting a value in a column") @@ -36,7 +36,7 @@ cdef class OBIDMS_column_multi_elts_float(OBIDMS_column_multi_elts): cpdef object get_item(self, index_t line_nb, str element_name): cdef obifloat_t value cdef object result - value = obi_column_get_obifloat_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) + value = obi_get_float_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) if obi_errno > 0 : raise IndexError(line_nb, element_name) if value == OBIFloat_NA : @@ -54,7 +54,7 @@ cdef class OBIDMS_column_multi_elts_float(OBIDMS_column_multi_elts): result = {} all_NA = True for i in range(self.nb_elements_per_line) : - value = obi_column_get_obifloat_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) + value = obi_get_float_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIFloat_NA : @@ -71,6 +71,6 @@ cdef class OBIDMS_column_multi_elts_float(OBIDMS_column_multi_elts): cpdef set_item(self, index_t line_nb, str element_name, object value): if value is None : value = OBIFloat_NA - if obi_column_set_obifloat_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value) < 0: + if obi_set_float_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value) < 0: raise Exception("Problem setting a value in a column") \ No newline at end of file diff --git a/python/obitools3/obidms/_obidmscolumn_int.cfiles b/python/obitools3/obidms/_obidmscolumn_int.cfiles index bf37301..c87f58d 100644 --- a/python/obitools3/obidms/_obidmscolumn_int.cfiles +++ b/python/obitools3/obidms/_obidmscolumn_int.cfiles @@ -8,6 +8,8 @@ ../../../src/dna_seq_indexer.c ../../../src/encode.h ../../../src/encode.c +../../../src/hashtable.h +../../../src/hashtable.c ../../../src/murmurhash2.h ../../../src/murmurhash2.c ../../../src/obi_align.h diff --git a/python/obitools3/obidms/_obidmscolumn_int.pyx b/python/obitools3/obidms/_obidmscolumn_int.pyx index 8239bc7..42b4b9c 100644 --- a/python/obitools3/obidms/_obidmscolumn_int.pyx +++ b/python/obitools3/obidms/_obidmscolumn_int.pyx @@ -1,9 +1,9 @@ #cython: language_level=3 -from .capi.obiview cimport obi_column_get_obiint_with_elt_name_in_view, \ - obi_column_get_obiint_with_elt_idx_in_view, \ - obi_column_set_obiint_with_elt_name_in_view, \ - obi_column_set_obiint_with_elt_idx_in_view +from .capi.obiview cimport obi_get_int_with_elt_name_and_col_p_in_view, \ + obi_get_int_with_elt_idx_and_col_p_in_view, \ + obi_set_int_with_elt_name_and_col_p_in_view, \ + obi_set_int_with_elt_idx_and_col_p_in_view from .capi.obierrno cimport obi_errno from .capi.obitypes cimport OBIInt_NA, obiint_t @@ -17,7 +17,7 @@ cdef class OBIDMS_column_int(OBIDMS_column): cpdef object get_line(self, index_t line_nb): cdef obiint_t value cdef object result - value = obi_column_get_obiint_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) + value = obi_get_int_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIInt_NA : @@ -29,7 +29,7 @@ cdef class OBIDMS_column_int(OBIDMS_column): cpdef set_line(self, index_t line_nb, object value): if value is None : value = OBIInt_NA - if obi_column_set_obiint_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value) < 0: + if obi_set_int_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value) < 0: raise Exception("Problem setting a value in a column") @@ -38,7 +38,7 @@ cdef class OBIDMS_column_multi_elts_int(OBIDMS_column_multi_elts): cpdef object get_item(self, index_t line_nb, str element_name): cdef obiint_t value cdef object result - value = obi_column_get_obiint_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) + value = obi_get_int_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) if obi_errno > 0 : raise IndexError(line_nb, element_name) if value == OBIInt_NA : @@ -56,7 +56,7 @@ cdef class OBIDMS_column_multi_elts_int(OBIDMS_column_multi_elts): result = {} all_NA = True for i in range(self.nb_elements_per_line) : - value = obi_column_get_obiint_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) + value = obi_get_int_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIInt_NA : @@ -73,6 +73,6 @@ cdef class OBIDMS_column_multi_elts_int(OBIDMS_column_multi_elts): cpdef set_item(self, index_t line_nb, str element_name, object value): if value is None : value = OBIInt_NA - if obi_column_set_obiint_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value) < 0: + if obi_set_int_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value) < 0: raise Exception("Problem setting a value in a column") diff --git a/python/obitools3/obidms/_obidmscolumn_qual.cfiles b/python/obitools3/obidms/_obidmscolumn_qual.cfiles index bf37301..c87f58d 100644 --- a/python/obitools3/obidms/_obidmscolumn_qual.cfiles +++ b/python/obitools3/obidms/_obidmscolumn_qual.cfiles @@ -8,6 +8,8 @@ ../../../src/dna_seq_indexer.c ../../../src/encode.h ../../../src/encode.c +../../../src/hashtable.h +../../../src/hashtable.c ../../../src/murmurhash2.h ../../../src/murmurhash2.c ../../../src/obi_align.h diff --git a/python/obitools3/obidms/_obidmscolumn_qual.pyx b/python/obitools3/obidms/_obidmscolumn_qual.pyx index 7b6f74a..00d82ab 100644 --- a/python/obitools3/obidms/_obidmscolumn_qual.pyx +++ b/python/obitools3/obidms/_obidmscolumn_qual.pyx @@ -1,13 +1,13 @@ #cython: language_level=3 -from .capi.obiview cimport obi_column_get_obiqual_char_with_elt_name_in_view, \ - obi_column_get_obiqual_char_with_elt_idx_in_view, \ - obi_column_set_obiqual_char_with_elt_name_in_view, \ - obi_column_set_obiqual_char_with_elt_idx_in_view, \ - obi_column_get_obiqual_int_with_elt_name_in_view, \ - obi_column_get_obiqual_int_with_elt_idx_in_view, \ - obi_column_set_obiqual_int_with_elt_name_in_view, \ - obi_column_set_obiqual_int_with_elt_idx_in_view +from .capi.obiview cimport obi_get_qual_char_with_elt_name_and_col_p_in_view, \ + obi_get_qual_char_with_elt_idx_and_col_p_in_view, \ + obi_set_qual_char_with_elt_name_and_col_p_in_view, \ + obi_set_qual_char_with_elt_idx_and_col_p_in_view, \ + obi_get_qual_int_with_elt_name_and_col_p_in_view, \ + obi_get_qual_int_with_elt_idx_and_col_p_in_view, \ + obi_set_qual_int_with_elt_name_and_col_p_in_view, \ + obi_set_qual_int_with_elt_idx_and_col_p_in_view from .capi.obierrno cimport obi_errno from .capi.obitypes cimport OBIQual_char_NA, OBIQual_int_NA, const_char_p @@ -29,7 +29,7 @@ cdef class OBIDMS_column_qual(OBIDMS_column): cdef int value_length cdef object result cdef int i - value = obi_column_get_obiqual_int_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, &value_length) + value = obi_get_qual_int_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, &value_length) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIQual_int_NA : @@ -44,7 +44,7 @@ cdef class OBIDMS_column_qual(OBIDMS_column): cdef char* value cdef object result cdef int i - value = obi_column_get_obiqual_char_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) + value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIQual_char_NA : @@ -58,23 +58,23 @@ cdef class OBIDMS_column_qual(OBIDMS_column): cdef uint8_t* value_b cdef int value_length if value is None : - 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: + if obi_set_qual_int_with_elt_idx_and_col_p_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 = malloc(value_length * sizeof(uint8_t)) for i in range(value_length) : value_b[i] = 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: + if obi_set_qual_int_with_elt_idx_and_col_p_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): if value is None : - if obi_column_set_obiqual_char_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], 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)[0], line_nb, 0, OBIQual_char_NA) < 0: raise Exception("Problem setting a value in a column") else : - if obi_column_set_obiqual_char_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, str2bytes(value)) < 0: + if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, str2bytes(value)) < 0: raise Exception("Problem setting a value in a column") @@ -85,7 +85,7 @@ cdef class OBIDMS_column_multi_elts_qual(OBIDMS_column_multi_elts): cdef int value_length cdef object result cdef int i - value = obi_column_get_obiqual_int_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), &value_length) + value = obi_get_qual_int_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), &value_length) if obi_errno > 0 : raise IndexError(line_nb, element_name) if value == OBIQual_int_NA : @@ -99,7 +99,7 @@ cdef class OBIDMS_column_multi_elts_qual(OBIDMS_column_multi_elts): cpdef object get_str_item(self, index_t line_nb, str element_name): cdef char* value cdef object result - value = obi_column_get_obiqual_char_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) + value = obi_get_qual_char_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) if obi_errno > 0 : raise IndexError(line_nb, element_name) if value == OBIQual_char_NA : @@ -120,7 +120,7 @@ cdef class OBIDMS_column_multi_elts_qual(OBIDMS_column_multi_elts): result = {} all_NA = True for i in range(self.nb_elements_per_line) : - value = obi_column_get_obiqual_int_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, i, &value_length) + value = obi_get_qual_int_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, i, &value_length) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIQual_int_NA : @@ -145,7 +145,7 @@ cdef class OBIDMS_column_multi_elts_qual(OBIDMS_column_multi_elts): result = {} all_NA = True for i in range(self.nb_elements_per_line) : - value = obi_column_get_obiqual_char_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) + value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIQual_char_NA : @@ -164,21 +164,21 @@ cdef class OBIDMS_column_multi_elts_qual(OBIDMS_column_multi_elts): cdef uint8_t* value_b cdef int value_length if value is None : - if obi_column_set_obiqual_int_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), OBIQual_int_NA, 0) < 0: + if obi_set_qual_int_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), OBIQual_int_NA, 0) < 0: raise Exception("Problem setting a value in a column") else : value_length = len(value) value_b = malloc(value_length * sizeof(uint8_t)) for i in range(value_length) : value_b[i] = value[i] - if obi_column_set_obiqual_int_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value_b, value_length) < 0: + if obi_set_qual_int_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value_b, value_length) < 0: raise Exception("Problem setting a value in a column") free(value_b) cpdef set_str_item(self, index_t line_nb, str element_name, object value): if value is None : - if obi_column_set_obiqual_char_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), OBIQual_char_NA) < 0: + if obi_set_qual_char_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), OBIQual_char_NA) < 0: raise Exception("Problem setting a value in a column") else : - if obi_column_set_obiqual_char_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), str2bytes(value)) < 0: + if obi_set_qual_char_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), str2bytes(value)) < 0: raise Exception("Problem setting a value in a column") diff --git a/python/obitools3/obidms/_obidmscolumn_seq.cfiles b/python/obitools3/obidms/_obidmscolumn_seq.cfiles index bf37301..c87f58d 100644 --- a/python/obitools3/obidms/_obidmscolumn_seq.cfiles +++ b/python/obitools3/obidms/_obidmscolumn_seq.cfiles @@ -8,6 +8,8 @@ ../../../src/dna_seq_indexer.c ../../../src/encode.h ../../../src/encode.c +../../../src/hashtable.h +../../../src/hashtable.c ../../../src/murmurhash2.h ../../../src/murmurhash2.c ../../../src/obi_align.h diff --git a/python/obitools3/obidms/_obidmscolumn_seq.pyx b/python/obitools3/obidms/_obidmscolumn_seq.pyx index 2cf6b93..134289c 100644 --- a/python/obitools3/obidms/_obidmscolumn_seq.pyx +++ b/python/obitools3/obidms/_obidmscolumn_seq.pyx @@ -1,9 +1,9 @@ #cython: language_level=3 -from .capi.obiview cimport obi_column_get_obiseq_with_elt_name_in_view, \ - obi_column_get_obiseq_with_elt_idx_in_view, \ - obi_column_set_obiseq_with_elt_name_in_view, \ - obi_column_set_obiseq_with_elt_idx_in_view +from .capi.obiview cimport obi_get_seq_with_elt_name_and_col_p_in_view, \ + obi_get_seq_with_elt_idx_and_col_p_in_view, \ + obi_set_seq_with_elt_name_and_col_p_in_view, \ + obi_set_seq_with_elt_idx_and_col_p_in_view from .capi.obialign cimport obi_align_one_column from .capi.obierrno cimport obi_errno from .capi.obitypes cimport OBISeq_NA, const_char_p @@ -20,7 +20,7 @@ cdef class OBIDMS_column_seq(OBIDMS_column): cpdef object get_line(self, index_t line_nb): cdef char* value cdef object result - value = obi_column_get_obiseq_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) + value = obi_get_seq_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) if obi_errno > 0 : raise IndexError(line_nb) if value == OBISeq_NA : @@ -32,10 +32,10 @@ cdef class OBIDMS_column_seq(OBIDMS_column): cpdef set_line(self, index_t line_nb, object value): if value is None : - if obi_column_set_obiseq_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, OBISeq_NA) < 0: + if obi_set_seq_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, OBISeq_NA) < 0: raise Exception("Problem setting a value in a column") else : - if obi_column_set_obiseq_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, str2bytes(value)) < 0: + if obi_set_seq_with_elt_idx_and_col_p_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 @@ -56,7 +56,7 @@ cdef class OBIDMS_column_multi_elts_seq(OBIDMS_column_multi_elts): cpdef object get_item(self, index_t line_nb, str element_name): cdef char* value cdef object result - value = obi_column_get_obiseq_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) + value = obi_get_seq_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) if obi_errno > 0 : raise IndexError(line_nb, element_name) if value == OBISeq_NA : @@ -75,7 +75,7 @@ cdef class OBIDMS_column_multi_elts_seq(OBIDMS_column_multi_elts): result = {} all_NA = True for i in range(self.nb_elements_per_line) : - value = obi_column_get_obiseq_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) + value = obi_get_seq_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) if obi_errno > 0 : raise IndexError(line_nb) if value == OBISeq_NA : @@ -102,7 +102,7 @@ cdef class OBIDMS_column_multi_elts_seq(OBIDMS_column_multi_elts): else: raise TypeError('Sequence value must be of type Bytes, Str or None') - if obi_column_set_obiseq_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value_b) < 0: + if obi_set_seq_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value_b) < 0: raise Exception("Problem setting a value in a column") # cpdef align(self, ): # TODO diff --git a/python/obitools3/obidms/_obidmscolumn_str.cfiles b/python/obitools3/obidms/_obidmscolumn_str.cfiles index bf37301..c87f58d 100644 --- a/python/obitools3/obidms/_obidmscolumn_str.cfiles +++ b/python/obitools3/obidms/_obidmscolumn_str.cfiles @@ -8,6 +8,8 @@ ../../../src/dna_seq_indexer.c ../../../src/encode.h ../../../src/encode.c +../../../src/hashtable.h +../../../src/hashtable.c ../../../src/murmurhash2.h ../../../src/murmurhash2.c ../../../src/obi_align.h diff --git a/python/obitools3/obidms/_obidmscolumn_str.pyx b/python/obitools3/obidms/_obidmscolumn_str.pyx index 2382ca9..aaa5366 100644 --- a/python/obitools3/obidms/_obidmscolumn_str.pyx +++ b/python/obitools3/obidms/_obidmscolumn_str.pyx @@ -1,9 +1,9 @@ #cython: language_level=3 -from .capi.obiview cimport obi_column_get_obistr_with_elt_name_in_view, \ - obi_column_get_obistr_with_elt_idx_in_view, \ - obi_column_set_obistr_with_elt_name_in_view, \ - obi_column_set_obistr_with_elt_idx_in_view +from .capi.obiview cimport obi_get_str_with_elt_name_and_col_p_in_view, \ + obi_get_str_with_elt_idx_and_col_p_in_view, \ + obi_set_str_with_elt_name_and_col_p_in_view, \ + obi_set_str_with_elt_idx_and_col_p_in_view from .capi.obierrno cimport obi_errno from .capi.obitypes cimport OBIStr_NA, const_char_p @@ -15,7 +15,7 @@ cdef class OBIDMS_column_str(OBIDMS_column): cpdef object get_line(self, index_t line_nb): cdef const_char_p value cdef object result - value = obi_column_get_obistr_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) + value = obi_get_str_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIStr_NA : @@ -27,10 +27,10 @@ cdef class OBIDMS_column_str(OBIDMS_column): cpdef set_line(self, index_t line_nb, object value): if value is None : - if obi_column_set_obistr_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, OBIStr_NA) < 0: + if obi_set_str_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, OBIStr_NA) < 0: raise Exception("Problem setting a value in a column") else : - if obi_column_set_obistr_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, str2bytes(value)) < 0: + if obi_set_str_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, str2bytes(value)) < 0: raise Exception("Problem setting a value in a column") @@ -39,7 +39,7 @@ cdef class OBIDMS_column_multi_elts_str(OBIDMS_column_multi_elts): cpdef object get_item(self, index_t line_nb, str element_name): cdef const_char_p value cdef object result - value = obi_column_get_obistr_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) + value = obi_get_str_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name)) if obi_errno > 0 : raise IndexError(line_nb, element_name) if value == OBIStr_NA : @@ -58,7 +58,7 @@ cdef class OBIDMS_column_multi_elts_str(OBIDMS_column_multi_elts): result = {} all_NA = True for i in range(self.nb_elements_per_line) : - value = obi_column_get_obistr_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) + value = obi_get_str_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, i) if obi_errno > 0 : raise IndexError(line_nb) if value == OBIStr_NA : @@ -79,6 +79,6 @@ cdef class OBIDMS_column_multi_elts_str(OBIDMS_column_multi_elts): value_b = OBIStr_NA else : value_b = str2bytes(value) - if obi_column_set_obistr_with_elt_name_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value_b) < 0: + if obi_set_str_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value_b) < 0: raise Exception("Problem setting a value in a column") diff --git a/python/obitools3/obidms/_obiseq.cfiles b/python/obitools3/obidms/_obiseq.cfiles index bf37301..c87f58d 100644 --- a/python/obitools3/obidms/_obiseq.cfiles +++ b/python/obitools3/obidms/_obiseq.cfiles @@ -8,6 +8,8 @@ ../../../src/dna_seq_indexer.c ../../../src/encode.h ../../../src/encode.c +../../../src/hashtable.h +../../../src/hashtable.c ../../../src/murmurhash2.h ../../../src/murmurhash2.c ../../../src/obi_align.h diff --git a/python/obitools3/obidms/_obitaxo.cfiles b/python/obitools3/obidms/_obitaxo.cfiles index bf37301..c87f58d 100644 --- a/python/obitools3/obidms/_obitaxo.cfiles +++ b/python/obitools3/obidms/_obitaxo.cfiles @@ -8,6 +8,8 @@ ../../../src/dna_seq_indexer.c ../../../src/encode.h ../../../src/encode.c +../../../src/hashtable.h +../../../src/hashtable.c ../../../src/murmurhash2.h ../../../src/murmurhash2.c ../../../src/obi_align.h diff --git a/python/obitools3/obidms/capi/obidmscolumn.pxd b/python/obitools3/obidms/capi/obidmscolumn.pxd index 84694c8..b23b85f 100644 --- a/python/obitools3/obidms/capi/obidmscolumn.pxd +++ b/python/obitools3/obidms/capi/obidmscolumn.pxd @@ -16,21 +16,28 @@ from libc.stdint cimport uint8_t cdef extern from "obidmscolumn.h" nogil: + struct Column_reference_t : + const_char_p column_name + obiversion_t version + + ctypedef Column_reference_t* Column_reference_p + struct OBIDMS_column_header_t: - size_t header_size - size_t data_size - index_t line_count - index_t lines_used - index_t nb_elements_per_line - const_char_p elements_names - OBIType_t returned_data_type - OBIType_t stored_data_type - time_t creation_date - obiversion_t version - obiversion_t cloned_from - const_char_p name - const_char_p indexer_name - const_char_p comments + size_t header_size + size_t data_size + index_t line_count + index_t lines_used + index_t nb_elements_per_line + const_char_p elements_names + OBIType_t returned_data_type + OBIType_t stored_data_type + time_t creation_date + obiversion_t version + obiversion_t cloned_from + const_char_p name + const_char_p indexer_name + Column_reference_t associated_column + const_char_p comments ctypedef OBIDMS_column_header_t* OBIDMS_column_header_p @@ -48,6 +55,8 @@ cdef extern from "obidmscolumn.h" nogil: index_t nb_elements_per_line, const_char_p elements_names, const_char_p indexer_name, + const_char_p associated_colum_name, + obiversion_t associated_colum_version, const_char_p comments) OBIDMS_column_p obi_open_column(OBIDMS_p dms, diff --git a/python/obitools3/obidms/capi/obiview.pxd b/python/obitools3/obidms/capi/obiview.pxd index 50cc56a..efd8f48 100644 --- a/python/obitools3/obidms/capi/obiview.pxd +++ b/python/obitools3/obidms/capi/obiview.pxd @@ -10,7 +10,9 @@ from .obitypes cimport const_char_p, \ index_t, \ time_t from ..capi.obidms cimport OBIDMS_p -from ..capi.obidmscolumn cimport OBIDMS_column_p +from ..capi.obidmscolumn cimport OBIDMS_column_p, \ + Column_reference_t, \ + Column_reference_p from libc.stdint cimport uint8_t @@ -24,11 +26,11 @@ cdef extern from "obiview.h" nogil: extern const_char_p QUALITY_COLUMN - struct Column_reference_t : - const_char_p column_name - obiversion_t version + struct Alias_column_pair_t : + Column_reference_t column_refs + const_char_p alias - ctypedef Column_reference_t* Column_reference_p + ctypedef Alias_column_pair_t* Alias_column_pair_p struct Obiview_infos_t : @@ -40,7 +42,7 @@ cdef extern from "obiview.h" nogil: Column_reference_t line_selection index_t line_count int column_count - Column_reference_p column_references + Alias_column_pair_p column_references const_char_p comments ctypedef Obiview_infos_t* Obiview_infos_p @@ -53,7 +55,9 @@ cdef extern from "obiview.h" nogil: OBIDMS_column_p line_selection OBIDMS_column_p new_line_selection OBIDMS_column_p columns - + int nb_predicates + # TODO declarations for column dictionary and predicate function array? + ctypedef Obiview_t* Obiview_p @@ -74,11 +78,14 @@ cdef extern from "obiview.h" nogil: int obi_view_add_column(Obiview_p view, const_char_p column_name, obiversion_t version_number, + const_char_p alias, OBIType_t data_type, index_t nb_lines, index_t nb_elements_per_line, const_char_p elements_names, const_char_p indexer_name, + const_char_p associated_column_name, + obiversion_t associated_column_version, const_char_p comments, bint create) @@ -92,189 +99,205 @@ cdef extern from "obiview.h" nogil: OBIDMS_column_p* obi_view_get_pointer_on_column_in_view(Obiview_p view, const_char_p column_name) + int obi_view_create_column_alias(Obiview_p view, const_char_p current_name, const_char_p alias) + int obi_save_view(Obiview_p view) int obi_close_view(Obiview_p view) int obi_save_and_close_view(Obiview_p view) - int obi_column_set_obiint_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + + # OBI_INT + int obi_set_int_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name, obiint_t value) - int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + int obi_set_int_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, obiint_t value) - obiint_t obi_column_get_obiint_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + obiint_t obi_get_int_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name) - obiint_t obi_column_get_obiint_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + obiint_t obi_get_int_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx) - int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + + # OBI_BOOL + int obi_set_bool_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name, obibool_t value) - int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + int obi_set_bool_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, obibool_t value) - obibool_t obi_column_get_obibool_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + obibool_t obi_get_bool_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name) - obibool_t obi_column_get_obibool_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + obibool_t obi_get_bool_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx) - int obi_column_set_obichar_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + + # OBI_CHAR + int obi_set_char_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name, obichar_t value) - int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + int obi_set_char_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, obichar_t value) - obichar_t obi_column_get_obichar_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + obichar_t obi_get_char_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name) - obichar_t obi_column_get_obichar_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + obichar_t obi_get_char_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx) - int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + + # OBI_FLOAT + int obi_set_float_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name, obifloat_t value) - int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + int obi_set_float_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, obifloat_t value) - obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + obifloat_t obi_get_float_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name) - obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + obifloat_t obi_get_float_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx) - int obi_column_set_obiqual_char_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + + # OBI_QUAL + int obi_set_qual_char_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, const char* value) - int obi_column_set_obiqual_int_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + int obi_set_qual_int_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, const uint8_t* value, int value_length) - char* obi_column_get_obiqual_char_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + char* obi_get_qual_char_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx) - const uint8_t* obi_column_get_obiqual_int_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + const uint8_t* obi_get_qual_int_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, int* value_length) - int obi_column_set_obiqual_char_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + int obi_set_qual_char_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const char* element_name, const char* value) - int obi_column_set_obiqual_int_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + int obi_set_qual_int_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const char* element_name, const uint8_t* value, int value_length) - char* obi_column_get_obiqual_char_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + char* obi_get_qual_char_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const char* element_name) - const uint8_t* obi_column_get_obiqual_int_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + const uint8_t* obi_get_qual_int_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const char* element_name, int* value_length) - int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + + # OBI_STR + int obi_set_str_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name, const_char_p value) - int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + int obi_set_str_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, const_char_p value) - const_char_p obi_column_get_obistr_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + const_char_p obi_get_str_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name) - const_char_p obi_column_get_obistr_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + const_char_p obi_get_str_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx) - int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + + # OBI_SEQ + int obi_set_seq_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name, const_char_p value) - int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + int obi_set_seq_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, const_char_p value) - char* obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, - OBIDMS_column_p column, + char* obi_get_seq_with_elt_name_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, const_char_p element_name) - char* obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, - OBIDMS_column_p column, + char* obi_get_seq_with_elt_idx_and_col_p_in_view(Obiview_p view, + OBIDMS_column_p column_p, index_t line_nb, index_t element_idx) diff --git a/src/hashtable.c b/src/hashtable.c new file mode 100644 index 0000000..356fa26 --- /dev/null +++ b/src/hashtable.c @@ -0,0 +1,197 @@ +/**************************************************************************** + * Hash table source file * + ****************************************************************************/ + +/** + * @file hashtable.c + * @author Celine Mercier + * @date July 26th 2016 + * @brief Source file for hash table functions. + */ + + +#include +#include +#include +#include "string.h" + +#include "murmurhash2.h" +#include "hashtable.h" + + +// Create a new hashtable +hashtable_p ht_create(size_t size) +{ + hashtable_p hashtable = NULL; + size_t i; + + // Allocate the table + hashtable = malloc(sizeof(hashtable_t)); + if (hashtable == NULL) + return NULL; + + // Allocate the head nodes + hashtable->table = malloc(size * sizeof(entry_p)); + if (hashtable->table == NULL) + return NULL; + + // Initialize the head nodes + for (i=0; itable[i] = NULL; + + hashtable->size = size; + + return hashtable; +} + + +// Create an entry +entry_p ht_new_entry(const char* key, void* value) +{ + entry_p new_entry; + + new_entry = malloc(sizeof(entry_t)); + if (new_entry == NULL) + return NULL; + + new_entry->key = strdup(key); + if (new_entry->key == NULL) + return NULL; + + new_entry->value = value; + + new_entry->next = NULL; + + return new_entry; +} + + +// Delete an entry +int ht_delete_entry(hashtable_p hashtable, const char* key) +{ + entry_p last = NULL; + entry_p entry = NULL; + size_t bin = 0; + + bin = murmurhash2(key, strlen(key), SEED); + bin = bin % hashtable->size; + + // Step through the bin looking for the value + entry = hashtable->table[bin]; + + while ((entry != NULL) && (strcmp(key, entry->key ) != 0)) + { + last = entry; + entry = entry->next; + } + + if (entry == NULL) // key not found + return -1; + + // Link the entries before and after the entry + if (last != NULL) // If not head node + last->next = entry->next; + else // If head node + hashtable->table[bin] = entry->next; + + // Free the entry + free(entry->key); + free(entry->value); + free(entry); + + return 0; +} + + +// Set a new entry in the hash table. If the key is already in the table, the value is replaced by the new one +int ht_set(hashtable_p hashtable, const char* key, void* value) +{ + size_t bin = 0; + entry_p new_entry = NULL; + entry_p next = NULL; + entry_p last = NULL; + + if ((key == NULL) || (value == NULL)) + return -1; + + bin = murmurhash2(key, strlen(key), SEED); + bin = bin % hashtable->size; + + next = hashtable->table[bin]; + + while ((next != NULL) && (strcmp(key, next->key) != 0)) + { + last = next; + next = next->next; + } + + // If the key is already in the table, the value is replaced + if ((next != NULL) && (strcmp(key, next->key) == 0)) + new_entry->value = value; + + // Else, create the new entry and link it at the end of the list + else + { + // Create the new entry + new_entry = ht_new_entry(key, value); + if (new_entry == NULL) + return -1; + + // If it is the first entry of that bin, we're at the head node of the list, and we replace it with the new entry + if (last == NULL) + hashtable->table[bin] = new_entry; + + // Else link the new entry at the end of the list + else + last->next = new_entry; + } + return 0; +} + + +// Retrieve a value from a hash table +void* ht_get(hashtable_p hashtable, const char* key) +{ + size_t bin = 0; + entry_p entry; + + bin = murmurhash2(key, strlen(key), SEED); + bin = bin % hashtable->size; + + // Step through the bin looking for the value + entry = hashtable->table[bin]; + + while ((entry != NULL) && (strcmp(key, entry->key ) != 0)) + entry = entry->next; + + if (entry == NULL) + return NULL; + + else + return entry->value; +} + + +// Free the hash table +void ht_free(hashtable_p hashtable) +{ + size_t i; + entry_p entry; + entry_p next; + + for (i=0; i < hashtable->size; i++) + { + next = hashtable->table[i]; + while (next != NULL) + { + entry = next; + free(entry->key); + next = entry->next; + free(entry); + } + } + free(hashtable->table); + free(hashtable); +} + + diff --git a/src/hashtable.h b/src/hashtable.h new file mode 100644 index 0000000..af1190a --- /dev/null +++ b/src/hashtable.h @@ -0,0 +1,123 @@ +/**************************************************************************** + * Hash table header file * + ****************************************************************************/ + +/** + * @file hashtable.h + * @author Celine Mercier + * @date July 26th 2016 + * @brief Header file for hash table functions. + */ + + +#ifndef HASHTABLE_H_ +#define HASHTABLE_H_ + + +#include +#include +#include + + +#define SEED (0x9747b28c) /**< The seed used by the hash function. + */ + + +/** + * @brief Structure for an entry. + */ +typedef struct entry_s { + char* key; /**< Key used to refer to the entry. + */ + void* value; /**< Pointer on the value to be stored. + */ + struct entry_s* next; /**< Pointer on the next entry in the bin. + */ +} entry_t, *entry_p; + + +/** + * @brief Structure for a hash table. + */ +typedef struct hashtable { + size_t size; /**< Number of bins in the table. + */ + entry_p* table; /**< Table of bins. + */ +} hashtable_t, *hashtable_p; + + +/** + * @brief Creates a new hashtable. + * + * @param size The number of bins in the hash table. + * + * @returns A pointer to the newly created hash table. + * @retval NULL if an error occurred. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +hashtable_p ht_create(size_t size); + + +/** + * @brief Inserts a new entry in the hash table. + * If the key is already in the table, the value is replaced by the new one. + * + * @param hashtable A pointer on the hash table structure. + * @param key The key. + * @param value A pointer on the value associated with the key. + * + * @retval 0 if the entry was correctly set. + * @retval -1 if an error occurred. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int ht_set(hashtable_p hashtable, const char* key, void* value); + + +/** + * @brief Retrieves a value from a hash table. + * + * @param hashtable A pointer on the hash table structure. + * @param key The key. + * + * @returns A pointer on the value associated with the key. + * @retval NULL if the key was not found. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +void* ht_get(hashtable_p hashtable, const char* key); + + +/** + * @brief Deletes an entry. + * + * @param hashtable A pointer on the hash table structure. + * @param key The key. + * + * @retval 0 if the entry was correctly deleted. + * @retval -1 if an error occurred. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int ht_delete_entry(hashtable_p hashtable, const char* key); + + +/** + * @brief Frees a hash table. + * + * @param hashtable A pointer on the hash table structure. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +void ht_free(hashtable_p hashtable); + + +#endif /* HASHTABLE_H_ */ + diff --git a/src/obidmscolumn.c b/src/obidmscolumn.c index 9f875df..f475c73 100644 --- a/src/obidmscolumn.c +++ b/src/obidmscolumn.c @@ -527,14 +527,16 @@ size_t obi_get_platform_header_size() } -OBIDMS_column_p obi_create_column(OBIDMS_p dms, - const char* column_name, - OBIType_t data_type, - index_t nb_lines, - index_t nb_elements_per_line, - const char* elements_names, - const char* indexer_name, - const char* comments +OBIDMS_column_p obi_create_column(OBIDMS_p dms, + const char* column_name, + OBIType_t data_type, + index_t nb_lines, + index_t nb_elements_per_line, + const char* elements_names, + const char* indexer_name, + const char* associated_column_name, + obiversion_t associated_column_version, + const char* comments ) { OBIDMS_column_p new_column; @@ -750,6 +752,30 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms, if (comments != NULL) strncpy(header->comments, comments, COMMENTS_MAX_LENGTH); + // Store the associated column reference if needed // TODO discuss cases + if (data_type == OBI_QUAL) + { + if (associated_column_name == NULL) + { + obidebug(1, "\nError: The name of the associated column when creating a new column is NULL"); + munmap(new_column->header, header_size); + close(column_file_descriptor); + free(new_column); + return NULL; + } + strcpy((header->associated_column).column_name, associated_column_name); + + if (associated_column_version == -1) + { + obidebug(1, "\nError: The version of the associated column when creating a new column is not defined"); + munmap(new_column->header, header_size); + close(column_file_descriptor); + free(new_column); + return NULL; + } + (header->associated_column).version = associated_column_version; + } + // If the data type is OBI_STR, OBI_SEQ or OBI_QUAL, the associated obi_indexer is opened or created if ((returned_data_type == OBI_STR) || (returned_data_type == OBI_SEQ) || (returned_data_type == OBI_QUAL)) { @@ -964,6 +990,8 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms, nb_elements_per_line, (column_to_clone->header)->elements_names, (column_to_clone->header)->indexer_name, + ((column_to_clone->header)->associated_column).column_name, + ((column_to_clone->header)->associated_column).version, (column_to_clone->header)->comments ); diff --git a/src/obidmscolumn.h b/src/obidmscolumn.h index ebc996c..ddf7f81 100644 --- a/src/obidmscolumn.h +++ b/src/obidmscolumn.h @@ -38,43 +38,56 @@ */ +/** + * @brief Structure referencing a column by its name and its version. + */ +typedef struct Column_reference { + char column_name[OBIDMS_COLUMN_MAX_NAME+1]; /**< Name of the column. + */ + obiversion_t version; /**< Version of the column. + */ +} Column_reference_t, *Column_reference_p; + + /** * @brief OBIDMS column header structure. */ typedef struct OBIDMS_column_header { - size_t header_size; /**< Size of the header in bytes. - */ - size_t data_size; /**< Size of the data in bytes. - */ - index_t line_count; /**< Number of lines of data allocated. - */ - index_t lines_used; /**< Number of lines of data used. - */ - index_t nb_elements_per_line; /**< Number of elements per line. - */ - char elements_names[ELEMENTS_NAMES_MAX+1]; /**< Names of the line elements with ';' as separator - * (should be the column name if one element per line). - */ - OBIType_t returned_data_type; /**< Type of the data that is returned when getting an - * element from the column. - */ - OBIType_t stored_data_type; /**< Type of the data that is actually stored in the data - * part of the column. - */ - time_t creation_date; /**< Date of creation of the file. - */ - obiversion_t version; /**< Version of the column. - */ - obiversion_t cloned_from; /**< Version of the column from which this column - * was cloned from (-1 if it was not created by cloning - * another column). - */ - char name[OBIDMS_COLUMN_MAX_NAME+1]; /**< The column name as a NULL terminated string. - */ - char indexer_name[INDEXER_MAX_NAME+1]; /**< If there is one, the indexer name as a NULL terminated string. - */ - char comments[COMMENTS_MAX_LENGTH+1]; /**< Comments stored as a classical zero end C string. - */ + size_t header_size; /**< Size of the header in bytes. + */ + size_t data_size; /**< Size of the data in bytes. + */ + index_t line_count; /**< Number of lines of data allocated. + */ + index_t lines_used; /**< Number of lines of data used. + */ + index_t nb_elements_per_line; /**< Number of elements per line. + */ + char elements_names[ELEMENTS_NAMES_MAX+1]; /**< Names of the line elements with ';' as separator + * (should be the column name if one element per line). + */ + OBIType_t returned_data_type; /**< Type of the data that is returned when getting an + * element from the column. + */ + OBIType_t stored_data_type; /**< Type of the data that is actually stored in the data + * part of the column. + */ + time_t creation_date; /**< Date of creation of the file. + */ + obiversion_t version; /**< Version of the column. + */ + obiversion_t cloned_from; /**< Version of the column from which this column + * was cloned from (-1 if it was not created by cloning + * another column). + */ + char name[OBIDMS_COLUMN_MAX_NAME+1]; /**< The column name as a NULL terminated string. + */ + char indexer_name[INDEXER_MAX_NAME+1]; /**< If there is one, the indexer name as a NULL terminated string. + */ + Column_reference_t associated_column; /**< If there is one, the reference to the associated column. + */ + char comments[COMMENTS_MAX_LENGTH+1]; /**< Comments stored as a classical zero end C string. + */ } OBIDMS_column_header_t, *OBIDMS_column_header_p; @@ -168,13 +181,15 @@ size_t obi_get_platform_header_size(); * @param nb_elements_per_line The number of elements per line. // TODO talk about default values * @param elements_names The names of the elements with ';' as separator. * @param indexer_name The name of the indexer if there is one associated with the column. + * @param associated_column_name The name of the associated column if there is one. + * @param associated_column_version The version of the associated column if there is one. * @param comments Optional comments associated with the column. * * @returns A pointer on the newly created column structure. * @retval NULL if an error occurred. * * @since May 2015 - * @author Eric Coissac (eric.coissac@metabarcoding.org) + * @author Celine Mercier (celine.mercier@metabarcoding.org) */ OBIDMS_column_p obi_create_column(OBIDMS_p dms, const char* column_name, @@ -183,6 +198,8 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms, index_t nb_elements_per_line, const char* elements_names, const char* indexer_name, + const char* associated_column_name, + obiversion_t associated_column_version, const char* comments ); diff --git a/src/obiview.c b/src/obiview.c index da23357..49bfc8d 100644 --- a/src/obiview.c +++ b/src/obiview.c @@ -30,6 +30,7 @@ #include "obierrno.h" #include "obidebug.h" #include "obilittlebigman.h" +#include "hashtable.h" #include "utils.h" @@ -42,6 +43,16 @@ * **************************************************************************/ +/** + * Internal function calculating the size of the file where the informations about an obiview are stored. + * + * @returns The size of the file in bytes. + * + * @since June 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +size_t get_platform_view_file_size(); + /** * Internal function building the file name where the informations about an obiview are stored. @@ -82,6 +93,14 @@ int create_obiview_file(OBIDMS_p dms, const char* view_name); * The column references stored in the mapped view infos structures are updated * to match the columns opened in the opened view structure. * + * @warning The column pointer array should be up to date before using this function. + * @warning Aliases are not updated by this function and have to be edited separately. + * This function simply reads the column pointer array associated with the view + * and fills the column names and versions in the column reference array accordingly, + * without touching the alias. + * That means that for example if there is a shift in the column pointer array, this + * function should not be used. + * * @param view A pointer on the view. * * @since June 2016 @@ -90,6 +109,69 @@ int create_obiview_file(OBIDMS_p dms, const char* view_name); void update_column_refs(Obiview_p view); +/** + * @brief Internal function creating the column dictionary associated with a view. + * + * The column dictionary is built from the column references array, and associates each column alias + * with the pointer on the column. + * + * @warning The column reference array and the column pointer array should be up to date before using this function. + * + * @param view A pointer on the view. + * + * @retval 0 if the operation was successfully completed. + * @retval -1 if an error occurred. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int create_column_dict(Obiview_p view); + + +/** + * @brief Internal function updating the column dictionary associated with a view. + * + * The column dictionary is built from the column references array, and associates each column alias + * with the pointer on the column. + * + * @warning The column reference array and the column pointer array should be up to date before using this function. + * + * @param view A pointer on the view. + * + * @retval 0 if the operation was successfully completed. + * @retval -1 if an error occurred. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int update_column_dict(Obiview_p view); + + +/** + * @brief Internal function updating the column reference array and the column dictionary associated with a view. + * + * The column reference array is updated from the column pointer array, then the column dictionary that + * and associates each column alias with the pointer on the column is updated from the column reference array. + * + * @warning The column pointer array should be up to date before using this function. + * @warning Aliases are not updated by this function and have to be edited separately. + * This function simply reads the column pointer array associated with the view + * and fills the column names and versions in the column reference array accordingly, + * without touching the alias. + * That means that for example if there is a shift in the column pointer array, this + * function should not be used. + * + * @param view A pointer on the view. + * + * @retval 0 if the operation was successfully completed. + * @retval -1 if an error occurred. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int update_column_refs_and_dict(Obiview_p view); + + /** * @brief Internal function to update the line count in the context of a view. * @@ -129,7 +211,7 @@ OBIDMS_column_p clone_column_in_view(Obiview_p view, const char* column_name); /** - * Internal function preparing to set a value in a column, in the context of a view. + * @brief Internal function preparing to set a value in a column, in the context of a view. * * The function checks that the view is not read-only, clones the column or all columns if needed, * and updates the line count if needed. @@ -148,7 +230,7 @@ int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, i /** - * Internal function preparing to get a value from a column, in the context of a view. + * @brief Internal function preparing to get a value from a column, in the context of a view. * * The function checks that the line index is not beyond the current line count of the view, * and modifies it if there is a line selection associated with the view. @@ -165,6 +247,122 @@ int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, i int prepare_to_get_value_from_column(Obiview_p view, index_t* line_nb_p); +/****** PREDICATE FUNCTIONS *******/ + +/** + * @brief Internal function checking if a view has a NUC_SEQUENCE_COLUMN column. + * + * The function checks that the view has a column with the name attributed to obligatory + * nucleotide sequence columns. + * + * @param view The view. + * + * @returns A character string describing the predicate. + * @retval NULL if the predicate is false or if there was an error. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +char* view_has_nuc_sequence_column(Obiview_p view); + + +/** + * @brief Internal function checking if a view has a QUALITY_COLUMN column. + * + * The function checks that the view has a column with the name attributed to obligatory + * quality columns. + * + * @param view The view. + * + * @returns A character string describing the predicate. + * @retval NULL if the predicate is false or if there was an error. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +char* view_has_quality_column(Obiview_p view); + + +/** + * @brief Internal function checking if a view has a ID_COLUMN column. + * + * The function checks that the view has a column with the name attributed to obligatory + * id columns. + * + * @param view The view. + * + * @returns A character string describing the predicate. + * @retval NULL if the predicate is false or if there was an error. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +char* view_has_id_column(Obiview_p view); + + +/** + * @brief Internal function checking if a view has a DEFINITION_COLUMN column. + * + * The function checks that the view has a column with the name attributed to obligatory + * definition columns. + * + * @param view The view. + * + * @returns A character string describing the predicate. + * @retval NULL if the predicate is false or if there was an error. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +char* view_has_definition_column(Obiview_p view); + + +/** + * @brief Internal function checking that the quality column of a view and the sequence column associated to it + * correspond properly: + * - when a line is defined for either column, it must also be defined for the other column + * - when a line is defined, the lengths of the sequence and of the quality must be equal + * + * @param view The view. + * + * @returns A character string describing the predicate. + * @retval NULL if the predicate is false or if there was an error. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +char* view_check_quality_matches_seq_column(Obiview_p view); + + +/** + * @brief Internal function checking one predicate function on a view. + * + * @param view The view. + * @param predicate_function The predicate function to use. + * + * @returns A character string describing the predicate. + * @retval NULL if the predicate is false or if there was an error. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +char* view_check_one_predicate(Obiview_p view, char* (*predicate_function)(Obiview_p view)); + + +/** + * @brief Internal function checking all the predicates associated with a view. + * + * @param view The view. + * + * @returns A character string describing all the predicates separated by line breaks. + * @retval NULL if at least one of the predicates is false or if there was an error. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +char* view_check_all_predicates(Obiview_p view); + + /************************************************************************ * * D E F I N I T I O N O F T H E P R I V A T E F U N C T I O N S @@ -229,11 +427,11 @@ int create_obiview_file(OBIDMS_p dms, const char* view_name) { obi_set_errno(OBIVIEW_ERROR); obidebug(1, "\nError creating an obiview file"); -// free(file_name); TODO +// free(file_name); return -1; } - //free(file_name); TODO + //free(file_name); // Truncate file to the right size file_size = get_platform_view_file_size(); @@ -252,19 +450,72 @@ int create_obiview_file(OBIDMS_p dms, const char* view_name) } - void update_column_refs(Obiview_p view) { int i; for (i=0; i < (view->infos)->column_count; i++) { - strcpy((((view->infos)->column_references)+i)->column_name, (((view->columns)[i])->header)->name); - (((view->infos)->column_references)+i)->version = (((view->columns)[i])->header)->version; + strcpy(((((view->infos)->column_references)[i]).column_refs).column_name, (((view->columns)[i])->header)->name); + ((((view->infos)->column_references)[i]).column_refs).version = (((view->columns)[i])->header)->version; } } +int create_column_dict(Obiview_p view) +{ + int i; + + view->column_dict = ht_create(MAX_NB_OPENED_COLUMNS); + if (view->column_dict == NULL) + { + obi_set_errno(OBIVIEW_ERROR); + obidebug(1, "\nError creating a column dictionary"); + return -1; + } + + // Rebuild the dictionary from the column references and the column pointer array associated with the view + for (i=0; i < (view->infos)->column_count; i++) + { + // Check that each alias is unique + if (ht_get(view->column_dict, (((view->infos)->column_references)[i]).alias) != NULL) + { + obi_set_errno(OBIVIEW_ERROR); + obidebug(1, "\nError: the name/alias identifying a column in a view is not unique"); + return -1; + } + + if (ht_set(view->column_dict, (((view->infos)->column_references)[i]).alias, (view->columns)[i]) < 0) + { + obi_set_errno(OBIVIEW_ERROR); + obidebug(1, "\nError adding a column in a column dictionary"); + return -1; + } + } + + return 0; +} + + +int update_column_dict(Obiview_p view) +{ + // Re-initialize the dictionary to rebuild it from scratch + ht_free(view->column_dict); + + if (create_column_dict(view) < 0) + return -1; + + return 0; +} + + +int update_column_refs_and_dict(Obiview_p view) +{ + update_column_refs(view); + return update_column_dict(view); +} + + int update_lines(Obiview_p view, index_t line_count) { int i; @@ -292,6 +543,7 @@ OBIDMS_column_p clone_column_in_view(Obiview_p view, const char* column_name) OBIDMS_column_p current_line_selection = NULL; OBIDMS_column_p column = NULL; OBIDMS_column_p column_buffer; + bool found; // Check that the view is not read-only if (view->read_only) @@ -306,9 +558,10 @@ OBIDMS_column_p clone_column_in_view(Obiview_p view, const char* column_name) else current_line_selection = view->line_selection; + found = false; for (i=0; i<((view->infos)->column_count); i++) { - if ((current_line_selection != NULL) || (!(strcmp((((view->columns)[i])->header)->name, column_name)))) + if ((current_line_selection != NULL) || (!strcmp((((view->infos)->column_references)[i]).alias, column_name))) { // Clone with the right line selection and replace (for all columns if there is a line selection) // Save pointer to close column after cloning @@ -326,7 +579,7 @@ OBIDMS_column_p clone_column_in_view(Obiview_p view, const char* column_name) // Close old cloned column obi_close_column(column_buffer); - if (!(strcmp((((view->columns)[i])->header)->name, column_name))) + if (!strcmp((((view->infos)->column_references)[i]).alias, column_name)) { // Found the column to return column = (view->columns)[i]; } @@ -348,8 +601,8 @@ OBIDMS_column_p clone_column_in_view(Obiview_p view, const char* column_name) view->new_line_selection = NULL; } - // Update column references in view infos - update_column_refs(view); + // Update column refs and dict + update_column_refs_and_dict(view); return column; } @@ -357,7 +610,8 @@ OBIDMS_column_p clone_column_in_view(Obiview_p view, const char* column_name) int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, index_t* line_nb_p) { - char* column_name; + int i; + char* column_name = NULL; // Check that the view is not read-only if (view->read_only) @@ -375,22 +629,25 @@ int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, i if (view->line_selection != NULL) (*line_nb_p) = *(((index_t*) ((view->line_selection)->data)) + (*line_nb_p)); - column_name = (char*) malloc(strlen(((*column_pp)->header)->name) * sizeof(char)); + // Get the name/alias of the column from the pointer + for (i=0; i<((view->infos)->column_count); i++) + { + if (obi_view_get_column(view, (((view->infos)->column_references)[i]).alias) == *column_pp) + column_name = (((view->infos)->column_references)[i]).alias; + } if (column_name == NULL) { - obi_set_errno(OBI_MALLOC_ERROR); - obidebug(1, "\nError trying to allocate memory for a column name"); + obi_set_errno(OBIVIEW_ERROR); + obidebug(1, "\nError trying to clone a column in a view: column alias not found from pointer"); return -1; } - strcpy(column_name, ((*column_pp)->header)->name); + (*column_pp) = clone_column_in_view(view, column_name); if ((*column_pp) == NULL) { obidebug(1, "\nError trying to clone a column to modify it"); return -1; } - - free(column_name); } if (((*line_nb_p)+1) > (view->infos)->line_count) @@ -419,6 +676,232 @@ int prepare_to_get_value_from_column(Obiview_p view, index_t* line_nb_p) } + +/****** PREDICATE FUNCTIONS *******/ + +char* view_has_nuc_sequence_column(Obiview_p view) +{ + char* predicate; + + predicate = (char*) malloc((strlen("The view has an associated nucleotide sequence column.") + 1) * sizeof(char)); + if (predicate == NULL) + { + obi_set_errno(OBI_MALLOC_ERROR); + obidebug(1, "\nError allocating memory for predicate character string."); + return NULL; + } + + strcpy(predicate, "The view has an associated nucleotide sequence column."); + + if (obi_view_get_column(view, NUC_SEQUENCE_COLUMN) != NULL) + return predicate; + else + return NULL; +} + + +char* view_has_quality_column(Obiview_p view) +{ + char* predicate; + + predicate = (char*) malloc((strlen("The view has an associated sequence quality column.") + 1) * sizeof(char)); + if (predicate == NULL) + { + obi_set_errno(OBI_MALLOC_ERROR); + obidebug(1, "\nError allocating memory for predicate character string."); + return NULL; + } + + strcpy(predicate, "The view has an associated sequence quality column."); + + if (obi_view_get_column(view, QUALITY_COLUMN) != NULL) + return predicate; + else + return NULL; +} + + +char* view_has_id_column(Obiview_p view) +{ + char* predicate; + + predicate = (char*) malloc((strlen("The view has an associated identifier column.") + 1) * sizeof(char)); + if (predicate == NULL) + { + obi_set_errno(OBI_MALLOC_ERROR); + obidebug(1, "\nError allocating memory for predicate character string."); + return NULL; + } + + strcpy(predicate, "The view has an associated identifier column."); + + if (obi_view_get_column(view, ID_COLUMN) != NULL) + return predicate; + else + return NULL; +} + + +char* view_has_definition_column(Obiview_p view) +{ + char* predicate; + + predicate = (char*) malloc((strlen("The view has an associated definition column.") + 1) * sizeof(char)); + if (predicate == NULL) + { + obi_set_errno(OBI_MALLOC_ERROR); + obidebug(1, "\nError allocating memory for predicate character string."); + return NULL; + } + + strcpy(predicate, "The view has an associated definition column."); + + if (obi_view_get_column(view, DEFINITION_COLUMN) != NULL) + return predicate; + else + return NULL; +} + + +char* view_check_quality_matches_seq_column(Obiview_p view) // TODO Print error if there is one? +{ + index_t i, j; + index_t nb_elements_per_line; + int qual_len; + const uint8_t* qual; + char* seq; + OBIDMS_column_p qual_column; + OBIDMS_column_p seq_column; + char* predicate; + + predicate = (char*) malloc((strlen("The sequences and sequence quality arrays match.") + 1) * sizeof(char)); + if (predicate == NULL) + { + obi_set_errno(OBI_MALLOC_ERROR); + obidebug(1, "\nError allocating memory for predicate character string."); + return NULL; + } + + strcpy(predicate, "The sequences and sequence quality arrays match."); + + qual_column = obi_view_get_column(view, QUALITY_COLUMN); + if (qual_column == NULL) + return NULL; + + seq_column = obi_view_get_column(view, ((qual_column->header)->associated_column).column_name); + //seq_column = obi_open_column(view->dms, ((qual_column->header)->associated_column).column_name, ((qual_column->header)->associated_column).version); + // TODO discuss the fact that it's opened outside of the context of the view or not + // TODO if outside of view, make function that opens a column from a column reference structure? + + if (seq_column == NULL) + return NULL; + + nb_elements_per_line = (qual_column->header)->nb_elements_per_line; + // Check that the quality and the sequence columns have the same number of elements per line + if (nb_elements_per_line != (seq_column->header)->nb_elements_per_line) + return NULL; + + for (i=0; i < (view->infos)->line_count; i++) + { + for (j=0; j < nb_elements_per_line; j++) + { + qual = obi_column_get_obiqual_int_with_elt_idx(qual_column, i, j, &qual_len); + seq = obi_column_get_obiseq_with_elt_idx(seq_column, i, j); + if ((qual != OBIQual_int_NA) && (seq != OBISeq_NA)) + { + // Test that the lengths of the quality and the sequence are equal + if (qual_len != (int)strlen(seq)) + return NULL; + } + // Test if one value is NA and not the other + else if (((qual == OBIQual_int_NA) && (seq != OBISeq_NA)) || ((qual != OBIQual_int_NA) && (seq == OBISeq_NA))) + return NULL; + } + } + + //obi_close_column(seq_column); + + return predicate; +} + + +char* view_check_one_predicate(Obiview_p view, char* (*predicate_function)(Obiview_p view)) +{ + return predicate_function(view); +} + + +char* view_check_all_predicates(Obiview_p view) +{ + int i, j; + size_t size_to_allocate; + char* predicate = NULL; + char* all_predicates_string = NULL; + char** all_predicates = NULL; + + size_to_allocate = 0; + + // Allocate memory for predicate array + all_predicates = (char**) malloc((view->nb_predicates) * sizeof(char*)); + if (all_predicates == NULL) + { + obi_set_errno(OBI_MALLOC_ERROR); + obidebug(1, "\nError allocating memory for predicate array."); + return NULL; + } + + for (i=0; i < view->nb_predicates; i++) + { + // Initialize predicate in predicate array + all_predicates[i] = NULL; + + // Check the predicate + predicate = view_check_one_predicate(view, (view->predicate_functions)[i]); + if (predicate == NULL) + { + // TODO discuss + for (j=0; j<=i; j++) + free(all_predicates[j]); + free(all_predicates); + return NULL; + } + else + { + all_predicates[i] = predicate; + size_to_allocate = size_to_allocate + strlen(predicate) + 1; // +1 for '\n' + } + } + + size_to_allocate += 1; // +1 for '\0' + + all_predicates_string = (char*) malloc(size_to_allocate * sizeof(char)); + if (all_predicates_string == NULL) + { + obi_set_errno(OBI_MALLOC_ERROR); + obidebug(1, "\nError allocating memory for predicate character string."); + return NULL; + } + + // Build the character string with all the predicates + strcpy(all_predicates_string, all_predicates[0]); + for (i=1; i < view->nb_predicates; i++) + { + strcat(all_predicates_string, "\n"); + strcat(all_predicates_string, all_predicates[i]); + } + + // Free everything + for (i=0; i < view->nb_predicates; i++) + free(all_predicates[i]); + free(all_predicates); + + return all_predicates_string; +} + + +// TODO predicate function that goes through each line / each elements + + /********************************************************************** * * D E F I N I T I O N O F T H E P U B L I C F U N C T I O N S @@ -455,6 +938,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl } view->dms = dms; + view->read_only = 0; // Create view file if (create_obiview_file(dms, view_name) < 0) @@ -499,7 +983,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl // If there is a new line selection, build it by combining it with the one from the view to clone if there is one else if (line_selection != NULL) { - view->line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, LINES_COLUMN_NAME, NULL, NULL); + view->line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, LINES_COLUMN_NAME, NULL, NULL, -1, NULL); if ((view->line_selection) == NULL) { obidebug(1, "\nError creating a column corresponding to a line selection"); @@ -546,24 +1030,12 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl (view->infos)->line_count = (view_to_clone->infos)->line_count; } - for (i=0; i<((view_to_clone->infos)->column_count); i++) - { - (view->columns)[i] = obi_open_column(dms, (((view_to_clone->columns)[i])->header)->name, (((view_to_clone->columns)[i])->header)->version); - if ((view->columns)[i] == NULL) - { - if (view->line_selection != NULL) - obi_close_column(view->line_selection); - obi_view_unmap_file(view->dms, view->infos); - free(view); - return NULL; - } - } - - (view->infos)->column_count = (view_to_clone->infos)->column_count; + // Fill informations strcpy((view->infos)->view_type, (view_to_clone->infos)->view_type); strcpy((view->infos)->created_from, (view_to_clone->infos)->name); view->new_line_selection = NULL; } + // Else, fill empty view structure else { @@ -577,10 +1049,12 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl //view->columns = NULL; // TODO } + // Fill last informations strcpy((view->infos)->name, view_name); strcpy((view->infos)->comments, comments); (view->infos)->creation_date = time(NULL); - view->read_only = 0; + view->nb_predicates = 0; + view->predicate_functions = NULL; // Store reference for line selection if (view->line_selection == NULL) @@ -594,8 +1068,44 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl ((view->infos)->line_selection).version = ((view->line_selection)->header)->version; } - // Store references for columns - update_column_refs(view); + // Create the column dictionary (hash table) associating column names (or aliases) to column pointers + if (create_column_dict(view) < 0) + { + obi_close_view(view); + return NULL; + } + + // Once the view has been created with all its elements and informations, add the columns if the view is cloned from another view + // Add the columns from the view to clone in the new view + if (view_to_clone != NULL) + { + (view->infos)->column_count = 0; + for (i=0; i<((view_to_clone->infos)->column_count); i++) + { + if (obi_view_add_column(view, + (((view_to_clone->columns)[i])->header)->name, + (((view_to_clone->columns)[i])->header)->version, + (((view_to_clone->infos)->column_references)[i]).alias, + 0, + (view->infos)->line_count, + 0, + NULL, + NULL, + NULL, + -1, + NULL, + false) + < 0) + { + obidebug(1, "\nError adding a column in a new view from a view to clone"); + if (view->line_selection != NULL) + obi_close_column(view->line_selection); + obi_view_unmap_file(view->dms, view->infos); + free(view); + return NULL; + } + } + } return view; } @@ -619,7 +1129,8 @@ Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const char* view_name, con Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection, const char* comments) { - Obiview_p view; + Obiview_p view; + OBIDMS_column_p associated_nuc_column; if (view_to_clone != NULL) { // Check that the view to clone is already a NUC_SEQS view (TODO discuss possibility of transforming type of a view) @@ -640,31 +1151,43 @@ Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p v if (view_to_clone == NULL) { // Adding sequence column - if (obi_view_add_column(view, NUC_SEQUENCE_COLUMN, -1, OBI_SEQ, 0, 1, NUC_SEQUENCE_COLUMN, "", "Nucleotide sequences", true) < 0) + if (obi_view_add_column(view, NUC_SEQUENCE_COLUMN, -1, NUC_SEQUENCE_COLUMN, OBI_SEQ, 0, 1, NUC_SEQUENCE_COLUMN, "", NULL, -1, "Nucleotide sequences", true) < 0) { obidebug(1, "Error adding an obligatory column in a nucleotide sequences view"); return NULL; } // Adding id column - if (obi_view_add_column(view, ID_COLUMN, -1, OBI_STR, 0, 1, ID_COLUMN, "", "Ids", true) < 0) + if (obi_view_add_column(view, ID_COLUMN, -1, ID_COLUMN, OBI_STR, 0, 1, ID_COLUMN, "", NULL, -1, "Ids", true) < 0) { obidebug(1, "Error adding an obligatory column in a nucleotide sequences view"); return NULL; } // Adding definition column - if (obi_view_add_column(view, DEFINITION_COLUMN, -1, OBI_STR, 0, 1, DEFINITION_COLUMN, "", "Definitions", true) < 0) + if (obi_view_add_column(view, DEFINITION_COLUMN, -1, DEFINITION_COLUMN, OBI_STR, 0, 1, DEFINITION_COLUMN, "", NULL, -1, "Definitions", true) < 0) { obidebug(1, "Error adding an obligatory column in a nucleotide sequences view"); return NULL; } // Adding quality column - if (obi_view_add_column(view, QUALITY_COLUMN, -1, OBI_QUAL, 0, 1, QUALITY_COLUMN, "", "Sequence qualities", true) < 0) + associated_nuc_column = obi_view_get_column(view, NUC_SEQUENCE_COLUMN); + if (obi_view_add_column(view, QUALITY_COLUMN, -1, QUALITY_COLUMN, OBI_QUAL, 0, 1, QUALITY_COLUMN, "", (associated_nuc_column->header)->name, (associated_nuc_column->header)->version, "Sequence qualities", true) < 0) // TODO discuss automatic association { obidebug(1, "Error adding an obligatory column in a nucleotide sequences view"); return NULL; } } + // Add predicate functions of the view type + view->nb_predicates = 5; // TODO macro? + + view->predicate_functions = malloc((view->nb_predicates) * sizeof(char* (*) (bool))); + + (view->predicate_functions)[0] = view_has_nuc_sequence_column; + (view->predicate_functions)[1] = view_has_quality_column; + (view->predicate_functions)[2] = view_has_id_column; + (view->predicate_functions)[3] = view_has_definition_column; + (view->predicate_functions)[4] = view_check_quality_matches_seq_column; + return view; } @@ -704,11 +1227,11 @@ Obiview_infos_p obi_view_map_file(OBIDMS_p dms, const char* view_name) { obi_set_errno(OBIVIEW_ERROR); obidebug(1, "\nError opening an obiview file"); -// free(file_name); TODO +// free(file_name); return NULL; } - //free(file_name); TODO + //free(file_name); // Map the view infos structure file_size = get_platform_view_file_size(); @@ -750,11 +1273,11 @@ int obi_view_unmap_file(OBIDMS_p dms, Obiview_infos_p view_infos) { obi_set_errno(OBIVIEW_ERROR); obidebug(1, "\nError opening an obiview file"); - // free(file_name); TODO + // free(file_name); return -1; } - //free(file_name); TODO + //free(file_name); // Unmap the view infos structure file_size = get_platform_view_file_size(); @@ -774,8 +1297,11 @@ int obi_view_unmap_file(OBIDMS_p dms, Obiview_infos_p view_infos) Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name) { - Obiview_p view; - int i; + Obiview_p view; + const char* column_name; + obiversion_t column_version; + OBIDMS_column_p column_pointer; + int i; // Alllocate the memory for the view structure view = (Obiview_p) malloc(sizeof(Obiview_t)); @@ -807,18 +1333,33 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name) // Open the columns to read for (i=0; i < ((view->infos)->column_count); i++) { - (view->columns)[i] = obi_open_column(dms, (((view->infos)->column_references)+i)->column_name, (((view->infos)->column_references)+i)->version); - if ((view->columns)[i] == NULL) + column_name = ((((view->infos)->column_references)[i]).column_refs).column_name; + column_version = ((((view->infos)->column_references)[i]).column_refs).version; + + column_pointer = obi_open_column(dms, column_name, column_version); + if (column_pointer == NULL) { - obidebug(1, "\nError opening a column for a view: column %d: %s, version %d", i, (((view->infos)->column_references)+i)->column_name, (((view->infos)->column_references)+i)->version); + obidebug(1, "\nError opening a column for a view: column %d: %s, version %d", i, column_name, column_version); obi_close_view(view); return NULL; } + (view->columns)[i] = column_pointer; + } view->dms = dms; view->new_line_selection = NULL; view->read_only = true; + view->nb_predicates = 0; + view->predicate_functions = NULL; + + // Create the column dictionary associating each column alias with its pointer + if (create_column_dict(view) < 0) + { + obidebug(1, "\nError creating the column dictionary when opening a view"); + obi_close_view(view); + return NULL; + } return view; } @@ -827,18 +1368,21 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name) int obi_view_add_column(Obiview_p view, const char* column_name, obiversion_t version_number, + const char* alias, OBIType_t data_type, index_t nb_lines, index_t nb_elements_per_line, const char* elements_names, const char* indexer_name, + const char* associated_column_name, + obiversion_t associated_column_version, const char* comments, bool create) // all infos for creation or open { - int i; - OBIDMS_column_p column; - OBIDMS_column_p column_buffer; - OBIDMS_column_p current_line_selection; + int i; + OBIDMS_column_p column; + OBIDMS_column_p column_buffer; + OBIDMS_column_p current_line_selection; // Check that the view is not read-only if (view->read_only) @@ -901,7 +1445,7 @@ int obi_view_add_column(Obiview_p view, // Open or create the column if (create) { // Create column - column = obi_create_column(view->dms, column_name, data_type, nb_lines, nb_elements_per_line, elements_names, indexer_name, comments); + column = obi_create_column(view->dms, column_name, data_type, nb_lines, nb_elements_per_line, elements_names, indexer_name, associated_column_name, associated_column_version, comments); } else { // Open column @@ -914,14 +1458,29 @@ int obi_view_add_column(Obiview_p view, return -1; } - // Store column in the view + // Store column pointer in the view structure (view->columns)[(view->infos)->column_count] = column; + + // If an alias is not defined, it's the original name of the column. // TODO discuss + if (alias == NULL) + alias = column_name; + + // Save column alias + strcpy((((view->infos)->column_references)[(view->infos)->column_count]).alias, alias); + (view->infos)->column_count++; if ((view->infos)->column_count == 1) // first column in the view - (view->infos)->line_count = (column->header)->lines_used; + (view->infos)->line_count = nb_lines; - // Update reference in view infos - update_column_refs(view); + // Update column references and dictionary + update_column_refs_and_dict(view); + +// // Print dict +// for (i=0; i<((view->infos)->column_count); i++) +// { +// fprintf(stderr, "\n\nalias: %s", (((view->infos)->column_references)[i]).alias); +// fprintf(stderr, "\npointer: %x\n", obi_view_get_column(view, (((view->infos)->column_references)[i]).alias)); +// } return 0; } @@ -942,59 +1501,107 @@ int obi_view_delete_column(Obiview_p view, const char* column_name) return -1; } - found = 0; - + found = false; for (i=0; i<((view->infos)->column_count); i++) { - if (!strcmp((((view->columns)[i])->header)->name, column_name)) + if ((!found) && (!strcmp((((view->infos)->column_references)[i]).alias, column_name))) { obi_close_column((view->columns)[i]); - found = 1; + found = true; } if (found) { if (i != (((view->infos)->column_count) - 1)) // not the last one + { // Shift the pointer and the references (view->columns)[i] = (view->columns)[i+1]; + strcpy((((view->infos)->column_references)[i]).alias, (((view->infos)->column_references)[i+1]).alias); + strcpy(((((view->infos)->column_references)[i]).column_refs).column_name, ((((view->infos)->column_references)[i+1]).column_refs).column_name); + ((((view->infos)->column_references)[i]).column_refs).version = ((((view->infos)->column_references)[i+1]).column_refs).version; + } else // Last column (view->columns)[i] = NULL; } } if (!found) + { + obi_set_errno(OBIVIEW_ERROR); + obidebug(1, "\nError trying to delete a column: column not found"); return -1; + } ((view->infos)->column_count)--; - // Update reference in view infos - update_column_refs(view); + // Update column dictionary + update_column_dict(view); return 0; } OBIDMS_column_p obi_view_get_column(Obiview_p view, const char* column_name) +{ + return (OBIDMS_column_p)(ht_get(view->column_dict, column_name)); +} + + +OBIDMS_column_p* obi_view_get_pointer_on_column_in_view(Obiview_p view, const char* column_name) { int i; - for (i=0; i<((view->infos)->column_count); i++) + for (i=0; i < (view->infos)->column_count; i++) { - if (!(strcmp((((view->columns)[i])->header)->name, column_name))) - return (view->columns)[i]; + if (strcmp((((view->infos)->column_references)[i]).alias, column_name) == 0) + return ((view->columns)+i); } + obidebug(1, "\nError: column not found"); return NULL; } -OBIDMS_column_p* obi_view_get_pointer_on_column_in_view(Obiview_p view, const char* column_name) // TODO delete? +int obi_view_create_column_alias(Obiview_p view, const char* current_name, const char* alias) { int i; + bool found; + // Check that the view is not read-only + if (view->read_only) + { + obi_set_errno(OBIVIEW_ERROR); + obidebug(1, "\nError trying to change a column alias in a read-only view"); + return -1; + } + + // Check that the new alias is unique + if (ht_get(view->column_dict, alias) != NULL) + { + obi_set_errno(OBIVIEW_ERROR); + obidebug(1, "\nError: the new name/alias identifying a column in a view is not unique"); + return -1; + } + + // Set the new alias in the column references + found = false; for (i=0; i<((view->infos)->column_count); i++) { - if (!(strcmp((((view->columns)[i])->header)->name, column_name))) - return ((view->columns)+i); + if (!strcmp((((view->infos)->column_references)[i]).alias, current_name)) + { + strcpy((((view->infos)->column_references)[i]).alias, alias); + found = true; + } } - return NULL; + + if (found == false) + { + obi_set_errno(OBIVIEW_ERROR); + obidebug(1, "\nError: can't find the column '%s' to change its alias", current_name); + return -1; + } + + // Update the column dictionary + update_column_dict(view); + + return 0; } @@ -1011,7 +1618,7 @@ int obi_select_line(Obiview_p view, index_t line_nb) // If the column for line selection doesn't already exists, create it and store its informations if ((view->new_line_selection) == NULL) { - view->new_line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, LINES_COLUMN_NAME, NULL, NULL); + view->new_line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, LINES_COLUMN_NAME, NULL, NULL, -1, NULL); if ((view->new_line_selection) == NULL) { obidebug(1, "\nError creating a column corresponding to a line selection"); @@ -1046,7 +1653,7 @@ int obi_select_lines(Obiview_p view, index_t* line_nbs) // If column for line selection doesn't already exists, create it and store its informations if ((view->new_line_selection) == NULL) { - view->new_line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, LINES_COLUMN_NAME, NULL, NULL); + view->new_line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, LINES_COLUMN_NAME, NULL, NULL, -1, NULL); if ((view->new_line_selection) == NULL) { obidebug(1, "\nError creating a column corresponding to a line selection"); @@ -1142,6 +1749,9 @@ int obi_close_view(Obiview_p view) } } + // Free the column dictionary + ht_free(view->column_dict); + // Unmap view file if (obi_view_unmap_file(view->dms, view->infos) < 0) { @@ -1157,8 +1767,19 @@ int obi_close_view(Obiview_p view) int obi_save_and_close_view(Obiview_p view) { + char* predicates; + if (!(view->read_only)) { + predicates = view_check_all_predicates(view); + if (predicates == NULL) + return -1; // TODO reverse view (delete files) + else + { + // TODO check size and grow file if needed + strcpy((view->infos)->comments, predicates); + free(predicates); + } if (obi_save_view(view) < 0) return -1; } @@ -1170,37 +1791,77 @@ int obi_save_and_close_view(Obiview_p view) /*********** FOR BOOL COLUMNS ***********/ -int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obibool_t value) +int obi_set_bool_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, obibool_t value) { - if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) + if (prepare_to_set_value_in_column(view, &column_p, &line_nb) < 0) return -1; - return obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value); + return obi_column_set_obibool_with_elt_idx(column_p, line_nb, element_idx, value); } -obibool_t obi_column_get_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +obibool_t obi_get_bool_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx) { if (prepare_to_get_value_from_column(view, &line_nb) < 0) return OBIBool_NA; - return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx); + return obi_column_get_obibool_with_elt_idx(column_p, line_nb, element_idx); } -int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value) +int obi_set_bool_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name, obibool_t value) { - index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column_p, element_name); if (element_idx == OBIIdx_NA) return -1; - return obi_column_set_obibool_with_elt_idx_in_view(view, column, line_nb, element_idx, value); + return obi_set_bool_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx, value); } -obibool_t obi_column_get_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +obibool_t obi_get_bool_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name) { - index_t element_idx = obi_column_get_element_index_from_name(column, element_name); + index_t element_idx = obi_column_get_element_index_from_name(column_p, element_name); if (element_idx == OBIIdx_NA) return OBIBool_NA; - return obi_column_get_obibool_with_elt_idx_in_view(view, column, line_nb, element_idx); + return obi_get_bool_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx); +} + + +int obi_set_bool_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, obibool_t value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_bool_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name, value); +} + + +int obi_set_bool_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, obibool_t value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_bool_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx, value); +} + + +obibool_t obi_get_bool_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIBool_NA; + return obi_get_bool_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx); +} + + +obibool_t obi_get_bool_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIBool_NA; + return obi_get_bool_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name); } /****************************************/ @@ -1208,7 +1869,7 @@ obibool_t obi_column_get_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_co /*********** FOR CHAR COLUMNS ***********/ -int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obichar_t value) +int obi_set_char_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obichar_t value) { if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) return -1; @@ -1216,7 +1877,7 @@ int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p } -obichar_t obi_column_get_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +obichar_t obi_get_char_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) { if (prepare_to_get_value_from_column(view, &line_nb) < 0) return OBIChar_NA; @@ -1224,21 +1885,61 @@ obichar_t obi_column_get_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_col } -int obi_column_set_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value) +int obi_set_char_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; - return obi_column_set_obichar_with_elt_idx_in_view(view, column, line_nb, element_idx, value); + return obi_set_char_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx, value); } -obichar_t obi_column_get_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +obichar_t obi_get_char_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIChar_NA; - return obi_column_get_obichar_with_elt_idx_in_view(view, column, line_nb, element_idx); + return obi_get_char_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx); +} + + +int obi_set_char_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, obichar_t value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_char_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name, value); +} + + +int obi_set_char_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, obichar_t value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_char_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx, value); +} + + +obichar_t obi_get_char_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIChar_NA; + return obi_get_char_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx); +} + + +obichar_t obi_get_char_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIChar_NA; + return obi_get_char_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name); } /****************************************/ @@ -1246,7 +1947,7 @@ obichar_t obi_column_get_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_co /*********** FOR FLOAT COLUMNS ***********/ -int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value) +int obi_set_float_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value) { if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) return -1; @@ -1254,7 +1955,7 @@ int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p } -obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +obifloat_t obi_get_float_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) { if (prepare_to_get_value_from_column(view, &line_nb) < 0) return OBIFloat_NA; @@ -1262,21 +1963,61 @@ obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_c } -int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value) +int obi_set_float_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; - return obi_column_set_obifloat_with_elt_idx_in_view(view, column, line_nb, element_idx, value); + return obi_set_float_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx, value); } -obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +obifloat_t obi_get_float_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIFloat_NA; - return obi_column_get_obifloat_with_elt_idx_in_view(view, column, line_nb, element_idx); + return obi_get_float_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx); +} + + +int obi_set_float_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, obifloat_t value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_float_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name, value); +} + + +int obi_set_float_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, obifloat_t value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_float_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx, value); +} + + +obifloat_t obi_get_float_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIFloat_NA; + return obi_get_float_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx); +} + + +obifloat_t obi_get_float_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIFloat_NA; + return obi_get_float_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name); } /****************************************/ @@ -1284,7 +2025,7 @@ obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_ /*********** FOR INT COLUMNS ***********/ -int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obiint_t value) +int obi_set_int_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obiint_t value) { if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) return -1; @@ -1292,7 +2033,7 @@ int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p c } -obiint_t obi_column_get_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +obiint_t obi_get_int_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) { if (prepare_to_get_value_from_column(view, &line_nb) < 0) return OBIInt_NA; @@ -1300,21 +2041,61 @@ obiint_t obi_column_get_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_colum } -int obi_column_set_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value) +int obi_set_int_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; - return obi_column_set_obiint_with_elt_idx_in_view(view, column, line_nb, element_idx, value); + return obi_set_int_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx, value); } -obiint_t obi_column_get_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +obiint_t obi_get_int_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIInt_NA; - return obi_column_get_obiint_with_elt_idx_in_view(view, column, line_nb, element_idx); + return obi_get_int_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx); +} + + +int obi_set_int_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, obiint_t value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_int_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name, value); +} + + +int obi_set_int_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, obiint_t value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_int_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx, value); +} + + +obiint_t obi_get_int_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIInt_NA; + return obi_get_int_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx); +} + + +obiint_t obi_get_int_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIInt_NA; + return obi_get_int_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name); } /****************************************/ @@ -1322,7 +2103,7 @@ obiint_t obi_column_get_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_colu /*********** FOR QUAL COLUMNS ***********/ -int obi_column_set_obiqual_char_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value) +int obi_set_qual_char_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value) { if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) return -1; @@ -1330,7 +2111,7 @@ int obi_column_set_obiqual_char_with_elt_idx_in_view(Obiview_p view, OBIDMS_colu } -int obi_column_set_obiqual_int_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const uint8_t* value, int value_length) +int obi_set_qual_int_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const uint8_t* value, int value_length) { if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) return -1; @@ -1338,7 +2119,7 @@ int obi_column_set_obiqual_int_with_elt_idx_in_view(Obiview_p view, OBIDMS_colum } -char* obi_column_get_obiqual_char_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +char* obi_get_qual_char_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) { if (prepare_to_get_value_from_column(view, &line_nb) < 0) return OBIQual_char_NA; @@ -1346,7 +2127,7 @@ char* obi_column_get_obiqual_char_with_elt_idx_in_view(Obiview_p view, OBIDMS_co } -const uint8_t* obi_column_get_obiqual_int_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, int* value_length) +const uint8_t* obi_get_qual_int_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, int* value_length) { if (prepare_to_get_value_from_column(view, &line_nb) < 0) return OBIQual_int_NA; @@ -1354,39 +2135,119 @@ const uint8_t* obi_column_get_obiqual_int_with_elt_idx_in_view(Obiview_p view, O } -int obi_column_set_obiqual_char_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value) +int obi_set_qual_char_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; - return obi_column_set_obiqual_char_with_elt_idx_in_view(view, column, line_nb, element_idx, value); + return obi_set_qual_char_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx, value); } -int obi_column_set_obiqual_int_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const uint8_t* value, int value_length) +int obi_set_qual_int_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const uint8_t* value, int value_length) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; - return obi_column_set_obiqual_int_with_elt_idx_in_view(view, column, line_nb, element_idx, value, value_length); + return obi_set_qual_int_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx, value, value_length); } -char* obi_column_get_obiqual_char_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +char* obi_get_qual_char_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIQual_char_NA; - return obi_column_get_obiqual_char_with_elt_idx_in_view(view, column, line_nb, element_idx); + return obi_get_qual_char_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx); } -const uint8_t* obi_column_get_obiqual_int_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, int* value_length) +const uint8_t* obi_get_qual_int_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, int* value_length) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIQual_int_NA; - return obi_column_get_obiqual_int_with_elt_idx_in_view(view, column, line_nb, element_idx, value_length); + return obi_get_qual_int_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx, value_length); +} + + +int obi_set_qual_char_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, const char* value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_qual_char_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name, value); +} + + +int obi_set_qual_char_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, const char* value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_qual_char_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx, value); +} + + +char* obi_get_qual_char_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIQual_char_NA; + return obi_get_qual_char_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx); +} + + +char* obi_get_qual_char_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIQual_char_NA; + return obi_get_qual_char_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name); +} + + +int obi_set_qual_int_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, const uint8_t* value, int value_length) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_qual_int_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name, value, value_length); +} + + +int obi_set_qual_int_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, const uint8_t* value, int value_length) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_qual_int_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx, value, value_length); +} + + +const uint8_t* obi_get_qual_int_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, int* value_length) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIQual_int_NA; + return obi_get_qual_int_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx, value_length); +} + + +const uint8_t* obi_get_qual_int_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, int* value_length) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIQual_int_NA; + return obi_get_qual_int_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name, value_length); } /****************************************/ @@ -1394,7 +2255,7 @@ const uint8_t* obi_column_get_obiqual_int_with_elt_name_in_view(Obiview_p view, /*********** FOR SEQ COLUMNS ***********/ -int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value) +int obi_set_seq_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value) { if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) return -1; @@ -1402,7 +2263,7 @@ int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p c } -char* obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +char* obi_get_seq_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) { if (prepare_to_get_value_from_column(view, &line_nb) < 0) return OBISeq_NA; @@ -1410,21 +2271,61 @@ char* obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p } -int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value) +int obi_set_seq_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; - return obi_column_set_obiseq_with_elt_idx_in_view(view, column, line_nb, element_idx, value); + return obi_set_seq_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx, value); } -char* obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +char* obi_get_seq_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBISeq_NA; - return obi_column_get_obiseq_with_elt_idx_in_view(view, column, line_nb, element_idx); + return obi_get_seq_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx); +} + + +int obi_set_seq_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, const char* value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_seq_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name, value); +} + + +int obi_set_seq_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, const char* value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_seq_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx, value); +} + + +char* obi_get_seq_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBISeq_NA; + return obi_get_seq_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx); +} + + +char* obi_get_seq_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBISeq_NA; + return obi_get_seq_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name); } /****************************************/ @@ -1432,7 +2333,7 @@ char* obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_ /*********** FOR STR COLUMNS ***********/ -int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value) +int obi_set_str_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value) { if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0) return -1; @@ -1440,7 +2341,7 @@ int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p c } -const char* obi_column_get_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) +const char* obi_get_str_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx) { if (prepare_to_get_value_from_column(view, &line_nb) < 0) return OBIStr_NA; @@ -1448,21 +2349,61 @@ const char* obi_column_get_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_co } -int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value) +int obi_set_str_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return -1; - return obi_column_set_obistr_with_elt_idx_in_view(view, column, line_nb, element_idx, value); + return obi_set_str_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx, value); } -const char* obi_column_get_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) +const char* obi_get_str_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name) { index_t element_idx = obi_column_get_element_index_from_name(column, element_name); if (element_idx == OBIIdx_NA) return OBIStr_NA; - return obi_column_get_obistr_with_elt_idx_in_view(view, column, line_nb, element_idx); + return obi_get_str_with_elt_idx_and_col_p_in_view(view, column, line_nb, element_idx); +} + + +int obi_set_str_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, const char* value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_str_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name, value); +} + + +int obi_set_str_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, const char* value) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return -1; + return obi_set_str_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx, value); +} + + +const char* obi_get_str_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIStr_NA; + return obi_get_str_with_elt_idx_and_col_p_in_view(view, column_p, line_nb, element_idx); +} + + +const char* obi_get_str_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name) +{ + OBIDMS_column_p column_p; + column_p = obi_view_get_column(view, column_name); + if (column_p == NULL) + return OBIStr_NA; + return obi_get_str_with_elt_name_and_col_p_in_view(view, column_p, line_nb, element_name); } /****************************************/ diff --git a/src/obiview.h b/src/obiview.h index 1f018e3..eefd4ef 100644 --- a/src/obiview.h +++ b/src/obiview.h @@ -25,6 +25,7 @@ #include "obidms.h" #include "obidmscolumn.h" #include "obierrno.h" +#include "hashtable.h" #define OBIVIEW_NAME_MAX_LENGTH (1000) /**< The maximum length of an OBIDMS view name. @@ -55,14 +56,15 @@ /** - * @brief Structure referencing a column by its name and its version. + * @brief Structure for column aliases. + * Column aliases are alternative names used to identify a column in the context of a view. */ -typedef struct Column_reference { - char column_name[OBIDMS_COLUMN_MAX_NAME+1]; /**< Name of the column. - */ - obiversion_t version; /**< Version of the column. - */ -} Column_reference_t, *Column_reference_p; +typedef struct Alias_column_pair { + Column_reference_t column_refs; /**< References (name and version) of the column. + */ + char alias[OBIDMS_COLUMN_MAX_NAME+1]; /**< Alias of the column in the context of a view. + */ +} Alias_column_pair_t, *Alias_column_pair_p; /** @@ -82,14 +84,14 @@ typedef struct Obiview_infos { */ bool all_lines; /**< Whether there is a line selection associated with the view. */ - Column_reference_t line_selection; /**< Whether there is a line selection associated with the view. + Column_reference_t line_selection; /**< The references of the line selection associated with the view if there is one. */ index_t line_count; /**< The number of lines in the view. */ int column_count; /**< The number of columns in the view. */ - Column_reference_t column_references[MAX_NB_OPENED_COLUMNS]; /**< References (name and version) for all the columns in the view. - */ + Alias_column_pair_t column_references[MAX_NB_OPENED_COLUMNS]; /**< References (name, version and alias) for all the columns in the view. + */ char comments[OBIVIEW_COMMENTS_MAX_LENGTH+1]; /**< Comments, additional informations on the view. */ } Obiview_infos_t, *Obiview_infos_p; @@ -99,51 +101,34 @@ typedef struct Obiview_infos { * @brief Structure for an opened view. */ typedef struct Obiview { - Obiview_infos_p infos; /**< A pointer on the mapped view informations. - */ - OBIDMS_p dms; /**< A pointer on the DMS to which the view belongs. - */ - bool read_only; /**< Whether the view is read-only or can be modified. - */ - OBIDMS_column_p line_selection; /**< A pointer on the column containing the line selection - * associated with the view if there is one. - * This line selection is read-only, and when a line from the view is read, - * it is this line selection that is used. - */ - OBIDMS_column_p new_line_selection; /**< A pointer on the column containing the new line selection being built - * to associate with the view, if there is one. - * When a line is selected with obi_select_line() or obi_select_lines(), - * it is recorded in this line selection. - */ - OBIDMS_column_p columns[MAX_NB_OPENED_COLUMNS]; /**< Array of pointers on all the columns of the view. - */ + Obiview_infos_p infos; /**< A pointer on the mapped view informations. + */ + OBIDMS_p dms; /**< A pointer on the DMS to which the view belongs. + */ + bool read_only; /**< Whether the view is read-only or can be modified. + */ + OBIDMS_column_p line_selection; /**< A pointer on the column containing the line selection + * associated with the view if there is one. + * This line selection is read-only, and when a line from the view is read, + * it is this line selection that is used. + */ + OBIDMS_column_p new_line_selection; /**< A pointer on the column containing the new line selection being built + * to associate with the view, if there is one. + * When a line is selected with obi_select_line() or obi_select_lines(), + * it is recorded in this line selection. + */ + OBIDMS_column_p columns[MAX_NB_OPENED_COLUMNS]; /**< Array of pointers on all the columns of the view. + */ + hashtable_p column_dict; /**< Hash table storing the pairs of column names or aliases with the associated + * column pointers. + */ + int nb_predicates; /**< Number of predicates to test when closing the view. + */ + char* (**predicate_functions)(struct Obiview* view); /**< Array of pointers on all predicate functions to test when closing the view. + */ } Obiview_t, *Obiview_p; -/** - * @brief Structure for the header of view files. - */ -typedef struct Obiviews_header { - size_t header_size; /**< Size of the header in bytes. - */ - size_t views_size; /**< Size of the views in bytes. - */ - int view_count; /**< Number of views saved. - */ -} Obiviews_header_t, *Obiviews_header_p; - - -/** - * @brief Structure for the information stored in view files. - */ -typedef struct Obiviews_infos_all { - Obiviews_header_p header; /**< Pointer on the header of the view file. - */ - Obiview_infos_p view_infos; /**< Pointer on the beginning (first view) of the informations on views. - */ -} Obiviews_infos_all_t, *Obiviews_infos_all_p; - - /** * @brief Creates a new view. * @@ -306,6 +291,7 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name); * @param view A pointer on the view. * @param column_name The name of the column. * @param version_number The version of the column if it should be opened and not created (if -1, the latest version is retrieved). + * @param alias The unique name used to identify the column in the context of this view. * @param data_type The OBIType code of the data. * @param nb_lines The number of lines to be stored. * @param nb_elements_per_line The number of elements per line. @@ -324,11 +310,14 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name); int obi_view_add_column(Obiview_p view, const char* column_name, obiversion_t version_number, + const char* alias, OBIType_t data_type, index_t nb_lines, index_t nb_elements_per_line, const char* elements_names, const char* indexer_name, + const char* associated_column_name, + obiversion_t associated_column_version, const char* comments, bool create); @@ -383,6 +372,27 @@ OBIDMS_column_p obi_view_get_column(Obiview_p view, const char* column_name); OBIDMS_column_p* obi_view_get_pointer_on_column_in_view(Obiview_p view, const char* column_name); +/** + * @brief Changes the name that identifies a column in the context of a view. + * + * In the context of a view, each column is identified by a name that is unique in this view. + * + * @warning The view must be writable. + * + * @param view A pointer on the view. + * @param current_name The current name that identifies the column in this view. + * @param alias The new name that should be used to identify the column in this view. + * + * @returns A value indicating the success of the operation. + * @retval 0 if the operation was successfully completed. + * @retval -1 if an error occurred. + * + * @since July 2016 + * @author Celine Mercier (celine.mercier@metabarcoding.org) + */ +int obi_view_create_column_alias(Obiview_p view, const char* current_name, const char* alias); + + /** * @brief Selects a line in the context of a view. * @@ -479,38 +489,6 @@ int obi_close_view(Obiview_p view); int obi_save_and_close_view(Obiview_p view); -/** - * @brief Opens the structure containing all the informations written in the view file. - * - * @param dms A pointer on the OBIDMS to which the view file belongs. - * - * @returns A pointer on the view informations structure. - * @retval NULL if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -Obiviews_infos_all_p obi_read_view_infos(OBIDMS_p dms); - - -/** - * @brief Closes the structure containing all the informations written in the view file. - * - * @param views A pointer on the view informations structure. - * - * @returns A value indicating the success of the operation. - * @retval 0 if the operation was successfully completed. - * @retval -1 if an error occurred. - * - * @since February 2016 - * @author Celine Mercier (celine.mercier@metabarcoding.org) - */ -int obi_close_view_infos(Obiviews_infos_all_p views); - - -// TODO in following functions would it be better to use column names instead of column pointers? -// check if it would be a gain or loss of time - /** * @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL, using the index of the element in the line, * in the context of a view. @@ -518,7 +496,7 @@ int obi_close_view_infos(Obiviews_infos_all_p views); * Note: If the column is read-only or if there is a line selection associated with the view (making columns non-writable), it is cloned. * * @param view A pointer on the opened writable view. - * @param column A pointer on the column. + * @param column_p A pointer on the column. * @param line_nb The number of the line where the value should be set. * @param element_idx The index of the element that should be set in the line. * @param value The value that should be set. @@ -530,14 +508,17 @@ int obi_close_view_infos(Obiviews_infos_all_p views); * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obibool_t value); +int obi_set_bool_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, obibool_t value); + +// TODO +int obi_set_bool_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, obibool_t value); /** * @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL, in the context of a view. * * @param view A pointer on the opened view. - * @param column A pointer on the column. + * @param column_p A pointer on the column. * @param line_nb The number of the line where the value should be recovered. * @param element_idx The index of the element that should be recovered in the line. * @@ -547,7 +528,10 @@ int obi_column_set_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obibool_t obi_column_get_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx); +obibool_t obi_get_bool_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx); + +// TODO +obibool_t obi_get_bool_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx); /** @@ -555,7 +539,7 @@ obibool_t obi_column_get_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_col * using the name of the element in the line, in the context of a view. * * @param view A pointer on the opened writable view. - * @param column A pointer on the column. + * @param column_p A pointer on the column. * @param line_nb The number of the line where the value should be set. * @param element_name The name of the element that should be set in the line. * @param value The value that should be set. @@ -567,7 +551,11 @@ obibool_t obi_column_get_obibool_with_elt_idx_in_view(Obiview_p view, OBIDMS_col * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value); +int obi_set_bool_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name, obibool_t value); + + +// TODO +int obi_set_bool_with_elt_name_and_column_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, obibool_t value); /** @@ -575,7 +563,7 @@ int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p * using the name of the element in the line, in the context of a view. * * @param view A pointer on the opened view. - * @param column A pointer on the column. + * @param column_p A pointer on the column. * @param line_nb The number of the line where the value should be recovered. * @param element_name The name of the element that should be recovered in the line. * @@ -585,7 +573,11 @@ int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obibool_t obi_column_get_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); +obibool_t obi_get_bool_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name); + + +// TODO +obibool_t obi_get_bool_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name); /** @@ -607,7 +599,11 @@ obibool_t obi_column_get_obibool_with_elt_name_in_view(Obiview_p view, OBIDMS_co * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obichar_t value); +int obi_set_char_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, obichar_t value); + + +// TODO +int obi_set_char_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, obichar_t value); /** @@ -624,7 +620,11 @@ int obi_column_set_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obichar_t obi_column_get_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx); +obichar_t obi_get_char_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx); + + +// TODO +obichar_t obi_get_char_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx); /** @@ -644,7 +644,11 @@ obichar_t obi_column_get_obichar_with_elt_idx_in_view(Obiview_p view, OBIDMS_col * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value); +int obi_set_char_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name, obichar_t value); + + +// TODO +int obi_set_char_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, obichar_t value); /** @@ -662,7 +666,11 @@ int obi_column_set_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obichar_t obi_column_get_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); +obichar_t obi_get_char_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name); + + +// TODO +obichar_t obi_get_char_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name); /** @@ -684,7 +692,11 @@ obichar_t obi_column_get_obichar_with_elt_name_in_view(Obiview_p view, OBIDMS_co * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value); +int obi_set_float_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, obifloat_t value); + + +// TODO +int obi_set_float_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, obifloat_t value); /** @@ -701,7 +713,11 @@ int obi_column_set_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx); +obifloat_t obi_get_float_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx); + + +// TODO +obifloat_t obi_get_float_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx); /** @@ -721,7 +737,11 @@ obifloat_t obi_column_get_obifloat_with_elt_idx_in_view(Obiview_p view, OBIDMS_c * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value); +int obi_set_float_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name, obifloat_t value); + + +// TODO +int obi_set_float_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, obifloat_t value); /** @@ -739,7 +759,11 @@ int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_ * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); +obifloat_t obi_get_float_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name); + + +// TODO +obifloat_t obi_get_float_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name); /** @@ -761,7 +785,11 @@ obifloat_t obi_column_get_obifloat_with_elt_name_in_view(Obiview_p view, OBIDMS_ * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, obiint_t value); +int obi_set_int_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, obiint_t value); + + +// TODO +int obi_set_int_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, obiint_t value); /** @@ -778,7 +806,11 @@ int obi_column_set_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p c * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obiint_t obi_column_get_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx); +obiint_t obi_get_int_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx); + + +// TODO +obiint_t obi_get_int_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx); /** @@ -798,7 +830,11 @@ obiint_t obi_column_get_obiint_with_elt_idx_in_view(Obiview_p view, OBIDMS_colum * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value); +int obi_set_int_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name, obiint_t value); + + +// TODO +int obi_set_int_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, obiint_t value); /** @@ -816,7 +852,11 @@ int obi_column_set_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -obiint_t obi_column_get_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); +obiint_t obi_get_int_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name); + + +// TODO +obiint_t obi_get_int_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name); /** @@ -841,7 +881,11 @@ obiint_t obi_column_get_obiint_with_elt_name_in_view(Obiview_p view, OBIDMS_colu * @since May 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obiqual_char_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value); +int obi_set_qual_char_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, const char* value); + + +// TODO +int obi_set_qual_char_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, const char* value); /** @@ -867,7 +911,11 @@ int obi_column_set_obiqual_char_with_elt_idx_in_view(Obiview_p view, OBIDMS_colu * @since May 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obiqual_int_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const uint8_t* value, int value_length); +int obi_set_qual_int_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, const uint8_t* value, int value_length); + + +// TODO +int obi_set_qual_int_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, const uint8_t* value, int value_length); /** @@ -888,7 +936,11 @@ int obi_column_set_obiqual_int_with_elt_idx_in_view(Obiview_p view, OBIDMS_colum * @since May 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -char* obi_column_get_obiqual_char_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx); +char* obi_get_qual_char_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx); + + +// TODO +char* obi_get_qual_char_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx); /** @@ -910,7 +962,11 @@ char* obi_column_get_obiqual_char_with_elt_idx_in_view(Obiview_p view, OBIDMS_co * @since May 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -const uint8_t* obi_column_get_obiqual_int_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, int* value_length); +const uint8_t* obi_get_qual_int_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, int* value_length); + + +// TODO +const uint8_t* obi_get_qual_int_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, int* value_length); /** @@ -935,7 +991,11 @@ const uint8_t* obi_column_get_obiqual_int_with_elt_idx_in_view(Obiview_p view, O * @since May 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obiqual_char_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value); +int obi_set_qual_char_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name, const char* value); + + +// TODO +int obi_set_qual_char_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, const char* value); /** @@ -961,7 +1021,11 @@ int obi_column_set_obiqual_char_with_elt_name_in_view(Obiview_p view, OBIDMS_col * @since May 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obiqual_int_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const uint8_t* value, int value_length); +int obi_set_qual_int_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name, const uint8_t* value, int value_length); + + +// TODO +int obi_set_qual_int_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, const uint8_t* value, int value_length); /** @@ -982,7 +1046,11 @@ int obi_column_set_obiqual_int_with_elt_name_in_view(Obiview_p view, OBIDMS_colu * @since May 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -char* obi_column_get_obiqual_char_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); +char* obi_get_qual_char_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name); + + +// TODO +char* obi_get_qual_char_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name); /** @@ -1004,7 +1072,11 @@ char* obi_column_get_obiqual_char_with_elt_name_in_view(Obiview_p view, OBIDMS_c * @since May 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -const uint8_t* obi_column_get_obiqual_int_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, int* value_length); +const uint8_t* obi_get_qual_int_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name, int* value_length); + + +// TODO +const uint8_t* obi_get_qual_int_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, int* value_length); /** @@ -1026,7 +1098,11 @@ const uint8_t* obi_column_get_obiqual_int_with_elt_name_in_view(Obiview_p view, * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value); +int obi_set_seq_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, const char* value); + + +// TODO +int obi_set_seq_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, const char* value); /** @@ -1043,7 +1119,11 @@ int obi_column_set_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p c * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -char* obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx); +char* obi_get_seq_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx); + + +// TODO +char* obi_get_seq_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx); /** @@ -1063,7 +1143,11 @@ char* obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value); +int obi_set_seq_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name, const char* value); + + +// TODO +int obi_set_seq_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, const char* value); /** @@ -1081,7 +1165,11 @@ int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -char* obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); +char* obi_get_seq_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name); + + +// TODO +char* obi_get_seq_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name); /** @@ -1103,7 +1191,11 @@ char* obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view, OBIDMS_column_ * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value); +int obi_set_str_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx, const char* value); + + +// TODO +int obi_set_str_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx, const char* value); /** @@ -1120,7 +1212,11 @@ int obi_column_set_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p c * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -const char* obi_column_get_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, index_t element_idx); +const char* obi_get_str_with_elt_idx_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, index_t element_idx); + + +// TODO +const char* obi_get_str_with_elt_idx_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, index_t element_idx); /** @@ -1140,7 +1236,11 @@ const char* obi_column_get_obistr_with_elt_idx_in_view(Obiview_p view, OBIDMS_co * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value); +int obi_set_str_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name, const char* value); + + +// TODO +int obi_set_str_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name, const char* value); /** @@ -1158,7 +1258,11 @@ int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p * @since February 2016 * @author Celine Mercier (celine.mercier@metabarcoding.org) */ -const char* obi_column_get_obistr_with_elt_name_in_view(Obiview_p view, OBIDMS_column_p column, index_t line_nb, const char* element_name); +const char* obi_get_str_with_elt_name_and_col_p_in_view(Obiview_p view, OBIDMS_column_p column_p, index_t line_nb, const char* element_name); + + +// TODO +const char* obi_get_str_with_elt_name_and_col_name_in_view(Obiview_p view, const char* column_name, index_t line_nb, const char* element_name); #endif /* OBIVIEW_H_ */