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
;
80 # Object preamble - inherits from Bio::Root::Root
82 use base
qw(Bio::Root::Root Bio::AnnotationI);
87 Usage : my $sv = Bio::Annotation::Relation->new();
88 Function: Instantiate a new Relation object
89 Returns : Bio::Annotation::Relation object
90 Args : -type => $type of relation [optional]
91 -to => $obj which $self is in relation to [optional]
92 -tagname => $tag to initialize the tagname [optional]
93 -tag_term => ontology term representation of the tag [optional]
98 my ($class,@args) = @_;
100 my $self = $class->SUPER::new
(@args);
102 my ($type, $to, $tag, $term) =
103 $self->_rearrange([qw(TYPE TO TAGNAME TAG_TERM)], @args);
106 defined $term && $self->tag_term($term);
107 defined $type && $self->type($type);
108 defined $to && $self->to($to);
109 defined $tag && $self->tagname($tag);
115 =head1 AnnotationI implementing functions
122 Usage : my $text = $obj->as_text
123 Function: return the string "Value: $v" where $v is the value
133 return $self->type." to ".$self->to->id;
139 Usage : my $str = $ann->display_text();
140 Function: returns a string. Unlike as_text(), this method returns a string
141 formatted as would be expected for te specific implementation.
143 One can pass a callback as an argument which allows custom text
144 generation; the callback is passed the current instance and any text
148 Args : [optional] callback
153 my $DEFAULT_CB = sub { return $_[0]->type." to ".$_[0]->to->id };
154 #my $DEFAULT_CB = sub { $_[0]->value};
157 my ($self, $cb) = @_;
159 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
168 Usage : my $hashtree = $value->hash_tree
169 Function: For supporting the AnnotationI interface just returns the value
170 as a hashref with the key 'value' pointing to the value
181 $h->{'type'} = $self->type;
182 $h->{'to'} = $self->to;
189 Usage : $obj->tagname($newval)
190 Function: Get/set the tagname for this annotation value.
192 Setting this is optional. If set, it obviates the need to
193 provide a tag to AnnotationCollection when adding this
197 Returns : value of tagname (a scalar)
198 Args : new value (a scalar, optional)
206 # check for presence of an ontology term
207 if($self->{'_tag_term'}) {
208 # keep a copy in case the term is removed later
209 $self->{'tagname'} = $_[0] if @_;
210 # delegate to the ontology term object
211 return $self->tag_term->name(@_);
213 return $self->{'tagname'} = shift if @_;
214 return $self->{'tagname'};
218 =head1 Specific accessors for Relation
225 Usage : $obj->type($newval)
226 Function: Get/Set the type
227 Returns : type of relation
228 Args : newtype (optional)
234 my ($self,$type) = @_;
237 $self->{'type'} = $type;
239 return $self->{'type'};
245 Usage : $obj->to($newval)
246 Function: Get/Set the object which $self is in relation to
247 Returns : the object which the relation applies to
248 Args : new target object (optional)
259 return $self->{'to'};
265 Usage : $self->confidence($newval)
266 Function: Gives the confidence value.
268 Returns : value of confidence
269 Args : newvalue (optional)
275 my ($self,$value) = @_;
276 if( defined $value) {
277 $self->{'confidence'} = $value;
279 return $self->{'confidence'};
283 =head2 confidence_type
285 Title : confidence_type
286 Usage : $self->confidence_type($newtype)
287 Function: Gives the confidence type.
289 Returns : type of confidence
290 Args : newtype (optional)
296 my ($self,$type) = @_;
298 $self->{'confidence_type'} = $type;
300 return $self->{'confidence_type'};
306 Usage : $obj->tag_term($newval)
307 Function: Get/set the L<Bio::Ontology::TermI> object representing
310 This is so you can specifically relate the tag of this
311 annotation to an entry in an ontology. You may want to do
312 this to associate an identifier with the tag, or a
313 particular category, such that you can better match the tag
314 against a controlled vocabulary.
316 This accessor will return undef if it has never been set
317 before in order to allow this annotation to stay
318 light-weight if an ontology term representation of the tag
319 is not needed. Once it is set to a valid value, tagname()
320 will actually delegate to the name() of this term.
323 Returns : a L<Bio::Ontology::TermI> compliant object, or undef
324 Args : on set, new value (a L<Bio::Ontology::TermI> compliant
325 object or undef, optional)
333 return $self->{'_tag_term'} = shift if @_;
334 return $self->{'_tag_term'};