Bio/Ontology/SimpleGOEngine/GraphAdaptor.pm

filter: Statementstmt 100% 55 / 55 Branchbran 100% 4 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 24 / 24 Podpod 6.2% 1 / 16 totaltotal 81.7% 85 / 104 CC 4 SCAR 2.0
CC
4
Cov
97%
new
2.0
_vertex2attributes
2.0
_edge2attributes
2.0
CRAP 1.2
« Bio/SeqFeature/TypedSeqFeatureI.pm ↑ Summary Bio/Factory/ObjectFactoryI.pm »
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 <bioperl-l@bioperl.org>
6 #
7 # Cared for by Nat Goodman <natg at shore.net>
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<bioperl-l@bioperl.org>
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 12 $Bio::Ontology::SimpleGOEngine::GraphAdaptor::VERSION = '1.7.8';
125 12 ▶use Graph::Directed;
Subroutine BEGIN: called CC=1 SCAR=0.0
126  
127 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
128  
129 12 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
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 9 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
144 9 my( $class ) = @_;
145 9 ▶ $class = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
090
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
146  
147 9 my $self= bless( {}, $class );
148 9 $self->{_graph}=Graph::Directed->new();
149 9 $self->{_vertex_attributes}={};
150 9 $self->{_edge_attributes}={};
151 9 return $self;
152 }
153  
154 # Here are the main methods
155  
156 1250 ▶sub add_vertex {
Subroutine add_vertex: called CC=1 SCAR=0.0
Pod undocumented
157 1250 my $self=shift;
158 1250 $self->_graph->add_vertex(@_);
159 }
160 17382 ▶sub has_vertex {
Subroutine has_vertex: called CC=1 SCAR=0.0
Pod undocumented
161 17382 my $self=shift;
162 17382 $self->_graph->has_vertex(@_);
163 }
164 1473 ▶sub add_edge {
Subroutine add_edge: called CC=1 SCAR=0.0
Pod undocumented
165 1473 my $self=shift;
166 1473 $self->_graph->add_edge(@_);
167 }
168 1489 ▶sub has_edge {
Subroutine has_edge: called CC=1 SCAR=0.0
Pod undocumented
169 1489 my $self=shift;
170 1489 $self->_graph->has_edge(@_);
171 }
172 9 ▶sub vertices {
Subroutine vertices: called CC=1 SCAR=0.0
Pod undocumented
173 9 my $self=shift;
174 9 $self->_graph->vertices(@_);
175 }
176 5 ▶sub edges {
Subroutine edges: called CC=1 SCAR=0.0
Pod undocumented
177 5 my $self=shift;
178 5 $self->_graph->edges(@_);
179 }
180 4 ▶sub edges_at {
Subroutine edges_at: called CC=1 SCAR=0.0
Pod undocumented
181 4 my $self=shift;
182 4 $self->_graph->edges_at(@_);
183 }
184 106 ▶sub predecessors {
Subroutine predecessors: called CC=1 SCAR=0.0
Pod undocumented
185 106 my $self=shift;
186 106 $self->_graph->predecessors(@_);
187 }
188 327 ▶sub successors {
Subroutine successors: called CC=1 SCAR=0.0
Pod undocumented
189 327 my $self=shift;
190 327 $self->_graph->successors(@_);
191 }
192 8 ▶sub source_vertices {
Subroutine source_vertices: called CC=1 SCAR=0.0
Pod undocumented
193 8 my $self=shift;
194 8 $self->_graph->source_vertices();
195 }
196 3 ▶sub sink_vertices {
Subroutine sink_vertices: called CC=1 SCAR=0.0
Pod undocumented
197 3 my $self=shift;
198 3 $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 1253 ▶sub set_vertex_attribute {
Subroutine set_vertex_attribute: called CC=1 SCAR=0.0
Pod undocumented
203 1253 my($self,$v,$attribute,$value)=@_;
204 1253 $self->_vertex2attributes($v)->{$attribute}=$value;
205 }
206 10022 ▶sub get_vertex_attribute {
Subroutine get_vertex_attribute: called CC=1 SCAR=0.0
Pod undocumented
207 10022 my($self,$v,$attribute)=@_;
208 10022 $self->_vertex2attributes($v)->{$attribute};
209 }
210 2946 ▶sub set_edge_attribute {
Subroutine set_edge_attribute: called CC=1 SCAR=0.0
Pod undocumented
211 2946 my($self,$u,$v,$attribute,$value)=@_;
212 2946 $self->_edge2attributes($u,$v)->{$attribute}=$value;
213 }
214 2858 ▶sub get_edge_attribute {
Subroutine get_edge_attribute: called CC=1 SCAR=0.0
Pod undocumented
215 2858 my($self,$u,$v,$attribute)=@_;
216 2858 $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 ▶sub _graph {$_[0]->{_graph}; }
Subroutine _graph: called CC=1 SCAR=0.0
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 ▶sub _vertex_attributes {$_[0]->{_vertex_attributes}; }
Subroutine _vertex_attributes: called CC=1 SCAR=0.0
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 ▶sub _edge_attributes {$_[0]->{_edge_attributes}; }
Subroutine _edge_attributes: called CC=1 SCAR=0.0
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 11275 ▶sub _vertex2attributes {
Subroutine _vertex2attributes: called CC=2 SCAR=6.9
267 11275 my($self,$vertex)=@_;
268 11275 ▶ $self->_vertex_attributes->{$vertex} or $self->_vertex_attributes->{$vertex}={};
Branch: 1 branch
BranchTrueFalseTotal
$self->_vertex_attributes->{$vertex} or $self->_vertex_attributes->{$vertex} = {} 10024 1251 11275
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 5804 ▶sub _edge2attributes {
Subroutine _edge2attributes: called CC=2 SCAR=6.9
283 5804 my($self,$u,$v)=@_;
284 5804 ▶ $self->_edge_attributes->{$u,$v} or $self->_edge_attributes->{$u,$v}={};
Branch: 1 branch
BranchTrueFalseTotal
$self->_edge_attributes->{join $;, $u, $v} or $self->_edge_attributes->{join $;, $u, $v} = {} 4331 1473 5804
285 }
286  
287 12 1;
« Bio/SeqFeature/TypedSeqFeatureI.pm ↑ Summary Bio/Factory/ObjectFactoryI.pm »