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:

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

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

      Exports:
        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 ]
        .status:
           [ rawTaxon.status value, read-only, a string that 
             matches STATUS_RE  ]
        .canon:         [ rawTaxon.canon value, read-only ]
        .disamb:        [ rawTaxon.disamb value, read-only ]
        .shortTxKey:
          [ if self's parent is None ->
              None
            else ->
              self's taxonomic key string without trailing zeroes ]
        .txKey:
          [ self's taxonomic key string, right-zero-padded to length
            self.hier.txKeyLen ]
        .birthOrder:
          [ if self.parent is None ->
              0
            else ->
              return self's birth order relative to its parent ]
        .__len__(self):
          [ 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 ]
        .__iter__():
          [ return an iterator for self's children in birth order,
            if any ]
        .__str__():
          [ return self as a string ]
        .abbr():
          [ 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 ]
        .writeXML(parent):
          [ 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.

nomcompile3
      State/invariants:
        .__childList:
          [ a list of self's child Taxon instances, in birth order ]
    '''