t/SeqFeature/Generic.t: fix typo on required module for testing
[bioperl-live.git] / lib / Bio / Annotation / Relation.pm
blob8bf5afb3e24d099cf14ea3b750dc00b2a3f79b2d
1 # $Id: Relation.pm 14708 2008-06-10 00:08:17Z heikki $
3 # BioPerl module for Bio::Annotation::Relation
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by bioperl <bioperl-l@bioperl.org>
9 # Copyright bioperl
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
15 =head1 NAME
17 Bio::Annotation::Relation - Relationship (pairwise) with other objects SeqI and NodeI;
19 =head1 SYNOPSIS
21 use Bio::Annotation::Relation;
22 use Bio::Annotation::Collection;
24 my $col = Bio::Annotation::Collection->new();
25 my $sv = Bio::Annotation::Relation->new(-type => "paralogy" -to => "someSeqI");
26 $col->add_Annotation('tagname', $sv);
28 =head1 DESCRIPTION
30 Scalar value annotation object
32 =head1 FEEDBACK
34 =head2 Mailing Lists
36 User feedback is an integral part of the evolution of this and other
37 Bioperl modules. Send your comments and suggestions preferably to one
38 of the Bioperl mailing lists. Your participation is much appreciated.
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
43 =head2 Support
45 Please direct usage questions or support issues to the mailing list:
47 I<bioperl-l@bioperl.org>
49 rather than to the module maintainer directly. Many experienced and
50 reponsive experts will be able look at the problem and quickly
51 address it. Please include a thorough description of the problem
52 with code and data examples if at all possible.
54 =head2 Reporting Bugs
56 Report bugs to the Bioperl bug tracking system to help us keep track
57 the bugs and their resolution. Bug reports can be submitted via
58 the web:
60 https://github.com/bioperl/bioperl-live/issues
62 =head1 AUTHOR - Mira Han
64 Email mirhan@indiana.edu
66 =head1 APPENDIX
68 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
70 =cut
73 # Let the code begin...
76 package Bio::Annotation::Relation;
77 use strict;
79 # Object preamble - inherits from Bio::Root::Root
81 use base qw(Bio::Root::Root Bio::AnnotationI);
83 =head2 new
85 Title : new
86 Usage : my $sv = Bio::Annotation::Relation->new();
87 Function: Instantiate a new Relation object
88 Returns : Bio::Annotation::Relation object
89 Args : -type => $type of relation [optional]
90 -to => $obj which $self is in relation to [optional]
91 -tagname => $tag to initialize the tagname [optional]
92 -tag_term => ontology term representation of the tag [optional]
94 =cut
96 sub new{
97 my ($class,@args) = @_;
99 my $self = $class->SUPER::new(@args);
101 my ($type, $to, $tag, $term) =
102 $self->_rearrange([qw(TYPE TO TAGNAME TAG_TERM)], @args);
104 # set the term first
105 defined $term && $self->tag_term($term);
106 defined $type && $self->type($type);
107 defined $to && $self->to($to);
108 defined $tag && $self->tagname($tag);
110 return $self;
114 =head1 AnnotationI implementing functions
116 =cut
118 =head2 as_text
120 Title : as_text
121 Usage : my $text = $obj->as_text
122 Function: return the string "Value: $v" where $v is the value
123 Returns : string
124 Args : none
127 =cut
129 sub as_text{
130 my ($self) = @_;
132 return $self->type." to ".$self->to->id;
135 =head2 display_text
137 Title : display_text
138 Usage : my $str = $ann->display_text();
139 Function: returns a string. Unlike as_text(), this method returns a string
140 formatted as would be expected for te specific implementation.
142 One can pass a callback as an argument which allows custom text
143 generation; the callback is passed the current instance and any text
144 returned
145 Example :
146 Returns : a string
147 Args : [optional] callback
149 =cut
152 my $DEFAULT_CB = sub { return $_[0]->type." to ".$_[0]->to->id };
153 #my $DEFAULT_CB = sub { $_[0]->value};
155 sub display_text {
156 my ($self, $cb) = @_;
157 $cb ||= $DEFAULT_CB;
158 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
159 return $cb->($self);
164 =head2 hash_tree
166 Title : hash_tree
167 Usage : my $hashtree = $value->hash_tree
168 Function: For supporting the AnnotationI interface just returns the value
169 as a hashref with the key 'value' pointing to the value
170 Returns : hashrf
171 Args : none
174 =cut
176 sub hash_tree{
177 my $self = shift;
179 my $h = {};
180 $h->{'type'} = $self->type;
181 $h->{'to'} = $self->to;
182 return $h;
185 =head2 tagname
187 Title : tagname
188 Usage : $obj->tagname($newval)
189 Function: Get/set the tagname for this annotation value.
191 Setting this is optional. If set, it obviates the need to
192 provide a tag to AnnotationCollection when adding this
193 object.
195 Example :
196 Returns : value of tagname (a scalar)
197 Args : new value (a scalar, optional)
200 =cut
202 sub tagname{
203 my $self = shift;
205 # check for presence of an ontology term
206 if($self->{'_tag_term'}) {
207 # keep a copy in case the term is removed later
208 $self->{'tagname'} = $_[0] if @_;
209 # delegate to the ontology term object
210 return $self->tag_term->name(@_);
212 return $self->{'tagname'} = shift if @_;
213 return $self->{'tagname'};
217 =head1 Specific accessors for Relation
219 =cut
221 =head2 type
223 Title : type
224 Usage : $obj->type($newval)
225 Function: Get/Set the type
226 Returns : type of relation
227 Args : newtype (optional)
230 =cut
232 sub type{
233 my ($self,$type) = @_;
235 if( defined $type) {
236 $self->{'type'} = $type;
238 return $self->{'type'};
241 =head2 to
243 Title : to
244 Usage : $obj->to($newval)
245 Function: Get/Set the object which $self is in relation to
246 Returns : the object which the relation applies to
247 Args : new target object (optional)
250 =cut
252 sub to{
253 my ($self,$to) = @_;
255 if( defined $to) {
256 $self->{'to'} = $to;
258 return $self->{'to'};
261 =head2 confidence
263 Title : confidence
264 Usage : $self->confidence($newval)
265 Function: Gives the confidence value.
266 Example :
267 Returns : value of confidence
268 Args : newvalue (optional)
271 =cut
273 sub confidence{
274 my ($self,$value) = @_;
275 if( defined $value) {
276 $self->{'confidence'} = $value;
278 return $self->{'confidence'};
282 =head2 confidence_type
284 Title : confidence_type
285 Usage : $self->confidence_type($newtype)
286 Function: Gives the confidence type.
287 Example :
288 Returns : type of confidence
289 Args : newtype (optional)
292 =cut
294 sub confidence_type{
295 my ($self,$type) = @_;
296 if( defined $type) {
297 $self->{'confidence_type'} = $type;
299 return $self->{'confidence_type'};
302 =head2 tag_term
304 Title : tag_term
305 Usage : $obj->tag_term($newval)
306 Function: Get/set the L<Bio::Ontology::TermI> object representing
307 the tag name.
309 This is so you can specifically relate the tag of this
310 annotation to an entry in an ontology. You may want to do
311 this to associate an identifier with the tag, or a
312 particular category, such that you can better match the tag
313 against a controlled vocabulary.
315 This accessor will return undef if it has never been set
316 before in order to allow this annotation to stay
317 light-weight if an ontology term representation of the tag
318 is not needed. Once it is set to a valid value, tagname()
319 will actually delegate to the name() of this term.
321 Example :
322 Returns : a L<Bio::Ontology::TermI> compliant object, or undef
323 Args : on set, new value (a L<Bio::Ontology::TermI> compliant
324 object or undef, optional)
327 =cut
329 sub tag_term{
330 my $self = shift;
332 return $self->{'_tag_term'} = shift if @_;
333 return $self->{'_tag_term'};