File Coverage

Bio/Ontology/SimpleGOEngine/GraphAdaptor.pm
Criterion Covered Total %
statement 53 53 100.0
branch 4 4 100.0
condition 1 3 33.3
subroutine 24 24 100.0
pod 1 16 6.2
total 83 100 83.0


line stmt bran cond sub pod time code
1             # $Id: GraphAdaptor.pm 10525 2006-09-26 22:03:22Z sendu $
2             #
3             # BioPerl Graph adaptor for Bio::Ontology::SimpleGOEngine
4             #
5             # Please direct questions and support issues to
6             #
7             # Cared for by Nat Goodman
8             #
9             # (c) Nathan Goodman natg@shore.net 2005
10             # (c) ISB, Institute for Systems Biology 2005
11             #
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.
16             #
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.
20             #
21             # You may distribute this module under the same terms as perl itself
22              
23             # POD documentation - main docs before the code
24              
25             =head1 NAME
26              
27             Bio::Ontology::SimpleGOEngine::GraphAdaptor - Graph adaptor for
28             Bio::Ontology::SimpleGOEngine
29              
30             =head1 SYNOPSIS
31              
32             use Bio::Ontology::SimpleGOEngine::GraphAdaptor;
33              
34             my $graph = Bio::Ontology::SimpleGOEngine::GraphAdaptor;
35              
36             =head1 DESCRIPTION
37              
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.
44              
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.
48              
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
51              
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.
55              
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
71              
72             =head1 FEEDBACK
73              
74             =head2 Mailing Lists
75              
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.
79              
80             bioperl-l@bioperl.org - General discussion
81             http://bioperl.org/wiki/Mailing_lists - About the mailing lists
82              
83             =head2 Support
84              
85             Please direct usage questions or support issues to the mailing list:
86              
87             I
88              
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.
93              
94             =head2 Reporting Bugs
95              
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:
99              
100             https://github.com/bioperl/bioperl-live/issues
101              
102             =head1 AUTHOR
103              
104             Nat Goodman
105              
106             Email: natg at shore.net
107              
108             Address:
109              
110             Institute for Systems Biology
111             1441 N 34th St
112             Seattle, WA 98103-8904
113              
114             =head1 APPENDIX
115              
116             The rest of the documentation details each of the object
117             methods. Internal methods are usually preceded with a _
118              
119             =cut
120              
121             # Let the code begin...
122              
123             package Bio::Ontology::SimpleGOEngine::GraphAdaptor;
124              
125 4     4   1946 use Graph::Directed;
  4         464  
  4         61  
126              
127 4     4   15 use strict;
  4         4  
  4         62  
128              
129 4     4   12 use base qw(Bio::Root::Root);
  4         16  
  4         1748  
130              
131             =head2 new
132              
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
140              
141             =cut
142              
143             sub new {
144 8     8 1 143 my( $class ) = @_;
145 8   33     43 $class = ref $class || $class;
146              
147 8         16 my $self= bless( {}, $class );
148 8         72 $self->{_graph}=Graph::Directed->new();
149 8         1511 $self->{_vertex_attributes}={};
150 8         13 $self->{_edge_attributes}={};
151 8         22 return $self;
152             }
153              
154             # Here are the main methods
155              
156             sub add_vertex {
157 1250     1250 0 1845 my $self=shift;
158 1250         1293 $self->_graph->add_vertex(@_);
159             }
160             sub has_vertex {
161 17382     17382 0 12188 my $self=shift;
162 17382         17562 $self->_graph->has_vertex(@_);
163             }
164             sub add_edge {
165 1473     1473 0 1955 my $self=shift;
166 1473         1630 $self->_graph->add_edge(@_);
167             }
168             sub has_edge {
169 1489     1489 0 1646 my $self=shift;
170 1489         1503 $self->_graph->has_edge(@_);
171             }
172             sub vertices {
173 9     9 0 268 my $self=shift;
174 9         19 $self->_graph->vertices(@_);
175             }
176             sub edges {
177 5     5 0 257 my $self=shift;
178 5         13 $self->_graph->edges(@_);
179             }
180             sub edges_at {
181 4     4 0 1303 my $self=shift;
182 4         10 $self->_graph->edges_at(@_);
183             }
184             sub predecessors {
185 106     106 0 1334 my $self=shift;
186 106         128 $self->_graph->predecessors(@_);
187             }
188             sub successors {
189 327     327 0 1070 my $self=shift;
190 327         331 $self->_graph->successors(@_);
191             }
192             sub source_vertices {
193 8     8 0 819 my $self=shift;
194 8         18 $self->_graph->source_vertices();
195             }
196             sub sink_vertices {
197 3     3 0 903 my $self=shift;
198 3         7 $self->_graph->sink_vertices();
199             }
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 1253     1253 0 2227 my($self,$v,$attribute,$value)=@_;
204 1253         1492 $self->_vertex2attributes($v)->{$attribute}=$value;
205             }
206             sub get_vertex_attribute {
207 10022     10022 0 7460 my($self,$v,$attribute)=@_;
208 10022         8929 $self->_vertex2attributes($v)->{$attribute};
209             }
210             sub set_edge_attribute {
211 2946     2946 0 3063 my($self,$u,$v,$attribute,$value)=@_;
212 2946         3204 $self->_edge2attributes($u,$v)->{$attribute}=$value;
213             }
214             sub get_edge_attribute {
215 2858     2858 0 2628 my($self,$u,$v,$attribute)=@_;
216 2858         2981 $self->_edge2attributes($u,$v)->{$attribute};
217             }
218              
219             =head2 _graph
220              
221             Title : _graph
222             Usage : $self->_graph();
223             Function: Internal method to access 'real' graph
224             Returns : Graph::Directed object
225             Args : none
226              
227             =cut
228              
229 22056     22056   36532 sub _graph {$_[0]->{_graph}; }
230              
231             =head2 _vertex_attributes
232              
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
238              
239             =cut
240              
241 12526     12526   38432 sub _vertex_attributes {$_[0]->{_vertex_attributes}; }
242              
243             =head2 _edge_attributes
244              
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
250              
251             =cut
252              
253 7277     7277   26318 sub _edge_attributes {$_[0]->{_edge_attributes}; }
254              
255             =head2 _vertex2attributes
256              
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
263              
264             =cut
265              
266             sub _vertex2attributes {
267 11275     11275   7239 my($self,$vertex)=@_;
268 11275 100       10524 $self->_vertex_attributes->{$vertex} or $self->_vertex_attributes->{$vertex}={};
269             }
270              
271             =head2 _edge2attributes
272              
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
279              
280             =cut
281              
282             sub _edge2attributes {
283 5804     5804   4226 my($self,$u,$v)=@_;
284 5804 100       5720 $self->_edge_attributes->{$u,$v} or $self->_edge_attributes->{$u,$v}={};
285             }
286              
287             1;