Compare commits
18 Commits
check_avl_
...
refactorin
Author | SHA1 | Date | |
---|---|---|---|
02d67c257f | |||
e04ea85d1e | |||
527d3555f0 | |||
71492ad229 | |||
73d64e5aff | |||
4cb52e1632 | |||
9d042f7bd0 | |||
5ec2d8842e | |||
04c9470f7d | |||
be05c889e2 | |||
04e3a7b5a9 | |||
d8107533d8 | |||
cd4e65e190 | |||
375bfcce8a | |||
c225cfd8b6 | |||
966b1325ed | |||
019dfc01b4 | |||
edc4fd7b3e |
@ -1,7 +1,28 @@
|
||||
../../../src/bloom.h
|
||||
../../../src/bloom.c
|
||||
../../../src/char_str_indexer.h
|
||||
../../../src/char_str_indexer.c
|
||||
../../../src/crc64.h
|
||||
../../../src/crc64.c
|
||||
../../../src/dna_seq_indexer.h
|
||||
../../../src/dna_seq_indexer.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/MurmurHash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiblob_indexer.h
|
||||
../../../src/obiblob_indexer.c
|
||||
../../../src/obiblob.h
|
||||
../../../src/obiblob.c
|
||||
../../../src/obidebug.h
|
||||
../../../src/obidms_taxonomy.h
|
||||
../../../src/obidms_taxonomy.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
@ -12,19 +33,19 @@
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidms_taxonomy.c
|
||||
../../../src/obidms_taxonomy.h
|
||||
../../../src/bloom.c
|
||||
../../../src/bloom.h
|
||||
../../../src/MurmurHash2.c
|
||||
../../../src/murmurhash2.h
|
||||
../../../src/crc64.c
|
||||
../../../src/crc64.h
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
||||
../../../src/obidmscolumn_bool.c
|
||||
../../../src/obidmscolumn_bool.h
|
||||
../../../src/obidmscolumn_char.c
|
||||
../../../src/obidmscolumn_char.h
|
||||
../../../src/obidmscolumn_float.c
|
||||
../../../src/obidmscolumn_float.h
|
||||
../../../src/obidmscolumn_int.c
|
||||
../../../src/obidmscolumn_int.h
|
||||
../../../src/obidmscolumn_seq.c
|
||||
../../../src/obidmscolumn_seq.h
|
||||
../../../src/obidmscolumn_str.c
|
||||
../../../src/obidmscolumn_str.h
|
||||
|
@ -56,7 +56,7 @@ cdef class OBIView:
|
||||
index_t nb_lines=*,
|
||||
index_t nb_elements_per_line=*,
|
||||
list elements_names=*,
|
||||
str avl_name=*,
|
||||
str indexer_name=*,
|
||||
str comments=*,
|
||||
bint create=*
|
||||
)
|
||||
|
@ -5,7 +5,7 @@ from obitools3.utils cimport bytes2str, str2bytes
|
||||
from .capi.obidms cimport obi_dms, \
|
||||
obi_close_dms
|
||||
|
||||
from .capi.obidmscolumn cimport obi_truncate_and_close_column, \
|
||||
from .capi.obidmscolumn cimport obi_close_column, \
|
||||
obi_column_format_date, \
|
||||
OBIDMS_column_p, \
|
||||
OBIDMS_column_header_p
|
||||
@ -144,7 +144,7 @@ cdef class OBIDMS_column :
|
||||
return to_print
|
||||
|
||||
cpdef close(self):
|
||||
if obi_truncate_and_close_column((self.pointer)[0]) < 0 :
|
||||
if obi_close_column((self.pointer)[0]) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
|
||||
@ -352,7 +352,7 @@ cdef class OBIView :
|
||||
index_t nb_lines=0,
|
||||
index_t nb_elements_per_line=1, # TODO 1?
|
||||
list elements_names=None,
|
||||
str avl_name="default_AVL_tree",
|
||||
str indexer_name="",
|
||||
str comments="",
|
||||
bint create=True # TODO
|
||||
) :
|
||||
@ -388,7 +388,7 @@ cdef class OBIView :
|
||||
|
||||
if (obi_view_add_column(self.pointer, column_name_b, version_number, # should return pointer on column?
|
||||
data_type, nb_lines, nb_elements_per_line,
|
||||
elements_names_b, str2bytes(avl_name),
|
||||
elements_names_b, str2bytes(indexer_name),
|
||||
str2bytes(comments), create) < 0) :
|
||||
raise Exception("Problem adding a column in a view")
|
||||
|
||||
|
@ -1,20 +1,41 @@
|
||||
../../../src/obidmscolumn_bool.c
|
||||
../../../src/obidmscolumn_bool.h
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/bloom.h
|
||||
../../../src/bloom.c
|
||||
../../../src/char_str_indexer.h
|
||||
../../../src/char_str_indexer.c
|
||||
../../../src/crc64.h
|
||||
../../../src/crc64.c
|
||||
../../../src/dna_seq_indexer.h
|
||||
../../../src/dna_seq_indexer.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/MurmurHash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiblob_indexer.h
|
||||
../../../src/obiblob_indexer.c
|
||||
../../../src/obiblob.h
|
||||
../../../src/obiblob.c
|
||||
../../../src/obidebug.h
|
||||
../../../src/obidms_taxonomy.h
|
||||
../../../src/obidms_taxonomy.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
||||
|
@ -1,7 +1,6 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport obi_truncate_and_close_column, \
|
||||
obi_column_get_obibool_with_elt_name_in_view, \
|
||||
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
|
||||
|
@ -1,20 +1,41 @@
|
||||
../../../src/obidmscolumn_char.c
|
||||
../../../src/obidmscolumn_char.h
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/bloom.h
|
||||
../../../src/bloom.c
|
||||
../../../src/char_str_indexer.h
|
||||
../../../src/char_str_indexer.c
|
||||
../../../src/crc64.h
|
||||
../../../src/crc64.c
|
||||
../../../src/dna_seq_indexer.h
|
||||
../../../src/dna_seq_indexer.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/MurmurHash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiblob_indexer.h
|
||||
../../../src/obiblob_indexer.c
|
||||
../../../src/obiblob.h
|
||||
../../../src/obiblob.c
|
||||
../../../src/obidebug.h
|
||||
../../../src/obidms_taxonomy.h
|
||||
../../../src/obidms_taxonomy.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
||||
|
@ -1,7 +1,6 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport obi_truncate_and_close_column, \
|
||||
obi_column_get_obichar_with_elt_name_in_view, \
|
||||
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
|
||||
|
@ -1,20 +1,41 @@
|
||||
../../../src/obidmscolumn_float.c
|
||||
../../../src/obidmscolumn_float.h
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/char_str_indexer.h
|
||||
../../../src/char_str_indexer.c
|
||||
../../../src/bloom.h
|
||||
../../../src/bloom.c
|
||||
../../../src/crc64.h
|
||||
../../../src/crc64.c
|
||||
../../../src/dna_seq_indexer.h
|
||||
../../../src/dna_seq_indexer.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/MurmurHash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiblob_indexer.h
|
||||
../../../src/obiblob_indexer.c
|
||||
../../../src/obiblob.h
|
||||
../../../src/obiblob.c
|
||||
../../../src/obidebug.h
|
||||
../../../src/obidms_taxonomy.h
|
||||
../../../src/obidms_taxonomy.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
||||
|
@ -1,7 +1,6 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport obi_truncate_and_close_column,\
|
||||
obi_column_get_obifloat_with_elt_name_in_view, \
|
||||
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
|
||||
|
@ -1,20 +1,41 @@
|
||||
../../../src/obidmscolumn_int.c
|
||||
../../../src/obidmscolumn_int.h
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/char_str_indexer.h
|
||||
../../../src/char_str_indexer.c
|
||||
../../../src/bloom.h
|
||||
../../../src/bloom.c
|
||||
../../../src/crc64.h
|
||||
../../../src/crc64.c
|
||||
../../../src/dna_seq_indexer.h
|
||||
../../../src/dna_seq_indexer.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/MurmurHash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiblob_indexer.h
|
||||
../../../src/obiblob_indexer.c
|
||||
../../../src/obiblob.h
|
||||
../../../src/obiblob.c
|
||||
../../../src/obidebug.h
|
||||
../../../src/obidms_taxonomy.h
|
||||
../../../src/obidms_taxonomy.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
||||
|
@ -1,7 +1,6 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport obi_truncate_and_close_column, \
|
||||
obi_column_get_obiint_with_elt_name_in_view, \
|
||||
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
|
||||
|
@ -1,20 +1,41 @@
|
||||
../../../src/obidmscolumn_seq.c
|
||||
../../../src/obidmscolumn_seq.h
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/bloom.h
|
||||
../../../src/bloom.c
|
||||
../../../src/char_str_indexer.h
|
||||
../../../src/char_str_indexer.c
|
||||
../../../src/crc64.h
|
||||
../../../src/crc64.c
|
||||
../../../src/dna_seq_indexer.h
|
||||
../../../src/dna_seq_indexer.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/MurmurHash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiblob_indexer.h
|
||||
../../../src/obiblob_indexer.c
|
||||
../../../src/obiblob.h
|
||||
../../../src/obiblob.c
|
||||
../../../src/obidebug.h
|
||||
../../../src/obidms_taxonomy.h
|
||||
../../../src/obidms_taxonomy.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
||||
|
@ -1,7 +1,6 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport obi_truncate_and_close_column, \
|
||||
obi_column_get_obiseq_with_elt_name_in_view, \
|
||||
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
|
||||
@ -10,19 +9,23 @@ from .capi.obitypes cimport OBISeq_NA, const_char_p
|
||||
|
||||
from obitools3.utils cimport str2bytes, bytes2str
|
||||
|
||||
from libc.stdlib cimport free
|
||||
from libc.string cimport strcmp
|
||||
|
||||
|
||||
cdef class OBIDMS_column_seq(OBIDMS_column):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef bytes value
|
||||
cdef char* value
|
||||
cdef object result
|
||||
value = <bytes> obi_column_get_obiseq_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, 0)
|
||||
value = obi_column_get_obiseq_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBISeq_NA : # TODO
|
||||
if strcmp(value, OBISeq_NA) == 0 :
|
||||
result = None
|
||||
else :
|
||||
result = bytes2str(value)
|
||||
free(value)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
@ -38,33 +41,35 @@ cdef class OBIDMS_column_seq(OBIDMS_column):
|
||||
cdef class OBIDMS_column_multi_elts_seq(OBIDMS_column_multi_elts):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef bytes value
|
||||
cdef char* value
|
||||
cdef object result
|
||||
value = <bytes> obi_column_get_obiseq_with_elt_name_in_view(self.view, (self.pointer)[0], line_nb, str2bytes(element_name))
|
||||
value = obi_column_get_obiseq_with_elt_name_in_view(self.view, (self.pointer)[0], line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBISeq_NA :
|
||||
if strcmp(value, OBISeq_NA) == 0 :
|
||||
result = None
|
||||
else :
|
||||
result = bytes2str(value)
|
||||
free(value)
|
||||
return result
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef bytes value
|
||||
cdef object value_in_result
|
||||
cdef dict result
|
||||
cdef char* value
|
||||
cdef object value_in_result
|
||||
cdef dict result
|
||||
cdef index_t i
|
||||
cdef bint all_NA
|
||||
cdef bint all_NA
|
||||
result = {}
|
||||
all_NA = True
|
||||
for i in range(self.nb_elements_per_line) :
|
||||
value = <bytes> obi_column_get_obiseq_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, i)
|
||||
value = obi_column_get_obiseq_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBISeq_NA :
|
||||
if strcmp(value, OBISeq_NA) == 0 :
|
||||
value_in_result = None
|
||||
else :
|
||||
value_in_result = bytes2str(value)
|
||||
value_in_result = bytes2str(value)
|
||||
free(value)
|
||||
result[self.elements_names[i]] = value_in_result
|
||||
if all_NA and (value_in_result is not None) :
|
||||
all_NA = False
|
||||
|
@ -1,20 +1,41 @@
|
||||
../../../src/obidmscolumn_str.c
|
||||
../../../src/obidmscolumn_str.h
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/bloom.h
|
||||
../../../src/bloom.c
|
||||
../../../src/char_str_indexer.h
|
||||
../../../src/char_str_indexer.c
|
||||
../../../src/crc64.h
|
||||
../../../src/crc64.c
|
||||
../../../src/dna_seq_indexer.h
|
||||
../../../src/dna_seq_indexer.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/MurmurHash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiblob_indexer.h
|
||||
../../../src/obiblob_indexer.c
|
||||
../../../src/obiblob.h
|
||||
../../../src/obiblob.c
|
||||
../../../src/obidebug.h
|
||||
../../../src/obidms_taxonomy.h
|
||||
../../../src/obidms_taxonomy.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
||||
|
@ -1,7 +1,6 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport obi_truncate_and_close_column, \
|
||||
obi_column_get_obistr_with_elt_name_in_view, \
|
||||
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
|
||||
@ -10,19 +9,22 @@ from .capi.obitypes cimport OBIStr_NA, const_char_p
|
||||
|
||||
from obitools3.utils cimport str2bytes, bytes2str
|
||||
|
||||
from libc.string cimport strcmp
|
||||
|
||||
|
||||
cdef class OBIDMS_column_str(OBIDMS_column):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef bytes value
|
||||
cdef object result
|
||||
value = <bytes> obi_column_get_obistr_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, 0)
|
||||
cdef const_char_p value
|
||||
cdef object result
|
||||
value = obi_column_get_obistr_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIStr_NA : # TODO
|
||||
if strcmp(value, OBIStr_NA) == 0 :
|
||||
result = None
|
||||
else :
|
||||
result = bytes2str(value)
|
||||
# NOTE: value is not freed because the pointer points to a mmapped region in an AVL data file. (TODO discuss)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
@ -38,33 +40,35 @@ cdef class OBIDMS_column_str(OBIDMS_column):
|
||||
cdef class OBIDMS_column_multi_elts_str(OBIDMS_column_multi_elts):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef bytes value
|
||||
cdef object result
|
||||
value = <bytes> obi_column_get_obistr_with_elt_name_in_view(self.view, (self.pointer)[0], line_nb, str2bytes(element_name))
|
||||
cdef const_char_p value
|
||||
cdef object result
|
||||
value = obi_column_get_obistr_with_elt_name_in_view(self.view, (self.pointer)[0], line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIStr_NA :
|
||||
if strcmp(value, OBIStr_NA) == 0 :
|
||||
result = None
|
||||
else :
|
||||
result = bytes2str(value)
|
||||
# NOTE: value is not freed because the pointer points to a mmapped region in an AVL data file. (TODO discuss)
|
||||
return result
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef bytes value
|
||||
cdef object value_in_result
|
||||
cdef dict result
|
||||
cdef index_t i
|
||||
cdef bint all_NA
|
||||
cdef const_char_p value
|
||||
cdef object value_in_result
|
||||
cdef dict result
|
||||
cdef index_t i
|
||||
cdef bint all_NA
|
||||
result = {}
|
||||
all_NA = True
|
||||
for i in range(self.nb_elements_per_line) :
|
||||
value = <bytes> obi_column_get_obistr_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, i)
|
||||
value = obi_column_get_obistr_with_elt_idx_in_view(self.view, (self.pointer)[0], line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIStr_NA :
|
||||
if strcmp(value, OBIStr_NA) == 0 :
|
||||
value_in_result = None
|
||||
else :
|
||||
value_in_result = bytes2str(value)
|
||||
value_in_result = bytes2str(value)
|
||||
# NOTE: value is not freed because the pointer points to a mmapped region in an AVL data file. (TODO discuss)
|
||||
result[self.elements_names[i]] = value_in_result
|
||||
if all_NA and (value_in_result is not None) :
|
||||
all_NA = False
|
||||
|
@ -1,7 +1,28 @@
|
||||
../../../src/bloom.h
|
||||
../../../src/bloom.c
|
||||
../../../src/char_str_indexer.h
|
||||
../../../src/char_str_indexer.c
|
||||
../../../src/crc64.h
|
||||
../../../src/crc64.c
|
||||
../../../src/dna_seq_indexer.h
|
||||
../../../src/dna_seq_indexer.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/MurmurHash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiblob_indexer.h
|
||||
../../../src/obiblob_indexer.c
|
||||
../../../src/obiblob.h
|
||||
../../../src/obiblob.c
|
||||
../../../src/obidebug.h
|
||||
../../../src/obidms_taxonomy.h
|
||||
../../../src/obidms_taxonomy.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
@ -12,11 +33,7 @@
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
||||
|
@ -21,10 +21,6 @@ cdef class OBI_Nuc_Seq(OBI_Seq) :
|
||||
|
||||
|
||||
cdef class OBI_Nuc_Seq_Stored(OBIView_line) :
|
||||
cdef str id
|
||||
cdef str description
|
||||
cdef str sequence
|
||||
|
||||
cpdef set_id(self, str id)
|
||||
cpdef get_id(self)
|
||||
cpdef set_description(self, str description)
|
||||
|
@ -26,7 +26,7 @@ cdef class OBI_Seq(dict) :
|
||||
self[bytes2str(DESCRIPTION_COLUMN)] = description
|
||||
|
||||
cpdef get_description(self) :
|
||||
return self.description
|
||||
return self.description # TODO no
|
||||
|
||||
cpdef get_sequence(self) :
|
||||
return self.sequence
|
||||
@ -48,28 +48,25 @@ cdef class OBI_Nuc_Seq(OBI_Seq) :
|
||||
cdef class OBI_Nuc_Seq_Stored(OBIView_line) :
|
||||
|
||||
cpdef set_id(self, str id) :
|
||||
self.id = id
|
||||
self[bytes2str(ID_COLUMN)] = id
|
||||
|
||||
cpdef get_id(self) :
|
||||
return self.id
|
||||
return self[bytes2str(ID_COLUMN)]
|
||||
|
||||
cpdef set_description(self, str description) :
|
||||
self.description = description
|
||||
self[bytes2str(DESCRIPTION_COLUMN)] = description
|
||||
|
||||
cpdef get_description(self) :
|
||||
return self.description
|
||||
return self[bytes2str(DESCRIPTION_COLUMN)]
|
||||
|
||||
cpdef set_sequence(self, str sequence) :
|
||||
self.sequence = sequence
|
||||
self[bytes2str(NUC_SEQUENCE_COLUMN)] = sequence
|
||||
|
||||
cpdef get_sequence(self) :
|
||||
return self.sequence
|
||||
return self[bytes2str(NUC_SEQUENCE_COLUMN)]
|
||||
|
||||
def __str__(self) :
|
||||
return self.sequence # or not
|
||||
# def __str__(self) :
|
||||
# return self[bytes2str(NUC_SEQUENCE_COLUMN)] # or not
|
||||
|
||||
# cpdef str reverse_complement(self) : TODO in C ?
|
||||
# pass
|
||||
|
@ -1,7 +1,28 @@
|
||||
../../../src/bloom.h
|
||||
../../../src/bloom.c
|
||||
../../../src/char_str_indexer.h
|
||||
../../../src/char_str_indexer.c
|
||||
../../../src/crc64.h
|
||||
../../../src/crc64.c
|
||||
../../../src/dna_seq_indexer.h
|
||||
../../../src/dna_seq_indexer.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/MurmurHash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/obiblob_indexer.h
|
||||
../../../src/obiblob_indexer.c
|
||||
../../../src/obiblob.h
|
||||
../../../src/obiblob.c
|
||||
../../../src/obidebug.h
|
||||
../../../src/obidms_taxonomy.h
|
||||
../../../src/obidms_taxonomy.c
|
||||
../../../src/obidms.h
|
||||
../../../src/obidms.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
@ -12,13 +33,7 @@
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/private_at_functions.h
|
||||
../../../src/private_at_functions.c
|
||||
../../../src/obiavl.h
|
||||
../../../src/obiavl.c
|
||||
../../../src/encode.h
|
||||
../../../src/encode.c
|
||||
../../../src/obidmscolumn_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidms_taxonomy.c
|
||||
../../../src/obidms_taxonomy.h
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
||||
|
@ -27,7 +27,7 @@ cdef extern from "obidmscolumn.h" nogil:
|
||||
obiversion_t version
|
||||
obiversion_t cloned_from
|
||||
const_char_p name
|
||||
const_char_p avl_name
|
||||
const_char_p indexer_name
|
||||
const_char_p comments
|
||||
|
||||
ctypedef OBIDMS_column_header_t* OBIDMS_column_header_p
|
||||
@ -45,7 +45,7 @@ cdef extern from "obidmscolumn.h" nogil:
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
const_char_p elements_names,
|
||||
const_char_p avl_name,
|
||||
const_char_p indexer_name,
|
||||
const_char_p comments)
|
||||
|
||||
OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
@ -60,7 +60,7 @@ cdef extern from "obidmscolumn.h" nogil:
|
||||
obiversion_t version_number,
|
||||
bint clone_data)
|
||||
|
||||
int obi_truncate_and_close_column(OBIDMS_column_p column)
|
||||
int obi_close_column(OBIDMS_column_p column)
|
||||
|
||||
obiversion_t obi_column_get_latest_version_from_name(OBIDMS_p dms,
|
||||
const_char_p column_name)
|
||||
@ -69,37 +69,14 @@ cdef extern from "obidmscolumn.h" nogil:
|
||||
const_char_p column_name,
|
||||
obiversion_t version_number)
|
||||
|
||||
int obi_unmap_header(OBIDMS_column_header_p header)
|
||||
int obi_close_header(OBIDMS_column_header_p header)
|
||||
|
||||
char* obi_column_format_date(time_t date)
|
||||
|
||||
int obi_select(OBIDMS_column_p line_selection_column, index_t line_to_grep)
|
||||
|
||||
|
||||
from ..capi.obiview cimport Obiview_p # TODO
|
||||
|
||||
cdef extern from "obidmscolumn_int.h" nogil:
|
||||
int obi_column_set_obiint_with_elt_name_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
@ -121,28 +98,6 @@ cdef extern from "obidmscolumn_int.h" nogil:
|
||||
|
||||
cdef extern from "obidmscolumn_bool.h" nogil:
|
||||
|
||||
int obi_column_set_obibool_with_elt_name_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
@ -163,28 +118,6 @@ cdef extern from "obidmscolumn_bool.h" nogil:
|
||||
|
||||
cdef extern from "obidmscolumn_char.h" nogil:
|
||||
|
||||
int obi_column_set_obichar_with_elt_name_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
@ -205,83 +138,39 @@ cdef extern from "obidmscolumn_char.h" nogil:
|
||||
|
||||
cdef extern from "obidmscolumn_float.h" nogil:
|
||||
|
||||
int obi_column_set_obifloat_with_elt_name_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obifloat_t value)
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obifloat_t value)
|
||||
|
||||
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obifloat_t value)
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obifloat_t value)
|
||||
|
||||
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
cdef extern from "obidmscolumn_str.h" nogil:
|
||||
|
||||
int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
char* value)
|
||||
|
||||
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,
|
||||
char* value)
|
||||
|
||||
const_char_p obi_column_get_obistr_with_elt_name_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column,
|
||||
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,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
char* value)
|
||||
const_char_p value)
|
||||
|
||||
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
char* value)
|
||||
const_char_p value)
|
||||
|
||||
const_char_p obi_column_get_obistr_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
char* element_name)
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
const_char_p obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
@ -289,43 +178,21 @@ cdef extern from "obidmscolumn_str.h" nogil:
|
||||
|
||||
cdef extern from "obidmscolumn_seq.h" nogil:
|
||||
|
||||
int obi_column_set_obiseq_with_elt_name_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
char* value)
|
||||
|
||||
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,
|
||||
char* value)
|
||||
|
||||
const_char_p obi_column_get_obiseq_with_elt_name_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
const_char_p obi_column_get_obiseq_with_elt_idx_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
char* value)
|
||||
const_char_p value)
|
||||
|
||||
int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
char* value)
|
||||
const_char_p value)
|
||||
|
||||
const_char_p obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
char* element_name)
|
||||
char* obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
const_char_p obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
|
@ -3,6 +3,10 @@
|
||||
from .obitypes cimport const_char_p, \
|
||||
OBIType_t, \
|
||||
obiversion_t, \
|
||||
obiint_t, \
|
||||
obibool_t, \
|
||||
obichar_t, \
|
||||
obifloat_t, \
|
||||
index_t, \
|
||||
time_t
|
||||
from ..capi.obidms cimport OBIDMS_p
|
||||
@ -90,7 +94,7 @@ cdef extern from "obiview.h" nogil:
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
const_char_p elements_names,
|
||||
const_char_p avl_name,
|
||||
const_char_p indexer_name,
|
||||
const_char_p comments,
|
||||
bint create)
|
||||
|
||||
@ -111,4 +115,136 @@ cdef extern from "obiview.h" nogil:
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
int obi_column_set_obistr_with_elt_name_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
|
@ -5,7 +5,7 @@ import time
|
||||
from obitools3.obidms._obidms import OBIDMS
|
||||
|
||||
|
||||
def bufferedRead(fileobj,size=100000000):
|
||||
def bufferedRead(fileobj,size=209715200): ## 200 MB
|
||||
buffer = fileobj.readlines(size)
|
||||
while buffer:
|
||||
for l in buffer:
|
||||
@ -31,6 +31,8 @@ if __name__ == '__main__':
|
||||
# print(str(time.time())+'\t'+str(i))
|
||||
# id = "@HWI-D00405:142:C71BAANXX:4:1101:1234:2234_CONS_SUB_SUB_"+str(i)
|
||||
# view[i].set_id(id)
|
||||
# if id != view[i]["ID"] :
|
||||
# print("nope", id, view[i]["ID"])
|
||||
|
||||
input_file = open(args.input_file, 'r')
|
||||
input_file_buffered = bufferedRead(input_file)
|
||||
@ -120,11 +122,11 @@ if __name__ == '__main__':
|
||||
# break
|
||||
for line in input_file_buffered :
|
||||
#
|
||||
# #if i > 1E7 :
|
||||
#if i > 1E7 :
|
||||
# # print('hmm?')
|
||||
#
|
||||
# #if i == 10000000 :
|
||||
# # break
|
||||
# if i == 6000000 :
|
||||
# break
|
||||
#
|
||||
if l%4 == 0 :
|
||||
#
|
||||
@ -134,14 +136,14 @@ if __name__ == '__main__':
|
||||
# # #print("header", line)
|
||||
# #
|
||||
id = line.split(" ", 1)[0][1:]
|
||||
print(id)
|
||||
# print(id)
|
||||
# # #rest = (line[:-1].split(" ", 1)[1]).split(";")
|
||||
view[i].set_id(id)
|
||||
#print(view[i]["ID"])
|
||||
# print(view[i]["ID"])
|
||||
#
|
||||
i+=1
|
||||
# i+=1
|
||||
|
||||
l+=1
|
||||
# l+=1
|
||||
#
|
||||
# # description = ""
|
||||
# # for j in range(len(rest)) :
|
||||
@ -176,14 +178,14 @@ if __name__ == '__main__':
|
||||
# # description = description.strip()
|
||||
# # view[i].set_description(description)
|
||||
#
|
||||
# # elif l%4 == 1 :
|
||||
elif l%4 == 1 :
|
||||
# #
|
||||
# # seq = line[:-1]
|
||||
seq = line[:-1]
|
||||
# #print("seq", seq)
|
||||
# # view[i].set_sequence(seq)
|
||||
# # i+=1
|
||||
view[i].set_sequence(seq)
|
||||
i+=1
|
||||
#
|
||||
# l+=1
|
||||
l+=1
|
||||
#
|
||||
#
|
||||
input_file.close()
|
||||
|
@ -1,5 +1,5 @@
|
||||
--extra-index-url https://pypi.python.org/simple/
|
||||
Cython>=0.21
|
||||
Cython==0.23.5
|
||||
Sphinx>=1.2.0
|
||||
ipython>=3.0.0
|
||||
breathe>=4.0.0
|
||||
|
48
src/bloom.c
48
src/bloom.c
@ -122,6 +122,40 @@ static void setup_buckets(struct bloom * bloom, unsigned int cache_size)
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
int bloom_filter_size(int entries, double error)
|
||||
{
|
||||
int bytes;
|
||||
double num;
|
||||
double denom;
|
||||
double bpe;
|
||||
int bits;
|
||||
unsigned bucket_bytes;
|
||||
int not_even_by;
|
||||
|
||||
num = log(error);
|
||||
denom = 0.480453013918201; // ln(2)^2
|
||||
bpe = -(num / denom);
|
||||
bits = (int)(((double)entries) * bpe);
|
||||
|
||||
if (bits % 8) {
|
||||
bytes = (bits / 8) + 1;
|
||||
}
|
||||
else {
|
||||
bytes = bits / 8;
|
||||
}
|
||||
|
||||
bucket_bytes = BLOOM_BUCKET_SIZE_FALLBACK;
|
||||
not_even_by = bytes % bucket_bytes;
|
||||
if (not_even_by) {
|
||||
// adjust bytes
|
||||
bytes += (bucket_bytes - not_even_by);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
int bloom_init_size(struct bloom * bloom, int entries, double error,
|
||||
unsigned int cache_size)
|
||||
{
|
||||
@ -151,19 +185,21 @@ int bloom_init_size(struct bloom * bloom, int entries, double error,
|
||||
|
||||
setup_buckets(bloom, cache_size);
|
||||
|
||||
bloom->bf = (unsigned char *)calloc(bloom->bytes, sizeof(unsigned char));
|
||||
if (bloom->bf == NULL) {
|
||||
return 1;
|
||||
}
|
||||
// TODO comment
|
||||
memset(bloom->bf, 0, bloom->bytes);
|
||||
//bloom->bf = (unsigned char *)calloc(bloom->bytes, sizeof(unsigned char));
|
||||
//if (bloom->bf == NULL) {
|
||||
// return 1;
|
||||
//}
|
||||
|
||||
bloom->ready = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int bloom_init(struct bloom * bloom, int entries, double error)
|
||||
int bloom_init(struct bloom * bloom, int entries) //, double error)
|
||||
{
|
||||
return bloom_init_size(bloom, entries, error, 0);
|
||||
return bloom_init_size(bloom, entries, BLOOM_FILTER_ERROR_RATE, 0);
|
||||
}
|
||||
|
||||
|
||||
|
15
src/bloom.h
15
src/bloom.h
@ -9,6 +9,10 @@
|
||||
#define _BLOOM_H
|
||||
|
||||
|
||||
// TODO
|
||||
#define BLOOM_FILTER_ERROR_RATE (0.001)
|
||||
|
||||
|
||||
/** ***************************************************************************
|
||||
* On Linux, the code attempts to compute a bucket size based on CPU cache
|
||||
* size info, if available. If that fails for any reason, this fallback size
|
||||
@ -60,10 +64,17 @@ struct bloom
|
||||
unsigned bucket_bits_fast_mod_operand;
|
||||
|
||||
double bpe;
|
||||
unsigned char * bf;
|
||||
int ready;
|
||||
|
||||
unsigned char bf[];
|
||||
};
|
||||
|
||||
typedef struct bloom bloom_t;
|
||||
|
||||
|
||||
// TODO
|
||||
int bloom_filter_size(int entries, double error);
|
||||
|
||||
|
||||
/** ***************************************************************************
|
||||
* Initialize the bloom filter for use.
|
||||
@ -91,7 +102,7 @@ struct bloom
|
||||
* 1 - on failure
|
||||
*
|
||||
*/
|
||||
int bloom_init(struct bloom * bloom, int entries, double error);
|
||||
int bloom_init(struct bloom * bloom, int entries); //, double error);
|
||||
|
||||
|
||||
/** ***************************************************************************
|
||||
|
80
src/char_str_indexer.c
Normal file
80
src/char_str_indexer.c
Normal file
@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* Character string indexing functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file char_str_indexer.c
|
||||
* @author Celine Mercier
|
||||
* @date April 12th 2016
|
||||
* @brief Functions handling the indexing and retrieval of character strings.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "obiblob.h"
|
||||
#include "obiblob_indexer.h"
|
||||
#include "obidebug.h"
|
||||
#include "obitypes.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
Obi_blob_p obi_str_to_blob(const char* value)
|
||||
{
|
||||
Obi_blob_p value_b;
|
||||
int32_t length;
|
||||
|
||||
// Compute the number of bytes on which the value will be encoded
|
||||
length = strlen(value) + 1; // +1 to store \0 at the end (makes retrieving faster)
|
||||
|
||||
value_b = obi_blob((byte_t*)value, ELEMENT_SIZE_STR, length, length);
|
||||
if (value_b == NULL)
|
||||
{
|
||||
obidebug(1, "\nError encoding a character string in a blob");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return value_b;
|
||||
}
|
||||
|
||||
|
||||
char* obi_blob_to_str(Obi_blob_p value_b)
|
||||
{
|
||||
return value_b->value;
|
||||
}
|
||||
|
||||
|
||||
index_t obi_index_char_str(Obi_indexer_p indexer, const char* value)
|
||||
{
|
||||
Obi_blob_p value_b;
|
||||
index_t idx;
|
||||
|
||||
// Encode value
|
||||
value_b = obi_str_to_blob(value);
|
||||
if (value_b == NULL)
|
||||
return -1;
|
||||
|
||||
// Add in the indexer
|
||||
idx = obi_indexer_add(indexer, value_b);
|
||||
|
||||
free(value_b);
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
char* obi_retrieve_char_str(Obi_indexer_p indexer, index_t idx)
|
||||
{
|
||||
Obi_blob_p value_b;
|
||||
|
||||
// Get encoded value
|
||||
value_b = obi_indexer_get(indexer, idx);
|
||||
|
||||
// Return decoded character string
|
||||
return obi_blob_to_str(value_b);
|
||||
}
|
||||
|
61
src/char_str_indexer.h
Normal file
61
src/char_str_indexer.h
Normal file
@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
* DNA sequence indexer header file *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file dna_seq_indexer.h
|
||||
* @author Celine Mercier
|
||||
* @date April 12th 2016
|
||||
* @brief Header file for the functions handling the indexing of DNA sequences.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CHAR_STR_INDEXER_H_
|
||||
#define CHAR_STR_INDEXER_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obitypes.h"
|
||||
#include "obiblob.h"
|
||||
#include "obiblob_indexer.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a character string to a blob.
|
||||
*
|
||||
* @warning The blob must be freed by the caller.
|
||||
*
|
||||
* @param value The character string to convert.
|
||||
*
|
||||
* @returns A pointer to the blob created.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
Obi_blob_p obi_str_to_blob(char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a blob to a character string.
|
||||
*
|
||||
* @param value_b The blob to convert.
|
||||
*
|
||||
* @returns A pointer to the character string contained in the blob.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const char* obi_blob_to_str(Obi_blob_p value_b);
|
||||
|
||||
|
||||
// TODO doc
|
||||
index_t obi_index_char_str(Obi_indexer_p indexer, const char* value);
|
||||
|
||||
char* obi_retrieve_char_str(Obi_indexer_p indexer, index_t idx);
|
||||
|
||||
|
||||
#endif /* CHAR_STR_INDEXER_H_ */
|
||||
|
@ -171,7 +171,7 @@ static const uint64_t crc64_tab[256] = {
|
||||
};
|
||||
|
||||
|
||||
uint64_t crc64(const unsigned char* s, uint64_t l)
|
||||
uint64_t crc64(const char* s, uint64_t l)
|
||||
{
|
||||
uint64_t j;
|
||||
uint64_t crc = 0;
|
||||
|
@ -6,4 +6,4 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint64_t crc64(const unsigned char* s, uint64_t l);
|
||||
uint64_t crc64(const char* s, uint64_t l);
|
||||
|
102
src/dna_seq_indexer.c
Normal file
102
src/dna_seq_indexer.c
Normal file
@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
* DNA sequence indexing functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file dna_seq_indexer.c
|
||||
* @author Celine Mercier
|
||||
* @date April 12th 2016
|
||||
* @brief Functions handling the indexing and retrieval of DNA sequences.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "obiblob.h"
|
||||
#include "obiblob_indexer.h"
|
||||
#include "obidebug.h"
|
||||
#include "obitypes.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
Obi_blob_p obi_seq_to_blob(const char* seq)
|
||||
{
|
||||
Obi_blob_p value_b;
|
||||
int32_t length_encoded_seq; // length of the encoded sequence in bytes
|
||||
int32_t seq_length;
|
||||
byte_t* encoded_seq;
|
||||
|
||||
seq_length = strlen(seq);
|
||||
|
||||
// Check if just ATGC and encode accordingly
|
||||
if (only_ATGC(seq))
|
||||
{
|
||||
// Compute the length (in bytes) of the encoded sequence
|
||||
length_encoded_seq = ceil((double) seq_length / (double) 4.0);
|
||||
// Encode
|
||||
encoded_seq = encode_seq_on_2_bits(seq, seq_length);
|
||||
if (encoded_seq == NULL)
|
||||
return NULL;
|
||||
value_b = obi_blob(encoded_seq, ELEMENT_SIZE_SEQ_2, length_encoded_seq, seq_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Compute the length (in bytes) of the encoded sequence
|
||||
length_encoded_seq = ceil((double) seq_length / (double) 2.0);
|
||||
// Encode
|
||||
encoded_seq = encode_seq_on_4_bits(seq, seq_length);
|
||||
if (encoded_seq == NULL)
|
||||
return NULL;
|
||||
value_b = obi_blob(encoded_seq, ELEMENT_SIZE_SEQ_4, length_encoded_seq, seq_length);
|
||||
}
|
||||
|
||||
free(encoded_seq);
|
||||
|
||||
return value_b;
|
||||
}
|
||||
|
||||
|
||||
char* obi_blob_to_seq(Obi_blob_p value_b)
|
||||
{
|
||||
// Decode
|
||||
if (value_b->element_size == 2)
|
||||
return decode_seq_on_2_bits(value_b->value, value_b->length_decoded_value);
|
||||
else
|
||||
return decode_seq_on_4_bits(value_b->value, value_b->length_decoded_value);
|
||||
}
|
||||
|
||||
|
||||
index_t obi_index_dna_seq(Obi_indexer_p indexer, const char* value)
|
||||
{
|
||||
Obi_blob_p value_b;
|
||||
index_t idx;
|
||||
|
||||
// Encode value
|
||||
value_b = obi_seq_to_blob(value);
|
||||
if (value_b == NULL)
|
||||
return -1;
|
||||
|
||||
// Add in the indexer
|
||||
idx = obi_indexer_add(indexer, value_b);
|
||||
|
||||
free(value_b);
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
char* obi_retrieve_dna_seq(Obi_indexer_p indexer, index_t idx)
|
||||
{
|
||||
Obi_blob_p value_b;
|
||||
|
||||
// Get encoded value
|
||||
value_b = obi_indexer_get(indexer, idx);
|
||||
|
||||
// Return decoded sequence
|
||||
return obi_blob_to_seq(value_b);
|
||||
}
|
||||
|
63
src/dna_seq_indexer.h
Normal file
63
src/dna_seq_indexer.h
Normal file
@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
* DNA sequence indexer header file *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file dna_seq_indexer.h
|
||||
* @author Celine Mercier
|
||||
* @date April 12th 2016
|
||||
* @brief Header file for the functions handling the indexing of DNA sequences.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DNA_SEQ_INDEXER_H_
|
||||
#define DNA_SEQ_INDEXER_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidms.h"
|
||||
#include "obitypes.h"
|
||||
#include "obiblob.h"
|
||||
#include "obiblob_indexer.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a DNA sequence to a blob.
|
||||
*
|
||||
* @warning The blob must be freed by the caller.
|
||||
*
|
||||
* @param value The DNA sequence to convert.
|
||||
*
|
||||
* @returns A pointer to the blob created.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since November 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
Obi_blob_p obi_seq_to_blob(const char* seq);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a blob to a DNA sequence.
|
||||
*
|
||||
* @param value_b The blob to convert.
|
||||
*
|
||||
* @returns A pointer to the DNA sequence contained in the blob.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since November 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
char* obi_blob_to_seq(Obi_blob_p value_b);
|
||||
|
||||
|
||||
// TODO doc
|
||||
index_t obi_index_dna_seq(Obi_indexer_p indexer, const char* value);
|
||||
|
||||
char* obi_retrieve_dna_seq(Obi_indexer_p indexer, index_t idx);
|
||||
|
||||
|
||||
#endif /* DNA_SEQ_INDEXER_H_ */
|
||||
|
32
src/encode.c
32
src/encode.c
@ -54,7 +54,7 @@ bool only_ATGC(const char* seq)
|
||||
}
|
||||
|
||||
|
||||
byte_t* encode_seq_on_2_bits(char* seq, int32_t length)
|
||||
byte_t* encode_seq_on_2_bits(const char* seq, int32_t length)
|
||||
{
|
||||
byte_t* seq_b;
|
||||
uint8_t modulo;
|
||||
@ -64,6 +64,12 @@ byte_t* encode_seq_on_2_bits(char* seq, int32_t length)
|
||||
length_b = ceil((double) length / (double) 4.0);
|
||||
|
||||
seq_b = (byte_t*) malloc(length_b * sizeof(byte_t));
|
||||
if (seq_b == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR); // TODO
|
||||
obidebug(1, "\nError allocating memory for an encoded DNA sequence");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Initialize all the bits to 0
|
||||
memset(seq_b, 0, length_b);
|
||||
@ -93,6 +99,7 @@ byte_t* encode_seq_on_2_bits(char* seq, int32_t length)
|
||||
seq_b[i/4] |= NUC_T_2b;
|
||||
break;
|
||||
default:
|
||||
obi_set_errno(OBI_ENCODE_ERROR); // TODO
|
||||
obidebug(1, "\nInvalid nucleotide base when encoding (not [atgcATGC])");
|
||||
return NULL;
|
||||
}
|
||||
@ -116,6 +123,12 @@ char* decode_seq_on_2_bits(byte_t* seq_b, int32_t length_seq)
|
||||
uint8_t nuc;
|
||||
|
||||
seq = (char*) malloc((length_seq+1) * sizeof(char));
|
||||
if (seq == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR); // TODO
|
||||
obidebug(1, "\nError allocating memory for a decoded DNA sequence");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<length_seq; i++)
|
||||
{
|
||||
@ -138,6 +151,7 @@ char* decode_seq_on_2_bits(byte_t* seq_b, int32_t length_seq)
|
||||
seq[i] = 't';
|
||||
break;
|
||||
default:
|
||||
obi_set_errno(OBI_DECODE_ERROR); // TODO
|
||||
obidebug(1, "\nInvalid nucleotide base when decoding");
|
||||
return NULL;
|
||||
}
|
||||
@ -149,7 +163,7 @@ char* decode_seq_on_2_bits(byte_t* seq_b, int32_t length_seq)
|
||||
}
|
||||
|
||||
|
||||
byte_t* encode_seq_on_4_bits(char* seq, int32_t length)
|
||||
byte_t* encode_seq_on_4_bits(const char* seq, int32_t length)
|
||||
{
|
||||
byte_t* seq_b;
|
||||
uint8_t modulo;
|
||||
@ -159,6 +173,12 @@ byte_t* encode_seq_on_4_bits(char* seq, int32_t length)
|
||||
length_b = ceil((double) length / (double) 2.0);
|
||||
|
||||
seq_b = (byte_t*) malloc(length_b * sizeof(byte_t));
|
||||
if (seq_b == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR); // TODO
|
||||
obidebug(1, "\nError allocating memory for an encoded DNA sequence");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Initialize all the bits to 0
|
||||
memset(seq_b, 0, length_b);
|
||||
@ -232,6 +252,7 @@ byte_t* encode_seq_on_4_bits(char* seq, int32_t length)
|
||||
seq_b[i/2] |= NUC_N_4b;
|
||||
break;
|
||||
default:
|
||||
obi_set_errno(OBI_ENCODE_ERROR); // TODO
|
||||
obidebug(1, "\nInvalid nucleotide base when encoding (not IUPAC)");
|
||||
return NULL;
|
||||
}
|
||||
@ -255,6 +276,12 @@ char* decode_seq_on_4_bits(byte_t* seq_b, int32_t length_seq)
|
||||
uint8_t nuc;
|
||||
|
||||
seq = (char*) malloc((length_seq+1) * sizeof(char));
|
||||
if (seq == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR); // TODO
|
||||
obidebug(1, "\nError allocating memory for a decoded DNA sequence");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<length_seq; i++)
|
||||
{
|
||||
@ -310,6 +337,7 @@ char* decode_seq_on_4_bits(byte_t* seq_b, int32_t length_seq)
|
||||
seq[i] = 'n';
|
||||
break;
|
||||
default:
|
||||
obi_set_errno(OBI_DECODE_ERROR); // TODO
|
||||
obidebug(1, "\nInvalid nucleotide base when decoding");
|
||||
return NULL;
|
||||
}
|
||||
|
17
src/encode.h
17
src/encode.h
@ -10,6 +10,10 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ENCODE_H_
|
||||
#define ENCODE_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
@ -18,8 +22,10 @@
|
||||
#include "obitypes.h"
|
||||
|
||||
|
||||
#define NUC_MASK_2B 0x3 /**< Binary: 11 to use when decoding 2 bits sequences */
|
||||
#define NUC_MASK_4B 0xF /**< Binary: 1111 to use when decoding 4 bits sequences */
|
||||
#define NUC_MASK_2B 0x3 /**< Binary: 11 to use when decoding 2 bits sequences
|
||||
*/
|
||||
#define NUC_MASK_4B 0xF /**< Binary: 1111 to use when decoding 4 bits sequences
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
@ -90,7 +96,7 @@ bool only_ATGC(const char* seq);
|
||||
* @since November 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
byte_t* encode_seq_on_2_bits(char* seq, int32_t length);
|
||||
byte_t* encode_seq_on_2_bits(const char* seq, int32_t length);
|
||||
|
||||
|
||||
/**
|
||||
@ -141,7 +147,7 @@ char* decode_seq_on_2_bits(byte_t* seq_b, int32_t length_seq);
|
||||
* @since November 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
byte_t* encode_seq_on_4_bits(char* seq, int32_t length);
|
||||
byte_t* encode_seq_on_4_bits(const char* seq, int32_t length);
|
||||
|
||||
|
||||
/**
|
||||
@ -179,3 +185,6 @@ char* decode_seq_on_4_bits(byte_t* seq_b, int32_t length_seq);
|
||||
// little endian
|
||||
void print_bits(void* ptr, int32_t length);
|
||||
|
||||
|
||||
#endif /* ENCODE_H_ */
|
||||
|
||||
|
1518
src/obiavl.c
1518
src/obiavl.c
File diff suppressed because it is too large
Load Diff
338
src/obiavl.h
338
src/obiavl.h
@ -6,7 +6,7 @@
|
||||
* @file obiavl.h
|
||||
* @author Celine Mercier
|
||||
* @date December 3rd 2015
|
||||
* @brief Header file for handling AVL trees for storing and retrieving byte arrays (i.e. coding for character strings).
|
||||
* @brief Header file for handling AVL trees for storing and retrieving blobs (i.e. coding for character strings).
|
||||
*/
|
||||
|
||||
|
||||
@ -23,43 +23,49 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "obidms.h"
|
||||
#include "obiblob.h"
|
||||
#include "obitypes.h"
|
||||
#include "bloom.h"
|
||||
#include "utils.h"
|
||||
#include "encode.h"
|
||||
|
||||
|
||||
#define NODE_COUNT_PER_AVL (10000000)
|
||||
|
||||
#define BLOOM_FILTER_ERROR_RATE (0.001)
|
||||
|
||||
#define MAX_NB_OF_AVLS_IN_GROUP (100) /**< The maximum number of AVL trees in a group. // TODO discuss
|
||||
*/
|
||||
#define MAX_NODE_COUNT_PER_AVL (10000000) /**< The maximum number of nodes in an AVL tree.
|
||||
* Only used to decide when to create a new AVL in a group, and to initialize the bloom filter // TODO discuss.
|
||||
*/
|
||||
#define MAX_DATA_SIZE_PER_AVL (1073741824) /**< The maximum size of the data referred to by an AVL tree in a group.
|
||||
* Only used to decide when to create a new AVL in a group.
|
||||
* Should not be greater than int32_t max (2,147,483,647), as indexes will have to be stored on 32 bits.
|
||||
* Here 1073741824 B = 1 GB
|
||||
*/
|
||||
#define AVL_MAX_DEPTH (1024) /**< The maximum depth of an AVL tree. Used to save paths through the tree.
|
||||
*/
|
||||
#define AVL_MAX_NAME (1024) /**< The maximum length of an AVL tree name.
|
||||
*/
|
||||
#define AVL_GROWTH_FACTOR (2) /**< The growth factor when an AVL tree is enlarged.
|
||||
*/
|
||||
#define AVL_MAX_DEPTH (1000) /**< The maximum depth of an AVL tree.
|
||||
*/
|
||||
#define LEFT_CHILD(node) (avl->tree)+(node->left_child) /**< Pointer to the left child of a node in an AVL tree.
|
||||
*/
|
||||
#define RIGHT_CHILD(node) (avl->tree)+(node->right_child) /**< Pointer to the right child of a node in an AVL tree.
|
||||
*/
|
||||
#define BYTE_ARRAY_HEADER_SIZE (9) /**< The size of the header of a byte array.
|
||||
*/
|
||||
|
||||
typedef struct bloom bloom_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief AVL tree node structure.
|
||||
*/
|
||||
typedef struct AVL_node {
|
||||
index_t left_child; /**< Index of left less child node.
|
||||
*/
|
||||
index_t right_child; /**< Index of right greater child node.
|
||||
*/
|
||||
int8_t balance_factor; /**< Balance factor of the node.
|
||||
*/
|
||||
index_t value; /**< Index of the value associated with the node in the data array.
|
||||
*/
|
||||
uint64_t crc64; // TODO
|
||||
index_t left_child; /**< Index of left less child node.
|
||||
*/
|
||||
index_t right_child; /**< Index of right greater child node.
|
||||
*/
|
||||
int8_t balance_factor; /**< Balance factor of the node.
|
||||
*/
|
||||
index_t value; /**< Index of the value associated with the node in the data array.
|
||||
*/
|
||||
uint64_t crc64; /**< Cyclic Redundancy Check code on 64 bits associated with the value.
|
||||
*/
|
||||
} AVL_node_t, *AVL_node_p;
|
||||
|
||||
|
||||
@ -88,8 +94,10 @@ typedef struct OBIDMS_avl_data_header {
|
||||
typedef struct OBIDMS_avl_data {
|
||||
OBIDMS_avl_data_header_p header; /**< A pointer to the header of the AVL tree data.
|
||||
*/
|
||||
byte_t* data; /**< A pointer to the beginning of the data.
|
||||
byte_t* data; /**< A pointer to the beginning of the data.
|
||||
*/
|
||||
int data_fd; /**< File descriptor of the file containing the data.
|
||||
*/
|
||||
} OBIDMS_avl_data_t, *OBIDMS_avl_data_p;
|
||||
|
||||
|
||||
@ -111,38 +119,39 @@ typedef struct OBIDMS_avl_header {
|
||||
*/
|
||||
time_t creation_date; /**< Date of creation of the file.
|
||||
*/
|
||||
bloom_t bloom_filter;
|
||||
bloom_t bloom_filter; /**< Bloom filter associated with the AVL tree, enabling to know if a value
|
||||
* might already be stored in the data associated with the tree.
|
||||
*/
|
||||
} OBIDMS_avl_header_t, *OBIDMS_avl_header_p;
|
||||
|
||||
|
||||
/**
|
||||
* @brief OBIDMS AVL tree structure.
|
||||
* TODO doc
|
||||
*/
|
||||
typedef struct OBIDMS_avl {
|
||||
OBIDMS_p dms; /**< A pointer to the OBIDMS structure to which the AVL tree belongs.
|
||||
*/
|
||||
OBIDMS_avl_header_p header; /**< A pointer to the header of the AVL tree.
|
||||
*/
|
||||
struct AVL_node* tree; /**< A pointer to the root of the AVL tree.
|
||||
*/
|
||||
OBIDMS_p dms; /**< A pointer to the OBIDMS structure to which the AVL tree belongs.
|
||||
*/
|
||||
OBIDMS_avl_header_p header; /**< A pointer to the header of the AVL tree.
|
||||
*/
|
||||
struct AVL_node* tree; /**< A pointer to the root of the AVL tree.
|
||||
*/
|
||||
index_t path_idx[AVL_MAX_DEPTH]; /**< The path taken to a node from the root as an array of node indices.
|
||||
*/
|
||||
int8_t path_dir[AVL_MAX_DEPTH]; /**< The path taken to a node from the root as an array of directions
|
||||
* (0 for left, -1 for right).
|
||||
* (0 for left, -1 for right).
|
||||
*/
|
||||
OBIDMS_avl_data_p data; /**< A pointer to the structure containing the data
|
||||
* that the AVL tree references.
|
||||
*/
|
||||
DIR* directory; /**< A directory entry usable to
|
||||
* refer and scan the AVL tree directory.
|
||||
*/
|
||||
int dir_fd; /**< The file descriptor of the directory entry
|
||||
* usable to refer and scan the AVL tree directory.
|
||||
*/
|
||||
size_t counter; /**< Indicates by how many threads/programs (TODO) the AVL tree is used.
|
||||
*/
|
||||
int avl_fd;
|
||||
int data_fd;
|
||||
OBIDMS_avl_data_p data; /**< A pointer to the structure containing the data
|
||||
* that the AVL tree references.
|
||||
*/
|
||||
DIR* directory; /**< A directory entry usable to
|
||||
* refer and scan the AVL tree directory.
|
||||
*/
|
||||
int dir_fd; /**< The file descriptor of the directory entry
|
||||
* usable to refer and scan the AVL tree directory.
|
||||
*/
|
||||
int avl_fd; /**< The file descriptor of the file containing the AVL tree.
|
||||
*/
|
||||
} OBIDMS_avl_t, *OBIDMS_avl_p;
|
||||
|
||||
|
||||
@ -150,28 +159,30 @@ typedef struct OBIDMS_avl {
|
||||
* @brief OBIDMS AVL tree group structure.
|
||||
*/
|
||||
typedef struct OBIDMS_avl_group {
|
||||
// TODO put each group in a directory later
|
||||
OBIDMS_avl_p sub_avls[64]; // TODO macro for max
|
||||
int current_avl_idx;
|
||||
char avl_name[AVL_MAX_NAME+1];
|
||||
OBIDMS_p dms;
|
||||
OBIDMS_avl_p sub_avls[MAX_NB_OF_AVLS_IN_GROUP]; /**< Array containing the pointers to the AVL trees of the group.
|
||||
*/
|
||||
int current_avl_idx; /**< Index in the sub_avls array of the AVL tree currently being filled.
|
||||
*/
|
||||
char name[AVL_MAX_NAME+1]; /**< Base name of the AVL group. The AVL trees in it have names of the form basename_idx.
|
||||
*/
|
||||
OBIDMS_p dms; /**< Pointer to the OBIDMS structure to which the AVL group belongs.
|
||||
*/
|
||||
bool writable; /**< Indicates whether the AVL group is read-only or not.
|
||||
*/
|
||||
size_t counter; /**< Indicates by how many threads/programs (TODO) the AVL group is used.
|
||||
*/
|
||||
} OBIDMS_avl_group_t, *OBIDMS_avl_group_p;
|
||||
|
||||
|
||||
OBIDMS_avl_group_p obi_create_avl_group(OBIDMS_p dms, const char* avl_name);
|
||||
index_t insert_in_avl_group(OBIDMS_avl_group_p avl_group, byte_t* value);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Checks if an AVL tree already exists or not.
|
||||
* @brief Checks if an AVL tree or AVL tree group already exists or not.
|
||||
*
|
||||
* @param dms The OBIDMS to which the AVL tree belongs.
|
||||
* @param avl_name The name of the AVL tree.
|
||||
* @param dms The OBIDMS to which the AVL tree or AVL tree group belongs.
|
||||
* @param avl_name The name of the AVL treeor the base name of the AVL tree group.
|
||||
*
|
||||
* @returns A value indicating whether the AVL tree exists or not.
|
||||
* @retval 1 if the AVL tree exists.
|
||||
* @retval 0 if the AVL tree does not exist.
|
||||
* @returns A value indicating whether the AVL tree or AVL tree group exists or not.
|
||||
* @retval 1 if the AVL tree or AVL tree group exists.
|
||||
* @retval 0 if the AVL tree or AVL tree group does not exist.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since December 2015
|
||||
@ -180,36 +191,19 @@ index_t insert_in_avl_group(OBIDMS_avl_group_p avl_group, byte_t* value);
|
||||
int obi_avl_exists(OBIDMS_p dms, const char* avl_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Opens an AVL tree and creates it if it does not already exist.
|
||||
*
|
||||
* Note: An AVL tree is made of two files (referred to by two structures).
|
||||
* One file contains the indices referring to the data, and the other
|
||||
* file contains the data itself. The AVL tree as a whole is referred
|
||||
* to via the OBIDMS_avl structure.
|
||||
*
|
||||
* @param dms The OBIDMS to which the AVL tree belongs.
|
||||
* @param avl_name The name of the AVL tree.
|
||||
*
|
||||
* @returns A pointer to the AVL tree structure.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since December 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_avl_p obi_avl(OBIDMS_p dms, const char* avl_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates an AVL tree. Fails if it already exists.
|
||||
*
|
||||
* Note: An AVL tree is made of two files (referred to by two structures).
|
||||
* One file contains the indices referring to the data, and the other
|
||||
* file contains the data itself. The AVL tree as a whole is referred
|
||||
* to via the OBIDMS_avl structure.
|
||||
* to via the OBIDMS_avl structure. An AVL tree is stored in a directory
|
||||
* with the same name, or with the base name of the AVL group if it is
|
||||
* part of an AVL group.
|
||||
*
|
||||
* @param dms The OBIDMS to which the AVL tree belongs.
|
||||
* @param avl_name The name of the AVL tree.
|
||||
* @param avl_idx The index of the AVL tree if it is part of an AVL group.
|
||||
*
|
||||
* @returns A pointer to the newly created AVL tree structure.
|
||||
* @retval NULL if an error occurred.
|
||||
@ -217,7 +211,7 @@ OBIDMS_avl_p obi_avl(OBIDMS_p dms, const char* avl_name);
|
||||
* @since December 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_avl_p obi_create_avl(OBIDMS_p dms, const char* avl_name);
|
||||
OBIDMS_avl_p obi_create_avl(OBIDMS_p dms, const char* avl_name, int avl_idx);
|
||||
|
||||
|
||||
/**
|
||||
@ -230,6 +224,7 @@ OBIDMS_avl_p obi_create_avl(OBIDMS_p dms, const char* avl_name);
|
||||
*
|
||||
* @param dms The OBIDMS to which the AVL tree belongs.
|
||||
* @param avl_name The name of the AVL tree.
|
||||
* @param avl_idx The index of the AVL tree if it is part of an AVL group.
|
||||
*
|
||||
* @returns A pointer to the AVL tree structure.
|
||||
* @retval NULL if an error occurred.
|
||||
@ -237,17 +232,66 @@ OBIDMS_avl_p obi_create_avl(OBIDMS_p dms, const char* avl_name);
|
||||
* @since December 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_avl_p obi_open_avl(OBIDMS_p dms, const char* avl_name);
|
||||
OBIDMS_avl_p obi_open_avl(OBIDMS_p dms, const char* avl_name, int avl_idx);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Opens an AVL tree group and creates it if it does not already exist.
|
||||
*
|
||||
* Note: An AVL tree group is composed of multiple AVL trees that all have the
|
||||
* same base name, and an index differentiating them.
|
||||
*
|
||||
* @param dms The OBIDMS to which the AVL tree belongs.
|
||||
* @param avl_name The base name of the AVL tree group.
|
||||
*
|
||||
* @returns A pointer to the AVL tree group structure.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since April 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_avl_group_p obi_avl_group(OBIDMS_p dms, const char* avl_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates an AVL tree group.
|
||||
*
|
||||
* Note: An AVL tree group is composed of multiple AVL trees that all have the
|
||||
* same base name, and an index differentiating them.
|
||||
*
|
||||
* @param dms The OBIDMS to which the AVL tree belongs.
|
||||
* @param avl_name The base name of the AVL tree group.
|
||||
*
|
||||
* @returns A pointer to the AVL tree group structure.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since April 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_avl_group_p obi_create_avl_group(OBIDMS_p dms, const char* avl_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Opens an AVL tree group.
|
||||
*
|
||||
* Note: An AVL tree group is composed of multiple AVL trees that all have the
|
||||
* same base name, and an index differentiating them.
|
||||
*
|
||||
* @param dms The OBIDMS to which the AVL tree belongs.
|
||||
* @param avl_name The base name of the AVL tree group.
|
||||
*
|
||||
* @returns A pointer to the AVL tree group structure.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since April 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
OBIDMS_avl_group_p obi_open_avl_group(OBIDMS_p dms, const char* avl_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Closes an AVL tree.
|
||||
*
|
||||
* Note: An AVL tree is made of two files (referred to by two structures).
|
||||
* One file contains the indices referring to the data, and the other
|
||||
* file contains the data itself. The AVL tree as a whole is referred
|
||||
* to via the OBIDMS_avl structure.
|
||||
*
|
||||
* @param avl A pointer to the AVL tree structure to close and free.
|
||||
*
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
@ -260,29 +304,59 @@ int obi_close_avl(OBIDMS_avl_p avl);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Adds a value (byte array) in an AVL tree, checking if it is already in it.
|
||||
* @brief Closes an AVL tree group.
|
||||
*
|
||||
* @warning The byte array to add must already be encoded and contain its header.
|
||||
* @param avl_group A pointer to the AVL tree group structure to close and free.
|
||||
*
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since April 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_close_avl_group(OBIDMS_avl_group_p avl_group);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value (blob) in an AVL tree.
|
||||
*
|
||||
* @warning The blob recovered must be decoded to get the original value.
|
||||
*
|
||||
* @param avl A pointer to the AVL tree.
|
||||
* @param value The byte array to add in the AVL tree.
|
||||
* @param index The index of the value in the data array.
|
||||
*
|
||||
* @returns The index of the value, whether it was added or already in the AVL tree.
|
||||
* @returns A pointer to the blob recovered.
|
||||
*
|
||||
* @since December 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
Obi_blob_p obi_avl_get(OBIDMS_avl_p avl, index_t index);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Adds a value (blob) in an AVL tree NOT checking first if it is already in it. // TODO to discuss
|
||||
*
|
||||
* @warning The value given must be already be encoded into a blob structure (Obi_blob_t).
|
||||
*
|
||||
* @param avl A pointer to the AVL tree.
|
||||
* @param value The blob to add in the AVL tree.
|
||||
*
|
||||
* @returns The index of the value newly added in the AVL tree.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since December 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
index_t obi_avl_add(OBIDMS_avl_p avl, byte_t* value);
|
||||
index_t obi_avl_add(OBIDMS_avl_p avl, Obi_blob_p value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Finds a value (byte array) in an AVL tree, checking first if it is already in it.
|
||||
* @brief Finds a value (blob) in an AVL tree.
|
||||
*
|
||||
* @warning The byte array to add must already be encoded and contain its header.
|
||||
* @warning The value given must be already be encoded into a blob structure (Obi_blob_t).
|
||||
*
|
||||
* @param avl A pointer to the AVL tree.
|
||||
* @param value The byte array to add in the AVL tree.
|
||||
* @param value The blob to add in the AVL tree.
|
||||
*
|
||||
* @returns The data index of the value.
|
||||
* @retval -1 if the value is not in the tree.
|
||||
@ -290,86 +364,40 @@ index_t obi_avl_add(OBIDMS_avl_p avl, byte_t* value);
|
||||
* @since December 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
index_t obi_avl_find(OBIDMS_avl_p avl, byte_t* value);
|
||||
index_t obi_avl_find(OBIDMS_avl_p avl, Obi_blob_p value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value (byte array) in an AVL tree.
|
||||
* @brief Recovers a value (blob) in an AVL tree.
|
||||
*
|
||||
* @warning The byte array recovered is encoded and contains its header.
|
||||
* @warning The blob recovered must be decoded to get the original value.
|
||||
*
|
||||
* @param avl A pointer to the AVL tree.
|
||||
* @param avl_group A pointer to the AVL tree.
|
||||
* @param index The index of the value in the data array.
|
||||
*
|
||||
* @returns A pointer to the byte array recovered.
|
||||
* @returns A pointer to the blob recovered.
|
||||
*
|
||||
* @since December 2015
|
||||
* @since April 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
byte_t* obi_avl_get(OBIDMS_avl_p avl, index_t index);
|
||||
Obi_blob_p obi_avl_group_get(OBIDMS_avl_group_p avl_group, index_t idx);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a character string to a byte array with a header.
|
||||
* @brief Adds a value (blob) in an AVL tree group, checking if it is already in it.
|
||||
*
|
||||
* @warning The byte array must be freed by the caller.
|
||||
* @warning The value given must be already be encoded into a blob structure (Obi_blob_t).
|
||||
*
|
||||
* @param value The character string to convert.
|
||||
* @param avl_group A pointer to the AVL tree group.
|
||||
* @param value The blob to add in the AVL tree group.
|
||||
*
|
||||
* @returns A pointer to the byte array created.
|
||||
* @retval NULL if an error occurred.
|
||||
* @returns The index of the value newly added in the AVL tree group.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since October 2015
|
||||
* @since April 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
byte_t* obi_str_to_obibytes(char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a byte array to a character string.
|
||||
*
|
||||
* @param value_b The byte array to convert.
|
||||
*
|
||||
* @returns A pointer to the character string contained in the byte array.
|
||||
*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const char* obi_obibytes_to_str(byte_t* value_b);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a DNA sequence to a byte array with a header.
|
||||
*
|
||||
* @warning The byte array must be freed by the caller.
|
||||
*
|
||||
* @param value The DNA sequence to convert.
|
||||
*
|
||||
* @returns A pointer to the byte array created.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since November 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
byte_t* obi_seq_to_obibytes(char* seq);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Converts a byte array to a DNA sequence.
|
||||
*
|
||||
* @param value_b The byte array to convert.
|
||||
*
|
||||
* @returns A pointer to the DNA sequence contained in the byte array.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since November 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const char* obi_obibytes_to_seq(byte_t* value_b); // TODO move to encode source files
|
||||
|
||||
|
||||
// TODO
|
||||
byte_t* obi_avl_group_get(OBIDMS_avl_group_p avl_group, index_t idx);
|
||||
index_t obi_avl_group_add(OBIDMS_avl_group_p avl_group, Obi_blob_p value);
|
||||
|
||||
|
||||
#endif /* OBIAVL_H_ */
|
||||
|
57
src/obiblob.c
Normal file
57
src/obiblob.c
Normal file
@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
* Obiblob functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obiblob.c
|
||||
* @author Celine Mercier
|
||||
* @date April 11th 2016
|
||||
* @brief Functions handling Obiblob structures.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "obiblob.h"
|
||||
#include "obierrno.h"
|
||||
#include "obitypes.h" // For byte_t type
|
||||
#include "obidebug.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
// TODO: endianness problem?
|
||||
|
||||
|
||||
Obi_blob_p obi_blob(byte_t* encoded_value, uint8_t element_size, int32_t length_encoded_value, int32_t length_decoded_value)
|
||||
{
|
||||
Obi_blob_p blob;
|
||||
|
||||
// Allocate the memory for the blob structure
|
||||
blob = (Obi_blob_p) malloc(sizeof(Obi_blob_t) + length_encoded_value);
|
||||
if (blob == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR);
|
||||
obidebug(1, "\nError allocating memory for a blob");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Store the number of bits on which each element is encoded
|
||||
blob->element_size = element_size;
|
||||
|
||||
// Store the length (in bytes) of the encoded value
|
||||
blob->length_encoded_value = length_encoded_value;
|
||||
|
||||
// Store the initial length (in bytes) of the decoded value
|
||||
blob->length_decoded_value = length_decoded_value;
|
||||
|
||||
// Store the encoded value
|
||||
memcpy(blob->value, encoded_value, length_encoded_value);
|
||||
|
||||
return blob;
|
||||
}
|
||||
|
54
src/obiblob.h
Normal file
54
src/obiblob.h
Normal file
@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
* Obiblob header file *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obiblob.h
|
||||
* @author Celine Mercier
|
||||
* @date November 18th 2015
|
||||
* @brief Header file for handling Obi_blob structures.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIBLOB_H_
|
||||
#define OBIBLOB_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "obitypes.h"
|
||||
|
||||
|
||||
#define ELEMENT_SIZE_STR (8) /**< The size of an element from a value of type character string.
|
||||
*/
|
||||
#define ELEMENT_SIZE_SEQ_2 (2) /**< The size of an element from a value of type DNA sequence encoded on 2 bits.
|
||||
*/
|
||||
#define ELEMENT_SIZE_SEQ_4 (4) /**< The size of an element from a value of type DNA sequence encoded on 4 bits.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Blob structure.
|
||||
* TODO
|
||||
*/
|
||||
typedef struct Obi_blob {
|
||||
uint8_t element_size; /**< Size in bits of one element from the value.
|
||||
*/
|
||||
int32_t length_encoded_value; /**< Length in bytes of the encoded value.
|
||||
*/
|
||||
int32_t length_decoded_value; /**< Length in bytes of the decoded value.
|
||||
*/
|
||||
byte_t value[]; /**< Encoded value.
|
||||
*/
|
||||
} Obi_blob_t, *Obi_blob_p;
|
||||
|
||||
|
||||
|
||||
// TODO doc
|
||||
Obi_blob_p obi_blob(byte_t* encoded_value, uint8_t element_size, int32_t length_encoded_value, int32_t length_decoded_value);
|
||||
|
||||
|
||||
#endif /* OBIBLOB_H_ */
|
||||
|
37
src/obiblob_indexer.c
Normal file
37
src/obiblob_indexer.c
Normal file
@ -0,0 +1,37 @@
|
||||
/****************************************************************************
|
||||
* Obiblob functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obiblob_indexer.c
|
||||
* @author Celine Mercier
|
||||
* @date April 12th 2016
|
||||
* @brief Functions handling the indexing and retrieval of blob structures.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obiblob_indexer.h"
|
||||
#include "obidms.h"
|
||||
#include "obiavl.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
inline int obi_indexer_exists(OBIDMS_p dms, const char* name);
|
||||
|
||||
inline Obi_indexer_p obi_indexer(OBIDMS_p dms, const char* name);
|
||||
|
||||
inline Obi_indexer_p obi_create_indexer(OBIDMS_p dms, const char* name);
|
||||
|
||||
inline Obi_indexer_p obi_open_indexer(OBIDMS_p dms, const char* name);
|
||||
|
||||
inline int obi_close_indexer(Obi_indexer_p indexer);
|
||||
|
||||
inline index_t obi_indexer_add(Obi_indexer_p indexer, Obi_blob_p value);
|
||||
|
||||
inline Obi_blob_p obi_indexer_get(Obi_indexer_p indexer, index_t idx);
|
||||
|
80
src/obiblob_indexer.h
Normal file
80
src/obiblob_indexer.h
Normal file
@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* Blob indexer header file *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file obiblob_indexer.h
|
||||
* @author Celine Mercier
|
||||
* @date April 12th 2016
|
||||
* @brief Header file for the functions handling the indexing of values.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OBIBLOB_INDEXER_H_
|
||||
#define OBIBLOB_INDEXER_H_
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidms.h"
|
||||
#include "obiavl.h"
|
||||
#include "obitypes.h"
|
||||
#include "obiblob.h"
|
||||
|
||||
|
||||
#define INDEXER_MAX_NAME AVL_MAX_NAME /**< Macro to refer to the maximum size of the name of an indexer structure.
|
||||
*/
|
||||
|
||||
|
||||
typedef struct OBIDMS_avl_group Obi_indexer; /**< Typedef to refer to the used indexer structure.
|
||||
*/
|
||||
typedef OBIDMS_avl_group_p Obi_indexer_p; /**< Typedef to refer to the pointer of the used indexer structure.
|
||||
*/
|
||||
|
||||
|
||||
// TODO doc
|
||||
inline int obi_indexer_exists(OBIDMS_p dms, const char* name)
|
||||
{
|
||||
return obi_avl_exists(dms, name);
|
||||
}
|
||||
|
||||
|
||||
inline Obi_indexer_p obi_indexer(OBIDMS_p dms, const char* name)
|
||||
{
|
||||
return obi_avl_group(dms, name);
|
||||
}
|
||||
|
||||
|
||||
inline Obi_indexer_p obi_create_indexer(OBIDMS_p dms, const char* name)
|
||||
{
|
||||
return obi_create_avl_group(dms, name);
|
||||
}
|
||||
|
||||
|
||||
inline Obi_indexer_p obi_open_indexer(OBIDMS_p dms, const char* name)
|
||||
{
|
||||
return obi_open_avl_group(dms, name);
|
||||
}
|
||||
|
||||
|
||||
inline int obi_close_indexer(Obi_indexer_p indexer)
|
||||
{
|
||||
return obi_close_avl_group(indexer);
|
||||
}
|
||||
|
||||
|
||||
inline index_t obi_indexer_add(Obi_indexer_p indexer, Obi_blob_p value)
|
||||
{
|
||||
return obi_avl_group_add(indexer, value);
|
||||
}
|
||||
|
||||
|
||||
inline Obi_blob_p obi_indexer_get(Obi_indexer_p indexer, index_t idx)
|
||||
{
|
||||
return obi_avl_group_get(indexer, idx);
|
||||
}
|
||||
|
||||
|
||||
#endif /* OBIBLOB_INDEXER_H_ */
|
||||
|
219
src/obidms.c
219
src/obidms.c
@ -23,7 +23,8 @@
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obidmscolumn.h"
|
||||
#include "private_at_functions.h"
|
||||
#include "obiblob_indexer.h"
|
||||
#include "utils.h"
|
||||
#include "obilittlebigman.h"
|
||||
|
||||
|
||||
@ -249,7 +250,7 @@ OBIDMS_p obi_create_dms(const char* dms_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get file descriptor of DMS directory to create the AVL trees directory
|
||||
// Get file descriptor of DMS directory to create the indexer directory
|
||||
dms_dir = opendir(directory_name);
|
||||
if (dms_dir == NULL)
|
||||
{
|
||||
@ -269,11 +270,11 @@ OBIDMS_p obi_create_dms(const char* dms_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create the AVL trees directory
|
||||
if (mkdirat(dms_file_descriptor, AVL_TREES_DIR_NAME, 00777) < 0)
|
||||
// Create the indexer directory
|
||||
if (mkdirat(dms_file_descriptor, INDEXER_DIR_NAME, 00777) < 0)
|
||||
{
|
||||
obi_set_errno(OBI_AVL_ERROR);
|
||||
obidebug(1, "\nProblem creating an AVL trees directory");
|
||||
obi_set_errno(OBI_INDEXER_ERROR);
|
||||
obidebug(1, "\nProblem creating an indexer directory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -392,24 +393,24 @@ OBIDMS_p obi_open_dms(const char* dms_name)
|
||||
|
||||
dms->little_endian = little_endian_dms;
|
||||
|
||||
// Open the AVL trees directory
|
||||
dms->avl_directory = opendir_in_dms(dms, AVL_TREES_DIR_NAME);
|
||||
if (dms->avl_directory == NULL)
|
||||
// Open the indexer directory
|
||||
dms->indexer_directory = opendir_in_dms(dms, INDEXER_DIR_NAME);
|
||||
if (dms->indexer_directory == NULL)
|
||||
{
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError opening the AVL trees directory");
|
||||
obidebug(1, "\nError opening the indexer directory");
|
||||
closedir(dms->directory);
|
||||
free(dms);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Store the AVL trees directory's file descriptor
|
||||
dms->avl_dir_fd = dirfd(dms->avl_directory);
|
||||
if (dms->avl_dir_fd < 0)
|
||||
// Store the indexer directory's file descriptor
|
||||
dms->indexer_dir_fd = dirfd(dms->indexer_directory);
|
||||
if (dms->indexer_dir_fd < 0)
|
||||
{
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError getting the file descriptor of the AVL trees directory");
|
||||
closedir(dms->avl_directory);
|
||||
obidebug(1, "\nError getting the file descriptor of the indexer directory");
|
||||
closedir(dms->indexer_directory);
|
||||
closedir(dms->directory);
|
||||
free(dms);
|
||||
return NULL;
|
||||
@ -417,13 +418,11 @@ OBIDMS_p obi_open_dms(const char* dms_name)
|
||||
|
||||
// Initialize the list of opened columns
|
||||
dms->opened_columns = (Opened_columns_list_p) malloc(sizeof(Opened_columns_list_t));
|
||||
(dms->opened_columns)->columns = (OBIDMS_column_p*) malloc(MAX_NB_OPENED_COLUMNS*sizeof(OBIDMS_column_p));
|
||||
(dms->opened_columns)->nb_opened_columns = 0;
|
||||
|
||||
// Initialize the list of opened AVL trees
|
||||
dms->opened_avls = (Opened_avls_list_p) malloc(sizeof(Opened_avls_list_t));
|
||||
(dms->opened_avls)->avls = (OBIDMS_avl_p*) malloc(MAX_NB_OPENED_AVL_TREES*sizeof(OBIDMS_avl_p));
|
||||
(dms->opened_avls)->nb_opened_avls = 0;
|
||||
// Initialize the list of opened indexers // TODO should be handled somewhere else?
|
||||
dms->opened_indexers = (Opened_indexers_list_p) malloc(sizeof(Opened_indexers_list_t));
|
||||
(dms->opened_indexers)->nb_opened_indexers = 0;
|
||||
|
||||
return dms;
|
||||
}
|
||||
@ -456,7 +455,7 @@ int obi_close_dms(OBIDMS_p dms)
|
||||
while ((dms->opened_columns)->nb_opened_columns > 0)
|
||||
obi_close_column(*((dms->opened_columns)->columns));
|
||||
|
||||
// Close dms and AVL trees directories
|
||||
// Close dms and indexer directories
|
||||
if (closedir(dms->directory) < 0)
|
||||
{
|
||||
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
||||
@ -464,10 +463,10 @@ int obi_close_dms(OBIDMS_p dms)
|
||||
free(dms);
|
||||
return -1;
|
||||
}
|
||||
if (closedir(dms->avl_directory) < 0)
|
||||
if (closedir(dms->indexer_directory) < 0) // TODO should be handled somewhere else?
|
||||
{
|
||||
obi_set_errno(OBI_AVL_ERROR);
|
||||
obidebug(1, "\nError closing an AVL trees directory");
|
||||
obi_set_errno(OBI_INDEXER_ERROR);
|
||||
obidebug(1, "\nError closing an indexer directory");
|
||||
free(dms);
|
||||
return -1;
|
||||
}
|
||||
@ -477,3 +476,175 @@ int obi_close_dms(OBIDMS_p dms)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int obi_dms_is_column_name_in_list(OBIDMS_p dms, const char* column_name)
|
||||
{
|
||||
int i;
|
||||
Opened_columns_list_p columns_list;
|
||||
|
||||
columns_list = dms->opened_columns;
|
||||
|
||||
for (i=0; i < (columns_list->nb_opened_columns); i++)
|
||||
{
|
||||
if (!strcmp(((*((columns_list->columns)+i))->header)->name, column_name))
|
||||
{ // Found it
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_column_p obi_dms_get_column_from_list(OBIDMS_p dms, const char* column_name, obiversion_t version)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < ((dms->opened_columns)->nb_opened_columns); i++)
|
||||
{
|
||||
if (!strcmp(((*(((dms->opened_columns)->columns)+i))->header)->name, column_name)
|
||||
&& (((*(((dms->opened_columns)->columns)+i))->header)->version == version))
|
||||
{ // Found the column already opened, return it
|
||||
return *(((dms->opened_columns)->columns)+i);
|
||||
}
|
||||
}
|
||||
// Didn't find the column
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void obi_dms_list_column(OBIDMS_p dms, OBIDMS_column_p column)
|
||||
{
|
||||
*(((dms->opened_columns)->columns)+((dms->opened_columns)->nb_opened_columns)) = column;
|
||||
((dms->opened_columns)->nb_opened_columns)++;
|
||||
}
|
||||
|
||||
|
||||
int obi_dms_unlist_column(OBIDMS_p dms, OBIDMS_column_p column)
|
||||
{
|
||||
int i;
|
||||
Opened_columns_list_p columns_list;
|
||||
|
||||
columns_list = dms->opened_columns;
|
||||
|
||||
for (i=0; i < columns_list->nb_opened_columns; i++)
|
||||
{
|
||||
if (!strcmp(((*((columns_list->columns)+i))->header)->name, (column->header)->name)
|
||||
&& (((*((columns_list->columns)+i))->header)->version == (column->header)->version))
|
||||
{ // Found the column. Rearrange list
|
||||
(columns_list->nb_opened_columns)--;
|
||||
(columns_list->columns)[i] = (columns_list->columns)[columns_list->nb_opened_columns];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
obidebug(1, "\nCould not find the column to delete from list of open columns");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Obi_indexer_p obi_dms_get_indexer_from_list(OBIDMS_p dms, const char* indexer_name)
|
||||
{
|
||||
int i;
|
||||
Opened_indexers_list_p indexers_list;
|
||||
|
||||
indexers_list = dms->opened_indexers;
|
||||
|
||||
for (i=0; i < (indexers_list->nb_opened_indexers); i++)
|
||||
{
|
||||
if (!strcmp(((indexers_list->indexers)[i])->name, indexer_name)) // TODO it references something in AVL_group struct
|
||||
{ // Found the indexer already opened, return it
|
||||
return (indexers_list->indexers)[i];
|
||||
}
|
||||
}
|
||||
// Didn't find the indexer
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void obi_dms_list_indexer(OBIDMS_p dms, Obi_indexer_p indexer)
|
||||
{
|
||||
*(((dms->opened_indexers)->indexers)+((dms->opened_indexers)->nb_opened_indexers)) = indexer;
|
||||
((dms->opened_indexers)->nb_opened_indexers)++;
|
||||
}
|
||||
|
||||
|
||||
int obi_dms_unlist_indexer(OBIDMS_p dms, Obi_indexer_p indexer)
|
||||
{
|
||||
int i;
|
||||
Opened_indexers_list_p indexers_list;
|
||||
|
||||
indexers_list = dms->opened_indexers;
|
||||
|
||||
for (i=0; i < indexers_list->nb_opened_indexers; i++)
|
||||
{
|
||||
if (!strcmp(((indexers_list->indexers)[i])->name, indexer->name)) // TODO it references something in AVL_group struct
|
||||
{ // Found the indexer. Rearrange list
|
||||
(indexers_list->nb_opened_indexers)--;
|
||||
(indexers_list->indexers)[i] = (indexers_list->indexers)[indexers_list->nb_opened_indexers];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
obidebug(1, "\nCould not find the indexer to delete from list of open indexers");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
char* obi_dms_get_dms_path(OBIDMS_p dms)
|
||||
{
|
||||
char* full_path;
|
||||
|
||||
full_path = (char*) malloc((MAX_PATH_LEN)*sizeof(char));
|
||||
if (full_path == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR);
|
||||
obidebug(1, "\nError allocating memory for the char* path to a file or directory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (getcwd(full_path, MAX_PATH_LEN) == NULL) // TODO not sure at all about this because the DMS must be in the working directory.
|
||||
{ // Maybe better to store when opening, but opening function seems to assume that too.
|
||||
obi_set_errno(OBI_UTILS_ERROR);
|
||||
obidebug(1, "\nError getting the path to a file or directory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcat(full_path, "/");
|
||||
strcat(full_path, dms->directory_name);
|
||||
|
||||
return full_path;
|
||||
}
|
||||
|
||||
|
||||
char* obi_dms_get_full_path(OBIDMS_p dms, const char* path_name)
|
||||
{
|
||||
char* full_path;
|
||||
|
||||
full_path = obi_dms_get_dms_path(dms);
|
||||
strcat(full_path, "/");
|
||||
strcat(full_path, path_name);
|
||||
|
||||
return full_path;
|
||||
}
|
||||
|
||||
|
||||
DIR* opendir_in_dms(OBIDMS_p dms, const char* path_name)
|
||||
{
|
||||
char* full_path;
|
||||
DIR* directory;
|
||||
|
||||
full_path = obi_dms_get_full_path(dms, path_name);
|
||||
if (full_path == NULL)
|
||||
return NULL;
|
||||
|
||||
directory = opendir(full_path);
|
||||
if (directory == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_UTILS_ERROR);
|
||||
obidebug(1, "\nError opening a directory");
|
||||
}
|
||||
|
||||
free(full_path);
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
119
src/obidms.h
119
src/obidms.h
@ -23,34 +23,46 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "obierrno.h"
|
||||
//#include "obidmscolumn.h"
|
||||
//#include "obiblob_indexer.h"
|
||||
|
||||
|
||||
#define OBIDMS_MAX_NAME (2048) /**< The maximum length of an OBIDMS name.
|
||||
*/
|
||||
#define AVL_TREES_DIR_NAME "AVL_trees" /**< The name of the AVL trees directory.
|
||||
*/
|
||||
#define TAXONOMY_DIR_NAME "TAXONOMY" /**< The name of the taxonomy directory.
|
||||
*/
|
||||
#define MAX_NB_OPENED_COLUMNS (100) /**< The maximum number of columns open at the same time.
|
||||
*/
|
||||
#define MAX_NB_OPENED_AVL_TREES (100) /**< The maximum number of AVL trees open at the same time.
|
||||
*/
|
||||
#define OBIDMS_MAX_NAME (2048) /**< The maximum length of an OBIDMS name.
|
||||
*/
|
||||
#define INDEXER_DIR_NAME "OBIBLOB_INDEXERS" /**< The name of the Obiblob indexer directory.
|
||||
*/
|
||||
#define TAXONOMY_DIR_NAME "TAXONOMY" /**< The name of the taxonomy directory.
|
||||
*/
|
||||
#define MAX_NB_OPENED_COLUMNS (100) /**< The maximum number of columns open at the same time.
|
||||
*/
|
||||
#define MAX_NB_OPENED_INDEXERS (1000) /**< The maximum number of indexers open at the same time.
|
||||
*/
|
||||
#define MAX_PATH_LEN 4096 /**< Maximum length for the character string defining a
|
||||
* file or directory path.
|
||||
*/
|
||||
|
||||
|
||||
typedef int32_t obiversion_t; /**< TODO double
|
||||
*/
|
||||
|
||||
|
||||
struct OBIDMS_column; // TODO
|
||||
typedef struct OBIDMS_column* OBIDMS_column_p;
|
||||
|
||||
typedef struct Opened_columns_list {
|
||||
size_t nb_opened_columns;
|
||||
struct OBIDMS_column** columns; // TODO allocate array size here
|
||||
typedef struct Opened_columns_list { // TODO Handle the problem linked to columns with the same name + means only one version
|
||||
int nb_opened_columns;
|
||||
OBIDMS_column_p columns[MAX_NB_OPENED_COLUMNS];
|
||||
} Opened_columns_list_t, *Opened_columns_list_p;
|
||||
|
||||
|
||||
struct OBIDMS_avl; // TODO
|
||||
struct OBIDMS_avl_group; // TODO
|
||||
typedef struct OBIDMS_avl_group* OBIDMS_avl_group_p;
|
||||
typedef OBIDMS_avl_group_p Obi_indexer_p;
|
||||
|
||||
typedef struct Opened_avls_list {
|
||||
size_t nb_opened_avls;
|
||||
struct OBIDMS_avl** avls;
|
||||
} Opened_avls_list_t, *Opened_avls_list_p;
|
||||
typedef struct Opened_indexers_list {
|
||||
int nb_opened_indexers;
|
||||
Obi_indexer_p indexers[MAX_NB_OPENED_INDEXERS];
|
||||
} Opened_indexers_list_t, *Opened_indexers_list_p;
|
||||
|
||||
|
||||
/**
|
||||
@ -69,17 +81,17 @@ typedef struct OBIDMS {
|
||||
int dir_fd; /**< The file descriptor of the directory entry
|
||||
* usable to refer and scan the database directory.
|
||||
*/
|
||||
DIR* avl_directory; /**< A directory entry usable to
|
||||
* refer and scan the AVL trees directory.
|
||||
DIR* indexer_directory; /**< A directory entry usable to
|
||||
* refer and scan the indexer directory.
|
||||
*/
|
||||
int avl_dir_fd; /**< The file descriptor of the directory entry
|
||||
* usable to refer and scan the AVL trees directory.
|
||||
int indexer_dir_fd; /**< The file descriptor of the directory entry
|
||||
* usable to refer and scan the indexer directory.
|
||||
*/
|
||||
bool little_endian; /**< Endianness of the database.
|
||||
*/
|
||||
Opened_columns_list_p opened_columns; /**< List of opened columns.
|
||||
*/
|
||||
Opened_avls_list_p opened_avls; /**< List of opened AVL trees.
|
||||
Opened_indexers_list_p opened_indexers; /**< List of opened indexers.
|
||||
*/
|
||||
} OBIDMS_t, *OBIDMS_p;
|
||||
|
||||
@ -107,7 +119,7 @@ int obi_dms_exists(const char* dms_name);
|
||||
* if a directory with this name does not already exist
|
||||
* before creating the new database.
|
||||
*
|
||||
* A directory to store AVL trees is also created.
|
||||
* A directory to store Obiblob indexers is also created.
|
||||
*
|
||||
* @param dms_name A pointer to a C string containing the name of the database.
|
||||
* The actual directory name used to store the DMS will be
|
||||
@ -174,4 +186,63 @@ OBIDMS_p obi_dms(const char* dms_name);
|
||||
int obi_close_dms(OBIDMS_p dms);
|
||||
|
||||
|
||||
// TODO doc
|
||||
int obi_dms_is_column_name_in_list(OBIDMS_p dms, const char* column_name);
|
||||
|
||||
|
||||
OBIDMS_column_p obi_dms_get_column_from_list(OBIDMS_p dms, const char* column_name, obiversion_t version);
|
||||
|
||||
|
||||
void obi_dms_list_column(OBIDMS_p dms, OBIDMS_column_p column);
|
||||
|
||||
|
||||
int obi_dms_unlist_column(OBIDMS_p dms, OBIDMS_column_p column);
|
||||
|
||||
|
||||
Obi_indexer_p obi_dms_get_indexer_from_list(OBIDMS_p dms, const char* indexer_name);
|
||||
|
||||
|
||||
void obi_dms_list_indexer(OBIDMS_p dms, Obi_indexer_p indexer);
|
||||
|
||||
|
||||
int obi_dms_unlist_indexer(OBIDMS_p dms, Obi_indexer_p indexer);
|
||||
|
||||
|
||||
char* obi_dms_get_path(OBIDMS_p dms);
|
||||
|
||||
|
||||
/** TODO
|
||||
* @brief Internal function getting the full path of a file or a directory from its
|
||||
* path relative to a directory file descriptor.
|
||||
*
|
||||
* @warning The returned pointer has to be freed by the caller.
|
||||
*
|
||||
* @param directory_file_descriptor The file descriptor for the directory to which
|
||||
* path_name is relative.
|
||||
* @param path_name The path name for the file or directory, relative to directory_file_descriptor.
|
||||
*
|
||||
* @returns A pointer to the full path.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since June 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
char* obi_dms_get_full_path(OBIDMS_p dms, const char* path_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Replacement function for opendirat() : open a directory relative to a directory file descriptor.
|
||||
*
|
||||
* @param directory_file_descriptor The file descriptor for the directory in which the directory should be opened.
|
||||
* @param path_name The path name for the directory to be opened, relative to directory_file_descriptor.
|
||||
*
|
||||
* @returns The file descriptor of the opened directory.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since June 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
DIR* opendir_in_dms(OBIDMS_p dms, const char* path_name);
|
||||
|
||||
|
||||
#endif /* OBIDMS_H_ */
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "obidms.h"
|
||||
#include "obidebug.h"
|
||||
#include "obierrno.h"
|
||||
#include "private_at_functions.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
@ -379,7 +379,7 @@ OBIDMS_taxonomy_p obi_read_taxonomy(OBIDMS_p dms, const char* taxonomy_name, boo
|
||||
|
||||
buffer_size = 2048; // TODO
|
||||
|
||||
main_taxonomy_dir_path = get_full_path(dms, TAXONOMY_DIR_NAME);
|
||||
main_taxonomy_dir_path = obi_dms_get_full_path(dms, TAXONOMY_DIR_NAME);
|
||||
taxonomy_path = (char*) malloc((strlen(main_taxonomy_dir_path) + strlen(taxonomy_name) + strlen(taxonomy_name) + 3)*sizeof(char));
|
||||
if (sprintf(taxonomy_path, "%s/%s/%s", main_taxonomy_dir_path, taxonomy_name, taxonomy_name) < 0)
|
||||
{
|
||||
|
@ -29,7 +29,8 @@
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obilittlebigman.h"
|
||||
#include "obiavl.h"
|
||||
#include "obiblob_indexer.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
@ -518,7 +519,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
const char* elements_names,
|
||||
const char* avl_name,
|
||||
const char* indexer_name,
|
||||
const char* comments
|
||||
)
|
||||
{
|
||||
@ -534,6 +535,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
index_t minimum_line_count;
|
||||
OBIType_t returned_data_type;
|
||||
OBIType_t stored_data_type;
|
||||
char final_indexer_name[INDEXER_MAX_NAME];
|
||||
|
||||
new_column = NULL;
|
||||
|
||||
@ -553,11 +555,13 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
obidebug(1, "\nCan't create column because of invalid data type");
|
||||
return NULL;
|
||||
}
|
||||
if (((data_type == OBI_STR) || (data_type == OBI_SEQ)) && (avl_name == NULL))
|
||||
{
|
||||
obidebug(1, "\nCan't create column because of empty avl name");
|
||||
return NULL;
|
||||
if (((data_type == OBI_STR) || (data_type == OBI_SEQ)) && (strcmp(indexer_name, "") == 0))
|
||||
{ // TODO make function in obiblob_indexer.c and discuss the fact that it's here
|
||||
strcpy(final_indexer_name, column_name);
|
||||
strcat(final_indexer_name, "_indexer");
|
||||
}
|
||||
else
|
||||
strcpy(final_indexer_name, indexer_name);
|
||||
|
||||
returned_data_type = data_type;
|
||||
if ((data_type == OBI_STR) || (data_type == OBI_SEQ))
|
||||
@ -723,19 +727,19 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
if (comments != NULL)
|
||||
strncpy(header->comments, comments, COMMENTS_MAX_LENGTH);
|
||||
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated obi_avl is opened or created
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated obi_indexer is opened or created
|
||||
if ((returned_data_type == OBI_STR) || (returned_data_type == OBI_SEQ))
|
||||
{
|
||||
new_column->avl = obi_create_avl_group(dms, avl_name);
|
||||
// if (avl == NULL) TODO
|
||||
// {
|
||||
// obidebug(1, "\nError opening or creating the aVL tree associated with a column");
|
||||
// munmap(new_column->header, header_size);
|
||||
// close(column_file_descriptor);
|
||||
// free(new_column);
|
||||
// return NULL;
|
||||
// }
|
||||
strncpy(header->avl_name, avl_name, AVL_MAX_NAME);
|
||||
new_column->indexer = obi_indexer(dms, final_indexer_name);
|
||||
if (new_column->indexer == NULL)
|
||||
{
|
||||
obidebug(1, "\nError opening or creating the indexer associated with a column");
|
||||
munmap(new_column->header, header_size);
|
||||
close(column_file_descriptor);
|
||||
free(new_column);
|
||||
return NULL;
|
||||
}
|
||||
strncpy(header->indexer_name, final_indexer_name, INDEXER_MAX_NAME);
|
||||
}
|
||||
|
||||
// Fill the data with NA values
|
||||
@ -744,8 +748,9 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
close(column_file_descriptor);
|
||||
|
||||
// Add in the list of opened columns
|
||||
*(((dms->opened_columns)->columns)+((dms->opened_columns)->nb_opened_columns)) = new_column;
|
||||
((dms->opened_columns)->nb_opened_columns)++;
|
||||
obi_dms_list_column(dms, new_column);
|
||||
|
||||
// Set counter to 1 // TODO Discuss counters
|
||||
new_column->counter = 1;
|
||||
|
||||
return new_column;
|
||||
@ -761,8 +766,6 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
char* column_file_name;
|
||||
int column_file_descriptor;
|
||||
size_t header_size;
|
||||
size_t i;
|
||||
OBIDMS_avl_p avl;
|
||||
|
||||
column = NULL;
|
||||
|
||||
@ -770,7 +773,7 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
column_directory = obi_open_column_directory(dms, column_name);
|
||||
if (column_directory == NULL)
|
||||
{
|
||||
//obidebug(1, "\nError opening a column directory structure");
|
||||
//obidebug(1, "\nError opening a column directory structure"); // TODO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -786,14 +789,12 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
}
|
||||
|
||||
// Check if the column is already in the list of opened columns
|
||||
for (i=0; i < ((dms->opened_columns)->nb_opened_columns); i++)
|
||||
column = obi_dms_get_column_from_list(dms, column_name, version_number);
|
||||
// If it's found, increment its counter and return it
|
||||
if (column != NULL)
|
||||
{
|
||||
if (!strcmp(((*(((dms->opened_columns)->columns)+i))->header)->name, column_name)
|
||||
&& (((*(((dms->opened_columns)->columns)+i))->header)->version == version_number))
|
||||
{ // Found the column already opened, increase its counter and return the column
|
||||
((*(((dms->opened_columns)->columns)+i))->counter)++;
|
||||
return *(((dms->opened_columns)->columns)+i);
|
||||
}
|
||||
(column->counter)++;
|
||||
return column;
|
||||
}
|
||||
|
||||
// Get the column file name
|
||||
@ -876,26 +877,26 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
|
||||
column->writable = false;
|
||||
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated AVL tree is opened
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated indexer is opened
|
||||
if (((column->header)->returned_data_type == OBI_STR) || ((column->header)->returned_data_type == OBI_SEQ))
|
||||
{
|
||||
avl = obi_avl(dms, (column->header)->avl_name);
|
||||
if (avl == NULL)
|
||||
column->indexer = obi_open_indexer(dms, (column->header)->indexer_name);
|
||||
if (column->indexer == NULL)
|
||||
{
|
||||
obidebug(1, "\nError opening the AVL tree associated with a column");
|
||||
obidebug(1, "\nError opening the indexer associated with a column");
|
||||
munmap(column->header, header_size);
|
||||
close(column_file_descriptor);
|
||||
free(column);
|
||||
return NULL;
|
||||
}
|
||||
//column->avl = avl; TODO
|
||||
}
|
||||
|
||||
close(column_file_descriptor);
|
||||
|
||||
// Add in the list of opened columns and set column counter to 1
|
||||
*(((dms->opened_columns)->columns)+((dms->opened_columns)->nb_opened_columns)) = column;
|
||||
((dms->opened_columns)->nb_opened_columns)++;
|
||||
// Add in the list of opened columns
|
||||
obi_dms_list_column(dms, column);
|
||||
|
||||
// Set counter to 1
|
||||
column->counter = 1;
|
||||
|
||||
return column;
|
||||
@ -941,7 +942,7 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
nb_lines,
|
||||
nb_elements_per_line,
|
||||
(column_to_clone->header)->elements_names,
|
||||
(column_to_clone->header)->avl_name,
|
||||
(column_to_clone->header)->indexer_name,
|
||||
(column_to_clone->header)->comments
|
||||
);
|
||||
|
||||
@ -964,18 +965,13 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
}
|
||||
else if (clone_data && (line_selection != NULL))
|
||||
{
|
||||
obidebug(1, "\nCloning data from line selection\n");
|
||||
line_size = obi_sizeof((new_column->header)->stored_data_type) * (new_column->header)->nb_elements_per_line;
|
||||
fprintf(stderr, "\nline size = %ld\n", line_size);
|
||||
for (i=0; i<((line_selection->header)->lines_used); i++)
|
||||
{
|
||||
index = *(((index_t*) (line_selection->data)) + i);
|
||||
fprintf(stderr, "\nindex = %lld, i = %lld\n", index, i);
|
||||
memcpy((new_column->data)+(i*line_size), (column_to_clone->data)+(index*line_size), line_size);
|
||||
fprintf(stderr, "\nmemcpied\n");
|
||||
}
|
||||
(new_column->header)->lines_used = (line_selection->header)->lines_used;
|
||||
obidebug(1, "\nCloned data from line selection\n");
|
||||
}
|
||||
|
||||
// Close column_to_clone
|
||||
@ -991,50 +987,35 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
|
||||
int obi_close_column(OBIDMS_column_p column)
|
||||
{
|
||||
size_t i;
|
||||
bool close_dir;
|
||||
Opened_columns_list_p columns_list;
|
||||
bool close_dir;
|
||||
int ret_val = 0;
|
||||
|
||||
columns_list = (column->dms)->opened_columns;
|
||||
// Truncate the column to the number of lines used if it's not read-only
|
||||
if (column->writable)
|
||||
ret_val = obi_truncate_column(column);
|
||||
|
||||
(column->counter)--;
|
||||
|
||||
if (column->counter == 0)
|
||||
{
|
||||
// Delete from the list of opened columns
|
||||
for (i=0; i < (columns_list)->nb_opened_columns; i++)
|
||||
{
|
||||
if (!strcmp(((*((columns_list->columns)+i))->header)->name, (column->header)->name)
|
||||
&& (((*((columns_list->columns)+i))->header)->version == (column->header)->version))
|
||||
{ // Found the column. Rearrange list
|
||||
(columns_list->nb_opened_columns)--;
|
||||
(columns_list->columns)[i] = (columns_list->columns)[columns_list->nb_opened_columns];
|
||||
}
|
||||
}
|
||||
if (obi_dms_unlist_column(column->dms, column) < 0)
|
||||
ret_val = -1;
|
||||
|
||||
// Close column directory if it was the last column opened from that directory
|
||||
close_dir = 1;
|
||||
for (i=0; i < (columns_list->nb_opened_columns); i++)
|
||||
{
|
||||
if (!strcmp(((*((columns_list->columns)+i))->header)->name, (column->header)->name))
|
||||
{ // Not the last column from that directory
|
||||
close_dir = 0;
|
||||
}
|
||||
}
|
||||
close_dir = obi_dms_is_column_name_in_list(column->dms, (column->header)->name);
|
||||
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated AVL tree is closed TODO
|
||||
// if (((column->header)->returned_data_type == OBI_STR) || ((column->header)->returned_data_type == OBI_SEQ))
|
||||
// {
|
||||
// if (obi_close_avl(column->avl) < 0)
|
||||
// return -1;
|
||||
// }
|
||||
// If the data type is OBI_STR or OBI_SEQ, the associated indexer is closed
|
||||
if (((column->header)->returned_data_type == OBI_STR) || ((column->header)->returned_data_type == OBI_SEQ))
|
||||
if (obi_close_indexer(column->indexer) < 0)
|
||||
ret_val = -1;
|
||||
|
||||
// Munmap data
|
||||
if (munmap(column->data, (column->header)->data_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError munmapping column data");
|
||||
return -1;
|
||||
ret_val = -1;
|
||||
}
|
||||
|
||||
// Munmap header
|
||||
@ -1042,20 +1023,22 @@ int obi_close_column(OBIDMS_column_p column)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError munmapping a column header");
|
||||
return -1;
|
||||
ret_val = -1;
|
||||
}
|
||||
|
||||
free(column);
|
||||
|
||||
// Close column directory
|
||||
if (close_dir)
|
||||
obi_close_column_directory(column->column_directory);
|
||||
if (obi_close_column_directory(column->column_directory) < 0)
|
||||
ret_val = -1;
|
||||
|
||||
free(column);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it necessary to unmap/remap?
|
||||
int obi_truncate_column(OBIDMS_column_p column) // TODO is it necessary to unmap/remap?
|
||||
{
|
||||
size_t file_size;
|
||||
size_t data_size;
|
||||
@ -1230,20 +1213,6 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
||||
}
|
||||
|
||||
|
||||
int obi_truncate_and_close_column(OBIDMS_column_p column)
|
||||
{
|
||||
if (column->writable) // TODO discuss
|
||||
{
|
||||
if (obi_truncate_column_to_lines_used(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
if (obi_close_column(column) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void obi_ini_to_NA_values(OBIDMS_column_p column,
|
||||
index_t first_line_nb,
|
||||
index_t nb_lines)
|
||||
@ -1371,7 +1340,7 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
|
||||
}
|
||||
|
||||
|
||||
int obi_unmap_header(OBIDMS_column_header_p header)
|
||||
int obi_close_header(OBIDMS_column_header_p header)
|
||||
{
|
||||
if (munmap(header, header->header_size) < 0)
|
||||
{
|
||||
@ -1399,7 +1368,7 @@ index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const cha
|
||||
|
||||
element_index = 0;
|
||||
|
||||
name = strtok (elements_names, ";"); // TODO not thread safe, see strtok_r maybe
|
||||
name = strtok(elements_names, ";"); // TODO not thread safe, see strtok_r maybe
|
||||
if (strcmp(element_name, name) == 0)
|
||||
{
|
||||
free(elements_names);
|
||||
@ -1409,7 +1378,7 @@ index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const cha
|
||||
|
||||
while (name != NULL)
|
||||
{
|
||||
name = strtok (NULL, ";"); // TODO not thread safe, see strtok_r maybe
|
||||
name = strtok(NULL, ";"); // TODO not thread safe, see strtok_r maybe
|
||||
if (strcmp(element_name, name) == 0)
|
||||
{
|
||||
free(elements_names);
|
||||
@ -1424,7 +1393,53 @@ index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const cha
|
||||
}
|
||||
|
||||
|
||||
char* obi_column_format_date(time_t date)
|
||||
int obi_column_prepare_to_set_value(OBIDMS_column_p column, index_t line_nb)
|
||||
{
|
||||
// Check if the column is read-only
|
||||
if (!(column->writable))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to set a value in a read-only column");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the file needs to be enlarged
|
||||
while ((line_nb+1) > (column->header)->line_count)
|
||||
{
|
||||
// Enlarge the file
|
||||
if (obi_enlarge_column(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update lines used
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
(column->header)->lines_used = line_nb+1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int obi_column_prepare_to_get_value(OBIDMS_column_p column, index_t line_nb)
|
||||
{
|
||||
if ((line_nb+1) > ((column->header)->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char* obi_column_format_date(time_t date) // TODO put in utils.c
|
||||
{
|
||||
char* formatted_time;
|
||||
struct tm* tmp;
|
||||
|
@ -25,11 +25,9 @@
|
||||
#include "obierrno.h"
|
||||
#include "obilittlebigman.h"
|
||||
#include "obidmscolumndir.h"
|
||||
#include "obiavl.h"
|
||||
#include "obiblob_indexer.h"
|
||||
|
||||
|
||||
#define ONE_IF_ZERO(x) (((x)==0)?1:(x)) /**< If x is equal to 0, x takes the value 1.
|
||||
*/
|
||||
#define ELEMENTS_NAMES_MAX (2048) /**< The maximum length of the list of elements names.
|
||||
*/
|
||||
#define COLUMN_GROWTH_FACTOR (2) /**< The growth factor when a column is enlarged.
|
||||
@ -78,7 +76,7 @@ typedef struct OBIDMS_column_header {
|
||||
*/
|
||||
char name[OBIDMS_COLUMN_MAX_NAME+1]; /**< The column name as a NULL terminated string.
|
||||
*/
|
||||
char avl_name[AVL_MAX_NAME+1]; /**< If there is one, the AVL tree 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.
|
||||
*/
|
||||
@ -98,7 +96,7 @@ typedef struct OBIDMS_column {
|
||||
*/
|
||||
OBIDMS_column_header_p header; /**< A pointer to the header of the column.
|
||||
*/
|
||||
OBIDMS_avl_group_p avl; /**< TODO A pointer to the group of AVL trees associated with the column if there is one.
|
||||
Obi_indexer_p indexer; /**< A pointer to the blob indexer associated with the column if there is one.
|
||||
*/
|
||||
void* data; /**< A `void` pointer to the beginning of the data.
|
||||
*
|
||||
@ -164,7 +162,7 @@ size_t obi_get_platform_header_size();
|
||||
* @brief Creates a column.
|
||||
*
|
||||
* The minimum data size allocated is one memory page, and the data is initialized to the NA value of the OBIType.
|
||||
* If there is an AVL tree associated with the column, it is opened or created if it does not already exist.
|
||||
* If there is an indexer associated with the column, it is opened or created if it does not already exist.
|
||||
*
|
||||
* @warning If there is one element per line, elements_names should be equal to column_name. // TODO change this condition?
|
||||
*
|
||||
@ -174,7 +172,7 @@ size_t obi_get_platform_header_size();
|
||||
* @param nb_lines The number of lines to be stored.
|
||||
* @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 avl_name The name of the AVL tree if there is one associated with the column.
|
||||
* @param indexer_name The name of the indexer if there is one associated with the column.
|
||||
* @param comments Optional comments associated with the column.
|
||||
*
|
||||
* @returns A pointer on the newly created column structure.
|
||||
@ -189,7 +187,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
const char* elements_names,
|
||||
const char* avl_name,
|
||||
const char* indexer_name,
|
||||
const char* comments
|
||||
);
|
||||
|
||||
@ -228,7 +226,7 @@ OBIDMS_column_p obi_clone_column(OBIDMS_p dms, OBIDMS_column_p line_selection, c
|
||||
|
||||
|
||||
/**
|
||||
* @brief Closes a column.
|
||||
* @brief Truncates a column to the number of lines used if it is not read-only and closes it.
|
||||
*
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
*
|
||||
@ -253,7 +251,7 @@ int obi_close_column(OBIDMS_column_p column);
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_truncate_column_to_lines_used(OBIDMS_column_p column);
|
||||
int obi_truncate_column(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/**
|
||||
@ -270,21 +268,6 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column);
|
||||
int obi_enlarge_column(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Truncates a column file to the number of lines used rounded to the nearest
|
||||
* greater multiple of the page size and closes it.
|
||||
*
|
||||
* @param column A pointer on an OBIDMS column.
|
||||
*
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since August 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_truncate_and_close_column(OBIDMS_column_p column);
|
||||
|
||||
|
||||
/*
|
||||
* @brief Sets the data in a column to the NA value of the data OBIType.
|
||||
*
|
||||
@ -328,7 +311,7 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_unmap_header(OBIDMS_column_header_p header);
|
||||
int obi_close_header(OBIDMS_column_header_p header);
|
||||
|
||||
|
||||
/**
|
||||
@ -346,7 +329,15 @@ int obi_unmap_header(OBIDMS_column_header_p header);
|
||||
index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name);
|
||||
|
||||
|
||||
/**
|
||||
// TODO doc
|
||||
int obi_column_prepare_to_set_value(OBIDMS_column_p column, index_t line_nb);
|
||||
|
||||
|
||||
// TODO doc
|
||||
int obi_column_prepare_to_get_value(OBIDMS_column_p column, index_t line_nb);
|
||||
|
||||
|
||||
/** TODO put in utils.c
|
||||
* @brief Formats a date in a way that is easy to read.
|
||||
*
|
||||
* @warning The pointer returned must be freed by the caller.
|
||||
@ -361,8 +352,4 @@ index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const cha
|
||||
char* obi_column_format_date(time_t date);
|
||||
|
||||
|
||||
int obi_select(OBIDMS_column_p lines_column, index_t line_to_grep);
|
||||
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_H_ */
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obiview.h"
|
||||
#include "obitypes.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
@ -32,25 +31,8 @@
|
||||
|
||||
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obibool_t value)
|
||||
{
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the file needs to be enlarged
|
||||
while ((line_nb+1) > (column->header)->line_count)
|
||||
{
|
||||
// Enlarge the file
|
||||
if (obi_enlarge_column(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update lines used
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
(column->header)->lines_used = line_nb+1;
|
||||
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
|
||||
return -1;
|
||||
|
||||
// Set the value
|
||||
*(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||
@ -59,111 +41,31 @@ int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
// Check that the view is not read-only
|
||||
if (view->read_only)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError trying to set a value in a column in a read-only view");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((view->line_selection != NULL) || (!(column->writable)))
|
||||
{
|
||||
// Get the right line number
|
||||
if (column->writable)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
column = obi_view_clone_column(view, (column->header)->name);
|
||||
if (column == NULL)
|
||||
{
|
||||
obidebug(1, "\nError trying to clone a column to modify it");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((line_nb+1) > view->line_count)
|
||||
{
|
||||
if (obi_view_update_lines(view, (line_nb+1)) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > ((column->header)->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column");
|
||||
if (obi_column_prepare_to_get_value(column, line_nb) < 0)
|
||||
return OBIBool_NA;
|
||||
}
|
||||
|
||||
return *(((obibool_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if ((line_nb+1) > (view->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count of the view");
|
||||
return OBIBool_NA;
|
||||
}
|
||||
|
||||
if (view->line_selection)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obibool_t value)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obibool_with_elt_idx_in_view(view, column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
return obi_column_set_obibool_with_elt_idx(column, line_nb, element_idx, value);
|
||||
}
|
||||
|
||||
|
||||
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return OBIBool_NA;
|
||||
|
||||
return obi_column_get_obibool_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, 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);
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obitypes.h"
|
||||
#include "obiview.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -96,79 +95,5 @@ int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb
|
||||
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_BOOL_H_ */
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obiview.h"
|
||||
#include "obitypes.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
@ -32,25 +31,8 @@
|
||||
|
||||
int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obichar_t value)
|
||||
{
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the file needs to be enlarged
|
||||
while ((line_nb+1) > (column->header)->line_count)
|
||||
{
|
||||
// Enlarge the file
|
||||
if (obi_enlarge_column(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update lines used
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
(column->header)->lines_used = line_nb+1;
|
||||
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
|
||||
return -1;
|
||||
|
||||
// Set the value
|
||||
*(((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||
@ -59,111 +41,30 @@ int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
// Check that the view is not read-only
|
||||
if (view->read_only)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError trying to set a value in a column in a read-only view");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((view->line_selection != NULL) || (!(column->writable)))
|
||||
{
|
||||
// Get the right line number
|
||||
if (column->writable)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
column = obi_view_clone_column(view, (column->header)->name);
|
||||
if (column == NULL)
|
||||
{
|
||||
obidebug(1, "\nError trying to clone a column to modify it");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((line_nb+1) > view->line_count)
|
||||
{
|
||||
if (obi_view_update_lines(view, (line_nb+1)) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (obi_column_set_obichar_with_elt_idx(column, line_nb, element_idx, value) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > ((column->header)->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column");
|
||||
if (obi_column_prepare_to_get_value(column, line_nb) < 0)
|
||||
return OBIChar_NA;
|
||||
}
|
||||
|
||||
return *(((obichar_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if ((line_nb+1) > (view->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count of the view");
|
||||
return OBIChar_NA;
|
||||
}
|
||||
|
||||
if (view->line_selection)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
return obi_column_get_obichar_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obichar_t value)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obichar_with_elt_idx(column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obichar_with_elt_idx_in_view(view, column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
return obi_column_set_obichar_with_elt_idx(column, line_nb, element_idx, value);
|
||||
}
|
||||
|
||||
|
||||
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, 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(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obitypes.h"
|
||||
#include "obiview.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -96,79 +95,5 @@ int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb
|
||||
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIChar_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIChar_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_CHAR_H_ */
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obiview.h"
|
||||
#include "obitypes.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
@ -31,25 +30,8 @@
|
||||
|
||||
int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obifloat_t value)
|
||||
{
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the file needs to be enlarged
|
||||
while ((line_nb+1) > (column->header)->line_count)
|
||||
{
|
||||
// Enlarge the file
|
||||
if (obi_enlarge_column(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update lines used
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
(column->header)->lines_used = line_nb+1;
|
||||
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
|
||||
return -1;
|
||||
|
||||
// Set the value
|
||||
*(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||
@ -58,111 +40,31 @@ int obi_column_set_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
// Check that the view is not read-only
|
||||
if (view->read_only)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError trying to set a value in a column in a read-only view");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((view->line_selection != NULL) || (!(column->writable)))
|
||||
{
|
||||
// Get the right line number
|
||||
if (column->writable)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
column = obi_view_clone_column(view, (column->header)->name);
|
||||
if (column == NULL)
|
||||
{
|
||||
obidebug(1, "\nError trying to clone a column to modify it");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((line_nb+1) > view->line_count)
|
||||
{
|
||||
if (obi_view_update_lines(view, (line_nb+1)) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obifloat_t obi_column_get_obifloat_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > ((column->header)->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column");
|
||||
if (obi_column_prepare_to_get_value(column, line_nb) < 0)
|
||||
return OBIFloat_NA;
|
||||
}
|
||||
|
||||
return *(((obifloat_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if ((line_nb+1) > (view->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count of the view");
|
||||
return OBIFloat_NA;
|
||||
}
|
||||
|
||||
if (view->line_selection)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obifloat_t value)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obifloat_with_elt_idx_in_view(view, column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
return obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value);
|
||||
}
|
||||
|
||||
|
||||
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, 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(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obitypes.h"
|
||||
#include "obiview.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -96,79 +95,5 @@ int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_n
|
||||
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIFloat_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIFloat_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_FLOAT_H_ */
|
||||
|
||||
|
@ -31,25 +31,8 @@
|
||||
|
||||
int obi_column_set_index(OBIDMS_column_p column, index_t line_nb, index_t value)
|
||||
{
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the file needs to be enlarged
|
||||
while ((line_nb+1) > (column->header)->line_count)
|
||||
{
|
||||
// Enlarge the file
|
||||
if (obi_enlarge_column(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update lines used
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
(column->header)->lines_used = line_nb+1;
|
||||
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
|
||||
return -1;
|
||||
|
||||
// Set the value
|
||||
*(((index_t*) (column->data)) + line_nb) = value;
|
||||
@ -60,12 +43,8 @@ int obi_column_set_index(OBIDMS_column_p column, index_t line_nb, index_t value)
|
||||
|
||||
index_t obi_column_get_index(OBIDMS_column_p column, index_t line_nb)
|
||||
{
|
||||
if ((line_nb+1) > ((column->header)->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column");
|
||||
if (obi_column_prepare_to_get_value(column, line_nb) < 0)
|
||||
return OBIIdx_NA;
|
||||
}
|
||||
|
||||
return *(((index_t*) (column->data)) + line_nb);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "obidmscolumn.h"
|
||||
#include "obitypes.h"
|
||||
|
||||
// TODO doc
|
||||
|
||||
int obi_column_set_index(OBIDMS_column_p column, index_t line_nb, index_t value);
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obiview.h"
|
||||
#include "obitypes.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
@ -29,28 +28,10 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, obiint_t value)
|
||||
{
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the file needs to be enlarged
|
||||
while ((line_nb+1) > (column->header)->line_count)
|
||||
{
|
||||
// Enlarge the file
|
||||
if (obi_enlarge_column(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update lines used
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
(column->header)->lines_used = line_nb+1;
|
||||
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
|
||||
return -1;
|
||||
|
||||
// Set the value
|
||||
*(((obiint_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = value;
|
||||
@ -59,112 +40,31 @@ int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
// Check that the view is not read-only
|
||||
if (view->read_only)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError trying to set a value in a column in a read-only view");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((view->line_selection != NULL) || (!(column->writable)))
|
||||
{
|
||||
// Get the right line number
|
||||
if (column->writable)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
column = obi_view_clone_column(view, (column->header)->name);
|
||||
if (column == NULL)
|
||||
{
|
||||
obidebug(1, "\nError trying to clone a column to modify it");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((line_nb+1) > view->line_count)
|
||||
{
|
||||
if (obi_view_update_lines(view, (line_nb+1)) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (obi_column_set_obiint_with_elt_idx(column, line_nb, element_idx, value) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
if ((line_nb+1) > ((column->header)->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column");
|
||||
if (obi_column_prepare_to_get_value(column, line_nb) < 0)
|
||||
return OBIInt_NA;
|
||||
}
|
||||
|
||||
return *(((obiint_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if ((line_nb+1) > (view->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count of the view");
|
||||
return OBIInt_NA;
|
||||
}
|
||||
|
||||
if (view->line_selection)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
return obi_column_get_obiint_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, obiint_t value)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obiint_with_elt_idx(column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obiint_with_elt_idx_in_view(view, column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
return obi_column_set_obiint_with_elt_idx(column, line_nb, element_idx, value);
|
||||
}
|
||||
|
||||
|
||||
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, 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(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obitypes.h"
|
||||
#include "obiview.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -96,79 +95,5 @@ int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb,
|
||||
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_INT, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_INT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_INT_H_ */
|
||||
|
||||
|
@ -14,11 +14,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obiview.h"
|
||||
#include "obitypes.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obiavl.h"
|
||||
#include "dna_seq_indexer.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
@ -30,104 +29,31 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value)
|
||||
int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value)
|
||||
{
|
||||
byte_t* value_b;
|
||||
index_t idx;
|
||||
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the file needs to be enlarged
|
||||
while ((line_nb+1) > (column->header)->line_count)
|
||||
{
|
||||
// Enlarge the file
|
||||
if (obi_enlarge_column(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update lines used
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
(column->header)->lines_used = line_nb+1;
|
||||
|
||||
// Encode the value on a byte array with a header
|
||||
value_b = obi_seq_to_obibytes(value);
|
||||
if (value_b == NULL)
|
||||
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
|
||||
return -1;
|
||||
|
||||
//if (strlen(value_b) == 0)
|
||||
// fprintf(stderr, "\nPOUIC");
|
||||
|
||||
//fprintf(stderr, "\n>%s||%s", value, obi_obibytes_to_seq(value_b));
|
||||
|
||||
// Add in the AVL tree
|
||||
idx = insert_in_avl_group(column->avl, value_b);
|
||||
// Add the value in the indexer
|
||||
idx = obi_index_dna_seq(column->indexer, value);
|
||||
if (idx == -1)
|
||||
return -1;
|
||||
|
||||
// Add the value's index in the column
|
||||
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;
|
||||
|
||||
free(value_b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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, char* value)
|
||||
{
|
||||
// Check that the view is not read-only
|
||||
if (view->read_only)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError trying to set a value in a column in a read-only view");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((view->line_selection != NULL) || (!(column->writable)))
|
||||
{
|
||||
// Get the right line number
|
||||
if (column->writable)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
column = obi_view_clone_column(view, (column->header)->name);
|
||||
if (column == NULL)
|
||||
{
|
||||
obidebug(1, "\nError trying to clone a column to modify it");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((line_nb+1) > view->line_count)
|
||||
{
|
||||
if (obi_view_update_lines(view, (line_nb+1)) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (obi_column_set_obiseq_with_elt_idx(column, line_nb, element_idx, value) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
index_t idx;
|
||||
byte_t* value_b;
|
||||
|
||||
if ((line_nb+1) > ((column->header)->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column");
|
||||
if (obi_column_prepare_to_get_value(column, line_nb) < 0)
|
||||
return OBISeq_NA;
|
||||
}
|
||||
|
||||
idx = *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
|
||||
@ -135,68 +61,26 @@ const char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t l
|
||||
if (idx == OBIIdx_NA)
|
||||
return OBISeq_NA;
|
||||
|
||||
value_b = obi_avl_group_get(column->avl, idx);
|
||||
|
||||
return obi_obibytes_to_seq(value_b);
|
||||
return obi_retrieve_dna_seq(column->indexer, idx);
|
||||
}
|
||||
|
||||
|
||||
const 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)
|
||||
int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value)
|
||||
{
|
||||
if ((line_nb+1) > (view->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count of the view");
|
||||
return OBISeq_NA;
|
||||
}
|
||||
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
|
||||
if (view->line_selection)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
return obi_column_set_obiseq_with_elt_idx(column, line_nb, element_idx, value);
|
||||
}
|
||||
|
||||
|
||||
char* obi_column_get_obiseq_with_elt_name(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(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obiseq_with_elt_idx(column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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, char* value)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obiseq_with_elt_idx_in_view(view, column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
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(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
const 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)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences in an AVL tree, using the index of the element in the line.
|
||||
* to DNA sequences handled by an indexer, and using the index of the element in the column's line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
@ -40,12 +40,12 @@
|
||||
* @since November 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value);
|
||||
int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences in an AVL tree, using the index of the element in the line.
|
||||
* to DNA sequences handled by an indexer, and using the index of the element in the column's line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column().
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
@ -57,12 +57,12 @@ int obi_column_set_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
|
||||
* @since November 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx);
|
||||
char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences in an AVL tree, using the name of the element in the line.
|
||||
* to DNA sequences handled by an indexer, using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
@ -78,12 +78,12 @@ const char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column, index_t l
|
||||
* @since November 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value);
|
||||
int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences in an AVL tree, using the name of the element in the line.
|
||||
* to DNA sequences handled by an indexer, using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
@ -95,83 +95,7 @@ int obi_column_set_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb,
|
||||
* @since November 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const char* obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences in an AVL tree, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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, char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences in an AVL tree, using the index of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since February 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const 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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences in an AVL tree, using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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, char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences in an AVL tree, using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @since February 2016
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
const 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_column_get_obiseq_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_SEQ_H_ */
|
||||
|
@ -14,11 +14,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "obidmscolumn.h"
|
||||
#include "obiview.h"
|
||||
#include "obitypes.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obiavl.h"
|
||||
#include "char_str_indexer.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
@ -30,83 +29,21 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value)
|
||||
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value)
|
||||
{
|
||||
byte_t* value_b;
|
||||
index_t idx;
|
||||
|
||||
// Check that the line number is not greater than the maximum allowed
|
||||
if (line_nb >= MAXIMUM_LINE_COUNT)
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to set a value at a line number greater than the maximum allowed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the file needs to be enlarged
|
||||
while ((line_nb+1) > (column->header)->line_count)
|
||||
{
|
||||
// Enlarge the file
|
||||
if (obi_enlarge_column(column) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update lines used
|
||||
if ((line_nb+1) > (column->header)->lines_used)
|
||||
(column->header)->lines_used = line_nb+1;
|
||||
|
||||
// Encode the value on a byte array with a header
|
||||
value_b = obi_str_to_obibytes(value);
|
||||
if (value_b == NULL)
|
||||
if (obi_column_prepare_to_set_value(column, line_nb) < 0)
|
||||
return -1;
|
||||
|
||||
// Add in the AVL tree
|
||||
idx = insert_in_avl_group(column->avl, value_b);
|
||||
// Add the value in the indexer
|
||||
idx = obi_index_char_str(column->indexer, value);
|
||||
if (idx == -1)
|
||||
return -1;
|
||||
|
||||
// Add the value's index in the column
|
||||
*(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx) = idx;
|
||||
|
||||
free(value_b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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, char* value)
|
||||
{
|
||||
// Check that the view is not read-only
|
||||
if (view->read_only)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError trying to set a value in a column in a read-only view");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((view->line_selection != NULL) || (!(column->writable)))
|
||||
{
|
||||
// Get the right line number
|
||||
if (column->writable)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
column = obi_view_clone_column(view, (column->header)->name);
|
||||
if (column == NULL)
|
||||
{
|
||||
obidebug(1, "\nError trying to clone a column to modify it");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((line_nb+1) > view->line_count)
|
||||
{
|
||||
if (obi_view_update_lines(view, (line_nb+1)) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -114,14 +51,9 @@ 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(OBIDMS_column_p column, index_t line_nb, index_t element_idx)
|
||||
{
|
||||
index_t idx;
|
||||
byte_t* value_b;
|
||||
|
||||
if ((line_nb+1) > ((column->header)->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current number of lines used in the column");
|
||||
return OBIStr_NA;
|
||||
}
|
||||
if (obi_column_prepare_to_get_value(column, line_nb) < 0)
|
||||
return OBISeq_NA;
|
||||
|
||||
idx = *(((index_t*) (column->data)) + (line_nb * ((column->header)->nb_elements_per_line)) + element_idx);
|
||||
|
||||
@ -129,68 +61,26 @@ const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t l
|
||||
if (idx == OBIIdx_NA)
|
||||
return OBIStr_NA;
|
||||
|
||||
value_b = obi_avl_group_get(column->avl, idx);
|
||||
|
||||
return obi_obibytes_to_str(value_b);
|
||||
return obi_retrieve_char_str(column->indexer, idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value)
|
||||
{
|
||||
if ((line_nb+1) > (view->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count of the view");
|
||||
return OBIStr_NA;
|
||||
}
|
||||
|
||||
if (view->line_selection)
|
||||
line_nb = *(((index_t*) ((view->line_selection)->data)) + line_nb);
|
||||
|
||||
return obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
index_t element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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, char* value)
|
||||
{
|
||||
index_t element_idx;
|
||||
element_idx = obi_column_get_element_index_from_name(column, element_name);
|
||||
if (element_idx == OBIIdx_NA)
|
||||
return -1;
|
||||
obi_column_set_obistr_with_elt_idx_in_view(view, column, line_nb, element_idx, value);
|
||||
return 0;
|
||||
return obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value);
|
||||
}
|
||||
|
||||
|
||||
const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
element_idx = obi_column_get_element_index_from_name(column, 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(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
index_t element_idx;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an AVL tree, using the index of the element in the line.
|
||||
* to character strings handled by an indexer, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
@ -40,12 +40,12 @@
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, char* value);
|
||||
int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb, index_t element_idx, const char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an AVL tree, using the index of the element in the line.
|
||||
* to character strings handled by an indexer, using the index of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column().
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
@ -62,7 +62,7 @@ const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t l
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an AVL tree, using the name of the element in the line.
|
||||
* to character strings handled by an indexer, using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
@ -78,12 +78,12 @@ const char* obi_column_get_obistr_with_elt_idx(OBIDMS_column_p column, index_t l
|
||||
* @since October 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, char* value);
|
||||
int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name, const char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an AVL tree, using the name of the element in the line.
|
||||
* to character strings handled by an indexer, using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_column().
|
||||
* @param line_nb The number of the line where the value should be recovered.
|
||||
@ -98,81 +98,5 @@ int obi_column_set_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb,
|
||||
const char* obi_column_get_obistr_with_elt_name(OBIDMS_column_p column, index_t line_nb, const char* element_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an AVL tree, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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, char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an AVL tree, using the index of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an AVL tree, using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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, char* value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings in an AVL tree, using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
#endif /* OBIDMSCOLUMN_STR_H_ */
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include "obidmscolumndir.h"
|
||||
#include "obidms.h"
|
||||
#include "private_at_functions.h"
|
||||
#include "utils.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
|
||||
@ -105,7 +105,7 @@ int obi_column_directory_exists(OBIDMS_p dms, const char* column_name)
|
||||
return -1;
|
||||
|
||||
// Get the full path for the column directory
|
||||
full_path = get_full_path(dms, column_directory_name);
|
||||
full_path = obi_dms_get_full_path(dms, column_directory_name);
|
||||
if (full_path == NULL)
|
||||
{
|
||||
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
|
||||
|
@ -98,12 +98,22 @@ extern int obi_errno;
|
||||
*/
|
||||
#define OBICOL_ACCESS_ERROR (19) /**< Permission error trying to access an OBIDSM column directory
|
||||
*/
|
||||
#define OBI_AVL_ERROR (20) /** Error while handling an AVL tree
|
||||
#define OBI_AVL_ERROR (20) /** Error while handling an AVL tree // TODO delete and just keep OBI_INDEXER_ERROR?
|
||||
*/
|
||||
#define OBIVIEW_ERROR (21) /** Error while handling an OBIView
|
||||
*/
|
||||
#define OBI_TAXONOMY_ERROR (22) /** Error while handling binary taxonomy files
|
||||
*/
|
||||
#define OBI_MALLOC_ERROR (23) /** Error while allocating memory
|
||||
*/
|
||||
#define OBI_ENCODE_ERROR (24) /** Error while encoding a value
|
||||
*/
|
||||
#define OBI_DECODE_ERROR (25) /** Error while decoding a value
|
||||
*/
|
||||
#define OBI_UTILS_ERROR (26) /** Error in a utils function
|
||||
*/
|
||||
#define OBI_INDEXER_ERROR (27) /** Error handling a blob indexer
|
||||
*/
|
||||
/**@}*/
|
||||
|
||||
#endif /* OBIERRNO_H_ */
|
||||
|
@ -59,8 +59,7 @@ typedef char obichar_t;
|
||||
// TODO same for obistr_t and obiseq_t ?
|
||||
|
||||
|
||||
typedef char byte_t; /**< Defining byte type since the data referred to by AVL trees is stored in bits
|
||||
* and char (stored on one byte) is the smallest addressable unit.
|
||||
typedef char byte_t; /**< Defining byte type.
|
||||
*/
|
||||
|
||||
|
||||
|
316
src/obiview.c
316
src/obiview.c
@ -22,9 +22,15 @@
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obidmscolumn.h"
|
||||
#include "private_at_functions.h"
|
||||
#include "utils.h"
|
||||
#include "obilittlebigman.h"
|
||||
#include "obidmscolumn_idx.h"
|
||||
#include "obidmscolumn_bool.h"
|
||||
#include "obidmscolumn_char.h"
|
||||
#include "obidmscolumn_float.h"
|
||||
#include "obidmscolumn_int.h"
|
||||
#include "obidmscolumn_seq.h"
|
||||
#include "obidmscolumn_str.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
@ -73,6 +79,14 @@ static char* build_obiview_file_name();
|
||||
int create_obiview_file(int dms_file_descriptor);
|
||||
|
||||
|
||||
// TODO doc
|
||||
int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, index_t* line_nb_p);
|
||||
|
||||
|
||||
// TODO doc
|
||||
int prepare_to_get_value_in_column(Obiview_p view, OBIDMS_column_p column, index_t* line_nb_p);
|
||||
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* 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
|
||||
@ -203,6 +217,58 @@ int create_obiview_file(int dms_file_descriptor)
|
||||
}
|
||||
|
||||
|
||||
int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, index_t* line_nb_p)
|
||||
{
|
||||
// Check that the view is not read-only
|
||||
if (view->read_only)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError trying to set a value in a column in a read-only view");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// If there is a line selection associated with the view or if the column
|
||||
// is read-only, all columns or this column respectively must be cloned
|
||||
if ((view->line_selection != NULL) || (!((*column_pp)->writable)))
|
||||
{
|
||||
// Get the right line number
|
||||
if (view->line_selection != NULL)
|
||||
(*line_nb_p) = *(((index_t*) ((view->line_selection)->data)) + (*line_nb_p));
|
||||
|
||||
(*column_pp) = obi_view_clone_column(view, ((*column_pp)->header)->name);
|
||||
if ((*column_pp) == NULL)
|
||||
{
|
||||
obidebug(1, "\nError trying to clone a column to modify it");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (((*line_nb_p)+1) > view->line_count)
|
||||
{
|
||||
if (obi_view_update_lines(view, ((*line_nb_p)+1)) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int prepare_to_get_value_from_column(Obiview_p view, OBIDMS_column_p column, index_t* line_nb_p)
|
||||
{
|
||||
if (((*line_nb_p)+1) > (view->line_count))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError trying to get a value that is beyond the current line count of the view");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (view->line_selection)
|
||||
(*line_nb_p) = *(((index_t*) ((view->line_selection)->data)) + (*line_nb_p));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
*
|
||||
* 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
|
||||
@ -233,19 +299,19 @@ 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, NUC_SEQUENCE_AVL, "Nucleotide sequences", true) < 0)
|
||||
if (obi_view_add_column(view, NUC_SEQUENCE_COLUMN, -1, OBI_SEQ, 0, 1, NUC_SEQUENCE_COLUMN, NUC_SEQUENCE_INDEXER, "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, ID_AVL, "Ids", true) < 0)
|
||||
if (obi_view_add_column(view, ID_COLUMN, -1, OBI_STR, 0, 1, ID_COLUMN, ID_INDEXER, "Ids", true) < 0)
|
||||
{
|
||||
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
|
||||
return NULL;
|
||||
}
|
||||
// Adding description column
|
||||
if (obi_view_add_column(view, DESCRIPTION_COLUMN, -1, OBI_STR, 0, 1, DESCRIPTION_COLUMN, DESCRIPTION_AVL, "Descriptions", true) < 0)
|
||||
if (obi_view_add_column(view, DESCRIPTION_COLUMN, -1, OBI_STR, 0, 1, DESCRIPTION_COLUMN, DESCRIPTION_INDEXER, "Descriptions", true) < 0)
|
||||
{
|
||||
obidebug(1, "Error adding an obligatory column in a nucleotide sequences view");
|
||||
return NULL;
|
||||
@ -696,7 +762,7 @@ int obi_view_add_column(Obiview_p view,
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
const char* elements_names,
|
||||
const char* avl_name,
|
||||
const char* indexer_name,
|
||||
const char* comments,
|
||||
bool create) // all infos for creation or open
|
||||
{
|
||||
@ -718,7 +784,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, avl_name, comments);
|
||||
column = obi_create_column(view->dms, column_name, data_type, nb_lines, nb_elements_per_line, elements_names, indexer_name, comments);
|
||||
}
|
||||
else
|
||||
{ // Open column
|
||||
@ -777,18 +843,18 @@ OBIDMS_column_p obi_view_clone_column(Obiview_p view, const char* column_name)
|
||||
if (!(strcmp((((view->columns)[i])->header)->name, column_name)))
|
||||
column = (view->columns)[i];
|
||||
else
|
||||
obi_truncate_and_close_column(column_buffer); // TODO weird closing after cloning but can't think of cleaner yet
|
||||
obi_close_column(column_buffer); // TODO weird closing after cloning but can't think of cleaner yet
|
||||
}
|
||||
}
|
||||
|
||||
if (view->line_selection != NULL)
|
||||
{
|
||||
obi_truncate_and_close_column(view->line_selection);
|
||||
obi_close_column(view->line_selection);
|
||||
view->line_selection = NULL;
|
||||
}
|
||||
if (view->new_line_selection != NULL)
|
||||
{
|
||||
obi_truncate_and_close_column(view->new_line_selection);
|
||||
obi_close_column(view->new_line_selection);
|
||||
view->new_line_selection = NULL;
|
||||
}
|
||||
|
||||
@ -817,7 +883,7 @@ int obi_view_delete_column(Obiview_p view, const char* column_name)
|
||||
{
|
||||
if (!strcmp((((view->columns)[i])->header)->name, column_name))
|
||||
{
|
||||
obi_truncate_and_close_column((view->columns)[i]);
|
||||
obi_close_column((view->columns)[i]);
|
||||
found = 1;
|
||||
}
|
||||
if (found)
|
||||
@ -985,7 +1051,7 @@ int obi_save_view(Obiview_p view)
|
||||
return -1;
|
||||
|
||||
// Get the full path for the column directory
|
||||
full_path = get_full_path(view->dms, view_file_name);
|
||||
full_path = obi_dms_get_full_path(view->dms, view_file_name);
|
||||
if (full_path == NULL)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
@ -1148,3 +1214,231 @@ int obi_save_and_close_view(Obiview_p view)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*********** 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)
|
||||
{
|
||||
if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0)
|
||||
return -1;
|
||||
return obi_column_set_obibool_with_elt_idx(column, 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)
|
||||
{
|
||||
if (prepare_to_get_value_from_column(view, column, &line_nb) < 0)
|
||||
return OBIBool_NA;
|
||||
return obi_column_get_obibool_with_elt_idx(column, 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)
|
||||
{
|
||||
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_obibool_with_elt_idx_in_view(view, column, 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)
|
||||
{
|
||||
index_t element_idx = obi_column_get_element_index_from_name(column, 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);
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
||||
|
||||
/*********** 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)
|
||||
{
|
||||
if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0)
|
||||
return -1;
|
||||
return obi_column_set_obichar_with_elt_idx(column, line_nb, element_idx, value);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if (prepare_to_get_value_from_column(view, column, &line_nb) < 0)
|
||||
return OBIChar_NA;
|
||||
return obi_column_get_obichar_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
||||
|
||||
/*********** 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)
|
||||
{
|
||||
if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0)
|
||||
return -1;
|
||||
return obi_column_set_obifloat_with_elt_idx(column, line_nb, element_idx, value);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if (prepare_to_get_value_from_column(view, column, &line_nb) < 0)
|
||||
return OBIFloat_NA;
|
||||
return obi_column_get_obifloat_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
||||
|
||||
/*********** 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)
|
||||
{
|
||||
if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0)
|
||||
return -1;
|
||||
return obi_column_set_obiint_with_elt_idx(column, line_nb, element_idx, value);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if (prepare_to_get_value_from_column(view, column, &line_nb) < 0)
|
||||
return OBIInt_NA;
|
||||
return obi_column_get_obiint_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
||||
|
||||
/*********** 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)
|
||||
{
|
||||
if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0)
|
||||
return -1;
|
||||
return obi_column_set_obiseq_with_elt_idx(column, line_nb, element_idx, value);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if (prepare_to_get_value_from_column(view, column, &line_nb) < 0)
|
||||
return OBISeq_NA;
|
||||
return obi_column_get_obiseq_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
||||
|
||||
/*********** 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)
|
||||
{
|
||||
if (prepare_to_set_value_in_column(view, &column, &line_nb) < 0)
|
||||
return -1;
|
||||
return obi_column_set_obistr_with_elt_idx(column, line_nb, element_idx, value);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if (prepare_to_get_value_from_column(view, column, &line_nb) < 0)
|
||||
return OBIStr_NA;
|
||||
return obi_column_get_obistr_with_elt_idx(column, line_nb, element_idx);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
||||
|
459
src/obiview.h
459
src/obiview.h
@ -37,13 +37,13 @@
|
||||
#define VIEW_TYPE_NUC_SEQS "NUC_SEQS_VIEW"
|
||||
|
||||
#define NUC_SEQUENCE_COLUMN "NUC_SEQ"
|
||||
#define NUC_SEQUENCE_AVL "NUC_SEQ_AVL"
|
||||
#define NUC_SEQUENCE_INDEXER "NUC_SEQ_INDEXER"
|
||||
|
||||
#define ID_COLUMN "ID"
|
||||
#define ID_AVL "ID_AVL"
|
||||
#define ID_INDEXER "ID_INDEXER"
|
||||
|
||||
#define DESCRIPTION_COLUMN "DESCRIPTION"
|
||||
#define DESCRIPTION_AVL "DESCRIPTION_AVL"
|
||||
#define DESCRIPTION_INDEXER "DESCRIPTION_INDEXER"
|
||||
|
||||
#define LINES_COLUMN_NAME "LINES"
|
||||
|
||||
@ -162,7 +162,7 @@ int obi_view_add_column(Obiview_p view,
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
const char* elements_names,
|
||||
const char* avl_name,
|
||||
const char* indexer_name,
|
||||
const char* comments,
|
||||
bool create);
|
||||
|
||||
@ -186,4 +186,455 @@ int obi_close_view(Obiview_p view);
|
||||
|
||||
int obi_save_and_close_view(Obiview_p view);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_BOOL,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_BOOL,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIChar_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_CHAR,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_CHAR,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIChar_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIFloat_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_FLOAT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_FLOAT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIFloat_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_INT, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data with the type OBI_INT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data with the type OBI_INT,
|
||||
* using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval OBIBool_NA the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences handled by an indexer, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences handled by an indexer, using the index of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences handled by an indexer, using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to DNA sequences handled by an indexer, using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings handled by an indexer, using the index of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings handled by an indexer, using the index of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings handled by an indexer, using the name of the element in the line.
|
||||
*
|
||||
* @warning Pointers returned by obi_open_column() don't allow writing.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns An integer value indicating the success of the operation.
|
||||
* @retval 0 on success.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Recovers a value in an OBIDMS column containing data in the form of indices referring
|
||||
* to character strings handled by an indexer, using the name of the element in the line.
|
||||
*
|
||||
* @param column A pointer as returned by obi_create_column() or obi_clone_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.
|
||||
*
|
||||
* @returns The recovered value.
|
||||
* @retval '\0' the NA value of the type if an error occurred and obi_errno is set.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
||||
#endif /* OBIVIEW_H_ */
|
||||
|
@ -1,76 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Private *at functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file private_at_functions.c
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
* @date 15 June 2015
|
||||
* @brief Private replacement functions for *at functions.
|
||||
*/
|
||||
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "private_at_functions.h"
|
||||
#include "obidebug.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidms.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
char* get_full_path(OBIDMS_p dms, const char* path_name)
|
||||
{
|
||||
char* full_path;
|
||||
|
||||
full_path = (char*) malloc((MAX_PATH_LEN)*sizeof(char));
|
||||
if (full_path == NULL)
|
||||
{
|
||||
obidebug(1, "\nError allocating memory for the char* path to a file or directory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (getcwd(full_path, MAX_PATH_LEN) == NULL)
|
||||
{
|
||||
obidebug(1, "\nError getting the path to a file or directory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO check errors?
|
||||
strcat(full_path, "/");
|
||||
strcat(full_path, dms->directory_name);
|
||||
strcat(full_path, "/");
|
||||
strcat(full_path, path_name);
|
||||
|
||||
return full_path;
|
||||
}
|
||||
|
||||
|
||||
DIR* opendir_in_dms(OBIDMS_p dms, const char* path_name)
|
||||
{
|
||||
char* full_path;
|
||||
DIR* directory;
|
||||
|
||||
full_path = get_full_path(dms, path_name);
|
||||
if (full_path == NULL)
|
||||
return NULL;
|
||||
|
||||
directory = opendir(full_path);
|
||||
if (directory == NULL)
|
||||
obidebug(1, "\nError opening a directory");
|
||||
|
||||
free(full_path);
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
|
@ -1,59 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Header file for private *at functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file private_at_functions.h
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
* @date 15 June 2015
|
||||
* @brief Header file for the private replacement functions for *at functions.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PRIVATE_OPENAT_H_
|
||||
#define PRIVATE_OPENAT_H_
|
||||
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "obidms.h"
|
||||
|
||||
#define MAX_PATH_LEN 4096 /**< Maximum length for the character string defining a
|
||||
file or directory path */
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal function getting the full path of a file or a directory from its
|
||||
* path relative to a directory file descriptor.
|
||||
*
|
||||
* @warning The returned pointer has to be freed by the caller.
|
||||
*
|
||||
* @param directory_file_descriptor The file descriptor for the directory to which
|
||||
* path_name is relative.
|
||||
* @param path_name The path name for the file or directory, relative to directory_file_descriptor.
|
||||
*
|
||||
* @returns A pointer to the full path.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since June 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
char* get_full_path(OBIDMS_p dms, const char* path_name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Replacement function for opendirat() : open a directory relative to a directory file descriptor.
|
||||
*
|
||||
* @param directory_file_descriptor The file descriptor for the directory in which the directory should be opened.
|
||||
* @param path_name The path name for the directory to be opened, relative to directory_file_descriptor.
|
||||
*
|
||||
* @returns The file descriptor of the opened directory.
|
||||
* @retval NULL if an error occurred.
|
||||
*
|
||||
* @since June 2015
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
DIR* opendir_in_dms(OBIDMS_p dms, const char* path_name);
|
||||
|
||||
|
||||
#endif /* PRIVATEOPENAT_H_ */
|
58
src/utils.c
Normal file
58
src/utils.c
Normal file
@ -0,0 +1,58 @@
|
||||
/****************************************************************************
|
||||
* Utility functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file utils.c
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
* @date 29 March 2016
|
||||
* @brief Code for utility functions.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "obidebug.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidms.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
*
|
||||
* 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
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
int count_dir(char *dir)
|
||||
{
|
||||
struct dirent *dp;
|
||||
DIR *fd;
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
if ((fd = opendir(dir)) == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_UTILS_ERROR);
|
||||
obidebug(1, "Error opening a directory: %s\n", dir);
|
||||
return -1;
|
||||
}
|
||||
while ((dp = readdir(fd)) != NULL)
|
||||
{
|
||||
if ((dp->d_name)[0] == '.')
|
||||
continue;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
32
src/utils.h
Normal file
32
src/utils.h
Normal file
@ -0,0 +1,32 @@
|
||||
/****************************************************************************
|
||||
* Header file for utility functions *
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file utils.h
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
* @date 29 March 2016
|
||||
* @brief Header file for utility functions.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef UTILS_H_
|
||||
#define UTILS_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "obidms.h"
|
||||
|
||||
|
||||
#define ONE_IF_ZERO(x) (((x)==0)?1:(x)) /**< If x is equal to 0, x takes the value 1.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* TODO
|
||||
*/
|
||||
int count_dir(char *dir);
|
||||
|
||||
|
||||
#endif /* UTILS_H_ */
|
Reference in New Issue
Block a user