From 3847850a9dc2f6f1f6947831dd75ce383de65427 Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Tue, 14 Aug 2018 17:09:40 +0200 Subject: [PATCH] Taxonomy Cython API: added is_ancestor() function --- python/obitools3/dms/taxo/taxo.pyx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/python/obitools3/dms/taxo/taxo.pyx b/python/obitools3/dms/taxo/taxo.pyx index 3cdd500..a5894f2 100644 --- a/python/obitools3/dms/taxo/taxo.pyx +++ b/python/obitools3/dms/taxo/taxo.pyx @@ -113,7 +113,7 @@ cdef class Taxonomy(OBIWrapper) : raise Exception("Not implemented") - cpdef Taxon get_taxon_by_taxid(self, int taxid): + cpdef Taxon get_taxon_by_taxid(self, int taxid): # TODO check deleted taxon behavior (403122) cdef ecotx_t* taxon_p cdef object taxon_capsule taxon_p = obi_taxo_get_taxon_with_taxid(self.pointer(), taxid) @@ -254,7 +254,10 @@ cdef class Taxonomy(OBIWrapper) : first ancestor to the root. """ cdef Taxon taxon - taxon = self.get_taxon_by_taxid(taxid) + try: + taxon = self.get_taxon_by_taxid(taxid) + except: # TODO error handling (related to deleted taxon thing) + raise StopIteration if taxon is not None: while taxon.parent.taxid != 1: # TODO was 0 before? yield taxon @@ -264,6 +267,10 @@ cdef class Taxonomy(OBIWrapper) : raise StopIteration + def is_ancestor(self, int ancestor_taxid, int taxid): + return ancestor_taxid in [x.taxid for x in self.parental_tree_iterator(taxid)] + + def last_common_taxon(self, *taxids): cdef list t1