def _visit(self, L, marked, tempmarked):
assert not self.is_pseudo<EOL>if self in tempmarked:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>if self not in marked:<EOL><INDENT>tempmarked[self] = True<EOL>features = list()<EOL>if self.siblings is not None and self.is_toplevel:<EOL><INDENT>features.extend(reversed(self.siblings))<EOL><DEDENT>if self.children is not None:<EOL><INDENT>features.extend(reversed(self.children))<EOL><DEDENT>if len(features) > <NUM_LIT:0>:<EOL><INDENT>for feature in features:<EOL><INDENT>feature._visit(L, marked, tempmarked)<EOL><DEDENT><DEDENT>marked[self] = True<EOL>del tempmarked[self]<EOL>L.insert(<NUM_LIT:0>, self)<EOL><DEDENT>
Sort features topologically.

This recursive function uses depth-first search to find an ordering of
the features in the feature graph that is sorted both topologically and
with respect to genome coordinates.

Implementation based on Wikipedia's description of the algorithm in
Cormen's *Introduction to Algorithms*.
http://en.wikipedia.org/wiki/Topological_sorting#Algorithms

There are potentially many valid topological sorts of a feature graph,
but only one that is also sorted with respect to genome coordinates
(excluding different orderings of, for example, exons and CDS features
with the same coordinates). Iterating through feature children in
reversed order (in this functions' inner-most loop) seems to be the key
to sorting with respect to genome coordinates.