Next / Previous / Contents / Shipman's homepage

7.2. Hier.canParentHaveChild()

The test for whether a parent of rank p can have a child of rank c can be rephrased like this: are there any ranks between p and c that are not optional?

xnomo3.py
# - - -   H i e r . c a n P a r e n t H a v e C h i l d   - - -

    def canParentHaveChild ( self, p, c ):
        """Can a taxon of rank p have an immediate child of rank c?
        """

        #-- 1 --
        for rankIndex in range ( p.depth+1, c.depth ):
            #-- 1 body --
            # [ if self.__rankList[rankIndex] is not optional ->
            #     return 0
            #   else -> I ]
            m = self.__rankList[rankIndex]
            if  not m.isOptional:
                return 0

        #-- 2 --
        return 1