Strong refactoring 1
This commit is contained in:
0
python/obitools3/dms/__init__.py
Normal file
0
python/obitools3/dms/__init__.py
Normal file
65
python/obitools3/dms/_obidms.cfiles
Normal file
65
python/obitools3/dms/_obidms.cfiles
Normal file
@ -0,0 +1,65 @@
|
||||
../../../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
|
20
python/obitools3/dms/_obidms.pxd
Normal file
20
python/obitools3/dms/_obidms.pxd
Normal file
@ -0,0 +1,20 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obidms cimport OBIDMS_p
|
||||
from .capi.obidmscolumn cimport OBIDMS_column_p
|
||||
from .capi.obiview cimport Obiview_p
|
||||
from .capi.obitypes cimport obiversion_t, OBIType_t, index_t
|
||||
from ._obitaxo cimport OBI_Taxonomy
|
||||
|
||||
|
||||
|
||||
cdef class OBIDMS:
|
||||
|
||||
cdef OBIDMS_p _pointer
|
||||
|
||||
cpdef close(self)
|
||||
cpdef OBI_Taxonomy open_taxonomy(self, str taxo_name)
|
||||
|
||||
cpdef dict read_view_infos(self, str view_name)
|
||||
# cpdef dict read_views(self) TODO
|
||||
|
107
python/obitools3/dms/_obidms.pyx
Normal file
107
python/obitools3/dms/_obidms.pyx
Normal file
@ -0,0 +1,107 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from obitools3.utils cimport bytes2str, str2bytes
|
||||
|
||||
from .capi.obidms cimport obi_dms, \
|
||||
obi_close_dms
|
||||
|
||||
from .capi.obidmscolumn cimport obi_close_column, \
|
||||
OBIDMS_column_p, \
|
||||
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, \
|
||||
OBI_FLOAT, \
|
||||
OBI_BOOL, \
|
||||
OBI_CHAR, \
|
||||
OBI_QUAL, \
|
||||
OBI_STR, \
|
||||
OBI_SEQ, \
|
||||
name_data_type, \
|
||||
only_ATGC # discuss
|
||||
|
||||
from ._obitaxo cimport OBI_Taxonomy
|
||||
|
||||
|
||||
|
||||
from libc.stdlib cimport malloc
|
||||
|
||||
|
||||
|
||||
cdef class OBIDMS :
|
||||
|
||||
def __init__(self, str dms_name) :
|
||||
|
||||
# Declarations
|
||||
cdef bytes dms_name_b
|
||||
|
||||
# Format the character string to send to C function
|
||||
dms_name_b = str2bytes(dms_name)
|
||||
|
||||
# Fill structure and create or open the DMS
|
||||
self._pointer = obi_dms(<const_char_p> dms_name_b)
|
||||
if self._pointer == NULL :
|
||||
raise Exception("Failed opening or creating an OBIDMS")
|
||||
|
||||
|
||||
# name property getter
|
||||
@property
|
||||
def name(self):
|
||||
return bytes2str(self._pointer.dms_name)
|
||||
|
||||
|
||||
cpdef close(self) :
|
||||
if (obi_close_dms(self._pointer)) < 0 :
|
||||
raise Exception("Problem closing an OBIDMS")
|
||||
|
||||
|
||||
cpdef OBI_Taxonomy open_taxonomy(self, str taxo_name) :
|
||||
return OBI_Taxonomy(self, taxo_name)
|
||||
|
||||
|
||||
cpdef dict read_view_infos(self, str view_name) :
|
||||
|
||||
cdef Obiview_infos_p view_infos_p
|
||||
cdef dict view_infos_d
|
||||
cdef Alias_column_pair_p column_refs
|
||||
cdef int i, j
|
||||
cdef str column_name
|
||||
|
||||
view_infos_p = obi_view_map_file(self._pointer, str2bytes(view_name))
|
||||
view_infos_d = {}
|
||||
view_infos_d["name"] = bytes2str(view_infos_p.name)
|
||||
view_infos_d["comments"] = bytes2str(view_infos_p.comments)
|
||||
view_infos_d["view_type"] = bytes2str(view_infos_p.view_type)
|
||||
view_infos_d["column_count"] = <int> view_infos_p.column_count
|
||||
view_infos_d["line_count"] = <int> view_infos_p.line_count
|
||||
view_infos_d["created_from"] = bytes2str(view_infos_p.created_from)
|
||||
view_infos_d["creation_date"] = bytes2str(obi_format_date(view_infos_p.creation_date))
|
||||
if (view_infos_p.all_lines) :
|
||||
view_infos_d["line_selection"] = None
|
||||
else :
|
||||
view_infos_d["line_selection"] = {}
|
||||
view_infos_d["line_selection"]["column_name"] = bytes2str((view_infos_p.line_selection).column_name)
|
||||
view_infos_d["line_selection"]["version"] = <int> (view_infos_p.line_selection).version
|
||||
view_infos_d["column_references"] = {}
|
||||
column_references = view_infos_p.column_references
|
||||
for j in range(view_infos_d["column_count"]) :
|
||||
column_name = bytes2str((column_references[j]).alias)
|
||||
view_infos_d["column_references"][column_name] = {}
|
||||
view_infos_d["column_references"][column_name]["original_name"] = bytes2str((column_references[j]).column_refs.column_name)
|
||||
view_infos_d["column_references"][column_name]["version"] = (column_references[j]).column_refs.version
|
||||
|
||||
obi_view_unmap_file(self._pointer, view_infos_p)
|
||||
|
||||
return view_infos_d
|
||||
|
||||
|
||||
|
65
python/obitools3/dms/_obidmscolumn.cfiles
Normal file
65
python/obitools3/dms/_obidmscolumn.cfiles
Normal file
@ -0,0 +1,65 @@
|
||||
../../../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
|
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
|
65
python/obitools3/dms/_obidmscolumn_bool.cfiles
Normal file
65
python/obitools3/dms/_obidmscolumn_bool.cfiles
Normal file
@ -0,0 +1,65 @@
|
||||
../../../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
|
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)
|
65
python/obitools3/dms/_obiseq.cfiles
Normal file
65
python/obitools3/dms/_obiseq.cfiles
Normal file
@ -0,0 +1,65 @@
|
||||
../../../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
|
21
python/obitools3/dms/_obiseq.pxd
Normal file
21
python/obitools3/dms/_obiseq.pxd
Normal file
@ -0,0 +1,21 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from ._obiview cimport OBIView_line
|
||||
|
||||
|
||||
cdef class OBI_Seq(dict) :
|
||||
cdef str _id
|
||||
cdef object _seq
|
||||
cdef str _definition
|
||||
|
||||
|
||||
cdef class OBI_Nuc_Seq(OBI_Seq) :
|
||||
cdef object _quality
|
||||
cpdef object get_str_quality(self)
|
||||
|
||||
#cpdef object reverse_complement(self)
|
||||
|
||||
cdef class OBI_Nuc_Seq_Stored(OBIView_line) :
|
||||
cpdef object get_str_quality(self)
|
||||
|
||||
#cpdef object reverse_complement(self)
|
188
python/obitools3/dms/_obiseq.pyx
Normal file
188
python/obitools3/dms/_obiseq.pyx
Normal file
@ -0,0 +1,188 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from obitools3.utils cimport bytes2str, str2bytes
|
||||
|
||||
from .capi.obiview cimport NUC_SEQUENCE_COLUMN, \
|
||||
ID_COLUMN, \
|
||||
DEFINITION_COLUMN, \
|
||||
QUALITY_COLUMN
|
||||
from docutils.nodes import definition
|
||||
|
||||
|
||||
cdef str __str__ID_COLUMN__ = bytes2str(ID_COLUMN)
|
||||
cdef str __str__DEFINITION_COLUMN__ = bytes2str(DEFINITION_COLUMN)
|
||||
cdef str __str__QUALITY_COLUMN__ = bytes2str(QUALITY_COLUMN)
|
||||
cdef str __str__NUC_SEQUENCE_COLUMN__ = bytes2str(NUC_SEQUENCE_COLUMN)
|
||||
|
||||
|
||||
cdef class OBI_Seq(dict) :
|
||||
|
||||
def __init__(self, str id,
|
||||
object seq,
|
||||
str definition=None,
|
||||
dict tags=None) :
|
||||
|
||||
if tags is not None:
|
||||
self.update(tags)
|
||||
|
||||
self._id = id
|
||||
self._seq = seq
|
||||
|
||||
if definition is not None :
|
||||
self._definition = definition
|
||||
else:
|
||||
self._definition = None
|
||||
|
||||
|
||||
|
||||
def __getitem__(self,str key):
|
||||
if key == __str__ID_COLUMN__:
|
||||
return self._id
|
||||
elif key == __str__DEFINITION_COLUMN__:
|
||||
return self._definition
|
||||
else:
|
||||
return dict.__getitem__(self,key)
|
||||
|
||||
def __setitem__(self,str key,object value):
|
||||
if key == __str__ID_COLUMN__:
|
||||
self._id=value
|
||||
elif key == __str__DEFINITION_COLUMN__:
|
||||
self._definition=value
|
||||
else:
|
||||
dict.__setitem__(self,key,value)
|
||||
|
||||
# sequence id property getter and setter
|
||||
@property
|
||||
def id(self): # @ReservedAssignment
|
||||
return self._id
|
||||
@id.setter
|
||||
def id(self, str new_id): # @ReservedAssignment @DuplicatedSignature
|
||||
self._id = new_id
|
||||
|
||||
# sequence property getter and setter
|
||||
@property
|
||||
def seq(self):
|
||||
return self._seq
|
||||
@seq.setter
|
||||
def seq(self, object new_seq): # @DuplicatedSignature
|
||||
self._seq = new_seq
|
||||
# self["SEQ"] = new_seq # TODO discuss
|
||||
|
||||
# sequence definition property getter and setter
|
||||
@property
|
||||
def definition(self):
|
||||
return self._definition
|
||||
@definition.setter
|
||||
def definition(self, object new_definition): # @DuplicatedSignature
|
||||
self._definition = new_definition
|
||||
|
||||
|
||||
cdef class OBI_Nuc_Seq(OBI_Seq) :
|
||||
|
||||
def __init__(self, str id,
|
||||
object seq,
|
||||
str quality=None,
|
||||
str definition=None,
|
||||
dict tags=None) :
|
||||
OBI_Seq.__init__(self,id,seq,tags)
|
||||
if quality is not None:
|
||||
self._quality=quality
|
||||
else:
|
||||
self._quality=None
|
||||
|
||||
|
||||
|
||||
def __getitem__(self,str key):
|
||||
if key == __str__NUC_SEQUENCE_COLUMN__:
|
||||
return self._seq
|
||||
elif key == __str__QUALITY_COLUMN__:
|
||||
return self._quality
|
||||
else:
|
||||
return OBI_Seq.__getitem__(self,key)
|
||||
|
||||
def __setitem__(self,str key, object value):
|
||||
if key == __str__NUC_SEQUENCE_COLUMN__:
|
||||
self._seq = value
|
||||
elif key == __str__QUALITY_COLUMN__:
|
||||
self._quality=value
|
||||
else:
|
||||
OBI_Seq.__setitem__(self,key,value)
|
||||
|
||||
|
||||
|
||||
cpdef object get_str_quality(self) : # TODO not ideal. Make quality_int and quality_str properties
|
||||
return self._quality
|
||||
|
||||
# nuc sequence property getter and setter
|
||||
@property
|
||||
def seq(self):
|
||||
return self._seq
|
||||
@seq.setter
|
||||
def seq(self, object new_seq): # @DuplicatedSignature
|
||||
self._seq = new_seq
|
||||
# self[bytes2str(NUC_SEQUENCE_COLUMN)] = new_seq
|
||||
|
||||
# sequence quality property getter and setter
|
||||
@property
|
||||
def quality(self):
|
||||
return self._quality
|
||||
@quality.setter
|
||||
def quality(self, object new_quality): # @DuplicatedSignature
|
||||
self._quality = new_quality
|
||||
# self[bytes2str(QUALITY_COLUMN)] = new_quality
|
||||
|
||||
# cpdef str reverse_complement(self) : TODO in C ?
|
||||
# pass
|
||||
|
||||
|
||||
cdef class OBI_Nuc_Seq_Stored(OBIView_line) :
|
||||
|
||||
# TODO store the str version of column name macros?
|
||||
|
||||
# sequence id property getter and setter
|
||||
@property
|
||||
def id(self): # @ReservedAssignment @DuplicatedSignature
|
||||
return self[__str__ID_COLUMN__]
|
||||
|
||||
@id.setter
|
||||
def id(self, str new_id): # @ReservedAssignment @DuplicatedSignature
|
||||
self[__str__ID_COLUMN__] = new_id
|
||||
|
||||
# sequence definition property getter and setter
|
||||
@property
|
||||
def definition(self):
|
||||
return self[__str__DEFINITION_COLUMN__]
|
||||
|
||||
@definition.setter
|
||||
def definition(self, str new_def): # @DuplicatedSignature
|
||||
self[__str__DEFINITION_COLUMN__] = new_def
|
||||
|
||||
# nuc_seq property getter and setter
|
||||
@property
|
||||
def nuc_seq(self):
|
||||
return self[__str__NUC_SEQUENCE_COLUMN__]
|
||||
|
||||
@nuc_seq.setter
|
||||
def nuc_seq(self, object new_seq): # @DuplicatedSignature
|
||||
self[__str__NUC_SEQUENCE_COLUMN__] = new_seq
|
||||
|
||||
# quality property getter and setter
|
||||
@property
|
||||
def quality(self):
|
||||
return self[__str__QUALITY_COLUMN__]
|
||||
|
||||
@quality.setter
|
||||
def quality(self, object new_qual): # @DuplicatedSignature
|
||||
if (type(new_qual) == list) or (new_qual is None) : # TODO check that quality column exists
|
||||
self[__str__QUALITY_COLUMN__] = new_qual
|
||||
else : # Quality is in str form
|
||||
(((self._view).columns)[__str__QUALITY_COLUMN__]).set_str_line(self._index, new_qual)
|
||||
|
||||
cpdef object get_str_quality(self) : # TODO not ideal. Make quality_int and quality_str properties
|
||||
return ((self._view).columns)[__str__QUALITY_COLUMN__].get_str_line(self._index)
|
||||
|
||||
# cpdef str reverse_complement(self) : TODO in C ?
|
||||
# pass
|
||||
|
||||
# TODO static method to import OBI_Nuc_Seq to OBI_Nuc_Seq_Stored ?
|
||||
|
65
python/obitools3/dms/_obitaxo.cfiles
Normal file
65
python/obitools3/dms/_obitaxo.cfiles
Normal file
@ -0,0 +1,65 @@
|
||||
../../../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
|
20
python/obitools3/dms/_obitaxo.pxd
Normal file
20
python/obitools3/dms/_obitaxo.pxd
Normal file
@ -0,0 +1,20 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitaxonomy cimport ecotx_t, OBIDMS_taxonomy_p
|
||||
from ._obidms cimport OBIDMS
|
||||
|
||||
|
||||
cdef class OBI_Taxonomy :
|
||||
|
||||
cdef str _name
|
||||
cdef OBIDMS_taxonomy_p _pointer
|
||||
cdef OBIDMS _dms
|
||||
|
||||
cpdef write(self, str prefix)
|
||||
cpdef int add_taxon(self, str name, str rank_name, int parent_taxid, int min_taxid=*)
|
||||
cpdef close(self)
|
||||
|
||||
|
||||
cdef class OBI_Taxon :
|
||||
|
||||
cdef ecotx_t* _pointer
|
129
python/obitools3/dms/_obitaxo.pyx
Normal file
129
python/obitools3/dms/_obitaxo.pyx
Normal file
@ -0,0 +1,129 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from obitools3.utils cimport bytes2str, str2bytes
|
||||
|
||||
from .capi.obitaxonomy cimport obi_read_taxonomy, \
|
||||
obi_read_taxdump, \
|
||||
obi_write_taxonomy, \
|
||||
obi_close_taxonomy, \
|
||||
obi_taxo_get_taxon_with_taxid, \
|
||||
obi_taxonomy_add_local_taxon, \
|
||||
ecotx_t
|
||||
|
||||
|
||||
from ._obidms cimport OBIDMS
|
||||
|
||||
from cpython.pycapsule cimport PyCapsule_New, PyCapsule_GetPointer
|
||||
from logging import raiseExceptions
|
||||
|
||||
|
||||
cdef class OBI_Taxonomy :
|
||||
|
||||
# TODO function to import taxonomy?
|
||||
|
||||
def __init__(self, OBIDMS dms, str name, bint taxdump=False) :
|
||||
|
||||
self._dms = dms
|
||||
self._name = name
|
||||
if taxdump :
|
||||
self._pointer = obi_read_taxdump(str2bytes(name))
|
||||
else :
|
||||
self._pointer = obi_read_taxonomy(dms._pointer, str2bytes(name), True) # TODO discuss
|
||||
# TODO if not found in DMS, try to import?
|
||||
|
||||
|
||||
def __getitem__(self, object ref):
|
||||
|
||||
cdef ecotx_t* taxon_p
|
||||
cdef object taxon_capsule
|
||||
|
||||
if type(ref) == int :
|
||||
taxon_p = obi_taxo_get_taxon_with_taxid(self._pointer, ref)
|
||||
if taxon_p == NULL :
|
||||
raise Exception("Taxon not found")
|
||||
taxon_capsule = PyCapsule_New(taxon_p, NULL, NULL)
|
||||
return OBI_Taxon(taxon_capsule)
|
||||
else :
|
||||
raise Exception("Not implemented")
|
||||
|
||||
|
||||
def __iter__(self):
|
||||
|
||||
cdef ecotx_t* taxa
|
||||
cdef ecotx_t* taxon_p
|
||||
cdef object taxon_capsule
|
||||
cdef int t
|
||||
|
||||
taxa = self._pointer.taxa.taxon
|
||||
|
||||
# Yield each taxid
|
||||
for t in range(self._pointer.taxa.count):
|
||||
taxon_p = <ecotx_t*> (taxa+t)
|
||||
taxon_capsule = PyCapsule_New(taxon_p, NULL, NULL)
|
||||
yield OBI_Taxon(taxon_capsule)
|
||||
|
||||
|
||||
cpdef write(self, str prefix) :
|
||||
if obi_write_taxonomy(self._dms._pointer, self._pointer, str2bytes(prefix)) < 0 :
|
||||
raise Exception("Error writing the taxonomy to binary files")
|
||||
|
||||
|
||||
cpdef int add_taxon(self, str name, str rank_name, int parent_taxid, int min_taxid=10000000) :
|
||||
cdef int taxid
|
||||
taxid = obi_taxonomy_add_local_taxon(self._pointer, str2bytes(name), str2bytes(rank_name), parent_taxid, min_taxid)
|
||||
if taxid < 0 :
|
||||
raise Exception("Error adding a new taxon to the taxonomy")
|
||||
else :
|
||||
return taxid
|
||||
|
||||
|
||||
cpdef close(self) :
|
||||
if (obi_close_taxonomy(self._pointer) < 0) :
|
||||
raise Exception("Error closing the taxonomy")
|
||||
|
||||
|
||||
|
||||
cdef class OBI_Taxon : # TODO dict subclass?
|
||||
|
||||
def __init__(self, object taxon_capsule) :
|
||||
self._pointer = <ecotx_t*> PyCapsule_GetPointer(taxon_capsule, NULL)
|
||||
if self._pointer == NULL :
|
||||
raise Exception("Error reading the taxonomy")
|
||||
|
||||
# name property getter
|
||||
@property
|
||||
def name(self):
|
||||
return bytes2str(self._pointer.name)
|
||||
|
||||
# taxid property getter
|
||||
@property
|
||||
def taxid(self):
|
||||
return self._pointer.taxid
|
||||
|
||||
# rank property getter
|
||||
@property
|
||||
def rank(self):
|
||||
return self._pointer.rank
|
||||
|
||||
# farest property getter
|
||||
@property
|
||||
def farest(self):
|
||||
return self._pointer.farest
|
||||
|
||||
# parent property getter
|
||||
@property
|
||||
def parent(self):
|
||||
cdef object parent_capsule
|
||||
parent_capsule = PyCapsule_New(self._pointer.parent, NULL, NULL)
|
||||
return OBI_Taxon(parent_capsule)
|
||||
|
||||
def __repr__(self):
|
||||
d = {}
|
||||
d['taxid'] = self.taxid
|
||||
d['name'] = self.name
|
||||
d['parent'] = self.parent.taxid
|
||||
d['farest'] = self.farest
|
||||
return str(d)
|
||||
|
||||
|
||||
|
96
python/obitools3/dms/_obiview.pxd
Normal file
96
python/obitools3/dms/_obiview.pxd
Normal file
@ -0,0 +1,96 @@
|
||||
#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, \
|
||||
obi_new_view_nuc_seqs, \
|
||||
obi_new_view, \
|
||||
obi_new_view_cloned_from_name, \
|
||||
obi_new_view_nuc_seqs_cloned_from_name, \
|
||||
obi_view_map_file, \
|
||||
obi_view_unmap_file, \
|
||||
obi_open_view, \
|
||||
obi_view_delete_column, \
|
||||
obi_view_add_column, \
|
||||
obi_view_create_column_alias, \
|
||||
obi_view_get_column, \
|
||||
obi_view_get_pointer_on_column_in_view, \
|
||||
obi_save_and_close_view, \
|
||||
VIEW_TYPE_NUC_SEQS, \
|
||||
NUC_SEQUENCE_COLUMN, \
|
||||
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)
|
||||
|
||||
cpdef OBIView clone(self,
|
||||
view_name,
|
||||
comments=*)
|
||||
|
||||
@staticmethod
|
||||
cdef OBIView _new(OBIDMS dms,
|
||||
bytes view_name,
|
||||
bytes comments=*)
|
||||
|
||||
@staticmethod
|
||||
cdef OBIView _open(OBIDMS dms,
|
||||
bytes view_name)
|
||||
|
||||
cpdef delete_column(self, column_name)
|
||||
cpdef add_column(self,
|
||||
str column_name,
|
||||
obiversion_t version_number=*,
|
||||
object alias=*,
|
||||
object type=*,
|
||||
index_t nb_lines=*,
|
||||
index_t nb_elements_per_line=*,
|
||||
list elements_names=*,
|
||||
object indexer_name=*,
|
||||
object associated_column_name=*,
|
||||
obiversion_t associated_column_version=*,
|
||||
object comments=*,
|
||||
bint create=*
|
||||
)
|
||||
|
||||
|
||||
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=*)
|
||||
|
||||
cdef class OBIView_line_selection(list):
|
||||
|
||||
cdef OBIView _view
|
||||
cdef str _view_name
|
||||
|
||||
cdef index_t* __build_binary_list__(self)
|
||||
cpdef OBIView materialize(self,
|
||||
str view_name,
|
||||
str comments=*)
|
||||
|
||||
cdef class OBIView_line :
|
||||
|
||||
cdef index_t _index
|
||||
cdef OBIView _view
|
||||
|
||||
|
403
python/obitools3/dms/_obiview.pyx
Normal file
403
python/obitools3/dms/_obiview.pyx
Normal file
@ -0,0 +1,403 @@
|
||||
#cython: language_level=3
|
||||
|
||||
|
||||
cdef class OBIView :
|
||||
|
||||
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 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 = 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,
|
||||
view_name,
|
||||
comments=b""):
|
||||
|
||||
cdef OBIView view = OBIView(self._dms,
|
||||
987654)
|
||||
|
||||
view._pointer = obi_new_view(self._pointer.dms,
|
||||
tobytes(view_name),
|
||||
self._pointer,
|
||||
NULL,
|
||||
tobytes(comments))
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
% (str(self.name),
|
||||
tobytes(view_name))
|
||||
)
|
||||
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
@staticmethod
|
||||
cdef OBIView _new(OBIDMS dms,
|
||||
bytes view_name,
|
||||
bytes comments=b""):
|
||||
|
||||
cdef OBIView view = OBIView(dms,
|
||||
987654) # @DuplicatedSignature
|
||||
|
||||
view._pointer = obi_new_view(dms._pointer,
|
||||
view_name,
|
||||
NULL,
|
||||
NULL,
|
||||
comments)
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot create view %s" % view_name)
|
||||
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
@staticmethod
|
||||
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(dms,
|
||||
987654) # @DuplicatedSignature
|
||||
|
||||
view._pointer = obi_open_view(dms._pointer,
|
||||
view_name)
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot open view %s" % bytes2str(view_name))
|
||||
|
||||
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) :
|
||||
raise Exception("Problem closing a view")
|
||||
|
||||
|
||||
def __repr__(self) :
|
||||
cdef str s
|
||||
s = str(self.name) + "\n" + str(self.comments) + "\n" + str(self.line_count) + " lines\n"
|
||||
for column_name in self._columns :
|
||||
s = s + repr(self._columns[column_name]) + '\n'
|
||||
return s
|
||||
|
||||
|
||||
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,
|
||||
object alias=None,
|
||||
object type=b'',
|
||||
index_t nb_lines=0,
|
||||
index_t nb_elements_per_line=1,
|
||||
list elements_names=None,
|
||||
object indexer_name=b"",
|
||||
object associated_column_name=b"",
|
||||
obiversion_t associated_column_version=-1,
|
||||
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 = tobytes(column_name)
|
||||
if alias is None :
|
||||
alias_b = column_name_b
|
||||
else :
|
||||
alias_b = tobytes(alias)
|
||||
|
||||
if elements_names is None :
|
||||
elements_names_b = b""
|
||||
else :
|
||||
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' :
|
||||
data_type = OBI_INT
|
||||
elif type == 'OBI_FLOAT' :
|
||||
data_type = OBI_FLOAT
|
||||
elif type == 'OBI_BOOL' :
|
||||
data_type = OBI_BOOL
|
||||
elif type == 'OBI_CHAR' :
|
||||
data_type = OBI_CHAR
|
||||
elif type == 'OBI_QUAL' :
|
||||
data_type = OBI_QUAL
|
||||
elif type == 'OBI_STR' :
|
||||
data_type = OBI_STR
|
||||
elif type == 'OBI_SEQ' :
|
||||
data_type = OBI_SEQ
|
||||
else :
|
||||
raise Exception("Invalid provided data type")
|
||||
|
||||
if (obi_view_add_column(self._pointer, column_name_b, version_number, alias_b,
|
||||
data_type, nb_lines, nb_elements_per_line,
|
||||
elements_names_b, str2bytes(indexer_name),
|
||||
str2bytes(associated_column_name), associated_column_version,
|
||||
str2bytes(comments), create) < 0) :
|
||||
raise Exception("Problem adding a column in a view")
|
||||
|
||||
# Get the column pointer
|
||||
column_p = obi_view_get_column(self._pointer, alias_b)
|
||||
|
||||
# Open and store the subclass
|
||||
subclass = OBIDMS_column.get_subclass_type(column_p)
|
||||
(self._columns)[alias] = subclass(self, alias)
|
||||
|
||||
|
||||
cpdef change_column_alias(self, bytes current_alias, bytes new_alias):
|
||||
cdef OBIDMS_column column
|
||||
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]
|
||||
column = self._columns[new_alias]
|
||||
column._alias = new_alias
|
||||
(self._columns).pop(current_alias)
|
||||
|
||||
|
||||
cdef update_column_pointers(self):
|
||||
cdef str column_n
|
||||
cdef OBIDMS_column column
|
||||
for column_n in self._columns :
|
||||
column = self._columns[column_n]
|
||||
column._pointer = <OBIDMS_column_p*> obi_view_get_pointer_on_column_in_view(self._pointer, str2bytes(column_n))
|
||||
|
||||
cpdef OBIView_line_selection new_selection(self,list lines=None):
|
||||
return OBIView_line_selection(self,lines)
|
||||
|
||||
def __iter__(self):
|
||||
# Iteration on each line of all columns
|
||||
|
||||
# Declarations
|
||||
cdef index_t line_nb
|
||||
cdef OBIView_line line
|
||||
|
||||
# Yield each line
|
||||
for line_nb in range(self.line_count) :
|
||||
line = self[line_nb]
|
||||
yield line
|
||||
|
||||
|
||||
def __getitem__(self, object item) :
|
||||
if type(item) == str :
|
||||
return (self._columns)[item]
|
||||
elif type(item) == int :
|
||||
return OBIView_line(self, item)
|
||||
|
||||
|
||||
def __contains__(self, str column_name):
|
||||
return (column_name in self._columns)
|
||||
|
||||
|
||||
def __len__(self):
|
||||
return(self.line_count)
|
||||
|
||||
|
||||
def __str__(self) :
|
||||
cdef OBIView_line line
|
||||
cdef str to_print
|
||||
to_print = ""
|
||||
for line in self :
|
||||
to_print = to_print + str(line) + "\n"
|
||||
return to_print
|
||||
|
||||
|
||||
@property
|
||||
def dms(self):
|
||||
return self._dms
|
||||
|
||||
# line_count property getter
|
||||
@property
|
||||
def line_count(self):
|
||||
return self._pointer.infos.line_count
|
||||
|
||||
# name property getter
|
||||
@property
|
||||
def name(self):
|
||||
return bytes2str(self._pointer.infos.name)
|
||||
|
||||
# view type property getter
|
||||
@property
|
||||
def type(self): # @ReservedAssignment
|
||||
return bytes2str(self._pointer.infos.view_type)
|
||||
|
||||
# columns property getter
|
||||
@property
|
||||
def columns(self):
|
||||
return self._columns
|
||||
|
||||
# comments property getter
|
||||
@property
|
||||
def comments(self):
|
||||
return bytes2str(self._pointer.infos.comments)
|
||||
# TODO setter that concatenates new comments?
|
||||
|
||||
|
||||
cdef class OBIView_line_selection(list):
|
||||
|
||||
def __init__(self, OBIView view, lines=None) :
|
||||
if view._pointer == NULL:
|
||||
raise Exception("Error: trying to create a line selection with an invalidated view")
|
||||
self._view = view
|
||||
self._view_name = view.name
|
||||
|
||||
if lines is not None:
|
||||
self.extend(lines)
|
||||
|
||||
def extend(self, iterable):
|
||||
cdef index_t i
|
||||
cdef index_t max_i = self._view.line_count
|
||||
|
||||
for i in iterable:
|
||||
if i > max_i:
|
||||
raise RuntimeError("Error: trying to select line %d beyond the line count %d of view %s" %
|
||||
(i,
|
||||
max_i,
|
||||
self._view_name)
|
||||
)
|
||||
list.append(self,i)
|
||||
|
||||
def append(self, index_t idx) :
|
||||
if idx >= self._view.line_count :
|
||||
raise RuntimeError("Error: trying to select line %d beyond the line count %d of view %s" %
|
||||
(i,
|
||||
max_i,
|
||||
self._view_name)
|
||||
)
|
||||
list.append(self,idx)
|
||||
|
||||
cdef index_t* __build_binary_list__(self):
|
||||
cdef index_t* line_selection_p = NULL
|
||||
cdef int i
|
||||
cdef size_t l_selection = len(self)
|
||||
|
||||
line_selection_p = <index_t*> malloc((l_selection + 1) * sizeof(index_t)) # +1 for the -1 flagging the end of the array
|
||||
for i in range(l_selection) :
|
||||
line_selection_p[i] = line_selection[i]
|
||||
line_selection_p[l_selection] = -1 # flagging the end of the array
|
||||
|
||||
return line_selection_p
|
||||
|
||||
cpdef OBIView materialize(self,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
|
||||
cdef OBIView view = OBIView(987654)
|
||||
|
||||
view._pointer = obi_new_view(self._view._pointer.dms,
|
||||
str2bytes(view_name),
|
||||
self._view._pointer,
|
||||
self.__build_binary_list__(),
|
||||
str2bytes(comments))
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
% (str(self.name),
|
||||
view_name)
|
||||
)
|
||||
|
||||
view.__init_columns__()
|
||||
|
||||
return view
|
||||
|
||||
|
||||
cdef class OBIView_line :
|
||||
|
||||
def __init__(self, OBIView view, index_t line_nb) :
|
||||
self._index = line_nb
|
||||
self._view = view
|
||||
|
||||
def __getitem__(self, str column_name) :
|
||||
return ((self._view)._columns)[column_name][self._index]
|
||||
|
||||
def __setitem__(self, str column_name, object value):
|
||||
# TODO detect multiple elements (dict type)? put somewhere else? but more risky (in get)
|
||||
# TODO OBI_QUAL ?
|
||||
cdef type value_type
|
||||
cdef str value_obitype
|
||||
cdef bytes value_b
|
||||
|
||||
if column_name not in self._view :
|
||||
if value == None :
|
||||
raise Exception("Trying to create a column from a None value (can't guess type)")
|
||||
value_type = type(value)
|
||||
if value_type == int :
|
||||
value_obitype = 'OBI_INT'
|
||||
elif value_type == float :
|
||||
value_obitype = 'OBI_FLOAT'
|
||||
elif value_type == bool :
|
||||
value_obitype = 'OBI_BOOL'
|
||||
elif value_type == str or value_type == bytes :
|
||||
if value_type == str :
|
||||
value_b = str2bytes(value)
|
||||
else :
|
||||
value_b = value
|
||||
if only_ATGC(value_b) : # TODO detect IUPAC
|
||||
value_obitype = 'OBI_SEQ'
|
||||
elif len(value) == 1 :
|
||||
value_obitype = 'OBI_CHAR'
|
||||
elif (len(value) > 1) :
|
||||
value_obitype = 'OBI_STR'
|
||||
else :
|
||||
raise Exception("Could not guess the type of a value to create a new column")
|
||||
self._view.add_column(column_name, type=value_obitype)
|
||||
|
||||
(((self._view)._columns)[column_name]).set_line(self._index, value)
|
||||
|
||||
def __iter__(self):
|
||||
for column_name in ((self._view)._columns) :
|
||||
yield column_name
|
||||
|
||||
def __contains__(self, str column_name):
|
||||
return (column_name in self._view._columns)
|
||||
|
||||
def __repr__(self):
|
||||
cdef dict line
|
||||
cdef str column_name
|
||||
line = {}
|
||||
for column_name in self._view._columns :
|
||||
line[column_name] = self[column_name]
|
||||
return str(line)
|
||||
|
||||
|
||||
|
25
python/obitools3/dms/_obiview_nuc_seq.pxd
Normal file
25
python/obitools3/dms/_obiview_nuc_seq.pxd
Normal file
@ -0,0 +1,25 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from ._obiview cimport OBIView
|
||||
from ._obiseq cimport OBI_Nuc_Seq, OBI_Nuc_Seq_Stored
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS_QUAL(OBIView_NUC_SEQS):
|
||||
cpdef OBIView clone(self,
|
||||
str view_name,
|
||||
OBIView_line_selection line_selection=*,
|
||||
str comments=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
str view_name)
|
||||
|
||||
cdef class OBIView_NUC_SEQS_line_selection(OBIView_line_selection):
|
||||
cpdef OBIView materialize(self,
|
||||
str view_name,
|
||||
str comments=*)
|
105
python/obitools3/dms/_obiview_nuc_seq.pyx
Normal file
105
python/obitools3/dms/_obiview_nuc_seq.pyx
Normal file
@ -0,0 +1,105 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS(OBIView):
|
||||
|
||||
cpdef OBIView clone(self,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS(987654)
|
||||
|
||||
view._pointer = obi_new_view_nuc_seqs(self._pointer.dms,
|
||||
str2bytes(view_name),
|
||||
self._pointer,
|
||||
NULL,
|
||||
str2bytes(comments),
|
||||
False)
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
% (str(self.name),
|
||||
view_name)
|
||||
)
|
||||
|
||||
view.__init_columns__(self)
|
||||
|
||||
return view
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS(987654) # @DuplicatedSignature
|
||||
|
||||
view._pointer = obi_new_view_nuc_seqs(dms._pointer,
|
||||
str2bytes(view_name),
|
||||
NULL,
|
||||
NULL,
|
||||
str2bytes(comments),
|
||||
False)
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot create view %s" % view_name)
|
||||
|
||||
view.__init_columns__(self)
|
||||
|
||||
return view
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
str view_name):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS(987654) # @DuplicatedSignature
|
||||
|
||||
view._pointer = obi_open_view(dms._pointer,
|
||||
str2bytes(view_name))
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot open view %s" % view_name)
|
||||
|
||||
view.__init_columns__(self)
|
||||
|
||||
return view
|
||||
|
||||
cpdef OBIView_line_selection new_selection(self,list lines=None):
|
||||
return OBIView_NUC_SEQS_line_selection(self,lines)
|
||||
|
||||
def __getitem__(self, object item) :
|
||||
if type(item) == str :
|
||||
return (self._columns)[item]
|
||||
elif type(item) == int :
|
||||
return OBI_Nuc_Seq_Stored(self, item)
|
||||
|
||||
|
||||
def __setitem__(self, index_t line_idx, OBI_Nuc_Seq sequence_obj) :
|
||||
for key in sequence_obj :
|
||||
self[line_idx][key] = sequence_obj[key]
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS_line_selection(OBIView_line_selection):
|
||||
|
||||
cpdef OBIView materialize(self,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS(987654)
|
||||
|
||||
view._pointer = obi_new_view(self._view._pointer.dms,
|
||||
str2bytes(view_name),
|
||||
self._view._pointer,
|
||||
self.__build_binary_list__(),
|
||||
str2bytes(comments))
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
% (str(self.name),
|
||||
view_name)
|
||||
)
|
||||
|
||||
view.__init_columns__(self)
|
||||
|
||||
return view
|
25
python/obitools3/dms/_obiview_nuc_seq_qual.pxd
Normal file
25
python/obitools3/dms/_obiview_nuc_seq_qual.pxd
Normal file
@ -0,0 +1,25 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from ._obidms cimport OBIView
|
||||
from ._obiseq cimport OBI_Nuc_Seq, OBI_Nuc_Seq_Stored
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS_QUAL(OBIView_NUC_SEQS):
|
||||
cpdef OBIView clone(self,
|
||||
str view_name,
|
||||
OBIView_line_selection line_selection=*,
|
||||
str comments=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=*)
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
str view_name)
|
||||
|
||||
cdef class OBIView_NUC_SEQS_QUAL_line_selection(OBIView_NUC_SEQS_line_selection):
|
||||
cpdef OBIView materialize(self,
|
||||
str view_name,
|
||||
str comments=*)
|
90
python/obitools3/dms/_obiview_nuc_seq_qual.pyx
Normal file
90
python/obitools3/dms/_obiview_nuc_seq_qual.pyx
Normal file
@ -0,0 +1,90 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .capi.obitypes cimport index_t
|
||||
|
||||
|
||||
cdef class OBIView_NUC_SEQS_QUAL(OBIView_NUC_SEQS):
|
||||
|
||||
cpdef OBIView clone(self,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS_QUAL(987654)
|
||||
|
||||
view._pointer = obi_new_view_nuc_seqs(self._pointer.dms,
|
||||
str2bytes(view_name),
|
||||
self._pointer,
|
||||
NULL,
|
||||
str2bytes(comments),
|
||||
True)
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
% (str(self.name),
|
||||
view_name)
|
||||
)
|
||||
|
||||
view.__init_columns__(self)
|
||||
|
||||
return view
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView new(OBIDMS dms,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS_QUAL(987654) # @DuplicatedSignature
|
||||
|
||||
view._pointer = obi_new_view_nuc_seqs(dms._pointer,
|
||||
str2bytes(view_name),
|
||||
NULL,
|
||||
NULL,
|
||||
str2bytes(comments),
|
||||
True)
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot create view %s" % view_name)
|
||||
|
||||
view.__init_columns__(self)
|
||||
|
||||
return view
|
||||
|
||||
@staticmethod
|
||||
cpdef OBIView open(OBIDMS dms,
|
||||
str view_name):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS_QUAL(987654) # @DuplicatedSignature
|
||||
|
||||
view._pointer = obi_open_view(dms._pointer,
|
||||
str2bytes(view_name))
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot open view %s" % view_name)
|
||||
|
||||
view.__init_columns__(self)
|
||||
|
||||
return view
|
||||
|
||||
cdef class OBIView_NUC_SEQS_QUAL_line_selection(OBIView_NUC_SEQS_line_selection):
|
||||
|
||||
cpdef OBIView materialize(self,
|
||||
str view_name,
|
||||
str comments=""):
|
||||
|
||||
cdef OBIView view = OBIView_NUC_SEQS_QUAL(987654)
|
||||
|
||||
view._pointer = obi_new_view(self._view._pointer.dms,
|
||||
str2bytes(view_name),
|
||||
self._view._pointer,
|
||||
self.__build_binary_list__(),
|
||||
str2bytes(comments))
|
||||
|
||||
if view._pointer == NULL :
|
||||
raise RuntimeError("Error : Cannot clone view %s into view %s"
|
||||
% (str(self.name),
|
||||
view_name)
|
||||
)
|
||||
|
||||
view.__init_columns__(self)
|
||||
|
||||
return view
|
0
python/obitools3/dms/capi/__init__.py
Normal file
0
python/obitools3/dms/capi/__init__.py
Normal file
22
python/obitools3/dms/capi/obialign.pxd
Normal file
22
python/obitools3/dms/capi/obialign.pxd
Normal file
@ -0,0 +1,22 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from obitools3.obidms.capi.obidms cimport OBIDMS_p
|
||||
from obitools3.obidms.capi.obitypes cimport const_char_p
|
||||
|
||||
|
||||
cdef extern from "obi_align.h" nogil:
|
||||
|
||||
int obi_lcs_align_one_column(OBIDMS_p dms,
|
||||
const_char_p seq_view_name,
|
||||
const_char_p seq_column_name,
|
||||
const_char_p seq_elt_name,
|
||||
const_char_p id_column_name,
|
||||
const_char_p output_view_name,
|
||||
const_char_p output_view_comments,
|
||||
bint print_seq,
|
||||
bint print_count,
|
||||
double threshold,
|
||||
bint normalize,
|
||||
int reference,
|
||||
bint similarity_mode)
|
||||
|
12
python/obitools3/dms/capi/obidms.pxd
Normal file
12
python/obitools3/dms/capi/obidms.pxd
Normal file
@ -0,0 +1,12 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .obitypes cimport const_char_p
|
||||
|
||||
cdef extern from "obidms.h" nogil:
|
||||
struct OBIDMS_t:
|
||||
const_char_p dms_name
|
||||
|
||||
ctypedef OBIDMS_t* OBIDMS_p
|
||||
|
||||
OBIDMS_p obi_dms(const_char_p dms_name)
|
||||
int obi_close_dms(OBIDMS_p dms)
|
250
python/obitools3/dms/capi/obidmscolumn.pxd
Normal file
250
python/obitools3/dms/capi/obidmscolumn.pxd
Normal file
@ -0,0 +1,250 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from ..capi.obidms cimport OBIDMS_p
|
||||
from ..capi.obitypes cimport const_char_p, \
|
||||
OBIType_t, \
|
||||
obiversion_t, \
|
||||
obiint_t, \
|
||||
obibool_t, \
|
||||
obichar_t, \
|
||||
obifloat_t, \
|
||||
index_t, \
|
||||
time_t
|
||||
|
||||
from libc.stdint cimport uint8_t
|
||||
|
||||
|
||||
cdef extern from "obidmscolumn.h" nogil:
|
||||
|
||||
struct Column_reference_t :
|
||||
const_char_p column_name
|
||||
obiversion_t version
|
||||
|
||||
ctypedef Column_reference_t* Column_reference_p
|
||||
|
||||
struct OBIDMS_column_header_t:
|
||||
size_t header_size
|
||||
size_t data_size
|
||||
index_t line_count
|
||||
index_t lines_used
|
||||
index_t nb_elements_per_line
|
||||
const_char_p elements_names
|
||||
OBIType_t returned_data_type
|
||||
OBIType_t stored_data_type
|
||||
time_t creation_date
|
||||
obiversion_t version
|
||||
obiversion_t cloned_from
|
||||
const_char_p name
|
||||
const_char_p indexer_name
|
||||
Column_reference_t associated_column
|
||||
const_char_p comments
|
||||
|
||||
ctypedef OBIDMS_column_header_t* OBIDMS_column_header_p
|
||||
|
||||
struct OBIDMS_column_t:
|
||||
OBIDMS_p dms
|
||||
OBIDMS_column_header_p header
|
||||
bint writable
|
||||
|
||||
ctypedef OBIDMS_column_t* OBIDMS_column_p
|
||||
|
||||
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
const_char_p column_name,
|
||||
OBIType_t type,
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
const_char_p elements_names,
|
||||
const_char_p indexer_name,
|
||||
const_char_p associated_colum_name,
|
||||
obiversion_t associated_colum_version,
|
||||
const_char_p comments)
|
||||
|
||||
OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
const_char_p column_name,
|
||||
obiversion_t version_number)
|
||||
|
||||
OBIDMS_column_p obi_clone_column(OBIDMS_p dms,
|
||||
OBIDMS_column_p line_selection,
|
||||
const_char_p column_name,
|
||||
obiversion_t version_number,
|
||||
bint clone_data)
|
||||
|
||||
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)
|
||||
|
||||
OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms,
|
||||
const_char_p column_name,
|
||||
obiversion_t version_number)
|
||||
|
||||
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:
|
||||
|
||||
int obi_column_set_obiint_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obiint_t value)
|
||||
|
||||
int obi_column_set_obiint_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obiint_t value)
|
||||
|
||||
obiint_t obi_column_get_obiint_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obiint_t obi_column_get_obiint_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
cdef extern from "obidmscolumn_bool.h" nogil:
|
||||
|
||||
int obi_column_set_obibool_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obibool_t value)
|
||||
|
||||
int obi_column_set_obibool_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obibool_t value)
|
||||
|
||||
obibool_t obi_column_get_obibool_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obibool_t obi_column_get_obibool_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
cdef extern from "obidmscolumn_char.h" nogil:
|
||||
|
||||
int obi_column_set_obichar_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obichar_t value)
|
||||
|
||||
int obi_column_set_obichar_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obichar_t value)
|
||||
|
||||
obichar_t obi_column_get_obichar_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obichar_t obi_column_get_obichar_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
cdef extern from "obidmscolumn_float.h" nogil:
|
||||
|
||||
int obi_column_set_obifloat_with_elt_name(OBIDMS_column_p column,
|
||||
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)
|
||||
|
||||
obifloat_t obi_column_get_obifloat_with_elt_name(OBIDMS_column_p column,
|
||||
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)
|
||||
|
||||
cdef extern from "obidmscolumn_str.h" nogil:
|
||||
|
||||
int obi_column_set_obistr_with_elt_name(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(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(OBIDMS_column_p column,
|
||||
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,
|
||||
index_t element_idx)
|
||||
|
||||
cdef extern from "obidmscolumn_seq.h" nogil:
|
||||
|
||||
int obi_column_set_obiseq_with_elt_name(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(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
const_char_p value)
|
||||
|
||||
char* obi_column_get_obiseq_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
char* obi_column_get_obiseq_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
|
||||
cdef extern from "obidmscolumn_qual.h" nogil:
|
||||
|
||||
int obi_column_set_obiqual_char_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
const_char_p value)
|
||||
|
||||
int obi_column_set_obiqual_char_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
const_char_p value)
|
||||
|
||||
int obi_column_set_obiqual_int_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
const uint8_t* value,
|
||||
int value_length)
|
||||
|
||||
int obi_column_set_obiqual_int_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
const uint8_t* value,
|
||||
int value_length)
|
||||
|
||||
char* obi_column_get_obiqual_char_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
char* obi_column_get_obiqual_char_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
const uint8_t* obi_column_get_obiqual_int_with_elt_name(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
int* value_length)
|
||||
|
||||
const uint8_t* obi_column_get_obiqual_int_with_elt_idx(OBIDMS_column_p column,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
int* value_length)
|
||||
|
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
|
59
python/obitools3/dms/capi/obitaxonomy.pxd
Normal file
59
python/obitools3/dms/capi/obitaxonomy.pxd
Normal file
@ -0,0 +1,59 @@
|
||||
#cython: language_level=3
|
||||
|
||||
from .obitypes cimport const_char_p
|
||||
from .obidms cimport OBIDMS_p
|
||||
from libc.stdint cimport int32_t
|
||||
|
||||
|
||||
cdef extern from "obidms_taxonomy.h" nogil:
|
||||
|
||||
struct ecotxnode :
|
||||
int32_t taxid
|
||||
int32_t rank
|
||||
int32_t farest
|
||||
ecotxnode* parent
|
||||
char* name
|
||||
|
||||
ctypedef ecotxnode ecotx_t
|
||||
|
||||
|
||||
struct ecotxidx_t :
|
||||
int32_t count
|
||||
int32_t max_taxid
|
||||
int32_t buffer_size
|
||||
ecotx_t* taxon
|
||||
|
||||
|
||||
struct OBIDMS_taxonomy_t :
|
||||
# ecorankidx_t* ranks
|
||||
# econameidx_t* names
|
||||
ecotxidx_t* taxa
|
||||
|
||||
ctypedef OBIDMS_taxonomy_t* OBIDMS_taxonomy_p
|
||||
|
||||
|
||||
OBIDMS_taxonomy_p obi_read_taxonomy(OBIDMS_p dms, const_char_p taxonomy_name, bint read_alternative_names)
|
||||
|
||||
OBIDMS_taxonomy_p obi_read_taxdump(const_char_p taxdump)
|
||||
|
||||
int obi_write_taxonomy(OBIDMS_p dms, OBIDMS_taxonomy_p tax, const_char_p tax_name)
|
||||
|
||||
int obi_close_taxonomy(OBIDMS_taxonomy_p taxonomy)
|
||||
|
||||
ecotx_t* obi_taxo_get_parent_at_rank(ecotx_t* taxon, int32_t rankidx)
|
||||
|
||||
ecotx_t* obi_taxo_get_taxon_with_taxid(OBIDMS_taxonomy_p taxonomy, int32_t taxid)
|
||||
|
||||
bint obi_taxo_is_taxon_under_taxid(ecotx_t* taxon, int32_t other_taxid)
|
||||
|
||||
ecotx_t* obi_taxo_get_species(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
|
||||
ecotx_t* obi_taxo_get_genus(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
|
||||
ecotx_t* obi_taxo_get_family(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
|
||||
ecotx_t* obi_taxo_get_kingdom(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
|
||||
ecotx_t* obi_taxo_get_superkingdom(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
|
||||
int obi_taxonomy_add_local_taxon(OBIDMS_taxonomy_p tax, const char* name, const char* rank_name, int32_t parent_taxid, int32_t min_taxid)
|
55
python/obitools3/dms/capi/obitypes.pxd
Normal file
55
python/obitools3/dms/capi/obitypes.pxd
Normal file
@ -0,0 +1,55 @@
|
||||
#cython: language_level=3
|
||||
|
||||
|
||||
from libc.stdint cimport int32_t, int64_t, uint8_t
|
||||
|
||||
from posix.types cimport time_t
|
||||
|
||||
|
||||
cdef extern from *:
|
||||
ctypedef char* const_char_p "const char*"
|
||||
|
||||
|
||||
cdef extern from "encode.h" nogil:
|
||||
bint only_ATGC(const_char_p seq)
|
||||
|
||||
|
||||
cdef extern from "obitypes.h" nogil:
|
||||
|
||||
enum OBIType:
|
||||
OBI_VOID,
|
||||
OBI_INT,
|
||||
OBI_FLOAT,
|
||||
OBI_BOOL,
|
||||
OBI_CHAR,
|
||||
OBI_QUAL,
|
||||
OBI_STR,
|
||||
OBI_SEQ,
|
||||
OBI_IDX
|
||||
|
||||
|
||||
ctypedef OBIType OBIType_t
|
||||
|
||||
enum OBIBool:
|
||||
pass
|
||||
|
||||
ctypedef OBIBool obibool_t
|
||||
ctypedef int32_t obiint_t
|
||||
ctypedef double obifloat_t
|
||||
ctypedef char obichar_t
|
||||
ctypedef int64_t index_t
|
||||
|
||||
ctypedef int32_t obiversion_t
|
||||
|
||||
extern obiint_t OBIInt_NA
|
||||
extern index_t OBIIdx_NA
|
||||
extern obifloat_t OBIFloat_NA
|
||||
extern obichar_t OBIChar_NA
|
||||
extern obibool_t OBIBool_NA
|
||||
extern const_char_p OBISeq_NA
|
||||
extern const_char_p OBIStr_NA
|
||||
extern const_char_p OBIQual_char_NA
|
||||
extern uint8_t* OBIQual_int_NA
|
||||
|
||||
const_char_p name_data_type(int data_type)
|
||||
|
12
python/obitools3/dms/capi/obiutils.pxd
Normal file
12
python/obitools3/dms/capi/obiutils.pxd
Normal file
@ -0,0 +1,12 @@
|
||||
#cython: language_level=3
|
||||
|
||||
|
||||
from posix.types cimport time_t
|
||||
|
||||
from ..capi.obitypes cimport const_char_p
|
||||
|
||||
|
||||
cdef extern from "utils.h" nogil:
|
||||
|
||||
const_char_p obi_format_date(time_t date)
|
||||
|
298
python/obitools3/dms/capi/obiview.pxd
Normal file
298
python/obitools3/dms/capi/obiview.pxd
Normal file
@ -0,0 +1,298 @@
|
||||
#cython: language_level=3
|
||||
|
||||
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
|
||||
from ..capi.obidmscolumn cimport OBIDMS_column_p, \
|
||||
Column_reference_t, \
|
||||
Column_reference_p
|
||||
|
||||
from libc.stdint cimport uint8_t
|
||||
|
||||
|
||||
cdef extern from "obiview.h" nogil:
|
||||
|
||||
extern const_char_p VIEW_TYPE_NUC_SEQS
|
||||
extern const_char_p NUC_SEQUENCE_COLUMN
|
||||
extern const_char_p ID_COLUMN
|
||||
extern const_char_p DEFINITION_COLUMN
|
||||
extern const_char_p QUALITY_COLUMN
|
||||
|
||||
|
||||
struct Alias_column_pair_t :
|
||||
Column_reference_t column_refs
|
||||
const_char_p alias
|
||||
|
||||
ctypedef Alias_column_pair_t* Alias_column_pair_p
|
||||
|
||||
|
||||
struct Obiview_infos_t :
|
||||
time_t creation_date
|
||||
const_char_p name
|
||||
const_char_p created_from
|
||||
const_char_p view_type
|
||||
bint all_lines
|
||||
Column_reference_t line_selection
|
||||
index_t line_count
|
||||
int column_count
|
||||
Alias_column_pair_p column_references
|
||||
const_char_p comments
|
||||
|
||||
ctypedef Obiview_infos_t* Obiview_infos_p
|
||||
|
||||
|
||||
struct Obiview_t :
|
||||
Obiview_infos_p infos
|
||||
OBIDMS_p dms
|
||||
bint read_only
|
||||
OBIDMS_column_p line_selection
|
||||
OBIDMS_column_p columns
|
||||
int nb_predicates
|
||||
# TODO declarations for column dictionary and predicate function array?
|
||||
|
||||
ctypedef Obiview_t* Obiview_p
|
||||
|
||||
|
||||
Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const_char_p view_name, Obiview_p view_to_clone, index_t* line_selection, const_char_p comments, bint quality_column)
|
||||
|
||||
Obiview_p obi_new_view(OBIDMS_p dms, const_char_p view_name, Obiview_p view_to_clone, index_t* line_selection, const_char_p comments)
|
||||
|
||||
Obiview_p obi_new_view_cloned_from_name(OBIDMS_p dms, const_char_p view_name, const_char_p view_to_clone_name, index_t* line_selection, const_char_p comments)
|
||||
|
||||
Obiview_p obi_new_view_nuc_seqs_cloned_from_name(OBIDMS_p dms, const_char_p view_name, const_char_p view_to_clone_name, index_t* line_selection, const_char_p comments, bint quality_column)
|
||||
|
||||
Obiview_infos_p obi_view_map_file(OBIDMS_p dms, const char* view_name)
|
||||
|
||||
int obi_view_unmap_file(OBIDMS_p dms, Obiview_infos_p view_infos)
|
||||
|
||||
Obiview_p obi_open_view(OBIDMS_p dms, const_char_p view_name)
|
||||
|
||||
int obi_view_add_column(Obiview_p view,
|
||||
const_char_p column_name,
|
||||
obiversion_t version_number,
|
||||
const_char_p alias,
|
||||
OBIType_t data_type,
|
||||
index_t nb_lines,
|
||||
index_t nb_elements_per_line,
|
||||
char* elements_names,
|
||||
const_char_p indexer_name,
|
||||
const_char_p associated_column_name,
|
||||
obiversion_t associated_column_version,
|
||||
const_char_p comments,
|
||||
bint create)
|
||||
|
||||
int obi_view_delete_column(Obiview_p view, const_char_p column_name)
|
||||
|
||||
OBIDMS_column_p obi_view_get_column(Obiview_p view, const_char_p column_name)
|
||||
|
||||
OBIDMS_column_p* obi_view_get_pointer_on_column_in_view(Obiview_p view, const_char_p column_name)
|
||||
|
||||
int obi_view_create_column_alias(Obiview_p view, const_char_p current_name, const_char_p alias)
|
||||
|
||||
int obi_save_view(Obiview_p view)
|
||||
|
||||
int obi_close_view(Obiview_p view)
|
||||
|
||||
int obi_save_and_close_view(Obiview_p view)
|
||||
|
||||
|
||||
# OBI_INT
|
||||
int obi_set_int_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obiint_t value)
|
||||
|
||||
int obi_set_int_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obiint_t value)
|
||||
|
||||
obiint_t obi_get_int_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obiint_t obi_get_int_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
|
||||
# OBI_BOOL
|
||||
int obi_set_bool_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obibool_t value)
|
||||
|
||||
int obi_set_bool_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obibool_t value)
|
||||
|
||||
obibool_t obi_get_bool_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obibool_t obi_get_bool_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
|
||||
# OBI_CHAR
|
||||
int obi_set_char_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obichar_t value)
|
||||
|
||||
int obi_set_char_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obichar_t value)
|
||||
|
||||
obichar_t obi_get_char_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obichar_t obi_get_char_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
|
||||
# OBI_FLOAT
|
||||
int obi_set_float_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
obifloat_t value)
|
||||
|
||||
int obi_set_float_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
obifloat_t value)
|
||||
|
||||
obifloat_t obi_get_float_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
obifloat_t obi_get_float_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
|
||||
# OBI_QUAL
|
||||
int obi_set_qual_char_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
const char* value)
|
||||
|
||||
int obi_set_qual_int_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
const uint8_t* value,
|
||||
int value_length)
|
||||
|
||||
char* obi_get_qual_char_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
const uint8_t* obi_get_qual_int_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
int* value_length)
|
||||
|
||||
int obi_set_qual_char_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const char* element_name,
|
||||
const char* value)
|
||||
|
||||
int obi_set_qual_int_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const char* element_name,
|
||||
const uint8_t* value,
|
||||
int value_length)
|
||||
|
||||
char* obi_get_qual_char_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const char* element_name)
|
||||
|
||||
const uint8_t* obi_get_qual_int_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const char* element_name,
|
||||
int* value_length)
|
||||
|
||||
|
||||
# OBI_STR
|
||||
int obi_set_str_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
const_char_p value)
|
||||
|
||||
int obi_set_str_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
const_char_p value)
|
||||
|
||||
const_char_p obi_get_str_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
const_char_p obi_get_str_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
||||
|
||||
# OBI_SEQ
|
||||
int obi_set_seq_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name,
|
||||
const_char_p value)
|
||||
|
||||
int obi_set_seq_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx,
|
||||
const_char_p value)
|
||||
|
||||
char* obi_get_seq_with_elt_name_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
const_char_p element_name)
|
||||
|
||||
char* obi_get_seq_with_elt_idx_and_col_p_in_view(Obiview_p view,
|
||||
OBIDMS_column_p column_p,
|
||||
index_t line_nb,
|
||||
index_t element_idx)
|
||||
|
Reference in New Issue
Block a user