1 # $Id: GraphAdaptor.pm 10525 2006-09-26 22:03:22Z sendu $
3 # BioPerl Graph adaptor for Bio::Ontology::SimpleGOEngine
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Nat Goodman <natg at shore.net>
9 # (c) Nathan Goodman natg@shore.net 2005
10 # (c) ISB, Institute for Systems Biology 2005
12 # You may distribute this module under the same terms as perl itself.
13 # Refer to the Perl Artistic License (see the license accompanying this
14 # software package, or see http://www.perl.com/language/misc/Artistic.html)
15 # for the terms under which you may use, modify, and redistribute this module.
17 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
18 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 # You may distribute this module under the same terms as perl itself
23 # POD documentation - main docs before the code
27 Bio::Ontology::SimpleGOEngine::GraphAdaptor - Graph adaptor for
28 Bio::Ontology::SimpleGOEngine
32 use Bio::Ontology::SimpleGOEngine::GraphAdaptor;
34 my $graph = Bio::Ontology::SimpleGOEngine::GraphAdaptor;
38 This is a think adaptor to simplify use of the old and new versions of
39 the standard CPAN Graph module (old is versions 0.2x; new is 0.5x and
40 beyond) within Bio::Ontology::SimpleGOEngine.
42 This module implements only those Graph methods used by
43 SimpleGOEngine. It is far from a complete compatibility layer! It
44 also implements workarounds for cerain performance problems in the
45 current versions of Graph v0.5x.
47 This class provides a 'new' method that determines which version of
48 Graph is available. The object returned by 'new' is blessed into this
49 class if the new version of Graph is available, else into the subclass
51 Bio::Ontology::SimpleGOEngine::GraphAdaptor02
53 This class provides implementations for the required graph methods
54 using the new version of Graph. In most cases, these are simple
55 pass-throughs. Methods that differ in v0.2x are implemented in the
58 The methods implemented here or in the subclasses are listed below.
59 In all cases, we implemented the Graph v0.5x interface. Consult the
60 Graph v0.5x man page for details.
82 User feedback is an integral part of the evolution of this and other
83 Bioperl modules. Send your comments and suggestions preferably to the
84 Bioperl mailing lists Your participation is much appreciated.
86 bioperl-l@bioperl.org - General discussion
87 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
91 Please direct usage questions or support issues to the mailing list:
93 I<bioperl-l@bioperl.org>
95 rather than to the module maintainer directly. Many experienced and
96 reponsive experts will be able look at the problem and quickly
97 address it. Please include a thorough description of the problem
98 with code and data examples if at all possible.
100 =head2 Reporting Bugs
102 report bugs to the Bioperl bug tracking system to help us keep track
103 the bugs and their resolution. Bug reports can be submitted via the
106 http://bugzilla.open-bio.org/
112 Email: natg at shore.net
116 Institute for Systems Biology
118 Seattle, WA 98103-8904
122 The rest of the documentation details each of the object
123 methods. Internal methods are usually preceded with a _
127 # Let the code begin...
129 package Bio
::Ontology
::SimpleGOEngine
::GraphAdaptor
;
134 use Bio
::Ontology
::SimpleGOEngine
::GraphAdaptor02
;
136 use base
qw(Bio::Root::Root);
141 Usage : $graph = Bio::Ontology::SimpleGOEngine::GraphAdaptor->new()
142 Function: Creates a new graph
143 Returns : Bio::Ontology::SimpleGOEngine::GraphAdaptor02 or
144 Bio::Ontology::SimpleGOEngine::GraphAdaptor05 object,
145 depending on which Graph version is available
152 $class = ref $class || $class;
155 ( defined $Graph::VERSION
&& $Graph::VERSION
>= 0.5 ) ?
156 bless ( {}, $class ) :
157 bless ( {}, 'Bio::Ontology::SimpleGOEngine::GraphAdaptor02' );
158 $self->{_graph
}=new Graph
::Directed
;
159 $self->{_vertex_attributes
}={};
160 $self->{_edge_attributes
}={};
164 # Here are the main methods
168 $self->_graph->add_vertex(@_);
172 $self->_graph->has_vertex(@_);
176 $self->_graph->add_edge(@_);
180 $self->_graph->has_edge(@_);
184 $self->_graph->vertices(@_);
188 $self->_graph->edges(@_);
192 $self->_graph->edges_at(@_);
196 $self->_graph->predecessors(@_);
200 $self->_graph->successors(@_);
202 sub source_vertices
{
204 $self->_graph->source_vertices();
208 $self->_graph->sink_vertices();
210 # The following methods workaround a performance problem in Graph v0.5x
211 # when attributes are attached to the graph
212 sub set_vertex_attribute
{
213 my($self,$v,$attribute,$value)=@_;
214 $self->_vertex2attributes($v)->{$attribute}=$value;
216 sub get_vertex_attribute
{
217 my($self,$v,$attribute)=@_;
218 $self->_vertex2attributes($v)->{$attribute};
220 sub set_edge_attribute
{
221 my($self,$u,$v,$attribute,$value)=@_;
222 $self->_edge2attributes($u,$v)->{$attribute}=$value;
224 sub get_edge_attribute
{
225 my($self,$u,$v,$attribute)=@_;
226 $self->_edge2attributes($u,$v)->{$attribute};
232 Usage : $self->_graph();
233 Function: Internal method to access 'real' graph
234 Returns : Graph::Directed object
239 sub _graph
{$_[0]->{_graph
}; }
241 =head2 _vertex_attributes
243 Title : _vertex_attributes
244 Usage : $self->vertex_attributes();
245 Function: Internal method to access HASH used to store vertex attributes
246 Returns : Graph::Directed object
251 sub _vertex_attributes
{$_[0]->{_vertex_attributes
}; }
253 =head2 _edge_attributes
255 Title : _edge_attributes
256 Usage : $self->edge_attributes();
257 Function: Internal method to access HASH used to store edge attributes
258 Returns : Graph::Directed object
263 sub _edge_attributes
{$_[0]->{_edge_attributes
}; }
265 =head2 _vertex2attributes
267 Title : _vertex2attributes
268 Usage : $value=$graph->_vertex2attributes($v_->{ATTRIBUTE};
269 $graph->_vertex2attributes($v)->{ATTRIBUTE}=$value;
270 Function: Internal method to access attributes for a specific vertex
276 sub _vertex2attributes
{
277 my($self,$vertex)=@_;
278 $self->_vertex_attributes->{$vertex} or $self->_vertex_attributes->{$vertex}={};
281 =head2 _edge2attributes
283 Title : _edge2attributes
284 Usage : $value=$graph->_edge2attributes($u,$v)->{ATTRIBUTE};
285 $graph->_edge2attributes($u,$v)->{ATTRIBUTE}=$value;
286 Function: Internal method to access HASH used to store edge attributes
292 sub _edge2attributes
{
294 $self->_edge_attributes->{$u,$v} or $self->_edge_attributes->{$u,$v}={};