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 an adaptor to simplify use of versions of the standard CPAN Graph module
39 (old is versions 0.2x; new is 0.5x and beyond) within
40 Bio::Ontology::SimpleGOEngine. Prior versions of this module supported Graph
41 version older than 0.5, however we are removing support for these older version
42 post BioPerl 1.6.901. If you absolutely require an old version of Graph, please
43 use an older version of BioPerl.
45 This module implements only those Graph methods used by SimpleGOEngine. It is
46 far from a complete compatibility layer! It also implements workarounds for
47 certain performance problems in the current versions of Graph v0.5x.
49 This class provides implementations for the required graph methods using the new
50 version of Graph. In most cases, these are simple pass-throughs
52 The methods implemented here or in the subclasses are listed below.
53 In all cases, we implemented the Graph v0.5x interface. Consult the
54 Graph v0.5x man page for details.
76 User feedback is an integral part of the evolution of this and other
77 Bioperl modules. Send your comments and suggestions preferably to the
78 Bioperl mailing lists Your participation is much appreciated.
80 bioperl-l@bioperl.org - General discussion
81 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
85 Please direct usage questions or support issues to the mailing list:
87 I<bioperl-l@bioperl.org>
89 rather than to the module maintainer directly. Many experienced and
90 reponsive experts will be able look at the problem and quickly
91 address it. Please include a thorough description of the problem
92 with code and data examples if at all possible.
96 report bugs to the Bioperl bug tracking system to help us keep track
97 the bugs and their resolution. Bug reports can be submitted via the
100 https://github.com/bioperl/bioperl-live/issues
106 Email: natg at shore.net
110 Institute for Systems Biology
112 Seattle, WA 98103-8904
116 The rest of the documentation details each of the object
117 methods. Internal methods are usually preceded with a _
121 # Let the code begin...
123 package Bio
::Ontology
::SimpleGOEngine
::GraphAdaptor
;
129 use base
qw(Bio::Root::Root);
134 Usage : $graph = Bio::Ontology::SimpleGOEngine::GraphAdaptor->new()
135 Function: Creates a new graph
136 Returns : Bio::Ontology::SimpleGOEngine::GraphAdaptor02 or
137 Bio::Ontology::SimpleGOEngine::GraphAdaptor05 object,
138 depending on which Graph version is available
145 $class = ref $class || $class;
147 my $self= bless( {}, $class );
148 $self->{_graph
}=Graph
::Directed
->new();
149 $self->{_vertex_attributes
}={};
150 $self->{_edge_attributes
}={};
154 # Here are the main methods
158 $self->_graph->add_vertex(@_);
162 $self->_graph->has_vertex(@_);
166 $self->_graph->add_edge(@_);
170 $self->_graph->has_edge(@_);
174 $self->_graph->vertices(@_);
178 $self->_graph->edges(@_);
182 $self->_graph->edges_at(@_);
186 $self->_graph->predecessors(@_);
190 $self->_graph->successors(@_);
192 sub source_vertices
{
194 $self->_graph->source_vertices();
198 $self->_graph->sink_vertices();
200 # The following methods workaround a performance problem in Graph v0.5x
201 # when attributes are attached to the graph
202 sub set_vertex_attribute
{
203 my($self,$v,$attribute,$value)=@_;
204 $self->_vertex2attributes($v)->{$attribute}=$value;
206 sub get_vertex_attribute
{
207 my($self,$v,$attribute)=@_;
208 $self->_vertex2attributes($v)->{$attribute};
210 sub set_edge_attribute
{
211 my($self,$u,$v,$attribute,$value)=@_;
212 $self->_edge2attributes($u,$v)->{$attribute}=$value;
214 sub get_edge_attribute
{
215 my($self,$u,$v,$attribute)=@_;
216 $self->_edge2attributes($u,$v)->{$attribute};
222 Usage : $self->_graph();
223 Function: Internal method to access 'real' graph
224 Returns : Graph::Directed object
229 sub _graph
{$_[0]->{_graph
}; }
231 =head2 _vertex_attributes
233 Title : _vertex_attributes
234 Usage : $self->vertex_attributes();
235 Function: Internal method to access HASH used to store vertex attributes
236 Returns : Graph::Directed object
241 sub _vertex_attributes
{$_[0]->{_vertex_attributes
}; }
243 =head2 _edge_attributes
245 Title : _edge_attributes
246 Usage : $self->edge_attributes();
247 Function: Internal method to access HASH used to store edge attributes
248 Returns : Graph::Directed object
253 sub _edge_attributes
{$_[0]->{_edge_attributes
}; }
255 =head2 _vertex2attributes
257 Title : _vertex2attributes
258 Usage : $value=$graph->_vertex2attributes($v_->{ATTRIBUTE};
259 $graph->_vertex2attributes($v)->{ATTRIBUTE}=$value;
260 Function: Internal method to access attributes for a specific vertex
266 sub _vertex2attributes
{
267 my($self,$vertex)=@_;
268 $self->_vertex_attributes->{$vertex} or $self->_vertex_attributes->{$vertex}={};
271 =head2 _edge2attributes
273 Title : _edge2attributes
274 Usage : $value=$graph->_edge2attributes($u,$v)->{ATTRIBUTE};
275 $graph->_edge2attributes($u,$v)->{ATTRIBUTE}=$value;
276 Function: Internal method to access HASH used to store edge attributes
282 sub _edge2attributes
{
284 $self->_edge_attributes->{$u,$v} or $self->_edge_attributes->{$u,$v}={};