Added functions to add new taxa to a taxonomy with handling of

associated *.ldx files
This commit is contained in:
Celine Mercier
2016-11-03 17:59:21 +01:00
parent 2504bf0fa9
commit 2d2fe5279d
5 changed files with 664 additions and 397 deletions

View File

@ -10,8 +10,9 @@ cdef class OBI_Taxonomy :
cdef OBIDMS_taxonomy_p _pointer
cdef OBIDMS _dms
cpdef close(self)
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 :

View File

@ -7,6 +7,7 @@ from .capi.obitaxonomy cimport obi_read_taxonomy, \
obi_write_taxonomy, \
obi_close_taxonomy, \
obi_taxo_get_taxon_with_taxid, \
obi_taxonomy_add_local_taxon, \
ecotx_t
@ -38,6 +39,8 @@ cdef class OBI_Taxonomy :
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 :
@ -55,7 +58,7 @@ cdef class OBI_Taxonomy :
# Yield each taxid
for t in range(self._pointer.taxa.count):
taxon_p = <ecotx_t*> (taxa+t) # TODO not compiling for mysterious cython reasons
taxon_p = <ecotx_t*> (taxa+t)
taxon_capsule = PyCapsule_New(taxon_p, NULL, NULL)
yield OBI_Taxon(taxon_capsule)
@ -64,6 +67,15 @@ cdef class OBI_Taxonomy :
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) :

View File

@ -56,3 +56,4 @@ cdef extern from "obidms_taxonomy.h" nogil:
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)