sync with trunk
[bioperl-network.git] / lib / Bio / Network / Interaction.pm
blob8b6c9fdf3e2dc1f36de9c88df9d4e73b1e1afa63
1 # $Id$
3 # BioPerl module for Bio::Network::Interaction
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::Network::Interaction - describes a protein-protein interaction
12 =head1 SYNOPSIS
14 # Add an interaction with some attributes
15 use Bio::Network::Interaction;
17 my $interx = Bio::Network::Interaction->new(-weight => $score,
18 -id => $id);
19 $gr->add_interaction(-nodes => [($node1,$node2)],
20 -interaction => $interx);
22 # Retrieve an interaction using an identifier
23 my $interaction = $gr->get_interaction_by_id($id);
25 my $id = $interaction->primary_id;
26 my $wt = $interaction->weight;
27 my @nodes = $interaction->nodes;
29 =head1 DESCRIPTION
31 This class contains information about a bi-molecular interaction.
32 At present it just contains data about a weight (optional) and an
33 identifier. Subclasses could hold more specific information. A pair
34 of nodes can have more than one Interaction object associated with it.
36 =head1 FEEDBACK
38 =head2 Mailing Lists
40 User feedback is an integral part of the evolution of this and other
41 Bioperl modules. Send your comments and suggestions preferably to one
42 of the Bioperl mailing lists. Your participation is much appreciated.
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47 =head2 Support
49 Please direct usage questions or support issues to the mailing list:
51 I<bioperl-l@bioperl.org>
53 rather than to the module maintainer directly. Many experienced and
54 reponsive experts will be able look at the problem and quickly
55 address it. Please include a thorough description of the problem
56 with code and data examples if at all possible.
58 =head2 Reporting Bugs
60 Report bugs to the Bioperl bug tracking system to help us keep track
61 the bugs and their resolution. Bug reports can be submitted via the
62 web:
64 http://bugzilla.open-bio.org/
66 =head1 AUTHORS
68 Brian Osborne bosborne at alum.mit.edu
69 Richard Adams richard.adams@ed.ac.uk
71 Maintained by Brian Osborne
73 =cut
75 use strict;
76 package Bio::Network::Interaction;
77 use base qw(Bio::Root::Root Bio::AnnotatableI Bio::Annotation::Collection);
80 =head2 new
82 Name : new
83 Purpose : Constructor for an Interaction object
84 Usage : my $interx = Bio::Network::Interaction->new(-id => $id);
85 Returns : A new Bio::Network::Interaction object
86 Arguments : -id => interaction id
87 -weight (optional) => weight score
89 =cut
91 sub new {
92 my ($caller,@args) = @_;
93 my $class = ref ($caller) || $caller;
94 my $self = {};
95 bless ($self, $class);
97 my ($weight,$id) = $self->_rearrange([qw( WEIGHT ID )], @args);
98 $self->{_weight} = defined($weight) ? $weight : undef;
99 $self->{_id} = defined($id) ? $id : undef;
100 return $self;
103 =head2 weight
105 Name : weight
106 Purpose : Get or set a weight or score
107 Usage : my $weight = $interx->weight()
109 $interx->weight(3)
110 Returns : a number
111 Arguments : Nothing or a number
113 =cut
115 sub weight {
116 my $self = shift;
117 $self->{_weight} = shift if @_;
118 return defined($self->{_weight}) ? $self->{_weight} : undef;
121 =head2 primary_id
123 Name : primary_id
124 Purpose : Get or set the primary_id
125 Usage : my $id = $interx->primary_id()
127 $interx->primary_id("SIB4")
128 Returns : A string identifier
129 Arguments : Nothing or an identifier
131 =cut
133 sub primary_id {
134 my $self = shift;
135 if (@_) {
136 my $v = shift;
137 $self->throw ("Primary interaction ID must be a text value, not a [" .
138 ref($v). "].") if (ref ($v));
139 $self->{_id} = $v;
141 return defined($self->{_id}) ? $self->{_id} : undef;
144 =head2 nodes
146 Name : nodes
147 Purpose : Get the pair of nodes for an Interaction
148 Usage : my $count = $interx->nodes
150 my @nodes = $interx->nodes
151 Returns : Gets an array of 2 Nodes or a count of the number of
152 Nodes
153 Arguments :
154 Notes : Getting a count of the number of Nodes in an Interaction
155 will almost always return 2, but there is a formal possibility
156 that a Node could interact with itself, returning 1
158 =cut
160 sub nodes {
161 my $self = shift;
162 my @nodes = @{$self->{_nodes}};
163 wantarray ? return @nodes : return scalar @nodes;
166 =head2 annotation
168 Title : annotation
169 Usage : my $annotation = $ix->annotation
171 $ix->annotation($annotation)
172 Function: Gets or sets the annotation
173 Returns : Bio::AnnotationCollectionI object
174 Args : None or Bio::AnnotationCollectionI object
176 See L<Bio::AnnotationCollectionI> and L<Bio::Annotation::Collection>
177 for more information
179 =cut
181 sub annotation {
182 my ($obj,$value) = @_;
183 if ( defined $value ) {
184 $obj->throw("Object of class " . ref($value) . " does not implement ".
185 "Bio::AnnotationCollectionI.")
186 unless $value->isa("Bio::AnnotationCollectionI");
187 $obj->{'_annotation'} = $value;
188 } elsif( ! defined $obj->{'_annotation'}) {
189 $obj->{'_annotation'} = Bio::Annotation::Collection->new();
191 return $obj->{'_annotation'};
194 =head2 object_id
196 Name : object_id
197 Purpose : Alias to primary_id
198 Usage : my $id = $edge->object_id()
199 Notes : Deprecated
201 =cut
203 sub object_id {
204 my ($self,$id) = @_;
205 $id ? $self->primary_id($id) : return $self->primary_id;
210 __END__