Bio::Graph::SimpleGraph Traversal
SummaryPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
Bio::Graph::SimpleGraph::Traversal - graph traversal operations for Bio::Graph::SimpleGraph and Bio::Graph::Protein::Graph objects
Package variables
No package variables defined.
Included modules
Bio::Graph::SimpleGraph
base qw ( Class::AutoClass )
strict
Synopsis
  use Bio::Graph::SimpleGraph::Traversal;
use Bio::Graph::SimpleGraph;
## get a graph , $g. my $traversal = Bio::Graph::SimpleGraph::Traversal->new(-graph=>$g, -start=>$start, -order=>$order, -what =>$what); ## cycle through nodes one at a time while ($traversal->has_next() ) { my $node = $traversal->get_next(); } ## reset traversal to start $traversal->reset; ## get all nodes my @all_nodes = $traversal->get_all();
Description
This is a helper class for performing graph traversal operations for
Bio::Graph::SimpleGraph objects and Bio::Graph::Protein::Graph
objects. The documentation concerning the use of this class is
described in the "Graph algorithms" section of the
Bio::Graph::SimpleGraph modules. Only the methods are documented here.
Methods
_init_self
No description
Code
has_nextDescriptionCode
get_nextDescriptionCode
get_allDescriptionCode
get_thisDescriptionCode
resetDescriptionCode
Methods description
has_nextcode    nextTop
 name      : has_next
usage : while (my $traversal->has_next() ) {..
purpose : returns true if there are more items in traversal, else undef
arguments : none
returns : true or unde;
get_nextcodeprevnextTop
 name      : get_next
usage : my $node = $traversal->get_next() ;
purpose : returns next item in traversal or undef if traversal is exhausted.
arguments : none
returns : a node or undef;
get_allcodeprevnextTop
 name      : get_all
usage : my @nodes = $traversal->get_all() ;
purpose : get all remaining items in traversal as ARRAY (in array context)
or ARRAY ref.
arguments : none
returns : an array, an array reference or undef.
get_thiscodeprevnextTop
 name      : get_all
usage : my @nodes = $traversal->get_all() ;
purpose : gets current node in traversal
arguments : none
returns : the current node or undef.
resetcodeprevnextTop
 name      : reset
usage : $traversal->reset() ;
purpose : restarts traversal from first node
arguments : none
returns : void.
Methods code
_init_selfdescriptionprevnextTop
sub _init_self {
	my($self,$class,$args)=@_;
	return unless $class eq __PACKAGE__; 
	# to prevent subclasses from re-running this
$self->graph or $self->graph(new Bio::Graph::SimpleGraph); # can't be in DEFAULTS - circular includes!
}
has_nextdescriptionprevnextTop
sub has_next {
  my($self)=@_;
  $self->reset unless $self->is_initialized;
  @{$self->_future}>0;
}
get_nextdescriptionprevnextTop
sub get_next {
  my($self)= @_;
  $self->reset unless $self->is_initialized;
  my $past   = $self->_past;
  my $future = $self->_future;
  my $present;
  my $graph  = $self->graph;
  while (@$future) {
    $present = shift @$future;
    unless($past->{$present}) {	# this is a new node
$self->_present($present); $past->{$present}=1; if ($self->order =~ /^d/i) { unshift(@$future,$graph->neighbors($present,$self->what)); } else { push(@$future,$graph->neighbors($present,$self->what)); } return $present; } } $self->_present(undef);
}
get_alldescriptionprevnextTop
sub get_all {
  my($self, $val)   = @_;
  $self->reset unless $self->is_initialized;
  my $past    = $self->_past;
  my $future  = $self->_future;
  my $i = 0; 
  my $present;
  my $graph   = $self->graph;
  my $nodes   = $graph->_nodes;

  my $results =[];
  while (@$future) {
    $present = shift @$future;
     if(!$past->{$present}) {	# this is a new node
$past->{$present} = 1; push(@$results,$present); $i++; if ($self->order =~ /^d/i) { unshift(@$future,$graph->neighbors($present,$self->what)); } else { push(@$future,$graph->neighbors($present,$self->what)); } } } $self->_present(undef); wantarray? @$results: $results;
}
get_thisdescriptionprevnextTop
sub get_this {
  my($self)=@_;
  $self->reset unless $self->is_initialized;
  $self->_present;
}
resetdescriptionprevnextTop
sub reset {
  my($self)= @_;
  $self->_past({});
  $self->order('d');
  $self->_present(undef);
  $self->_future([]);
  $self->is_initialized(1);
  my $graph = $self->graph;
  my $start = $self->start;
  my $what  = $self->what || 'node';
  if ($what=~/^n/i) {
    defined $start or $start=$graph->nodes->[0];
  } elsif ($what=~/^e/i) {
    $start=defined $start? $graph->edge($start): $graph->edges->[0];
  } else {
    $self->throw("Unrecognized\$ what parameter $what: should be 'node' or 'edge'");
  }
  return unless defined $start;
  $self->_future([$start]);
}
General documentation
FEEDBACKTop
Mailing ListsTop
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
  bioperl-l@bioperl.org                  - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via the
web:
  http://bugzilla.open-bio.org/
AUTHOR - Nat Goodman, Richard AdamsTop
Email natg@shore.net, richard.adams@ed.ac.uk