"""showtaxa.py: Module to assist in the display of a taxon in HTML
$Revision: 1.3 $ $Date: 2001/05/27 02:14:58 $
Exports:
htmlTaxon(taxon): Display a taxon with its complete lineage
"""
import hier
h = hier.Hier()
GENUS_DEPTH = h.genusRank().depth
# - - - s h o w T a x o n - - -
def showTaxon(t):
"""Display one taxon
"""
#-- 1 --
# [ if t is genus or deeper ->
# sci := t.sci marked up for italics in HTML
# else ->
# sci := t.sci ]
if t.rank.depth >= GENUS_DEPTH:
sci = "<i>%s</i>" % t.sci
else:
sci = t.sci
#-- 2 --
# [ if t has an English name ->
# <stdout> +:= (t.rank.name + sci + English name) in HTML
# else ->
# <Stdout> +:= (t.rank.name + sci) in HTML
if t.eng:
print ( "<br>%s %s: %s" %
( t.rank.name, sci, t.eng ) )
else:
print ( "<br>%s %s" % ( t.rank.name, sci ) )
# - - - h t m l T a x o n - - -
def htmlTaxon(taxon):
"""Display a taxon and all its ancestors in HTML
[ if taxon is a Taxon object ->
<stdout> +:= a display showing taxon and all its ancestors ]
"""
#-- 1 --
# [ rootPath := a list of Taxon objects [r, s0, s1, ..., sn, taxon]
# such that taxon is the child of sn and each si is
# the child of s(i-1) and s0 is the child of r ]
rootPath = [taxon]
next = taxon.parent()
while next is not None:
rootPath.insert(0, next)
next = next.parent()
#-- 2 --
# [ <stdout> +:= a display of the elements of rootPath ]
print "<p>"
for t in rootPath:
showTaxon(t)