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>
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
17 Bio::Annotation::Relation - Relationship (pairwise) with other objects SeqI and NodeI;
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);
30 Scalar value annotation object
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
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.
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
60 https://github.com/bioperl/bioperl-live/issues
62 =head1 AUTHOR - Mira Han
64 Email mirhan@indiana.edu
68 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
73 # Let the code begin...
76 package Bio
::Annotation
::Relation
;
79 # Object preamble - inherits from Bio::Root::Root
81 use base
qw(Bio::Root::Root Bio::AnnotationI);
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]
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);
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);
114 =head1 AnnotationI implementing functions
121 Usage : my $text = $obj->as_text
122 Function: return the string "Value: $v" where $v is the value
132 return $self->type." to ".$self->to->id;
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
147 Args : [optional] callback
152 my $DEFAULT_CB = sub { return $_[0]->type." to ".$_[0]->to->id };
153 #my $DEFAULT_CB = sub { $_[0]->value};
156 my ($self, $cb) = @_;
158 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
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
180 $h->{'type'} = $self->type;
181 $h->{'to'} = $self->to;
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
196 Returns : value of tagname (a scalar)
197 Args : new value (a scalar, optional)
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
224 Usage : $obj->type($newval)
225 Function: Get/Set the type
226 Returns : type of relation
227 Args : newtype (optional)
233 my ($self,$type) = @_;
236 $self->{'type'} = $type;
238 return $self->{'type'};
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)
258 return $self->{'to'};
264 Usage : $self->confidence($newval)
265 Function: Gives the confidence value.
267 Returns : value of confidence
268 Args : newvalue (optional)
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.
288 Returns : type of confidence
289 Args : newtype (optional)
295 my ($self,$type) = @_;
297 $self->{'confidence_type'} = $type;
299 return $self->{'confidence_type'};
305 Usage : $obj->tag_term($newval)
306 Function: Get/set the L<Bio::Ontology::TermI> object representing
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.
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)
332 return $self->{'_tag_term'} = shift if @_;
333 return $self->{'_tag_term'};