Strong refactoring 1
This commit is contained in:
@ -10,7 +10,13 @@ from .capi.obidmscolumn cimport obi_close_column, \
|
||||
OBIDMS_column_header_p
|
||||
|
||||
from .capi.obiutils cimport obi_format_date
|
||||
|
||||
|
||||
from .capi.obiview cimport Obiview_p, \
|
||||
Obiview_infos_p, \
|
||||
Alias_column_pair_p, \
|
||||
obi_view_map_file, \
|
||||
obi_view_unmap_file
|
||||
|
||||
from .capi.obitypes cimport const_char_p, \
|
||||
OBIType_t, \
|
||||
OBI_INT, \
|
||||
@ -23,11 +29,6 @@ from .capi.obitypes cimport const_char_p, \
|
||||
name_data_type, \
|
||||
only_ATGC # discuss
|
||||
|
||||
from ._obidms cimport OBIDMS, \
|
||||
OBIDMS_column, \
|
||||
OBIView, \
|
||||
OBIView_line
|
||||
|
||||
from ._obitaxo cimport OBI_Taxonomy
|
||||
|
||||
|
41
python/obitools3/dms/_obidmscolumn.pxd
Normal file
41
python/obitools3/dms/_obidmscolumn.pxd
Normal file
@ -0,0 +1,41 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport OBIDMS_column_p, \
|
||||
OBIDMS_column_header_p, \
|
||||
obi_close_column, \
|
||||
obi_column_prepare_to_get_value
|
||||
|
||||
from .capi.obiview cimport Obiview_p, \
|
||||
obi_view_get_pointer_on_column_in_view
|
||||
|
||||
from .capi.obitypes cimport obiversion_t, \
|
||||
OBIType_t, \
|
||||
index_t, \
|
||||
name_data_type
|
||||
|
||||
from .capi.obiutils cimport obi_format_date
|
||||
|
||||
from ._obiview cimport OBIView
|
||||
|
||||
cdef class OBIDMS_column:
|
||||
|
||||
cdef bytes _alias # associated property: alias
|
||||
cdef OBIDMS_column_p* _pointer
|
||||
cdef OBIView _view
|
||||
|
||||
cpdef close(self)
|
||||
|
||||
@staticmethod
|
||||
cdef type get_subclass_type(OBIDMS_column_p column_p)
|
||||
|
||||
cdef class OBIDMS_column_line:
|
||||
|
||||
cdef OBIDMS_column _column
|
||||
cdef OBIDMS_column_p _column_p
|
||||
cdef OBIDMS_column_p* _column_pp
|
||||
cdef index_t _index
|
||||
cdef int _len
|
||||
|
||||
cpdef update(self, data)
|
||||
|
||||
cdef register_column_class(OBIType_t obitype,type classe)
|
182
python/obitools3/dms/_obidmscolumn.pyx
Normal file
182
python/obitools3/dms/_obidmscolumn.pyx
Normal file
@ -0,0 +1,182 @@
|
||||
#cython: language_level=3
|
||||
|
||||
cdef dict __OBIDMS_COLUMN_CLASS__ = {}
|
||||
|
||||
cdef class Column :
|
||||
"""
|
||||
The OBIDMS.Column class
|
||||
"""
|
||||
|
||||
# Note: should only be initialized through a subclass
|
||||
def __init__(self,
|
||||
View view,
|
||||
object name):
|
||||
'''
|
||||
Create a new OBDMS column objected referring to a already created column
|
||||
in the context of a view.
|
||||
|
||||
This constructor is normally only called by subclass constructor.
|
||||
|
||||
@param view: The view object containing the column.
|
||||
@type view: OBIView
|
||||
@param name: The name of the column in the view
|
||||
@type name: a `str` or a `bytes`
|
||||
'''
|
||||
|
||||
cdef OBIDMS_column_p* column_pp
|
||||
|
||||
# Check that the class is only created as a subclass instance
|
||||
if type(self)==Column or not isinstance(self, Column):
|
||||
raise RuntimeError('OBIDMS.Column constructor cannot be called directly')
|
||||
|
||||
column_pp = obi_view_get_pointer_on_column_in_view(view._pointer,
|
||||
tobytes(column_alias))
|
||||
|
||||
# Fill structure
|
||||
self._alias = column_alias
|
||||
self._pointer = column_pp
|
||||
self._view = view
|
||||
|
||||
def __len__(self):
|
||||
'''
|
||||
implements the len() function for the Column class
|
||||
|
||||
@rtype: `int`
|
||||
'''
|
||||
return self.lines_used
|
||||
|
||||
def __sizeof__(self):
|
||||
'''
|
||||
returns the size of the C object wrapped by the Column instance
|
||||
'''
|
||||
cdef OBIDMS_column_header_p header = self._pointer[0].header
|
||||
return header.header_size + header.data_size
|
||||
|
||||
def __iter__(self):
|
||||
cdef index_t line_nb
|
||||
|
||||
for line_nb in range(self.lines_used):
|
||||
yield self[line_nb]
|
||||
|
||||
def __str__(self) :
|
||||
cdef str to_print
|
||||
to_print = ''
|
||||
for line in self :
|
||||
to_print = to_print + str(line) + "\n"
|
||||
return to_print
|
||||
|
||||
def __repr__(self) :
|
||||
return b"%s, original name: %s, version %d, data type: %d" % (
|
||||
self._alias,
|
||||
self.original_name,
|
||||
self.version,
|
||||
self.data_type
|
||||
)
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column((self._pointer)[0]) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
# Column alias property getter and setter
|
||||
@property
|
||||
def alias(self):
|
||||
return self._alias
|
||||
@alias.setter
|
||||
def alias(self, new_alias): # @DuplicatedSignature
|
||||
self._view.change_column_alias(self._alias, new_alias)
|
||||
|
||||
# elements_names property getter
|
||||
@property
|
||||
def elements_names(self):
|
||||
return (((self._pointer)[0].header).elements_names).split(b';')
|
||||
|
||||
# nb_elements_per_line property getter
|
||||
@property
|
||||
def nb_elements_per_line(self):
|
||||
return ((self._pointer)[0].header).nb_elements_per_line
|
||||
|
||||
# data_type property getter
|
||||
@property
|
||||
def data_type(self):
|
||||
return name_data_type(((self._pointer)[0].header).returned_data_type)
|
||||
|
||||
# original_name property getter
|
||||
@property
|
||||
def original_name(self):
|
||||
return ((self._pointer)[0].header).name
|
||||
|
||||
# version property getter
|
||||
@property
|
||||
def version(self):
|
||||
return ((self._pointer)[0].header).version
|
||||
|
||||
# lines_used property getter
|
||||
@property
|
||||
def lines_used(self):
|
||||
return (self._pointer)[0].header.lines_used
|
||||
|
||||
# comments property getter
|
||||
@property
|
||||
def comments(self):
|
||||
return (self._pointer)[0].header.comments
|
||||
|
||||
# creation_date property getter
|
||||
@property
|
||||
def creation_date(self):
|
||||
return obi_format_date((self._pointer)[0].header.creation_date)
|
||||
|
||||
@staticmethod
|
||||
cdef type get_subclass_type(OBIDMS_column_p column_p) :
|
||||
|
||||
cdef type subclass
|
||||
cdef OBIType_t col_type
|
||||
|
||||
col_type = column_p.header.returned_data_type
|
||||
subclass = __OBIDMS_COLUMN_CLASS__[col_type]
|
||||
|
||||
return subclass
|
||||
|
||||
|
||||
|
||||
|
||||
######################################################################################################
|
||||
|
||||
|
||||
cdef class OBIDMS_column_line :
|
||||
|
||||
def __init__(self, OBIDMS_column column, index_t line_nb) :
|
||||
self._index = line_nb
|
||||
self._column = column
|
||||
self._column_pp = column._pointer
|
||||
self._column_p = NULL
|
||||
self._len = self._column_pp[0].header.nb_elements_per_line
|
||||
|
||||
if obi_column_prepare_to_get_value(self._column_pp[0],line_nb) < 0:
|
||||
raise IndexError("Cannot access to the line %d" % line_nb)
|
||||
|
||||
|
||||
def __contains__(self, str element_name):
|
||||
return (element_name in self._column.elements_names)
|
||||
|
||||
def __repr__(self) :
|
||||
return str(self._column.get_line(self._index))
|
||||
|
||||
cpdef update(self, data):
|
||||
if isinstance(data, dict):
|
||||
data=data.items()
|
||||
for key,value in data:
|
||||
if key in self:
|
||||
self[key]=value
|
||||
|
||||
|
||||
######################################################################################################
|
||||
|
||||
|
||||
cdef register_column_class(OBIType_t obitype,type classe):
|
||||
"""
|
||||
Each sub class of `OBIDMS_column` needs to be registered after its declaration
|
||||
to declare its relationship with an `OBIType_t`
|
||||
"""
|
||||
assert issubclass(classe,OBIDMS_column)
|
||||
|
||||
__OBIDMS_COLUMN_CLASS__[obitype]=classe
|
57
python/obitools3/dms/_obidmscolumn_bool.pxd
Normal file
57
python/obitools3/dms/_obidmscolumn_bool.pxd
Normal file
@ -0,0 +1,57 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obiview cimport obi_get_bool_with_elt_name_and_col_p_in_view, \
|
||||
obi_get_bool_with_elt_idx_and_col_p_in_view, \
|
||||
obi_set_bool_with_elt_name_and_col_p_in_view, \
|
||||
obi_set_bool_with_elt_idx_and_col_p_in_view
|
||||
|
||||
from cpython.bool cimport bool, PyBool_FromLong
|
||||
from .capi.obitypes cimport index_t, \
|
||||
const_char_p, \
|
||||
OBIType_t, \
|
||||
obibool_t, \
|
||||
OBI_BOOL, \
|
||||
OBIBool_NA
|
||||
|
||||
from .capi.obierrno cimport obi_errno
|
||||
|
||||
from ._obidmscolumn cimport OBIDMS_column, \
|
||||
OBIDMS_column_line, \
|
||||
OBIDMS_column_p, \
|
||||
register_column_class
|
||||
|
||||
from .capi.obidmscolumn cimport obi_column_get_obibool_with_elt_name, \
|
||||
obi_column_get_obibool_with_elt_idx, \
|
||||
obi_column_set_obibool_with_elt_name, \
|
||||
obi_column_set_obibool_with_elt_idx
|
||||
|
||||
|
||||
from obitools3.utils cimport str2bytes, bytes2str
|
||||
|
||||
cdef class OBIDMS_column_line_bool(OBIDMS_column_line) :
|
||||
cdef update_pointer(self)
|
||||
|
||||
@staticmethod
|
||||
cdef bool obibool_t2bool(obibool_t value)
|
||||
|
||||
@staticmethod
|
||||
cdef bool2obibool_t(bool value)
|
||||
|
||||
cpdef bool get_bool_item_by_name(self,bytes element_name)
|
||||
cpdef bool get_bool_item_by_idx(self,index_t index)
|
||||
cpdef set_bool_item_by_name(self,bytes element_name,bool value)
|
||||
cpdef set_bool_item_by_idx(self,index_t index,bool value)
|
||||
|
||||
|
||||
# cdef obibool_t [:] _data_view
|
||||
|
||||
cdef class OBIDMS_column_bool(OBIDMS_column):
|
||||
cdef OBIDMS_column _new(OBIView view,
|
||||
bytes column_name,
|
||||
index_t nb_elements_per_line=1,
|
||||
object elements_names=None,
|
||||
bytes comments=b""):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
|
294
python/obitools3/dms/_obidmscolumn_bool.pyx
Normal file
294
python/obitools3/dms/_obidmscolumn_bool.pyx
Normal file
@ -0,0 +1,294 @@
|
||||
#cython: language_level=3
|
||||
|
||||
|
||||
cdef class OBIDMS_column_line_bool(OBIDMS_column_line) :
|
||||
|
||||
cdef update_pointer(self):
|
||||
"""
|
||||
Checks if the obicolumn address changed since the last call and update
|
||||
if need the `_column_p` and `_data_view` data structure fields.
|
||||
"""
|
||||
cdef OBIDMS_column_p column_p = self._column_pp[0]
|
||||
|
||||
if column_p != self._column_p:
|
||||
self._column_p = column_p
|
||||
# self._data_view = (<obibool_t*> (column_p.data)) + \
|
||||
# self._index * column_p.header.nb_elements_per_line
|
||||
|
||||
@staticmethod
|
||||
cdef bool obibool_t2bool(obibool_t value):
|
||||
cdef bool result
|
||||
|
||||
if value == OBIBool_NA :
|
||||
result = None
|
||||
else :
|
||||
result = PyBool_FromLong(value)
|
||||
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
cdef bool2obibool_t(bool value):
|
||||
cdef obibool_t result
|
||||
|
||||
if value is None:
|
||||
result=OBIBool_NA
|
||||
else:
|
||||
result= <obibool_t> <int> value
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def __init__(self, OBIDMS_column column, index_t line_nb) :
|
||||
"""
|
||||
Creates a new `OBIDMS_column_line_bool`
|
||||
|
||||
@param column: an OBIDMS_column instance
|
||||
@param line_nb: the line in the column
|
||||
"""
|
||||
|
||||
OBIDMS_column_line.__init__(self,column,line_nb)
|
||||
self.update_pointer()
|
||||
|
||||
|
||||
|
||||
cpdef bool get_bool_item_by_name(self,bytes element_name):
|
||||
"""
|
||||
Returns the value associated to the name `element_name` of the current line
|
||||
|
||||
@param element_name: a `bytes` instance containing the name of the element
|
||||
|
||||
@return: the `bool` value corresponding to the name
|
||||
"""
|
||||
cdef char* cname = element_name
|
||||
cdef obibool_t value
|
||||
global obi_errno
|
||||
|
||||
self.update_pointer()
|
||||
|
||||
value = obi_column_get_obibool_with_elt_name(self._column_p,
|
||||
self._index,
|
||||
cname)
|
||||
|
||||
if obi_errno > 0 :
|
||||
obi_errno = 0
|
||||
raise KeyError("Cannot access to key %s" % bytes2str(element_name))
|
||||
|
||||
return OBIDMS_column_line_bool.obibool_t2bool(value)
|
||||
|
||||
cpdef bool get_bool_item_by_idx(self,index_t index):
|
||||
"""
|
||||
Returns the value associated to the name `element_name` of the current line
|
||||
|
||||
@param index: a `int` instance containing the index of the element
|
||||
|
||||
@return: the `bool` value corresponding to the name
|
||||
"""
|
||||
cdef obibool_t value # @DuplicatedSignature
|
||||
global obi_errno
|
||||
|
||||
|
||||
self.update_pointer()
|
||||
|
||||
value = obi_column_get_obibool_with_elt_idx(self._column_p,
|
||||
self._index,
|
||||
index)
|
||||
|
||||
if obi_errno > 0 :
|
||||
obi_errno = 0
|
||||
raise IndexError("Cannot access to element %d" % index)
|
||||
|
||||
return OBIDMS_column_line_bool.obibool_t2bool(value)
|
||||
|
||||
|
||||
def __getitem__(self, object element_name) :
|
||||
cdef bytes name
|
||||
cdef int cindex
|
||||
cdef obibool_t value
|
||||
cdef type typearg = type(element_name)
|
||||
cdef bool result
|
||||
|
||||
|
||||
if typearg == int:
|
||||
cindex=element_name
|
||||
if cindex < 0:
|
||||
cindex = self._len - cindex
|
||||
result=self.get_bool_item_by_idx(cindex)
|
||||
elif typearg == bytes:
|
||||
result=self.get_bool_item_by_name(element_name)
|
||||
elif typearg == str:
|
||||
name = str2bytes(element_name)
|
||||
result=self.get_bool_item_by_name(name)
|
||||
|
||||
return result
|
||||
|
||||
cpdef set_bool_item_by_name(self,bytes element_name,bool value):
|
||||
"""
|
||||
Sets the value associated to the name `element_name` of the current line
|
||||
|
||||
@param element_name: a `bytes` instance containing the name of the element
|
||||
@param value: a `bool` instance of the new value
|
||||
|
||||
@return: the `bool` value corresponding to the name
|
||||
"""
|
||||
cdef char* cname = element_name
|
||||
cdef obibool_t cvalue
|
||||
|
||||
self.update_pointer()
|
||||
cvalue = OBIDMS_column_line_bool.bool2obibool_t(value)
|
||||
|
||||
if ( obi_column_set_obibool_with_elt_name(self._column_p,
|
||||
self._index,
|
||||
cname,
|
||||
cvalue) < 0 ):
|
||||
raise KeyError("Cannot access to key %s" % bytes2str(element_name))
|
||||
|
||||
cpdef set_bool_item_by_idx(self,index_t index,bool value):
|
||||
"""
|
||||
Sets the value associated to the name `element_name` of the current line
|
||||
|
||||
@param index: a `int` instance containing the index of the element
|
||||
@param value: a `bool` instance of the new value
|
||||
|
||||
@return: the `bool` value corresponding to the name
|
||||
"""
|
||||
cdef obibool_t cvalue # @DuplicatedSignature
|
||||
|
||||
self.update_pointer()
|
||||
cvalue = OBIDMS_column_line_bool.bool2obibool_t(value)
|
||||
|
||||
if ( obi_column_set_obibool_with_elt_idx(self._column_p,
|
||||
self._index,
|
||||
index,
|
||||
cvalue) < 0 ):
|
||||
raise IndexError("Cannot access to item index %d" % index)
|
||||
|
||||
|
||||
|
||||
def __setitem__(self, object element_name, object value):
|
||||
cdef bytes name
|
||||
cdef int cindex
|
||||
cdef type typearg = type(element_name)
|
||||
cdef bool result
|
||||
|
||||
|
||||
if typearg == int:
|
||||
cindex=element_name
|
||||
if cindex < 0:
|
||||
cindex = self._len - cindex
|
||||
self.set_bool_item_by_idx(cindex,value)
|
||||
elif typearg == bytes:
|
||||
self.set_bool_item_by_name(element_name,value)
|
||||
elif typearg == str:
|
||||
name = str2bytes(element_name)
|
||||
self.set_bool_item_by_name(name,value)
|
||||
|
||||
def __repr__(self) :
|
||||
return str(self._column.get_line(self._index))
|
||||
|
||||
def __len__(self):
|
||||
return self._len
|
||||
|
||||
|
||||
|
||||
cdef class OBIDMS_column_bool(OBIDMS_column):
|
||||
|
||||
@staticmethod
|
||||
cdef OBIDMS_column _new(OBIView view,
|
||||
bytes column_name,
|
||||
index_t nb_elements_per_line=1,
|
||||
object elements_names=None,
|
||||
bytes comments=b""):
|
||||
|
||||
cdef bytes elements_names_b
|
||||
cdef char* elements_names_p
|
||||
cdef OBIDMS_column new_column
|
||||
|
||||
if elements_names is not None:
|
||||
elements_names_b = b''.join([tobytes(x) for x in elements_names])
|
||||
elements_names_p = elements_names_b
|
||||
else:
|
||||
elements_names_p = NULL
|
||||
|
||||
if (obi_view_add_column(view = view._pointer,
|
||||
column_name = column_name,
|
||||
version_number = -1,
|
||||
alias = NULL,
|
||||
data_type = OBI_BOOL,
|
||||
nb_lines = len(view),
|
||||
nb_elements_per_line = nb_elements_per_line,
|
||||
elements_names = elements_names_p,
|
||||
indexer_name = NULL,
|
||||
associated_column_name = NULL,
|
||||
associated_column_version = -1,
|
||||
comments = comments,
|
||||
create = True)<0):
|
||||
raise RuntimeError("Cannot create column %s in view %s" % (bytes2str(column_name),
|
||||
bytes2str(view.name)))
|
||||
|
||||
view.__init_columns__()
|
||||
new_column = self._columns[column_name]
|
||||
|
||||
return new_column
|
||||
|
||||
@staticmethod
|
||||
def new(OBIView view,
|
||||
object column_name,
|
||||
index_t nb_elements_per_line=1,
|
||||
object elements_names=None,
|
||||
object comments=b""):
|
||||
|
||||
return OBIDMS_column_bool._new(view,
|
||||
tobytes(column_name),
|
||||
nb_elements_per_line,
|
||||
elements_names,
|
||||
tobytes(comments))
|
||||
|
||||
cpdef add_to_view(self,
|
||||
OBIView view,
|
||||
object column_name=None,
|
||||
object comments=b""):
|
||||
|
||||
cdef OBIDMS_column_p column_p = self._column_pp[0]
|
||||
cdef bytes alias
|
||||
|
||||
if (column_name is None):
|
||||
alias = self._alias
|
||||
else:
|
||||
alias = tobytes(column_name)
|
||||
|
||||
obi_view_add_column(view = view._ponter,
|
||||
column_name = column_p.header.name,
|
||||
version_number = column_p.header.version,
|
||||
alias = alias,
|
||||
data_type = OBI_BOOL,
|
||||
nb_lines = column_p.header.lines_used,
|
||||
nb_elements_per_line = column_p.header.nb_elements_per_line,
|
||||
elements_names = column_p.header.elements_names,
|
||||
indexer_name = NULL,
|
||||
associated_column_name = NULL,
|
||||
associated_column_version = NULL,
|
||||
comments = tobytes(comments),
|
||||
create = False)
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef obibool_t value
|
||||
cdef object result
|
||||
global obi_errno
|
||||
|
||||
value = obi_get_bool_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIBool_NA :
|
||||
result = None
|
||||
else :
|
||||
result = PyBool_FromLong(value)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
if value is None :
|
||||
value = OBIBool_NA
|
||||
if obi_set_bool_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, <obibool_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
|
||||
register_column_class(OBI_BOOL,OBIDMS_column_bool)
|
@ -1,6 +1,6 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from ._obidms cimport OBIView_line
|
||||
from ._obiview cimport OBIView_line
|
||||
|
||||
|
||||
cdef class OBI_Seq(dict) :
|
@ -1,5 +1,9 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport obiversion_t, \
|
||||
index_t, \
|
||||
only_ATGC
|
||||
|
||||
from .capi.obiview cimport Obiview_p, \
|
||||
Obiview_infos_p, \
|
||||
Alias_column_pair_p, \
|
||||
@ -21,45 +25,55 @@ from .capi.obiview cimport Obiview_p, \
|
||||
ID_COLUMN, \
|
||||
DEFINITION_COLUMN, \
|
||||
QUALITY_COLUMN
|
||||
|
||||
from ._obidmscolumn cimport OBIDMS_column_p, \
|
||||
OBIDMS_column
|
||||
|
||||
from ._obidms cimport OBIDMS
|
||||
from obitools3.utils cimport tobytes, \
|
||||
bytes2str, \
|
||||
tostr
|
||||
|
||||
cdef class OBIView:
|
||||
|
||||
cdef OBIDMS _dms
|
||||
cdef Obiview_p _pointer
|
||||
cdef dict _columns
|
||||
|
||||
cdef __init_columns__(self):
|
||||
cdef __init_columns__(self)
|
||||
|
||||
cpdef OBIView clone(self,
|
||||
str view_name,
|
||||
OBIView_line_selection line_selection=*,
|
||||
str comments=*)
|
||||
view_name,
|
||||
comments=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=*)
|
||||
cdef OBIView _new(OBIDMS dms,
|
||||
bytes view_name,
|
||||
bytes comments=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
str view_name)
|
||||
cdef OBIView _open(OBIDMS dms,
|
||||
bytes view_name)
|
||||
|
||||
cpdef delete_column(self, str column_name)
|
||||
cpdef delete_column(self, column_name)
|
||||
cpdef add_column(self,
|
||||
str column_name,
|
||||
obiversion_t version_number=*,
|
||||
str alias=*,
|
||||
str type=*,
|
||||
object alias=*,
|
||||
object type=*,
|
||||
index_t nb_lines=*,
|
||||
index_t nb_elements_per_line=*,
|
||||
list elements_names=*,
|
||||
str indexer_name=*,
|
||||
str associated_column_name=*,
|
||||
object indexer_name=*,
|
||||
object associated_column_name=*,
|
||||
obiversion_t associated_column_version=*,
|
||||
str comments=*,
|
||||
object comments=*,
|
||||
bint create=*
|
||||
)
|
||||
cpdef change_column_alias(self, str current_alias, str new_alias)
|
||||
cpdef update_column_pointers(self)
|
||||
)
|
||||
|
||||
|
||||
cpdef change_column_alias(self, bytes current_alias, bytes new_alias)
|
||||
cdef update_column_pointers(self)
|
||||
|
||||
cpdef OBIView_line_selection new_selection(self,
|
||||
list lines=*)
|
@ -3,84 +3,100 @@
|
||||
|
||||
cdef class OBIView :
|
||||
|
||||
def __init__(self,int __internalCall__):
|
||||
def __init__(self,dms,int __internalCall__):
|
||||
if __internalCall__!=987654:
|
||||
raise RuntimeError('OBIView constructor cannot be called directly')
|
||||
self._dms = dms
|
||||
self._pointer = NULL
|
||||
self._columns = {}
|
||||
|
||||
cdef __init_columns__(self):
|
||||
cdef size_t i
|
||||
cdef str col_alias
|
||||
cdef bytes col_alias
|
||||
cdef OBIDMS_column_p column_p
|
||||
cdef Obiview_p pointer = self._pointer
|
||||
|
||||
self._columns = {}
|
||||
|
||||
for i in range(pointer.infos.column_count) :
|
||||
col_alias = bytes2str(pointer.infos.column_references[i].alias)
|
||||
col_alias = pointer.infos.column_references[i].alias
|
||||
column_p = <OBIDMS_column_p> (pointer.columns)[i]
|
||||
subclass = OBIDMS_column.get_subclass_type(column_p)
|
||||
self._columns[col_alias] = subclass(self, col_alias)
|
||||
|
||||
|
||||
cpdef OBIView clone(self,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
view_name,
|
||||
comments=b""):
|
||||
|
||||
cdef OBIView view = OBIView(987654)
|
||||
cdef OBIView view = OBIView(self._dms,
|
||||
987654)
|
||||
|
||||
view._pointer = obi_new_view(self._pointer.dms,
|
||||
str2bytes(view_name),
|
||||
tobytes(view_name),
|
||||
self._pointer,
|
||||
NULL,
|
||||
str2bytes(comments))
|
||||
tobytes(comments))
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
% (str(self.name),
|
||||
view_name)
|
||||
tobytes(view_name))
|
||||
)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
cdef OBIView _new(OBIDMS dms,
|
||||
bytes view_name,
|
||||
bytes comments=b""):
|
||||
|
||||
cdef OBIView view = OBIView(987654) # @DuplicatedSignature
|
||||
cdef OBIView view = OBIView(dms,
|
||||
987654) # @DuplicatedSignature
|
||||
|
||||
view._pointer = obi_new_view(dms._pointer,
|
||||
str2bytes(view_name),
|
||||
view_name,
|
||||
NULL,
|
||||
NULL,
|
||||
str2bytes(comments))
|
||||
comments)
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot create view %s" % view_name)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
str view_name):
|
||||
def new(OBIDMS dms,
|
||||
view_name,
|
||||
comments=b""):
|
||||
return OBIView._new(dms,tobytes(view_name),tobytes(comments))
|
||||
|
||||
|
||||
@staticmethod
|
||||
cdef OBIView _open(OBIDMS dms,
|
||||
bytes view_name):
|
||||
|
||||
cdef OBIView view = OBIView(987654) # @DuplicatedSignature
|
||||
cdef OBIView view = OBIView(dms,
|
||||
987654) # @DuplicatedSignature
|
||||
|
||||
view._pointer = obi_open_view(dms._pointer,
|
||||
str2bytes(view_name))
|
||||
view_name)
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot open view %s" % view_name)
|
||||
raise RuntimeError("Error : Cannot open view %s" % bytes2str(view_name))
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
@staticmethod
|
||||
def open(OBIDMS dms, # @ReservedAssignment
|
||||
view_name):
|
||||
return OBIView._open(dms,tobytes(view_name))
|
||||
|
||||
def __dealloc__(self):
|
||||
if (obi_save_and_close_view(self._pointer) < 0) :
|
||||
@ -95,46 +111,45 @@ cdef class OBIView :
|
||||
return s
|
||||
|
||||
|
||||
cpdef delete_column(self, str column_name) :
|
||||
cdef str column_n
|
||||
if obi_view_delete_column(self._pointer, str2bytes(column_name)) < 0 :
|
||||
raise Exception("Problem deleting a column from a view")
|
||||
cpdef delete_column(self, column_name) :
|
||||
if obi_view_delete_column(self._pointer, tobytes(column_name)) < 0 :
|
||||
raise Exception("Problem deleting column %s from a view",
|
||||
tostr(column_name))
|
||||
# Update the dictionary of column objects:
|
||||
(self._columns).pop(column_name)
|
||||
self.update_column_pointers()
|
||||
|
||||
|
||||
|
||||
cpdef add_column(self,
|
||||
str column_name,
|
||||
obiversion_t version_number=-1,
|
||||
str alias='',
|
||||
str type='',
|
||||
object alias=None,
|
||||
object type=b'',
|
||||
index_t nb_lines=0,
|
||||
index_t nb_elements_per_line=1,
|
||||
list elements_names=None,
|
||||
str indexer_name="",
|
||||
str associated_column_name="",
|
||||
object indexer_name=b"",
|
||||
object associated_column_name=b"",
|
||||
obiversion_t associated_column_version=-1,
|
||||
str comments="",
|
||||
object comments=b"",
|
||||
bint create=True
|
||||
) :
|
||||
|
||||
cdef bytes column_name_b
|
||||
cdef bytes elements_names_b
|
||||
cdef bytes alias_b
|
||||
cdef object subclass
|
||||
cdef OBIDMS_column_p column_p
|
||||
|
||||
column_name_b = str2bytes(column_name)
|
||||
if alias == '' :
|
||||
alias = column_name
|
||||
column_name_b = tobytes(column_name)
|
||||
if alias is None :
|
||||
alias_b = column_name_b
|
||||
else :
|
||||
alias_b = str2bytes(alias)
|
||||
alias_b = tobytes(alias)
|
||||
|
||||
if elements_names is None :
|
||||
elements_names_b = str2bytes("")
|
||||
elements_names_b = b""
|
||||
else :
|
||||
elements_names_b = str2bytes(';'.join(elements_names))
|
||||
elements_names_b = b';'.join([tobytes(i) for i in elements_names])
|
||||
|
||||
if type : # TODO make C function that does that
|
||||
if type == 'OBI_INT' :
|
||||
@ -169,9 +184,9 @@ cdef class OBIView :
|
||||
(self._columns)[alias] = subclass(self, alias)
|
||||
|
||||
|
||||
cpdef change_column_alias(self, str current_alias, str new_alias):
|
||||
cpdef change_column_alias(self, bytes current_alias, bytes new_alias):
|
||||
cdef OBIDMS_column column
|
||||
if (obi_view_create_column_alias(self._pointer, str2bytes(current_alias), str2bytes(new_alias)) < 0) :
|
||||
if (obi_view_create_column_alias(self._pointer, current_alias, new_alias) < 0) :
|
||||
raise Exception("Problem changing a column alias")
|
||||
# Update the dictionaries of column objects
|
||||
self._columns[new_alias] = self._columns[current_alias]
|
||||
@ -180,7 +195,7 @@ cdef class OBIView :
|
||||
(self._columns).pop(current_alias)
|
||||
|
||||
|
||||
cpdef update_column_pointers(self):
|
||||
cdef update_column_pointers(self):
|
||||
cdef str column_n
|
||||
cdef OBIDMS_column column
|
||||
for column_n in self._columns :
|
||||
@ -227,6 +242,10 @@ cdef class OBIView :
|
||||
return to_print
|
||||
|
||||
|
||||
@property
|
||||
def dms(self):
|
||||
return self._dms
|
||||
|
||||
# line_count property getter
|
||||
@property
|
||||
def line_count(self):
|
||||
@ -317,7 +336,7 @@ cdef class OBIView_line_selection(list):
|
||||
view_name)
|
||||
)
|
||||
|
||||
view.__init_columns__(self)
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
@ -62,9 +62,7 @@ cdef extern from "obidmscolumn.h" nogil:
|
||||
OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
const_char_p column_name,
|
||||
obiversion_t version_number)
|
||||
|
||||
int obi_close_column(OBIDMS_column_p column)
|
||||
|
||||
|
||||
OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
OBIDMS_column_p line_selection,
|
||||
const_char_p column_name,
|
||||
@ -83,6 +81,8 @@ cdef extern from "obidmscolumn.h" nogil:
|
||||
int obi_close_header(OBIDMS_column_header_p header)
|
||||
|
||||
int obi_select(OBIDMS_column_p line_selection_column, index_t line_to_grep)
|
||||
|
||||
int obi_column_prepare_to_get_value(OBIDMS_column_p column, index_t line_nb)
|
||||
|
||||
|
||||
cdef extern from "obidmscolumn_int.h" nogil:
|
5
python/obitools3/dms/capi/obierrno.pxd
Normal file
5
python/obitools3/dms/capi/obierrno.pxd
Normal file
@ -0,0 +1,5 @@
|
||||
#cython: language_level=3
|
||||
|
||||
|
||||
cdef extern from "obierrno.h":
|
||||
int obi_errno
|
@ -1,54 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidmscolumn cimport OBIDMS_column_p
|
||||
from .capi.obiview cimport Obiview_p
|
||||
from .capi.obitypes cimport obiversion_t, OBIType_t, index_t
|
||||
|
||||
|
||||
from ._obidmscolumn_int cimport OBIDMS_column_int, \
|
||||
OBIDMS_column_multi_elts_int
|
||||
|
||||
from ._obidmscolumn_float cimport OBIDMS_column_float, \
|
||||
OBIDMS_column_multi_elts_float
|
||||
|
||||
from ._obidmscolumn_bool cimport OBIDMS_column_bool, \
|
||||
OBIDMS_column_multi_elts_bool
|
||||
|
||||
from ._obidmscolumn_char cimport OBIDMS_column_char, \
|
||||
OBIDMS_column_multi_elts_char
|
||||
|
||||
from ._obidmscolumn_qual cimport OBIDMS_column_qual, \
|
||||
OBIDMS_column_multi_elts_qual
|
||||
|
||||
from ._obidmscolumn_str cimport OBIDMS_column_str, \
|
||||
OBIDMS_column_multi_elts_str
|
||||
|
||||
from ._obidmscolumn_seq cimport OBIDMS_column_seq, \
|
||||
OBIDMS_column_multi_elts_seq
|
||||
|
||||
|
||||
from ._obiview cimport OBIView
|
||||
|
||||
cdef class OBIDMS_column:
|
||||
|
||||
cdef str _alias # associated property: alias
|
||||
cdef OBIDMS_column_p* _pointer
|
||||
cdef OBIView _view
|
||||
|
||||
cpdef close(self)
|
||||
|
||||
@staticmethod
|
||||
cdef object get_subclass_type(OBIDMS_column_p column_p)
|
||||
|
||||
|
||||
cdef class OBIDMS_column_multi_elts(OBIDMS_column):
|
||||
|
||||
cpdef set_line(self, index_t line_nb, dict values)
|
||||
|
||||
|
||||
cdef class OBIDMS_column_line:
|
||||
|
||||
cdef OBIDMS_column _column
|
||||
cdef index_t _index
|
||||
|
||||
cdef register_column_class(OBIType_t obitype,type classe)
|
@ -1,200 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
cdef dict __OBIDMS_COLUMN_CLASS__ = {}
|
||||
|
||||
cdef class OBIDMS_column :
|
||||
|
||||
# Note: should only be initialized through a subclass
|
||||
def __init__(self, OBIView view, str column_alias):
|
||||
|
||||
cdef OBIDMS_column_p column_p
|
||||
cdef OBIDMS_column_p* column_pp
|
||||
|
||||
column_pp = obi_view_get_pointer_on_column_in_view(view._pointer, str2bytes(column_alias))
|
||||
column_p = column_pp[0] # TODO ugly cython dereferencing but can't find better
|
||||
|
||||
# Fill structure
|
||||
self._alias = column_alias
|
||||
self._pointer = column_pp
|
||||
self._view = view
|
||||
|
||||
cpdef getitem(self,index_t line_nb, str element_name):
|
||||
|
||||
def __setitem__(self, index_t line_nb, object value):
|
||||
self.set_line(line_nb, value)
|
||||
|
||||
def __getitem__(self, index_t line_nb):
|
||||
return self.get_line(line_nb)
|
||||
|
||||
def __len__(self):
|
||||
return self.lines_used
|
||||
|
||||
def __sizeof__(self):
|
||||
return ((self._pointer)[0].header.header_size + (self._pointer)[0].header.data_size)
|
||||
|
||||
def __iter__(self):
|
||||
# Declarations
|
||||
cdef index_t line_nb
|
||||
# Yield each line
|
||||
for line_nb in range(self.lines_used):
|
||||
yield self.get_line(line_nb)
|
||||
|
||||
def __str__(self) :
|
||||
cdef str to_print
|
||||
to_print = ''
|
||||
for line in self :
|
||||
to_print = to_print + str(line) + "\n"
|
||||
return to_print
|
||||
|
||||
def __repr__(self) :
|
||||
return (self._alias + ", original name: " + self.original_name + ", version " + str(self.version) + ", data type: " + self.data_type)
|
||||
|
||||
cpdef close(self):
|
||||
if obi_close_column((self._pointer)[0]) < 0 :
|
||||
raise Exception("Problem closing a column")
|
||||
|
||||
# Column alias property getter and setter
|
||||
@property
|
||||
def alias(self):
|
||||
return self._alias
|
||||
@alias.setter
|
||||
def alias(self, new_alias): # @DuplicatedSignature
|
||||
self._view.change_column_alias(self._alias, new_alias)
|
||||
|
||||
# elements_names property getter
|
||||
@property
|
||||
def elements_names(self):
|
||||
return (bytes2str(((self._pointer)[0].header).elements_names)).split(';')
|
||||
|
||||
# nb_elements_per_line property getter
|
||||
@property
|
||||
def nb_elements_per_line(self):
|
||||
return ((self._pointer)[0].header).nb_elements_per_line
|
||||
|
||||
# data_type property getter
|
||||
@property
|
||||
def data_type(self):
|
||||
return bytes2str(name_data_type(((self._pointer)[0].header).returned_data_type))
|
||||
|
||||
# original_name property getter
|
||||
@property
|
||||
def original_name(self):
|
||||
return bytes2str(((self._pointer)[0].header).name)
|
||||
|
||||
# version property getter
|
||||
@property
|
||||
def version(self):
|
||||
return ((self._pointer)[0].header).version
|
||||
|
||||
# lines_used property getter
|
||||
@property
|
||||
def lines_used(self):
|
||||
return (self._pointer)[0].header.lines_used
|
||||
|
||||
# comments property getter
|
||||
@property
|
||||
def comments(self):
|
||||
return bytes2str((self._pointer)[0].header.comments)
|
||||
|
||||
# creation_date property getter
|
||||
@property
|
||||
def creation_date(self):
|
||||
return bytes2str(obi_format_date((self._pointer)[0].header.creation_date))
|
||||
|
||||
@staticmethod
|
||||
cdef object get_subclass_type(OBIDMS_column_p column_p) :
|
||||
|
||||
cdef object subclass
|
||||
cdef OBIDMS_column_header_p header
|
||||
cdef OBIType_t col_type
|
||||
cdef bint col_writable
|
||||
cdef bint col_one_element_per_line
|
||||
|
||||
header = column_p.header
|
||||
col_type = header.returned_data_type
|
||||
col_writable = column_p.writable
|
||||
col_one_element_per_line = ((header.nb_elements_per_line) == 1)
|
||||
|
||||
if col_type == OBI_INT :
|
||||
if col_one_element_per_line :
|
||||
subclass = OBIDMS_column_int
|
||||
else :
|
||||
subclass = OBIDMS_column_multi_elts_int
|
||||
elif col_type == OBI_FLOAT :
|
||||
if col_one_element_per_line :
|
||||
subclass = OBIDMS_column_float
|
||||
else :
|
||||
subclass = OBIDMS_column_multi_elts_float
|
||||
elif col_type == OBI_BOOL :
|
||||
if col_one_element_per_line :
|
||||
subclass = OBIDMS_column_bool
|
||||
else :
|
||||
subclass = OBIDMS_column_multi_elts_bool
|
||||
elif col_type == OBI_CHAR :
|
||||
if col_one_element_per_line :
|
||||
subclass = OBIDMS_column_char
|
||||
else :
|
||||
subclass = OBIDMS_column_multi_elts_char
|
||||
elif col_type == OBI_QUAL :
|
||||
if col_one_element_per_line :
|
||||
subclass = OBIDMS_column_qual
|
||||
else :
|
||||
subclass = OBIDMS_column_multi_elts_qual
|
||||
elif col_type == OBI_STR :
|
||||
if col_one_element_per_line :
|
||||
subclass = OBIDMS_column_str
|
||||
else :
|
||||
subclass = OBIDMS_column_multi_elts_str
|
||||
elif col_type == OBI_SEQ :
|
||||
if col_one_element_per_line :
|
||||
subclass = OBIDMS_column_seq
|
||||
else :
|
||||
subclass = OBIDMS_column_multi_elts_seq
|
||||
else :
|
||||
raise Exception("Problem with the data type")
|
||||
|
||||
return subclass
|
||||
|
||||
|
||||
######################################################################################################
|
||||
|
||||
|
||||
cdef class OBIDMS_column_multi_elts(OBIDMS_column) :
|
||||
|
||||
def __getitem__(self, index_t line_nb):
|
||||
return OBIDMS_column_line(self, line_nb)
|
||||
|
||||
cpdef set_line(self, index_t line_nb, dict values):
|
||||
for element_name in values :
|
||||
self.set_item(line_nb, element_name, values[element_name])
|
||||
|
||||
|
||||
######################################################################################################
|
||||
|
||||
|
||||
cdef class OBIDMS_column_line :
|
||||
|
||||
def __init__(self, OBIDMS_column column, index_t line_nb) :
|
||||
self._index = line_nb
|
||||
self._column = column
|
||||
|
||||
def __getitem__(self, str element_name) :
|
||||
return self._column.get_item(self._index, element_name)
|
||||
|
||||
def __setitem__(self, str element_name, object value):
|
||||
self._column.set_item(self._index, element_name, value)
|
||||
|
||||
def __contains__(self, str element_name):
|
||||
return (element_name in self._column.elements_names)
|
||||
|
||||
def __repr__(self) :
|
||||
return str(self._column.get_line(self._index))
|
||||
|
||||
|
||||
######################################################################################################
|
||||
|
||||
|
||||
cdef register_column_class(OBIType_t obitype,type classe):
|
||||
assert issubclass(classe,OBIDMS_column)
|
||||
|
||||
__OBIDMS_COLUMN_CLASS__[obitype]=classe
|
@ -1,14 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
from ._obidms cimport OBIDMS_column, OBIDMS_column_multi_elts
|
||||
|
||||
|
||||
cdef class OBIDMS_column_bool(OBIDMS_column):
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_bool(OBIDMS_column_multi_elts):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value)
|
@ -1,77 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obiview cimport obi_get_bool_with_elt_name_and_col_p_in_view, \
|
||||
obi_get_bool_with_elt_idx_and_col_p_in_view, \
|
||||
obi_set_bool_with_elt_name_and_col_p_in_view, \
|
||||
obi_set_bool_with_elt_idx_and_col_p_in_view
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIBool_NA, obibool_t
|
||||
|
||||
from obitools3.utils cimport str2bytes
|
||||
|
||||
from cpython.bool cimport PyBool_FromLong
|
||||
|
||||
|
||||
cdef class OBIDMS_column_bool(OBIDMS_column):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef obibool_t value
|
||||
cdef object result
|
||||
value = obi_get_bool_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIBool_NA :
|
||||
result = None
|
||||
else :
|
||||
result = PyBool_FromLong(value)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
if value is None :
|
||||
value = OBIBool_NA
|
||||
if obi_set_bool_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, <obibool_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_bool(OBIDMS_column_multi_elts):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef obibool_t value
|
||||
cdef object result
|
||||
value = obi_get_bool_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIBool_NA :
|
||||
result = None
|
||||
else :
|
||||
result = PyBool_FromLong(value)
|
||||
return result
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef obibool_t 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 = obi_get_bool_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIBool_NA :
|
||||
value_in_result = None
|
||||
else :
|
||||
value_in_result = PyBool_FromLong(value)
|
||||
result[self.elements_names[i]] = value_in_result
|
||||
if all_NA and (value_in_result is not None) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value):
|
||||
if value is None :
|
||||
value = OBIBool_NA
|
||||
if obi_set_bool_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), <obibool_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
@ -1,65 +0,0 @@
|
||||
../../../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/hashtable.h
|
||||
../../../src/hashtable.c
|
||||
../../../src/murmurhash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obi_align.h
|
||||
../../../src/obi_align.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_blob.c
|
||||
../../../src/obidmscolumn_blob.h
|
||||
../../../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_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn_int.c
|
||||
../../../src/obidmscolumn_int.h
|
||||
../../../src/obidmscolumn_qual.h
|
||||
../../../src/obidmscolumn_qual.c
|
||||
../../../src/obidmscolumn_seq.c
|
||||
../../../src/obidmscolumn_seq.h
|
||||
../../../src/obidmscolumn_str.c
|
||||
../../../src/obidmscolumn_str.h
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/sse_banded_LCS_alignment.h
|
||||
../../../src/sse_banded_LCS_alignment.c
|
||||
../../../src/uint8_indexer.h
|
||||
../../../src/uint8_indexer.c
|
||||
../../../src/upperband.h
|
||||
../../../src/upperband.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
@ -1,14 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
from ._obidms cimport OBIDMS_column, OBIDMS_column_multi_elts
|
||||
|
||||
|
||||
cdef class OBIDMS_column_char(OBIDMS_column):
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_char(OBIDMS_column_multi_elts):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value)
|
@ -1,76 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obiview cimport obi_get_char_with_elt_name_and_col_p_in_view, \
|
||||
obi_get_char_with_elt_idx_and_col_p_in_view, \
|
||||
obi_set_char_with_elt_name_and_col_p_in_view, \
|
||||
obi_set_char_with_elt_idx_and_col_p_in_view
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIChar_NA, obichar_t
|
||||
|
||||
from obitools3.utils cimport str2bytes, bytes2str
|
||||
|
||||
|
||||
cdef class OBIDMS_column_char(OBIDMS_column):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef obichar_t value
|
||||
cdef object result
|
||||
value = obi_get_char_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIChar_NA :
|
||||
result = None
|
||||
else :
|
||||
result = bytes2str(value)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
if value is None :
|
||||
value = OBIChar_NA
|
||||
if obi_set_char_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, str2bytes(value)[0]) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_char(OBIDMS_column_multi_elts):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef obichar_t value
|
||||
cdef object result
|
||||
value = obi_get_char_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIChar_NA :
|
||||
result = None
|
||||
else :
|
||||
result = bytes2str(value)
|
||||
return result
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef obichar_t 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 = obi_get_char_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIChar_NA :
|
||||
value_in_result = None
|
||||
else :
|
||||
value_in_result = bytes2str(value)
|
||||
result[self.elements_names[i]] = value_in_result
|
||||
if all_NA and (value_in_result is not None) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value):
|
||||
if value is None :
|
||||
value = OBIChar_NA
|
||||
if obi_set_char_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), str2bytes(value)[0]) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
@ -1,65 +0,0 @@
|
||||
../../../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/hashtable.h
|
||||
../../../src/hashtable.c
|
||||
../../../src/murmurhash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obi_align.h
|
||||
../../../src/obi_align.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_blob.c
|
||||
../../../src/obidmscolumn_blob.h
|
||||
../../../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_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn_int.c
|
||||
../../../src/obidmscolumn_int.h
|
||||
../../../src/obidmscolumn_qual.h
|
||||
../../../src/obidmscolumn_qual.c
|
||||
../../../src/obidmscolumn_seq.c
|
||||
../../../src/obidmscolumn_seq.h
|
||||
../../../src/obidmscolumn_str.c
|
||||
../../../src/obidmscolumn_str.h
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/sse_banded_LCS_alignment.h
|
||||
../../../src/sse_banded_LCS_alignment.c
|
||||
../../../src/uint8_indexer.h
|
||||
../../../src/uint8_indexer.c
|
||||
../../../src/upperband.h
|
||||
../../../src/upperband.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
@ -1,14 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
from ._obidms cimport OBIDMS_column, OBIDMS_column_multi_elts
|
||||
|
||||
|
||||
cdef class OBIDMS_column_float(OBIDMS_column):
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_float(OBIDMS_column_multi_elts):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value)
|
@ -1,76 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obiview cimport obi_get_float_with_elt_name_and_col_p_in_view, \
|
||||
obi_get_float_with_elt_idx_and_col_p_in_view, \
|
||||
obi_set_float_with_elt_name_and_col_p_in_view, \
|
||||
obi_set_float_with_elt_idx_and_col_p_in_view
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIFloat_NA, obifloat_t
|
||||
|
||||
from obitools3.utils cimport str2bytes
|
||||
|
||||
|
||||
cdef class OBIDMS_column_float(OBIDMS_column):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef obifloat_t value
|
||||
cdef object result
|
||||
value = obi_get_float_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIFloat_NA :
|
||||
result = None
|
||||
else :
|
||||
result = <double> value
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
if value is None :
|
||||
value = OBIFloat_NA
|
||||
if obi_set_float_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, <obifloat_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_float(OBIDMS_column_multi_elts):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef obifloat_t value
|
||||
cdef object result
|
||||
value = obi_get_float_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIFloat_NA :
|
||||
result = None
|
||||
else :
|
||||
result = <double> value
|
||||
return result
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef obifloat_t 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 = obi_get_float_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIFloat_NA :
|
||||
value_in_result = None
|
||||
else :
|
||||
value_in_result = <double> value
|
||||
result[self.elements_names[i]] = value_in_result
|
||||
if all_NA and (value_in_result is not None) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value):
|
||||
if value is None :
|
||||
value = OBIFloat_NA
|
||||
if obi_set_float_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), <obifloat_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
@ -1,65 +0,0 @@
|
||||
../../../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/hashtable.h
|
||||
../../../src/hashtable.c
|
||||
../../../src/murmurhash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obi_align.h
|
||||
../../../src/obi_align.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_blob.c
|
||||
../../../src/obidmscolumn_blob.h
|
||||
../../../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_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn_int.c
|
||||
../../../src/obidmscolumn_int.h
|
||||
../../../src/obidmscolumn_qual.h
|
||||
../../../src/obidmscolumn_qual.c
|
||||
../../../src/obidmscolumn_seq.c
|
||||
../../../src/obidmscolumn_seq.h
|
||||
../../../src/obidmscolumn_str.c
|
||||
../../../src/obidmscolumn_str.h
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/sse_banded_LCS_alignment.h
|
||||
../../../src/sse_banded_LCS_alignment.c
|
||||
../../../src/uint8_indexer.h
|
||||
../../../src/uint8_indexer.c
|
||||
../../../src/upperband.h
|
||||
../../../src/upperband.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
@ -1,14 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
from ._obidms cimport OBIDMS_column, OBIDMS_column_multi_elts
|
||||
|
||||
|
||||
cdef class OBIDMS_column_int(OBIDMS_column):
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_int(OBIDMS_column_multi_elts):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value)
|
@ -1,78 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obiview cimport obi_get_int_with_elt_name_and_col_p_in_view, \
|
||||
obi_get_int_with_elt_idx_and_col_p_in_view, \
|
||||
obi_set_int_with_elt_name_and_col_p_in_view, \
|
||||
obi_set_int_with_elt_idx_and_col_p_in_view
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIInt_NA, obiint_t
|
||||
|
||||
from obitools3.utils cimport str2bytes
|
||||
|
||||
from cpython.int cimport PyInt_FromLong
|
||||
|
||||
|
||||
cdef class OBIDMS_column_int(OBIDMS_column):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef obiint_t value
|
||||
cdef object result
|
||||
value = obi_get_int_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIInt_NA :
|
||||
result = None
|
||||
else :
|
||||
result = PyInt_FromLong(value)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
if value is None :
|
||||
value = OBIInt_NA
|
||||
if obi_set_int_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, <obiint_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_int(OBIDMS_column_multi_elts):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef obiint_t value
|
||||
cdef object result
|
||||
value = obi_get_int_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIInt_NA :
|
||||
result = None
|
||||
else :
|
||||
result = PyInt_FromLong(value)
|
||||
return result
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef obiint_t 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 = obi_get_int_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIInt_NA :
|
||||
value_in_result = None
|
||||
else :
|
||||
value_in_result = PyInt_FromLong(value)
|
||||
result[self.elements_names[i]] = value_in_result
|
||||
if all_NA and (value_in_result is not None) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None # TODO discuss
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value):
|
||||
if value is None :
|
||||
value = OBIInt_NA
|
||||
if obi_set_int_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), <obiint_t> value) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
@ -1,65 +0,0 @@
|
||||
../../../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/hashtable.h
|
||||
../../../src/hashtable.c
|
||||
../../../src/murmurhash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obi_align.h
|
||||
../../../src/obi_align.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_blob.c
|
||||
../../../src/obidmscolumn_blob.h
|
||||
../../../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_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn_int.c
|
||||
../../../src/obidmscolumn_int.h
|
||||
../../../src/obidmscolumn_qual.h
|
||||
../../../src/obidmscolumn_qual.c
|
||||
../../../src/obidmscolumn_seq.c
|
||||
../../../src/obidmscolumn_seq.h
|
||||
../../../src/obidmscolumn_str.c
|
||||
../../../src/obidmscolumn_str.h
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/sse_banded_LCS_alignment.h
|
||||
../../../src/sse_banded_LCS_alignment.c
|
||||
../../../src/uint8_indexer.h
|
||||
../../../src/uint8_indexer.c
|
||||
../../../src/upperband.h
|
||||
../../../src/upperband.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
@ -1,20 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
from ._obidms cimport OBIDMS_column , OBIDMS_column_multi_elts
|
||||
|
||||
|
||||
cdef class OBIDMS_column_qual(OBIDMS_column):
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef object get_str_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
cpdef set_str_line(self, index_t line_nb, object value)
|
||||
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_qual(OBIDMS_column_multi_elts):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_str_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef object get_str_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value)
|
||||
cpdef set_str_item(self, index_t line_nb, str element_name, object value)
|
@ -1,189 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obiview cimport obi_get_qual_char_with_elt_name_and_col_p_in_view, \
|
||||
obi_get_qual_char_with_elt_idx_and_col_p_in_view, \
|
||||
obi_set_qual_char_with_elt_name_and_col_p_in_view, \
|
||||
obi_set_qual_char_with_elt_idx_and_col_p_in_view, \
|
||||
obi_get_qual_int_with_elt_name_and_col_p_in_view, \
|
||||
obi_get_qual_int_with_elt_idx_and_col_p_in_view, \
|
||||
obi_set_qual_int_with_elt_name_and_col_p_in_view, \
|
||||
obi_set_qual_int_with_elt_idx_and_col_p_in_view
|
||||
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIQual_char_NA, OBIQual_int_NA, const_char_p
|
||||
|
||||
from ._obidms cimport OBIView
|
||||
|
||||
from obitools3.utils cimport str2bytes, bytes2str
|
||||
|
||||
from libc.stdlib cimport free
|
||||
from libc.string cimport strcmp
|
||||
from libc.stdint cimport uint8_t
|
||||
from libc.stdlib cimport malloc
|
||||
|
||||
|
||||
cdef class OBIDMS_column_qual(OBIDMS_column):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef const uint8_t* value
|
||||
cdef int value_length
|
||||
cdef object result
|
||||
cdef int i
|
||||
value = obi_get_qual_int_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, &value_length)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIQual_int_NA :
|
||||
result = None
|
||||
else :
|
||||
result = []
|
||||
for i in range(value_length) :
|
||||
result.append(<int>value[i])
|
||||
return result
|
||||
|
||||
cpdef object get_str_line(self, index_t line_nb):
|
||||
cdef char* value
|
||||
cdef object result
|
||||
cdef int i
|
||||
value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIQual_char_NA :
|
||||
result = None
|
||||
else :
|
||||
result = bytes2str(value)
|
||||
free(value)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
cdef uint8_t* value_b
|
||||
cdef int value_length
|
||||
if value is None :
|
||||
if obi_set_qual_int_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, OBIQual_int_NA, 0) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
else :
|
||||
value_length = len(value)
|
||||
value_b = <uint8_t*> malloc(value_length * sizeof(uint8_t))
|
||||
for i in range(value_length) :
|
||||
value_b[i] = <uint8_t>value[i]
|
||||
if obi_set_qual_int_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, value_b, value_length) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
free(value_b)
|
||||
|
||||
cpdef set_str_line(self, index_t line_nb, object value):
|
||||
cdef bytes value_b
|
||||
if value is None :
|
||||
if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, OBIQual_char_NA) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
else :
|
||||
if type(value) == str:
|
||||
value_b = str2bytes(value)
|
||||
else :
|
||||
value_b = value
|
||||
if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, value_b) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_qual(OBIDMS_column_multi_elts):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef const uint8_t* value
|
||||
cdef int value_length
|
||||
cdef object result
|
||||
cdef int i
|
||||
value = obi_get_qual_int_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), &value_length)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIQual_int_NA :
|
||||
result = None
|
||||
else :
|
||||
result = []
|
||||
for i in range(value_length) :
|
||||
result.append(<int>value[i])
|
||||
return result
|
||||
|
||||
cpdef object get_str_item(self, index_t line_nb, str element_name):
|
||||
cdef char* value
|
||||
cdef object result
|
||||
value = obi_get_qual_char_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIQual_char_NA :
|
||||
result = None
|
||||
else :
|
||||
result = bytes2str(value)
|
||||
free(value)
|
||||
return result
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef const uint8_t* value
|
||||
cdef int value_length
|
||||
cdef object value_in_result
|
||||
cdef dict result
|
||||
cdef index_t i
|
||||
cdef int j
|
||||
cdef bint all_NA
|
||||
result = {}
|
||||
all_NA = True
|
||||
for i in range(self.nb_elements_per_line) :
|
||||
value = obi_get_qual_int_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, i, &value_length)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIQual_int_NA :
|
||||
value_in_result = None
|
||||
else :
|
||||
value_in_result = []
|
||||
for j in range(value_length) :
|
||||
value_in_result.append(<int>value[j])
|
||||
result[self.elements_names[i]] = value_in_result
|
||||
if all_NA and (value_in_result is not None) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef object get_str_line(self, index_t line_nb) :
|
||||
cdef char* 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 = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIQual_char_NA :
|
||||
value_in_result = None
|
||||
else :
|
||||
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
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value):
|
||||
cdef uint8_t* value_b
|
||||
cdef int value_length
|
||||
if value is None :
|
||||
if obi_set_qual_int_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), OBIQual_int_NA, 0) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
else :
|
||||
value_length = len(value)
|
||||
value_b = <uint8_t*> malloc(value_length * sizeof(uint8_t))
|
||||
for i in range(value_length) :
|
||||
value_b[i] = <uint8_t>value[i]
|
||||
if obi_set_qual_int_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), value_b, value_length) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
free(value_b)
|
||||
|
||||
cpdef set_str_item(self, index_t line_nb, str element_name, object value):
|
||||
if value is None :
|
||||
if obi_set_qual_char_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), OBIQual_char_NA) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
else :
|
||||
if obi_set_qual_char_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), str2bytes(value)) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
@ -1,65 +0,0 @@
|
||||
../../../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/hashtable.h
|
||||
../../../src/hashtable.c
|
||||
../../../src/murmurhash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obi_align.h
|
||||
../../../src/obi_align.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_blob.c
|
||||
../../../src/obidmscolumn_blob.h
|
||||
../../../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_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn_int.c
|
||||
../../../src/obidmscolumn_int.h
|
||||
../../../src/obidmscolumn_qual.h
|
||||
../../../src/obidmscolumn_qual.c
|
||||
../../../src/obidmscolumn_seq.c
|
||||
../../../src/obidmscolumn_seq.h
|
||||
../../../src/obidmscolumn_str.c
|
||||
../../../src/obidmscolumn_str.h
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/sse_banded_LCS_alignment.h
|
||||
../../../src/sse_banded_LCS_alignment.c
|
||||
../../../src/uint8_indexer.h
|
||||
../../../src/uint8_indexer.c
|
||||
../../../src/upperband.h
|
||||
../../../src/upperband.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
@ -1,15 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
from ._obidms cimport OBIView, OBIDMS_column, OBIDMS_column_multi_elts
|
||||
|
||||
|
||||
cdef class OBIDMS_column_seq(OBIDMS_column):
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_seq(OBIDMS_column_multi_elts):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value)
|
@ -1,108 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obiview cimport obi_get_seq_with_elt_name_and_col_p_in_view, \
|
||||
obi_get_seq_with_elt_idx_and_col_p_in_view, \
|
||||
obi_set_seq_with_elt_name_and_col_p_in_view, \
|
||||
obi_set_seq_with_elt_idx_and_col_p_in_view
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBISeq_NA, const_char_p
|
||||
|
||||
from ._obidms cimport OBIView
|
||||
|
||||
from obitools3.utils cimport str2bytes, bytes2str
|
||||
|
||||
from libc.stdlib cimport free
|
||||
|
||||
|
||||
cdef class OBIDMS_column_seq(OBIDMS_column):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef char* value
|
||||
cdef object result
|
||||
value = obi_get_seq_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBISeq_NA :
|
||||
result = None
|
||||
else :
|
||||
try:
|
||||
result = <bytes> value
|
||||
finally:
|
||||
free(value)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
cdef bytes value_b
|
||||
|
||||
if value is None :
|
||||
value_b = OBISeq_NA
|
||||
elif isinstance(value, bytes) :
|
||||
value_b = value
|
||||
elif isinstance(value, str) :
|
||||
value_b = str2bytes(value)
|
||||
else:
|
||||
raise TypeError('Sequence value must be of type Bytes, Str or None')
|
||||
|
||||
if obi_set_seq_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, value_b) < 0:
|
||||
raise Exception("Problem setting a value in a 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 char* value
|
||||
cdef object result
|
||||
value = obi_get_seq_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBISeq_NA :
|
||||
result = None
|
||||
else :
|
||||
try:
|
||||
result = <bytes> value
|
||||
finally:
|
||||
free(value)
|
||||
return result
|
||||
|
||||
|
||||
cpdef object get_line(self, index_t line_nb) :
|
||||
cdef char* 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 = obi_get_seq_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBISeq_NA :
|
||||
value_in_result = None
|
||||
else :
|
||||
try:
|
||||
value_in_result = <bytes> value
|
||||
finally:
|
||||
free(value)
|
||||
result[self.elements_names[i]] = value_in_result
|
||||
if all_NA and (value_in_result is not None) :
|
||||
all_NA = False
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value):
|
||||
cdef bytes value_b
|
||||
|
||||
if value is None :
|
||||
value_b = OBISeq_NA
|
||||
elif isinstance(value, bytes) :
|
||||
value_b = value
|
||||
elif isinstance(value, str) :
|
||||
value_b = str2bytes(value)
|
||||
else:
|
||||
raise TypeError('Sequence value must be of type Bytes, Str or None')
|
||||
|
||||
if obi_set_seq_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), value_b) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
@ -1,65 +0,0 @@
|
||||
../../../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/hashtable.h
|
||||
../../../src/hashtable.c
|
||||
../../../src/murmurhash2.h
|
||||
../../../src/murmurhash2.c
|
||||
../../../src/obi_align.h
|
||||
../../../src/obi_align.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_blob.c
|
||||
../../../src/obidmscolumn_blob.h
|
||||
../../../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_idx.h
|
||||
../../../src/obidmscolumn_idx.c
|
||||
../../../src/obidmscolumn_int.c
|
||||
../../../src/obidmscolumn_int.h
|
||||
../../../src/obidmscolumn_qual.h
|
||||
../../../src/obidmscolumn_qual.c
|
||||
../../../src/obidmscolumn_seq.c
|
||||
../../../src/obidmscolumn_seq.h
|
||||
../../../src/obidmscolumn_str.c
|
||||
../../../src/obidmscolumn_str.h
|
||||
../../../src/obidmscolumn.h
|
||||
../../../src/obidmscolumn.c
|
||||
../../../src/obidmscolumndir.h
|
||||
../../../src/obidmscolumndir.c
|
||||
../../../src/obierrno.h
|
||||
../../../src/obierrno.c
|
||||
../../../src/obilittlebigman.h
|
||||
../../../src/obilittlebigman.c
|
||||
../../../src/obitypes.h
|
||||
../../../src/obitypes.c
|
||||
../../../src/obiview.h
|
||||
../../../src/obiview.c
|
||||
../../../src/sse_banded_LCS_alignment.h
|
||||
../../../src/sse_banded_LCS_alignment.c
|
||||
../../../src/uint8_indexer.h
|
||||
../../../src/uint8_indexer.c
|
||||
../../../src/upperband.h
|
||||
../../../src/upperband.c
|
||||
../../../src/utils.h
|
||||
../../../src/utils.c
|
@ -1,14 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
from ._obidms cimport OBIDMS_column, OBIDMS_column_multi_elts
|
||||
|
||||
|
||||
cdef class OBIDMS_column_str(OBIDMS_column):
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_line(self, index_t line_nb, object value)
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_str(OBIDMS_column_multi_elts):
|
||||
cpdef object get_item(self, index_t line_nb, str element_name)
|
||||
cpdef object get_line(self, index_t line_nb)
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value)
|
@ -1,84 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obiview cimport obi_get_str_with_elt_name_and_col_p_in_view, \
|
||||
obi_get_str_with_elt_idx_and_col_p_in_view, \
|
||||
obi_set_str_with_elt_name_and_col_p_in_view, \
|
||||
obi_set_str_with_elt_idx_and_col_p_in_view
|
||||
from .capi.obierrno cimport obi_errno
|
||||
from .capi.obitypes cimport OBIStr_NA, const_char_p
|
||||
|
||||
from obitools3.utils cimport str2bytes, bytes2str
|
||||
|
||||
|
||||
cdef class OBIDMS_column_str(OBIDMS_column):
|
||||
|
||||
cpdef object get_line(self, index_t line_nb):
|
||||
cdef const_char_p value
|
||||
cdef object result
|
||||
value = obi_get_str_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIStr_NA :
|
||||
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):
|
||||
if value is None :
|
||||
if obi_set_str_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, OBIStr_NA) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
else :
|
||||
if obi_set_str_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, 0, str2bytes(value)) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
|
||||
cdef class OBIDMS_column_multi_elts_str(OBIDMS_column_multi_elts):
|
||||
|
||||
cpdef object get_item(self, index_t line_nb, str element_name):
|
||||
cdef const_char_p value
|
||||
cdef object result
|
||||
value = obi_get_str_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name))
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb, element_name)
|
||||
if value == OBIStr_NA :
|
||||
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 const_char_p value # @DuplicatedSignature
|
||||
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 = obi_get_str_with_elt_idx_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, i)
|
||||
if obi_errno > 0 :
|
||||
raise IndexError(line_nb)
|
||||
if value == OBIStr_NA :
|
||||
value_in_result = None
|
||||
else :
|
||||
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
|
||||
if all_NA :
|
||||
result = None
|
||||
return result
|
||||
|
||||
cpdef set_item(self, index_t line_nb, str element_name, object value):
|
||||
cdef bytes value_b
|
||||
if value is None :
|
||||
value_b = OBIStr_NA
|
||||
else :
|
||||
value_b = str2bytes(value)
|
||||
if obi_set_str_with_elt_name_and_col_p_in_view(self._view._pointer, (self._pointer)[0], line_nb, str2bytes(element_name), value_b) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
@ -1,5 +0,0 @@
|
||||
#cython: language_level=3
|
||||
|
||||
|
||||
cdef extern from "obierrno.h" nogil:
|
||||
extern int obi_errno
|
@ -2,5 +2,6 @@
|
||||
|
||||
|
||||
cdef bytes str2bytes(str string)
|
||||
|
||||
cdef str bytes2str(bytes string)
|
||||
cdef str bytes2str(bytes string)
|
||||
cdef bytes tobytes(object string)
|
||||
cdef str tostr(object string)
|
@ -1,4 +1,5 @@
|
||||
#cython: language_level=3
|
||||
from IPython.utils._tokenize_py2 import String
|
||||
|
||||
|
||||
cdef bytes str2bytes(str string):
|
||||
@ -24,3 +25,32 @@ cdef str bytes2str(bytes string):
|
||||
"""
|
||||
return string.decode('ascii')
|
||||
|
||||
cdef bytes tobytes(object string):
|
||||
"""
|
||||
Short cut to convert ascii encoded string (str or bytes) to bytes
|
||||
which can be easily converted to C-strings.
|
||||
|
||||
@param string: the python string to be converted.
|
||||
@type string: bytes or str
|
||||
@return a transcoded string
|
||||
@rtype: bytes
|
||||
"""
|
||||
if isinstance(string, bytes):
|
||||
return string
|
||||
return str2bytes(string)
|
||||
|
||||
|
||||
cdef str tostr(object string):
|
||||
"""
|
||||
Short cut to convert ascii encoded string (str or bytes) to bytes
|
||||
which can be easily converted to C-strings.
|
||||
|
||||
@param string: the python string to be converted.
|
||||
@type string: bytes or str
|
||||
@return a transcoded string
|
||||
@rtype: bytes
|
||||
"""
|
||||
if isinstance(string, str):
|
||||
return string
|
||||
return bytes2str(string)
|
||||
|
||||
|
@ -639,7 +639,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
obidebug(1, "\nCan't create column because of empty column name");
|
||||
return NULL;
|
||||
}
|
||||
if ((data_type < 1) || (data_type > 8)) // TODO check in more robust way
|
||||
if ((data_type < 1) || (data_type > 8)) // TODO check in more robust way and use macro define somewhere
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nCan't create column because of invalid data type");
|
||||
@ -665,7 +665,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
// Build the indexer name if needed
|
||||
if ((data_type == OBI_STR) || (data_type == OBI_SEQ) || (data_type == OBI_QUAL))
|
||||
{
|
||||
if ((indexer_name == NULL) || (strcmp(indexer_name, "") == 0))
|
||||
if ((indexer_name == NULL) || (*indexer_name == 0))
|
||||
{
|
||||
final_indexer_name = obi_build_indexer_name(column_name, version_number);
|
||||
if (final_indexer_name == NULL)
|
||||
|
@ -102,18 +102,22 @@ typedef struct OBIDMS_column_header {
|
||||
* creating, opening or cloning an OBIDMS column.
|
||||
*/
|
||||
typedef struct OBIDMS_column {
|
||||
OBIDMS_p dms; /**< A pointer to the OBIDMS structure to which the column belongs.
|
||||
OBIDMS_p dms; /**< A pointer to the OBIDMS structure to
|
||||
* which the column belongs.
|
||||
*/
|
||||
OBIDMS_column_directory_p column_directory; /**< A pointer to the OBIDMS column directory structure to which the column belongs.
|
||||
OBIDMS_column_directory_p column_directory; /**< A pointer to the OBIDMS column directory
|
||||
* structure to which the column belongs.
|
||||
*/
|
||||
OBIDMS_column_header_p header; /**< A pointer to the header of the column.
|
||||
*/
|
||||
Obi_indexer_p indexer; /**< A pointer to the blob indexer 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.
|
||||
*
|
||||
* @warning Never use this member directly outside of the code of the
|
||||
* low level functions of the OBIDMS.
|
||||
* @warning Never use this member directly outside
|
||||
* of the code of the low level functions
|
||||
* of the OBIDMS.
|
||||
*/
|
||||
bool writable; /**< Indicates if the column is writable or not.
|
||||
* - `true` the column is writable
|
||||
@ -122,7 +126,8 @@ typedef struct OBIDMS_column {
|
||||
* A column is writable only by its creator
|
||||
* until it closes it.
|
||||
*/
|
||||
size_t counter; /**< Indicates by how many threads/programs (TODO) the column is used.
|
||||
size_t counter; /**< Indicates by how many threads/programs
|
||||
* (TODO) the column is used.
|
||||
*/
|
||||
} OBIDMS_column_t, *OBIDMS_column_p;
|
||||
|
||||
|
Reference in New Issue
Block a user