bug 2549; fixed small bug in Bio::Taxon which doesn't catch -common_name
[bioperl-live.git] / Bio / Graph / Edge.pm
blobb45da8e1310657dd07c980a8d057c9e4fcba8158
1 # $Id$
3 # BioPerl module for Bio::Graph::Edge
5 # You may distribute this module under the same terms as perl itself
6 # POD documentation - main docs before the code
8 =head1 NAME
10 Bio::Graph::Edge - encapsulation of an interaction between 2 Bio::Seq objects
12 =head1 SYNOPSIS
14 ## get an interaction between two nodes ##
16 my $edge = $gr->edge( $gr->nodes_by_id('P12345'),
17 $gr->nodes_by_id('P23456'));
18 my $id = $edge->object_id();
19 my $wt = $edge->weight();
20 my @nodes = $edge->nodes();
22 =head1 DESCRIPTION
24 This class contains information about a bimolecular interaction.
25 At present it just contains data about its component node, a weight
26 (if set) and an identifier. Subclasses could hold more specific
27 information.
29 =head1 FEEDBACK
31 =head2 Mailing Lists
33 User feedback is an integral part of the evolution of this and other
34 Bioperl modules. Send your comments and suggestions preferably to one
35 of the Bioperl mailing lists. Your participation is much appreciated.
37 bioperl-l@bioperl.org - General discussion
38 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
40 =head2 Reporting Bugs
42 Report bugs to the Bioperl bug tracking system to help us keep track
43 the bugs and their resolution. Bug reports can be submitted via the
44 web:
46 http://bugzilla.open-bio.org/
48 =head1 AUTHOR - Richard Adams
50 Email richard.adams@ed.ac.uk
52 =cut
54 use strict;
55 package Bio::Graph::Edge;
56 use base qw(Bio::Root::Root Bio::IdentifiableI);
59 =head2 new
61 Name : new
62 Purpose : constructor for an edge object
63 Usage : my $edge = Bio::Graph::Edge->new(nodes => [$node1,$node2]
64 id => $id);
65 $graph->add_edge($edge);
66 Returns : a new Bio::Graph::Edge object
67 Arguments : hash nodes => array reference of 2 nodes
68 id => edge id
69 weight(optional) => weight score.
71 =cut
73 sub new {
74 ##array based, not hash based ##..., therefore does not use
75 #Bio::Root::Root->new().
77 my ($caller, @args) = @_;
78 my $class = ref ($caller) || $caller;
79 my $self = [];
80 bless ($self, $class);
82 my ($weight, $id, $nodes) = $self->_rearrange([qw( WEIGHT ID NODES)], @args);
83 $self->[0] = $nodes->[0];
84 $self->[1] = $nodes->[1];
85 $self->[2] = defined($weight)?$weight:undef;
86 $self->[3] = defined($id)?$id:undef;
87 return $self;
91 =head2 weight
93 Name : weight
94 Purpose : get/setter for weight score
95 Usage : my $weight = $edge->weight();
96 Returns : anumber
97 Arguments : void/ a number
99 =cut
101 sub weight {
102 my $self = shift;
103 if (@_) {$self->[2] = shift;}
104 return defined($self->[2])?$self->[2]:undef;
107 =head2 object_id
109 Name : object_id
110 Purpose : get/setter for object_id
111 Usage : my $id = $edge->object_id();
112 Returns : a string identifier
113 Arguments : void/ an identifier
115 =cut
117 sub object_id {
118 my $self = shift;
119 if (@_) {
120 my $v = shift;
121 if (ref ($v)) {
122 $self->throw ("Edge ID must be a text value, not a [".
123 ref($v). "].");
125 $self->[3] = shift;
127 return defined($self->[3])?$self->[3]:undef;
130 =head2 nodes
132 Name : nodes
133 Purpose : get/setter for nodes
134 Usage : my @nodes = $edge->nodes();
135 Returns : a 2 element list of nodes /void
136 Arguments : void/ a 2 element list of nodes.
138 =cut
140 sub nodes {
141 my ($self, @args) = @_;
142 if (@args >= 2 ) {
143 $self->[0] = $args[0];
144 $self->[1] = $args[1];
146 return ($self->[0], $self->[1]);