Bio::Graph::SimpleGraph
Traversal
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
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
Methods description
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; |
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; |
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. |
name : get_all usage : my @nodes = $traversal->get_all() ; purpose : gets current node in traversal arguments : none returns : the current node or undef. |
name : reset usage : $traversal->reset() ; purpose : restarts traversal from first node arguments : none returns : void. |
Methods code
sub _init_self
{ my($self,$class,$args)=@_;
return unless $class eq __PACKAGE__;
$self->graph or $self->graph(new Bio::Graph::SimpleGraph);
} |
sub has_next
{ my($self)=@_;
$self->reset unless $self->is_initialized;
@{$self->_future}>0;} |
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}) { $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);} |
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}) { $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;} |
sub get_this
{ my($self)=@_;
$self->reset unless $self->is_initialized;
$self->_present; } |
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
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
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 Adams | Top |