t/AlignIO/AlignIO.t: fix number of tests in plan (fixup c523e6bed866)
[bioperl-live.git] / Bio / Ontology / SimpleGOEngine / GraphAdaptor.pm
blob68db62426f44093ae6ac91c7465adea0dcaa7591
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
25 =head1 NAME
27 Bio::Ontology::SimpleGOEngine::GraphAdaptor - Graph adaptor for
28 Bio::Ontology::SimpleGOEngine
30 =head1 SYNOPSIS
32 use Bio::Ontology::SimpleGOEngine::GraphAdaptor;
34 my $graph = Bio::Ontology::SimpleGOEngine::GraphAdaptor;
36 =head1 DESCRIPTION
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.
56 add_vertex
57 has_vertex
58 add_edge
59 has_edge
60 vertices
61 edges
62 edges_at
63 predecessors
64 successors
65 set_vertex_attribute
66 get_vertex_attribute
67 set_edge_attribute
68 get_edge_attribute
69 source_vertices
70 sink_vertices
72 =head1 FEEDBACK
74 =head2 Mailing Lists
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
83 =head2 Support
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.
94 =head2 Reporting Bugs
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
98 web:
100 https://github.com/bioperl/bioperl-live/issues
102 =head1 AUTHOR
104 Nat Goodman
106 Email: natg at shore.net
108 Address:
110 Institute for Systems Biology
111 1441 N 34th St
112 Seattle, WA 98103-8904
114 =head1 APPENDIX
116 The rest of the documentation details each of the object
117 methods. Internal methods are usually preceded with a _
119 =cut
121 # Let the code begin...
123 package Bio::Ontology::SimpleGOEngine::GraphAdaptor;
125 use Graph::Directed;
127 use strict;
129 use base qw(Bio::Root::Root);
131 =head2 new
133 Title : new
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
139 Args : none
141 =cut
143 sub new {
144 my( $class ) = @_;
145 $class = ref $class || $class;
147 my $self= bless( {}, $class );
148 $self->{_graph}=Graph::Directed->new();
149 $self->{_vertex_attributes}={};
150 $self->{_edge_attributes}={};
151 return $self;
154 # Here are the main methods
156 sub add_vertex {
157 my $self=shift;
158 $self->_graph->add_vertex(@_);
160 sub has_vertex {
161 my $self=shift;
162 $self->_graph->has_vertex(@_);
164 sub add_edge {
165 my $self=shift;
166 $self->_graph->add_edge(@_);
168 sub has_edge {
169 my $self=shift;
170 $self->_graph->has_edge(@_);
172 sub vertices {
173 my $self=shift;
174 $self->_graph->vertices(@_);
176 sub edges {
177 my $self=shift;
178 $self->_graph->edges(@_);
180 sub edges_at {
181 my $self=shift;
182 $self->_graph->edges_at(@_);
184 sub predecessors {
185 my $self=shift;
186 $self->_graph->predecessors(@_);
188 sub successors {
189 my $self=shift;
190 $self->_graph->successors(@_);
192 sub source_vertices {
193 my $self=shift;
194 $self->_graph->source_vertices();
196 sub sink_vertices {
197 my $self=shift;
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};
219 =head2 _graph
221 Title : _graph
222 Usage : $self->_graph();
223 Function: Internal method to access 'real' graph
224 Returns : Graph::Directed object
225 Args : none
227 =cut
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
237 Args : none
239 =cut
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
249 Args : none
251 =cut
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
261 Returns : HASH
262 Args : none
264 =cut
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
277 Returns : HASH
278 Args : none
280 =cut
282 sub _edge2attributes {
283 my($self,$u,$v)=@_;
284 $self->_edge_attributes->{$u,$v} or $self->_edge_attributes->{$u,$v}={};