Next / Previous / Contents / Shipman's homepage

19. class Taxon: One node in the taxonomy

In the taxonomic tree, each node is an instance of this class, representing one biological taxon. The root taxon has no parent; for all other taxa, the parent is the containing taxon. For example, the root taxon bird systematics is class Aves; its children are taxa at the order level; each order taxon has families as children, and so on. Here is the interface:

# - - - - -   c l a s s   T a x o n

class Taxon(object):
    '''Represents one biological taxon.

        Taxon ( hier, parent, rawTaxon ):
          [ (hier is a Hier instance) and
            (parent is the new taxon's parent as a Taxon or None) and
            (rawTaxon is a RawTaxon instance whose .rankCode is
            in self.hier) ->
              if all fields are acceptably short ->
                return a new Taxon object with those values
              else ->
                Log()  +:=  error message(s)
                raise SyntaxError ]
        .hier:          [ as passed to constructor ]
        .parent:        [ as passed to constructor ]
        .rank:          [ Rank representing rawTaxon.rank ]
        .sci:           [ rawTaxon.sci value, read-only ]
        .eng:           [ rawTaxon.eng value, read-only ]
           [ rawTaxon.status value, read-only, a string that 
             matches STATUS_RE  ]
        .canon:         [ value, read-only ]
        .disamb:        [ rawTaxon.disamb value, read-only ]
          [ if self's parent is None ->
            else ->
              self's taxonomic key string without trailing zeroes ]
          [ self's taxonomic key string, right-zero-padded to length
            self.hier.txKeyLen ]
          [ if self.parent is None ->
            else ->
              return self's birth order relative to its parent ]
          [ return the number of self's children, >= 0 ]
        .__getitem__(self, childx):
          [ if self has at least (childx+1) children ->
              return the (childx)th child
            else ->
              raise IndexError ]
          [ return an iterator for self's children in birth order,
            if any ]
          [ return self as a string ]
          [ if self has an unambiguous substitute bird code ->
              return that code
            else if self has a canonical bird code ->
              return that code
            else ->
              return None ]
        .childKey ( childRank ):
          [ childRank is a Rank instance ->
              return the .shortTxKey field for the next child of
              self to be added of rank (childRank) ]
        .writeFlat ( outFile ):
          [ outFile is a writeable file ->
              outFile  +:=  flat tree file representation of self ]
          [ parentNode is an et.Element ->
              parent  :=  parent with a new rnc.TAXON_N child
                  added representing self and self's descendants ]

Here is the internal state of an instance.

          [ a list of self's child Taxon instances, in birth order ]