Added C functions to write .rdx, .tdx, .ndx binary taxonomy files from a
taxonomy C structure
This commit is contained in:
@ -1,14 +1,17 @@
|
||||
#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 close(self)
|
||||
cpdef _write(self, str prefix)
|
||||
|
||||
|
||||
cdef class OBI_Taxon :
|
||||
|
@ -4,7 +4,10 @@ from obitools3.utils cimport bytes2str, str2bytes
|
||||
|
||||
from .capi.obitaxonomy cimport obi_read_taxonomy, \
|
||||
obi_close_taxonomy, \
|
||||
obi_taxo_get_taxon_with_taxid
|
||||
obi_taxo_get_taxon_with_taxid, \
|
||||
write_rankidx, \
|
||||
write_taxonomyidx, \
|
||||
write_nameidx
|
||||
|
||||
from ._obidms cimport OBIDMS
|
||||
|
||||
@ -18,6 +21,7 @@ cdef class OBI_Taxonomy :
|
||||
|
||||
def __init__(self, OBIDMS dms, str name) :
|
||||
|
||||
self._dms = dms
|
||||
self._name = name
|
||||
self._pointer = obi_read_taxonomy(dms._pointer, str2bytes(name), True) # TODO discuss
|
||||
# TODO if not found in DMS, try to import?
|
||||
@ -39,7 +43,16 @@ cdef class OBI_Taxonomy :
|
||||
cpdef close(self) :
|
||||
if (obi_close_taxonomy(self._pointer) < 0) :
|
||||
raise Exception("Error closing the taxonomy")
|
||||
|
||||
|
||||
|
||||
cpdef _write(self, str prefix) :
|
||||
if (write_rankidx(self._dms._pointer, self._pointer, str2bytes(prefix)) < 0) :
|
||||
raise Exception("Error writing the taxonomy rank file")
|
||||
if (write_taxonomyidx(self._dms._pointer, self._pointer, str2bytes(prefix)) < 0) :
|
||||
raise Exception("Error writing the taxonomy taxa file")
|
||||
if (write_nameidx(self._dms._pointer, self._pointer, str2bytes(prefix)) < 0) :
|
||||
raise Exception("Error writing the taxonomy taxa file")
|
||||
|
||||
|
||||
cdef class OBI_Taxon : # TODO dict subclass?
|
||||
|
||||
@ -82,6 +95,6 @@ cdef class OBI_Taxon : # TODO dict subclass?
|
||||
d['parent'] = self.parent.taxid
|
||||
d['farest'] = self.farest
|
||||
return str(d)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -40,3 +40,7 @@ cdef extern from "obidms_taxonomy.h" nogil:
|
||||
|
||||
ecotx_t* obi_taxo_get_superkingdom(ecotx_t* taxon, OBIDMS_taxonomy_p taxonomy)
|
||||
|
||||
|
||||
int write_rankidx(OBIDMS_p dms, OBIDMS_taxonomy_p tax, const_char_p taxonomy_name)
|
||||
int write_taxonomyidx(OBIDMS_p dms, OBIDMS_taxonomy_p tax, const_char_p taxonomy_name)
|
||||
int write_nameidx(OBIDMS_p dms, OBIDMS_taxonomy_p tax, const_char_p taxonomy_name)
|
||||
|
Reference in New Issue
Block a user