Next / Previous / Contents / Shipman's homepage

11. writeSubtree(): Recursive tree walker

nomcompile3
# - - -   w r i t e S u b t r e e

def writeSubtree ( treeFile, taxon ):
    '''Write tree records for taxon and its subtree.

      [ (treeFile is a writeable file) and
        (taxon is a Taxon instance) ->
         treeFile  :=  flat taxon records from the subtree rooted
                       in taxon, in pre-order ]
    '''

This function writes the flat file record for the given taxon, then recursively calls itself for all the taxon's children. For the function that writes one record, see Section 19.8, “Taxon.writeFlat(): Write a tree-file record”.

nomcompile3
    #-- 1 --
    # [ treeFile  +:=  a flat tree record representing taxon ]
    taxon.writeFlat ( treeFile )

For the function that generates all the children of a taxon, see Section 19.4, “Taxon.__iter__(): Iterator for the children”.

nomcompile3
    #-- 2 --
    # [ treeFile  +:=  flat tree records for all the subtrees
    #                  of taxon in preorder ]
    for child in taxon:
        writeSubtree ( treeFile, child )