2 # BioPerl module for Bio::SeqFeature::PositionProxy
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
8 # Copyright Ewan Birney
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::SeqFeature::PositionProxy - handle features when truncation/revcom sequences span a feature
20 $proxy = Bio::SeqFeature::PositionProxy->new( -loc => $loc,
21 -parent => $basefeature);
23 $seq->add_SeqFeature($feat);
27 PositionProxy is a Proxy Sequence Feature to handle truncation
28 and revcomp without duplicating all the data within the sequence features.
29 It holds a new location for a sequence feature and the original feature
30 it came from to provide the additional annotation information.
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 the
60 https://github.com/bioperl/bioperl-live/issues
62 =head1 AUTHOR - Ewan Birney
64 Ewan Birney E<lt>birney@sanger.ac.ukE<gt>
68 This class has been written with an eye out of inheritance. The fields
69 the actual object hash are:
71 _gsf_tag_hash = reference to a hash for the tags
72 _gsf_sub_array = reference to an array for sub arrays
73 _gsf_start = scalar of the start point
74 _gsf_end = scalar of the end point
75 _gsf_strand = scalar of the strand
79 The rest of the documentation details each of the object
80 methods. Internal methods are usually preceded with a _
85 # Let the code begin...
88 package Bio
::SeqFeature
::PositionProxy
;
94 use base
qw(Bio::Root::Root Bio::SeqFeatureI);
97 my ($caller, @args) = @_;
98 my $self = $caller->SUPER::new
(@args);
100 my ($feature,$location) = $self->_rearrange([qw(PARENT LOC)],@args);
102 if( !defined $feature || !ref $feature || !$feature->isa('Bio::SeqFeatureI') ) {
103 $self->throw("Must have a parent feature, not a [$feature]");
106 if( $feature->isa("Bio::SeqFeature::PositionProxy") ) {
107 $feature = $feature->parent();
110 if( !defined $location || !ref $location || !$location->isa('Bio::LocationI') ) {
111 $self->throw("Must have a location, not a [$location]");
122 Usage : my $location = $seqfeature->location()
123 Function: returns a location object suitable for identifying location
124 of feature on sequence or parent feature
125 Returns : Bio::LocationI object
131 my($self, $value ) = @_;
133 if (defined($value)) {
134 unless (ref($value) and $value->isa('Bio::LocationI')) {
135 $self->throw("object $value pretends to be a location but ".
136 "does not implement Bio::LocationI");
138 $self->{'_location'} = $value;
140 elsif (! $self->{'_location'}) {
141 # guarantees a real location object is returned every time
142 $self->{'_location'} = Bio
::Location
::Simple
->new();
144 return $self->{'_location'};
151 Usage : my $sf = $proxy->parent()
152 Function: returns the seqfeature parent of this proxy
153 Returns : Bio::SeqFeatureI object
159 my($self, $value ) = @_;
161 if (defined($value)) {
162 unless (ref($value) and $value->isa('Bio::SeqFeatureI')) {
163 $self->throw("object $value pretends to be a location but ".
164 "does not implement Bio::SeqFeatureI");
166 $self->{'_parent'} = $value;
169 return $self->{'_parent'};
177 Usage : $start = $feat->start
186 my ($self,$value) = @_;
187 return $self->location->start($value);
194 Usage : $end = $feat->end
203 my ($self,$value) = @_;
204 return $self->location->end($value);
221 return $self->end - $self->start() + 1;
228 Usage : $strand = $feat->strand()
229 $feat->strand($strand)
230 Function: get/set on strand information, being 1,-1 or 0
237 my ($self,$value) = @_;
238 return $self->location->strand($value);
245 Usage : $sf->attach_seq($seq)
246 Function: Attaches a Bio::Seq object to this feature. This
247 Bio::Seq object is for the *entire* sequence: ie
250 Returns : TRUE on success
256 my ($self, $seq) = @_;
258 if ( !defined $seq || !ref $seq || ! $seq->isa("Bio::PrimarySeqI") ) {
259 $self->throw("Must attach Bio::PrimarySeqI objects to SeqFeatures");
262 $self->{'_gsf_seq'} = $seq;
264 # attach to sub features if they want it
266 foreach my $sf ( $self->sub_SeqFeature() ) {
267 if ( $sf->can("attach_seq") ) {
268 $sf->attach_seq($seq);
278 Usage : $tseq = $sf->seq()
279 Function: returns the truncated sequence (if there) for this
281 Returns : sub seq on attached sequence bounded by start & end
287 my ($self, $arg) = @_;
289 if ( defined $arg ) {
290 $self->throw("Calling SeqFeature::PositionProxy->seq with an argument. You probably want attach_seq");
293 if ( ! exists $self->{'_gsf_seq'} ) {
297 # assumming our seq object is sensible, it should not have to yank
298 # the entire sequence out here.
300 my $seq = $self->{'_gsf_seq'}->trunc($self->start(), $self->end());
303 if ( $self->strand == -1 ) {
314 Usage : $whole_seq = $sf->entire_seq()
315 Function: gives the entire sequence that this seqfeature is attached to
325 return unless exists($self->{'_gsf_seq'});
326 return $self->{'_gsf_seq'};
333 Usage : $obj->seq_id($newval)
334 Function: There are many cases when you make a feature that you
335 do know the sequence name, but do not know its actual
336 sequence. This is an attribute such that you can store
339 This attribute should *not* be used in GFF dumping, as
340 that should come from the collection in which the seq
342 Returns : value of seqname
343 Args : newvalue (optional)
348 my ($obj,$value) = @_;
349 if ( defined $value ) {
350 $obj->{'_gsf_seqname'} = $value;
352 return $obj->{'_gsf_seqname'};
358 These functions chain back to the parent for all non sequence related stuff.
365 Usage : $tag = $feat->primary_tag()
366 Function: Returns the primary tag for a feature,
374 my ($self,@args) = @_;
376 return $self->parent->primary_tag();
383 Usage : $tag = $feat->source_tag()
384 Function: Returns the source tag for a feature,
394 return $self->parent->source_tag();
401 Usage : $tag_exists = $self->has_tag('some_tag')
403 Returns : TRUE if the specified tag exists, and FALSE otherwise
409 my ($self,$tag) = @_;
411 return $self->parent->has_tag($tag);
415 =head2 get_tag_values
417 Title : get_tag_values
418 Usage : @values = $self->get_tag_values('some_tag')
420 Returns : An array comprising the values of the specified tag.
425 *each_tag_value
= \
&get_tag_values
;
428 my ($self,$tag) = @_;
430 return $self->parent->get_tag_values($tag);
437 Usage : @tags = $feat->get_all_tags()
438 Function: gives all tags for this feature
439 Returns : an array of strings
444 *all_tags
= \
&get_all_tags
;
449 return $self->parent->all_tags();