From 2504bf0fa962d243c5bcefa1bf1030b499d137ab Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Wed, 2 Nov 2016 11:08:18 +0100 Subject: [PATCH] Added an iterator to the OBI_Taxonomy cython class --- python/obitools3/obidms/_obitaxo.pyx | 30 +++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/python/obitools3/obidms/_obitaxo.pyx b/python/obitools3/obidms/_obitaxo.pyx index dd82ecd..1e97123 100644 --- a/python/obitools3/obidms/_obitaxo.pyx +++ b/python/obitools3/obidms/_obitaxo.pyx @@ -6,7 +6,8 @@ from .capi.obitaxonomy cimport obi_read_taxonomy, \ obi_read_taxdump, \ obi_write_taxonomy, \ obi_close_taxonomy, \ - obi_taxo_get_taxon_with_taxid + obi_taxo_get_taxon_with_taxid, \ + ecotx_t from ._obidms cimport OBIDMS @@ -43,19 +44,20 @@ cdef class OBI_Taxonomy : raise Exception("Not implemented") -# def __iter__(self): -# -# cdef ecotx_t* taxa -# cdef ecotx_t* taxon_p -# cdef object taxon_capsule -# -# taxa = self._pointer.taxa.taxon -# -# # Yield each taxid -# for t in range(self._pointer.taxa.count): -# taxon_p = taxa+t # TODO not compiling for mysterious cython reasons -# taxon_capsule = PyCapsule_New(taxon_p, NULL, NULL) -# yield OBI_Taxon(taxon_capsule) + 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 = (taxa+t) # TODO not compiling for mysterious cython reasons + taxon_capsule = PyCapsule_New(taxon_p, NULL, NULL) + yield OBI_Taxon(taxon_capsule) cpdef write(self, str prefix) :