Added functions to add new taxa to a taxonomy with handling of
associated *.ldx files
This commit is contained in:
@ -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 :
|
||||
|
@ -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)
|
||||
|
||||
@ -65,6 +68,15 @@ cdef class OBI_Taxonomy :
|
||||
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")
|
||||
|
@ -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)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -17,6 +17,10 @@
|
||||
#include "obidms.h"
|
||||
|
||||
|
||||
#define MIN_LOCAL_TAXID (10000000)
|
||||
#define TAX_NAME_LEN (1024)
|
||||
|
||||
|
||||
typedef struct {
|
||||
int32_t taxid;
|
||||
int32_t rank;
|
||||
@ -33,11 +37,14 @@ typedef struct ecotxnode {
|
||||
int32_t idx;
|
||||
struct ecotxnode* parent;
|
||||
char* name;
|
||||
bool local;
|
||||
} ecotx_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int32_t count;
|
||||
int32_t ncbi_count;
|
||||
int32_t local_count;
|
||||
int32_t max_taxid;
|
||||
int32_t buffer_size;
|
||||
ecotx_t taxon[1];
|
||||
@ -74,6 +81,8 @@ typedef struct {
|
||||
|
||||
|
||||
typedef struct OBIDMS_taxonomy_t {
|
||||
char tax_name[TAX_NAME_LEN];
|
||||
OBIDMS_p dms;
|
||||
ecorankidx_t* ranks;
|
||||
econameidx_t* names;
|
||||
ecotxidx_t* taxa;
|
||||
@ -109,3 +118,4 @@ int obi_write_taxonomy(OBIDMS_p dms, OBIDMS_taxonomy_p tax, const char* tax_name
|
||||
|
||||
OBIDMS_taxonomy_p obi_read_taxdump(const char* taxdump);
|
||||
|
||||
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);
|
||||
|
Reference in New Issue
Block a user