t/SeqFeature/Generic.t: fix typo on required module for testing
[bioperl-live.git] / lib / Bio / Annotation / Target.pm
bloba42cc95a3ece1e1fccf8eb0fa3186fdd7c4a104a
2 # BioPerl module for Bio::Annotation::Target
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Scott Cain <cain@cshl.org>
8 # Copyright Scott Cain
10 # Based on the Bio::Annotation::DBLink by Ewan Birney
12 # You may distribute this module under the same terms as perl itself
14 # POD documentation - main docs before the code
16 =head1 NAME
18 Bio::Annotation::Target - Provides an object which represents a target (ie, a
19 similarity hit) from one object to something in another database
21 =head1 SYNOPSIS
23 $target1 = Bio::Annotation::Target->new(-target_id => 'F321966.1',
24 -start => 1,
25 -end => 200,
26 -strand => 1, # or -1
29 # or
31 $target2 = Bio::Annotation::Target->new();
32 $target2->target_id('Q75IM5');
33 $target2->start(7);
34 # ... etc ...
36 # Target is-a Bio::AnnotationI object, can be added to annotation
37 # collections, e.g. the one on features or seqs
38 $feat->annotation->add_Annotation('Target', $target2);
41 =head1 DESCRIPTION
43 Provides an object which represents a target (ie, a similarity hit) from
44 one object to something in another database without prescribing what is
45 in the other database
47 =head1 AUTHOR - Scott Cain
49 Scott Cain - cain@cshl.org
51 =head1 APPENDIX
53 The rest of the documentation details each of the object
54 methods. Internal methods are usually preceded with a _
56 =cut
59 # Let the code begin...
61 package Bio::Annotation::Target;
62 use strict;
64 use base qw(Bio::Annotation::DBLink Bio::AnnotationI Bio::Range);
67 sub new {
68 my($class,@args) = @_;
70 my $self = $class->SUPER::new(@args);
72 my ($target_id, $tstart, $tend, $tstrand) =
73 $self->_rearrange([ qw(
74 TARGET_ID
75 START
76 END
77 STRAND ) ], @args);
79 $target_id && $self->target_id($target_id);
80 $tstart && $self->start($tstart);
81 $tend && $self->end($tend);
82 $tstrand && $self->strand($tstrand);
84 return $self;
87 =head1 AnnotationI implementing functions
89 =cut
92 =head2 as_text
94 Title : as_text
95 Usage :
96 Function:
97 Example :
98 Returns :
99 Args :
102 =cut
104 sub as_text{
105 my ($self) = @_;
107 my $target = $self->target_id || '';
108 my $start = $self->start || '';
109 my $end = $self->end || '';
110 my $strand = $self->strand || '';
112 return "Target=".$target." ".$start." ".$end." ".$strand;
115 =head2 display_text
117 Title : display_text
118 Usage : my $str = $ann->display_text();
119 Function: returns a string. Unlike as_text(), this method returns a string
120 formatted as would be expected for te specific implementation.
122 One can pass a callback as an argument which allows custom text
123 generation; the callback is passed the current instance and any text
124 returned
125 Example :
126 Returns : a string
127 Args : [optional] callback
129 =cut
132 my $DEFAULT_CB = sub { $_[0]->as_text || ''};
134 sub display_text {
135 my ($self, $cb) = @_;
136 $cb ||= $DEFAULT_CB;
137 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
138 return $cb->($self);
143 =head2 tagname
145 Title : tagname
146 Usage : $obj->tagname($newval)
147 Function: Get/set the tagname for this annotation value.
149 Setting this is optional. If set, it obviates the need to
150 provide a tag to Bio::AnnotationCollectionI when adding
151 this object. When obtaining an AnnotationI object from the
152 collection, the collection will set the value to the tag
153 under which it was stored unless the object has a tag
154 stored already.
156 Example :
157 Returns : value of tagname (a scalar)
158 Args : new value (a scalar, optional)
161 =cut
163 sub tagname{
164 my ($self,$value) = @_;
165 if( defined $value) {
166 $self->{'tagname'} = $value;
168 return $self->{'tagname'};
171 =head1 Specific accessors for Targets
173 =cut
175 =head2 target_id
177 =over
179 =item Usage
181 $obj->target_id() #get existing value
182 $obj->target_id($newval) #set new value
184 =item Function
186 =item Returns
188 value of target_id (a scalar)
190 =item Arguments
192 new value of target_id (to set)
194 =back
196 =cut
198 sub target_id {
199 my $self = shift;
200 return $self->{'target_id'} = shift if defined($_[0]);
201 return $self->{'target_id'} || $self->primary_id();