nodes: 0, module; 1, function_definition; 2, function_name:_visit; 3, parameters; 4, block; 5, identifier:self; 6, identifier:L; 7, identifier:marked; 8, identifier:tempmarked; 9, expression_statement; 10, assert_statement; 11, if_statement; 12, if_statement; 13, comment:"""
          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.
          """; 14, not_operator; 15, comparison_operator:self in tempmarked; 16, block; 17, comparison_operator:self not in marked; 18, block; 19, attribute; 20, identifier:self; 21, identifier:tempmarked; 22, raise_statement; 23, identifier:self; 24, identifier:marked; 25, expression_statement; 26, expression_statement; 27, if_statement; 28, if_statement; 29, if_statement; 30, expression_statement; 31, delete_statement; 32, expression_statement; 33, identifier:self; 34, identifier:is_pseudo; 35, call; 36, assignment; 37, assignment; 38, boolean_operator; 39, block; 40, comparison_operator:self.children is not None; 41, block; 42, comparison_operator:len(features) > 0; 43, block; 44, assignment; 45, subscript; 46, call; 47, identifier:Exception; 48, argument_list; 49, subscript; 50, True; 51, identifier:features; 52, call; 53, comparison_operator:self.siblings is not None; 54, attribute; 55, expression_statement; 56, attribute; 57, None; 58, expression_statement; 59, call; 60, integer:0; 61, for_statement; 62, subscript; 63, True; 64, identifier:tempmarked; 65, identifier:self; 66, attribute; 67, argument_list; 68, string; 69, identifier:tempmarked; 70, identifier:self; 71, identifier:list; 72, argument_list; 73, attribute; 74, None; 75, identifier:self; 76, identifier:is_toplevel; 77, call; 78, identifier:self; 79, identifier:children; 80, call; 81, identifier:len; 82, argument_list; 83, identifier:feature; 84, identifier:features; 85, block; 86, identifier:marked; 87, identifier:self; 88, identifier:L; 89, identifier:insert; 90, integer:0; 91, identifier:self; 92, string_content:feature graph is cyclic; 93, identifier:self; 94, identifier:siblings; 95, attribute; 96, argument_list; 97, attribute; 98, argument_list; 99, identifier:features; 100, expression_statement; 101, identifier:features; 102, identifier:extend; 103, call; 104, identifier:features; 105, identifier:extend; 106, call; 107, call; 108, identifier:reversed; 109, argument_list; 110, identifier:reversed; 111, argument_list; 112, attribute; 113, argument_list; 114, attribute; 115, attribute; 116, identifier:feature; 117, identifier:_visit; 118, identifier:L; 119, identifier:marked; 120, identifier:tempmarked; 121, identifier:self; 122, identifier:siblings; 123, identifier:self; 124, identifier:children
code: def _visit(self, L, marked, tempmarked):
          """
          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.
          """
          assert not self.is_pseudo
          if self in tempmarked:
              raise Exception('feature graph is cyclic')
          if self not in marked:
              tempmarked[self] = True
              features = list()
              if self.siblings is not None and self.is_toplevel:
                  features.extend(reversed(self.siblings))
              if self.children is not None:
                  features.extend(reversed(self.children))
              if len(features) > 0:
                  for feature in features:
                      feature._visit(L, marked, tempmarked)
              marked[self] = True
              del tempmarked[self]
              L.insert(0, self)