maint: remove Travis stuff which has been replaced with Github actions (#325)
[bioperl-live.git] / lib / Bio / Annotation / Relation.pm
blobcb6a1de65444a1eda8b10522b589d2b3f19e404b
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;
78 use strict;
80 # Object preamble - inherits from Bio::Root::Root
82 use base qw(Bio::Root::Root Bio::AnnotationI);
84 =head2 new
86 Title : new
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]
95 =cut
97 sub new{
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);
105 # set the term first
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);
111 return $self;
115 =head1 AnnotationI implementing functions
117 =cut
119 =head2 as_text
121 Title : as_text
122 Usage : my $text = $obj->as_text
123 Function: return the string "Value: $v" where $v is the value
124 Returns : string
125 Args : none
128 =cut
130 sub as_text{
131 my ($self) = @_;
133 return $self->type." to ".$self->to->id;
136 =head2 display_text
138 Title : display_text
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
145 returned
146 Example :
147 Returns : a string
148 Args : [optional] callback
150 =cut
153 my $DEFAULT_CB = sub { return $_[0]->type." to ".$_[0]->to->id };
154 #my $DEFAULT_CB = sub { $_[0]->value};
156 sub display_text {
157 my ($self, $cb) = @_;
158 $cb ||= $DEFAULT_CB;
159 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
160 return $cb->($self);
165 =head2 hash_tree
167 Title : hash_tree
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
171 Returns : hashrf
172 Args : none
175 =cut
177 sub hash_tree{
178 my $self = shift;
180 my $h = {};
181 $h->{'type'} = $self->type;
182 $h->{'to'} = $self->to;
183 return $h;
186 =head2 tagname
188 Title : tagname
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
194 object.
196 Example :
197 Returns : value of tagname (a scalar)
198 Args : new value (a scalar, optional)
201 =cut
203 sub tagname{
204 my $self = shift;
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
220 =cut
222 =head2 type
224 Title : type
225 Usage : $obj->type($newval)
226 Function: Get/Set the type
227 Returns : type of relation
228 Args : newtype (optional)
231 =cut
233 sub type{
234 my ($self,$type) = @_;
236 if( defined $type) {
237 $self->{'type'} = $type;
239 return $self->{'type'};
242 =head2 to
244 Title : to
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)
251 =cut
253 sub to{
254 my ($self,$to) = @_;
256 if( defined $to) {
257 $self->{'to'} = $to;
259 return $self->{'to'};
262 =head2 confidence
264 Title : confidence
265 Usage : $self->confidence($newval)
266 Function: Gives the confidence value.
267 Example :
268 Returns : value of confidence
269 Args : newvalue (optional)
272 =cut
274 sub confidence{
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.
288 Example :
289 Returns : type of confidence
290 Args : newtype (optional)
293 =cut
295 sub confidence_type{
296 my ($self,$type) = @_;
297 if( defined $type) {
298 $self->{'confidence_type'} = $type;
300 return $self->{'confidence_type'};
303 =head2 tag_term
305 Title : tag_term
306 Usage : $obj->tag_term($newval)
307 Function: Get/set the L<Bio::Ontology::TermI> object representing
308 the tag name.
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.
322 Example :
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)
328 =cut
330 sub tag_term{
331 my $self = shift;
333 return $self->{'_tag_term'} = shift if @_;
334 return $self->{'_tag_term'};