---
name: "GO::Model::GraphIterator"
section: "3pm"
platform: "linux"
package: "libgo-perl"
version: "0.15-10"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/GO::Model::GraphIterator"
---

# GO::Model::GraphIterator(3pm)

## NAME

```
  GO::Model::GraphIterator - Graph iterator
```

## SYNOPSIS

```
  $it = $graph->create_iterator;
  # returns a GO::Model::GraphIterator object
  while (my $ni = $it->next_node_instance) {
    $depth = $ni->depth;
    $term = $ni->term;
    $reltype = $ni->parent_rel->type;
    printf
      "%s %8s Term = %s (%s)  // depth=%d\n",
          "----" x $depth,
          $reltype,
          $term->name,
          $term->public_acc,
          $depth;
  }
```

## DESCRIPTION

## SEE ALSO

GO::Model::Graph

GO::Model::GraphNodeInstance

### order

```
  Usage   - $graphiter->order("breadth");
  Returns - string
  Args    - string
```

gets/sets traversal order; breadth or depth; default is depth

### direction

```
  Usage   - $graphiter->direction("up");
  Returns - string
  Args    - string
```

gets/sets direction; default is "down"

### compact

```
  Usage   - $graphiter->compact(1);
  Returns - bool
  Args    - bool
```

set this if you don't want relationships to be traversed twice; this gives a more compact tree representation of the graph

### reltype\_filter

```
  Usage   - $graphiter->reltype_filter(qw(is_a part_of))
  Returns - array
  Args    - array
```

by default, all relationship types are treated as transitive, and will be traversed by the iterator

sometimes you don't want to traverse all relations, even if they are transitive. For example, when answering the query "find all genes expressed in the embryo" you way want subtypes of embryo and parts of the embryo but not things that develop\_from the embryo.

For more details, see \<http://sourceforge.net/mailarchive/forum.php?thread\_id=9448679&forum\_id=43082\>

### reset\_cursor

```
  Usage   -
  Returns -
  Args    -
```

### next\_node

```
  Usage   -
  Returns - GO::Model::Term
  Args    -
```

### next\_node\_instance

```
  Usage   -
  Returns - GO::Model::GraphNodeInstance
  Args    -
```

### flatten

```
  Usage   -
  Returns -
  Args    -
```

### \_sortby\_pos\_in\_list

Careful, this sort function work on Term objects, not GraphNodeInstance objects.  Comparison is done by the name of the term.
