Cython API: renamed OBI_Taxonomy to Taxonomy and OBI_Taxon to Taxon

This commit is contained in:
Celine Mercier
2017-07-27 19:21:45 +02:00
parent fa8f826cdc
commit 99ceed5fff
3 changed files with 17 additions and 17 deletions

View File

@ -5,7 +5,7 @@ from obitools3.dms.view.view import View, Line_selection
from obitools3.dms.view.typed_view.view_NUC_SEQS import View_NUC_SEQS from obitools3.dms.view.typed_view.view_NUC_SEQS import View_NUC_SEQS
from obitools3.dms.dms import DMS from obitools3.dms.dms import DMS
from obitools3.dms.column import Column from obitools3.dms.column import Column
from obitools3.dms.taxo.taxo import OBI_Taxonomy from obitools3.dms.taxo.taxo import Taxonomy
from obitools3.utils cimport str2bytes from obitools3.utils cimport str2bytes
from obitools3.dms.capi.obitypes cimport OBI_INT, \ from obitools3.dms.capi.obitypes cimport OBI_INT, \
OBI_FLOAT, \ OBI_FLOAT, \
@ -42,9 +42,9 @@ default_config = {
def test_taxo(config, infos): def test_taxo(config, infos):
tax1 = OBI_Taxonomy.open(infos['dms'], config['obi']['taxo'], taxdump=True) tax1 = Taxonomy.open(infos['dms'], config['obi']['taxo'], taxdump=True)
tax1.write(TAXTEST) tax1.write(TAXTEST)
tax2 = OBI_Taxonomy.open(infos['dms'], TAXTEST, taxdump=False) tax2 = Taxonomy.open(infos['dms'], TAXTEST, taxdump=False)
assert len(tax1) == len(tax2), "Length of written taxonomy != length of read taxdump : "+str(len(tax2))+" != "+str(len(tax1)) assert len(tax1) == len(tax2), "Length of written taxonomy != length of read taxdump : "+str(len(tax2))+" != "+str(len(tax1))
i = 0 i = 0

View File

@ -7,7 +7,7 @@ from ..dms cimport DMS
from ..object cimport OBIWrapper from ..object cimport OBIWrapper
cdef class OBI_Taxonomy(OBIWrapper) : cdef class Taxonomy(OBIWrapper) :
cdef str _name # TODO keep as bytes? cdef str _name # TODO keep as bytes?
cdef DMS _dms cdef DMS _dms
@ -18,6 +18,6 @@ cdef class OBI_Taxonomy(OBIWrapper) :
cpdef int add_taxon(self, str name, str rank_name, int parent_taxid, int min_taxid=*) cpdef int add_taxon(self, str name, str rank_name, int parent_taxid, int min_taxid=*)
cpdef close(self) cpdef close(self)
cdef class OBI_Taxon : cdef class Taxon :
cdef ecotx_t* _pointer cdef ecotx_t* _pointer
cdef OBI_Taxonomy _tax cdef Taxonomy _tax

View File

@ -14,7 +14,7 @@ from ..capi.obitaxonomy cimport obi_read_taxonomy, \
from cpython.pycapsule cimport PyCapsule_New, PyCapsule_GetPointer from cpython.pycapsule cimport PyCapsule_New, PyCapsule_GetPointer
cdef class OBI_Taxonomy(OBIWrapper) : cdef class Taxonomy(OBIWrapper) :
# TODO function to import taxonomy? # TODO function to import taxonomy?
cdef inline OBIDMS_taxonomy_p pointer(self) : cdef inline OBIDMS_taxonomy_p pointer(self) :
@ -24,8 +24,8 @@ cdef class OBI_Taxonomy(OBIWrapper) :
@staticmethod @staticmethod
def open(DMS dms, str name, bint taxdump=False) : def open(DMS dms, str name, bint taxdump=False) :
cdef void* pointer cdef void* pointer
cdef OBI_Taxonomy taxo cdef Taxonomy taxo
if taxdump : if taxdump :
pointer = <void*>obi_read_taxdump(tobytes(name)) pointer = <void*>obi_read_taxdump(tobytes(name))
@ -37,7 +37,7 @@ cdef class OBI_Taxonomy(OBIWrapper) :
raise RuntimeError("Error : Cannot read taxonomy %s" raise RuntimeError("Error : Cannot read taxonomy %s"
% name) % name)
taxo = OBIWrapper.new(OBI_Taxonomy, pointer) taxo = OBIWrapper.new_wrapper(Taxonomy, pointer)
dms.register(taxo) dms.register(taxo)
@ -57,7 +57,7 @@ cdef class OBI_Taxonomy(OBIWrapper) :
if taxon_p == NULL : if taxon_p == NULL :
raise Exception("Taxon not found") raise Exception("Taxon not found")
taxon_capsule = PyCapsule_New(taxon_p, NULL, NULL) taxon_capsule = PyCapsule_New(taxon_p, NULL, NULL)
return OBI_Taxon(taxon_capsule, self) return Taxon(taxon_capsule, self)
else : else :
raise Exception("Not implemented") raise Exception("Not implemented")
@ -71,7 +71,7 @@ cdef class OBI_Taxonomy(OBIWrapper) :
taxa = self.pointer().taxa.taxon taxa = self.pointer().taxa.taxon
taxon_p = <ecotx_t*> (taxa+idx) taxon_p = <ecotx_t*> (taxa+idx)
taxon_capsule = PyCapsule_New(taxon_p, NULL, NULL) taxon_capsule = PyCapsule_New(taxon_p, NULL, NULL)
return OBI_Taxon(taxon_capsule, self) return Taxon(taxon_capsule, self)
def __len__(self): def __len__(self):
@ -91,7 +91,7 @@ cdef class OBI_Taxonomy(OBIWrapper) :
for t in range(self.pointer().taxa.count): for t in range(self.pointer().taxa.count):
taxon_p = <ecotx_t*> (taxa+t) taxon_p = <ecotx_t*> (taxa+t)
taxon_capsule = PyCapsule_New(taxon_p, NULL, NULL) taxon_capsule = PyCapsule_New(taxon_p, NULL, NULL)
yield OBI_Taxon(taxon_capsule, self) yield Taxon(taxon_capsule, self)
cpdef write(self, str prefix) : cpdef write(self, str prefix) :
@ -126,9 +126,9 @@ cdef class OBI_Taxonomy(OBIWrapper) :
return self._name return self._name
cdef class OBI_Taxon : # TODO dict subclass? cdef class Taxon : # TODO dict subclass?
def __init__(self, object taxon_capsule, OBI_Taxonomy tax) : def __init__(self, object taxon_capsule, Taxonomy tax) :
self._pointer = <ecotx_t*> PyCapsule_GetPointer(taxon_capsule, NULL) self._pointer = <ecotx_t*> PyCapsule_GetPointer(taxon_capsule, NULL)
if self._pointer == NULL : if self._pointer == NULL :
raise Exception("Error reading a taxon (NULL pointer)") raise Exception("Error reading a taxon (NULL pointer)")
@ -136,7 +136,7 @@ cdef class OBI_Taxon : # TODO dict subclass?
# To test equality # To test equality
def __richcmp__(self, OBI_Taxon taxon2, int op): def __richcmp__(self, Taxon taxon2, int op):
return (self.name == taxon2.name) and \ return (self.name == taxon2.name) and \
(self.taxid == taxon2.taxid) and \ (self.taxid == taxon2.taxid) and \
(self.rank == taxon2.rank) and \ (self.rank == taxon2.rank) and \
@ -170,7 +170,7 @@ cdef class OBI_Taxon : # TODO dict subclass?
def parent(self): def parent(self):
cdef object parent_capsule cdef object parent_capsule
parent_capsule = PyCapsule_New(self._pointer.parent, NULL, NULL) parent_capsule = PyCapsule_New(self._pointer.parent, NULL, NULL)
return OBI_Taxon(parent_capsule, self._tax) return Taxon(parent_capsule, self._tax)
# preferred name property getter and setter # preferred name property getter and setter
@property @property