Taxonomy Cython API: added is_ancestor() function

This commit is contained in:
Celine Mercier
2018-08-14 17:09:40 +02:00
parent b57e938cc4
commit 3847850a9d

View File

@ -113,7 +113,7 @@ cdef class Taxonomy(OBIWrapper) :
raise Exception("Not implemented") 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 ecotx_t* taxon_p
cdef object taxon_capsule cdef object taxon_capsule
taxon_p = obi_taxo_get_taxon_with_taxid(self.pointer(), taxid) taxon_p = obi_taxo_get_taxon_with_taxid(self.pointer(), taxid)
@ -254,7 +254,10 @@ cdef class Taxonomy(OBIWrapper) :
first ancestor to the root. first ancestor to the root.
""" """
cdef Taxon taxon 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: if taxon is not None:
while taxon.parent.taxid != 1: # TODO was 0 before? while taxon.parent.taxid != 1: # TODO was 0 before?
yield taxon yield taxon
@ -264,6 +267,10 @@ cdef class Taxonomy(OBIWrapper) :
raise StopIteration 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): def last_common_taxon(self, *taxids):
cdef list t1 cdef list t1