Bio/SeqFeature/PositionProxy.pm

filter: Statementstmt 16.6% 13 / 78 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 15.7% 3 / 19 Podpod 100% 16 / 16 totaltotal 17.7% 32 / 180 CC 25 SCAR 33.1
CC
25
Cov
10%
new
72.0
attach_seq
42.0
location
30.0
CRAP 27.5
« Bio/Search/Hit/PullHitI.pm ↑ Summary Bio/Root/Test.pm »
1 #
2 # BioPerl module for Bio::SeqFeature::PositionProxy
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
7 #
8 # Copyright Ewan Birney
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::SeqFeature::PositionProxy - handle features when truncation/revcom sequences span a feature
17  
18 =head1 SYNOPSIS
19  
20 $proxy = Bio::SeqFeature::PositionProxy->new( -loc => $loc,
21 -parent => $basefeature);
22  
23 $seq->add_SeqFeature($feat);
24  
25 =head1 DESCRIPTION
26  
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.
31  
32 =head1 FEEDBACK
33  
34 =head2 Mailing Lists
35  
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.
39  
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42  
43 =head2 Support
44  
45 Please direct usage questions or support issues to the mailing list:
46  
47 I<bioperl-l@bioperl.org>
48  
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.
53  
54 =head2 Reporting Bugs
55  
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
58 web:
59  
60 https://github.com/bioperl/bioperl-live/issues
61  
62 =head1 AUTHOR - Ewan Birney
63  
64 Ewan Birney E<lt>birney@sanger.ac.ukE<gt>
65  
66 =head1 DEVELOPERS
67  
68 This class has been written with an eye out of inheritance. The fields
69 the actual object hash are:
70  
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
76  
77 =head1 APPENDIX
78  
79 The rest of the documentation details each of the object
80 methods. Internal methods are usually preceded with a _
81  
82 =cut
83  
84  
85 # Let the code begin...
86  
87  
88 package Bio::SeqFeature::PositionProxy;
89 1 $Bio::SeqFeature::PositionProxy::VERSION = '1.7.8';
90 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 1 ▶use Bio::Tools::GFF;
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94  
95 1 ▶use base qw(Bio::Root::Root Bio::SeqFeatureI);
Subroutine BEGIN: called CC=1 SCAR=0.0
96  
97 0 ▶sub new {
Subroutine new: not called CC=8 SCAR=42.8
Pod documented
98 0 my ($caller, @args) = @_;
99 0 my $self = $caller->SUPER::new(@args);
100  
101 0 my ($feature,$location) = $self->_rearrange([qw(PARENT LOC)],@args);
102  
103 0 ▶ if( !defined $feature || !ref $feature || !$feature->isa('Bio::SeqFeatureI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $feature and ref $feature and $feature->isa("Bio::SeqFeatureI")) 0 0 0
Condition0%0/6
defined $feature and ref $feature and $feature->isa("Bio::SeqFeatureI")
!ll&&!rl&&r
000
defined $feature and ref $feature
!ll&&!rl&&r
000
MC/DC0%0/3
defined $feature and ref $feature and $feature->isa("Bio::SeqFeatureI")
defined $feature ref $feature $feature->isa("Bio::SeqFeatureI")
Truth table0%0/4
A and B and C
A= defined $featureB= ref $featureC= $feature->isa("Bio::SeqFeatureI")
ABCresult
0XX0
10X0
1100
1111
104 0 $self->throw("Must have a parent feature, not a [$feature]");
105 }
106  
107 0 ▶ if( $feature->isa("Bio::SeqFeature::PositionProxy") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feature->isa("Bio::SeqFeature::PositionProxy")) 0 0 0
108 0 $feature = $feature->parent();
109 }
110  
111 0 ▶ if( !defined $location || !ref $location || !$location->isa('Bio::LocationI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $location and ref $location and $location->isa("Bio::LocationI")) 0 0 0
Condition0%0/6
defined $location and ref $location and $location->isa("Bio::LocationI")
!ll&&!rl&&r
000
defined $location and ref $location
!ll&&!rl&&r
000
MC/DC0%0/3
defined $location and ref $location and $location->isa("Bio::LocationI")
defined $location ref $location $location->isa("Bio::LocationI")
Truth table0%0/4
A and B and C
A= defined $locationB= ref $locationC= $location->isa("Bio::LocationI")
ABCresult
0XX0
10X0
1100
1111
112 0 $self->throw("Must have a location, not a [$location]");
113 }
114  
115  
116 0 return $self;
117 }
118  
119  
120 =head2 location
121  
122 Title : location
123 Usage : my $location = $seqfeature->location()
124 Function: returns a location object suitable for identifying location
125 of feature on sequence or parent feature
126 Returns : Bio::LocationI object
127 Args : none
128  
129 =cut
130  
131 0 ▶sub location {
Subroutine location: not called CC=5 SCAR=34.0
Pod documented
132 0 my($self, $value ) = @_;
133  
134 0 ▶ if (defined($value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $value) { } 0 0 0
elsif (not $self->{'_location'}) { } 0 0 0
135 0 ▶ unless (ref($value) and $value->isa('Bio::LocationI')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value and $value->isa("Bio::LocationI")) 0 0 0
Condition0%0/3
ref $value and $value->isa("Bio::LocationI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and $value->isa("Bio::LocationI")
ref $value $value->isa("Bio::LocationI")
Truth table0%0/3
A and B
A= ref $valueB= $value->isa("Bio::LocationI")
ABresult
0X0
100
111
136 0 $self->throw("object $value pretends to be a location but ".
137 "does not implement Bio::LocationI");
138 }
139 0 $self->{'_location'} = $value;
140 }
141 elsif (! $self->{'_location'}) {
142 # guarantees a real location object is returned every time
143 0 $self->{'_location'} = Bio::Location::Simple->new();
144 }
145 0 return $self->{'_location'};
146 }
147  
148  
149 =head2 parent
150  
151 Title : parent
152 Usage : my $sf = $proxy->parent()
153 Function: returns the seqfeature parent of this proxy
154 Returns : Bio::SeqFeatureI object
155 Args : none
156  
157 =cut
158  
159 0 ▶sub parent {
Subroutine parent: not called CC=4 SCAR=30.0
Pod documented
160 0 my($self, $value ) = @_;
161  
162 0 ▶ if (defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
163 0 ▶ unless (ref($value) and $value->isa('Bio::SeqFeatureI')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value and $value->isa("Bio::SeqFeatureI")) 0 0 0
Condition0%0/3
ref $value and $value->isa("Bio::SeqFeatureI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and $value->isa("Bio::SeqFeatureI")
ref $value $value->isa("Bio::SeqFeatureI")
Truth table0%0/3
A and B
A= ref $valueB= $value->isa("Bio::SeqFeatureI")
ABresult
0X0
100
111
164 0 $self->throw("object $value pretends to be a location but ".
165 "does not implement Bio::SeqFeatureI");
166 }
167 0 $self->{'_parent'} = $value;
168 }
169  
170 0 return $self->{'_parent'};
171 }
172  
173  
174  
175 =head2 start
176  
177 Title : start
178 Usage : $start = $feat->start
179 $feat->start(20)
180 Function: Get
181 Returns : integer
182 Args : none
183  
184 =cut
185  
186 0 ▶sub start {
Subroutine start: not called CC=1 SCAR=6.9
Pod documented
187 0 my ($self,$value) = @_;
188 0 return $self->location->start($value);
189 }
190  
191  
192 =head2 end
193  
194 Title : end
195 Usage : $end = $feat->end
196 $feat->end($end)
197 Function: get
198 Returns : integer
199 Args : none
200  
201 =cut
202  
203 0 ▶sub end {
Subroutine end: not called CC=1 SCAR=6.9
Pod documented
204 0 my ($self,$value) = @_;
205 0 return $self->location->end($value);
206 }
207  
208  
209 =head2 length
210  
211 Title : length
212 Usage :
213 Function:
214 Example :
215 Returns :
216 Args :
217  
218 =cut
219  
220 0 ▶sub length {
Subroutine length: not called CC=1 SCAR=6.9
Pod documented
221 0 my ($self) = @_;
222 0 return $self->end - $self->start() + 1;
223 }
224  
225  
226 =head2 strand
227  
228 Title : strand
229 Usage : $strand = $feat->strand()
230 $feat->strand($strand)
231 Function: get/set on strand information, being 1,-1 or 0
232 Returns : -1,1 or 0
233 Args : none
234  
235 =cut
236  
237 0 ▶sub strand {
Subroutine strand: not called CC=1 SCAR=6.9
Pod documented
238 0 my ($self,$value) = @_;
239 0 return $self->location->strand($value);
240 }
241  
242  
243 =head2 attach_seq
244  
245 Title : attach_seq
246 Usage : $sf->attach_seq($seq)
247 Function: Attaches a Bio::Seq object to this feature. This
248 Bio::Seq object is for the *entire* sequence: ie
249 from 1 to 10000
250 Example :
251 Returns : TRUE on success
252 Args :
253  
254 =cut
255  
256 0 ▶sub attach_seq {
Subroutine attach_seq: not called CC=6 SCAR=37.4
Pod documented
257 0 my ($self, $seq) = @_;
258  
259 0 ▶ if ( !defined $seq || !ref $seq || ! $seq->isa("Bio::PrimarySeqI") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $seq and ref $seq and $seq->isa("Bio::PrimarySeqI")) 0 0 0
Condition0%0/6
defined $seq and ref $seq and $seq->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
000
defined $seq and ref $seq
!ll&&!rl&&r
000
MC/DC0%0/3
defined $seq and ref $seq and $seq->isa("Bio::PrimarySeqI")
defined $seq ref $seq $seq->isa("Bio::PrimarySeqI")
Truth table0%0/4
A and B and C
A= defined $seqB= ref $seqC= $seq->isa("Bio::PrimarySeqI")
ABCresult
0XX0
10X0
1100
1111
260 0 $self->throw("Must attach Bio::PrimarySeqI objects to SeqFeatures");
261 }
262  
263 0 $self->{'_gsf_seq'} = $seq;
264  
265 # attach to sub features if they want it
266  
267 0 foreach my $sf ( $self->sub_SeqFeature() ) {
268 0 ▶ if ( $sf->can("attach_seq") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf->can("attach_seq")) 0 0 0
269 0 $sf->attach_seq($seq);
270 }
271 }
272 0 return 1;
273 }
274  
275  
276 =head2 seq
277  
278 Title : seq
279 Usage : $tseq = $sf->seq()
280 Function: returns the truncated sequence (if there) for this
281 Example :
282 Returns : sub seq on attached sequence bounded by start & end
283 Args : none
284  
285 =cut
286  
287 0 ▶sub seq {
Subroutine seq: not called CC=4 SCAR=30.0
Pod documented
288 0 my ($self, $arg) = @_;
289  
290 0 ▶ if ( defined $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) 0 0 0
291 0 $self->throw("Calling SeqFeature::PositionProxy->seq with an argument. You probably want attach_seq");
292 }
293  
294 0 ▶ if ( ! exists $self->{'_gsf_seq'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_gsf_seq"}) 0 0 0
295 0 return;
296 }
297  
298 # assumming our seq object is sensible, it should not have to yank
299 # the entire sequence out here.
300  
301 0 my $seq = $self->{'_gsf_seq'}->trunc($self->start(), $self->end());
302  
303  
304 0 ▶ if ( $self->strand == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->strand == -1) 0 0 0
305 0 $seq = $seq->revcom;
306 }
307  
308 0 return $seq;
309 }
310  
311  
312 =head2 entire_seq
313  
314 Title : entire_seq
315 Usage : $whole_seq = $sf->entire_seq()
316 Function: gives the entire sequence that this seqfeature is attached to
317 Example :
318 Returns :
319 Args :
320  
321 =cut
322  
323 0 ▶sub entire_seq {
Subroutine entire_seq: not called CC=2 SCAR=17.9
Pod documented
324 0 my ($self) = @_;
325  
326 0 ▶ return unless exists($self->{'_gsf_seq'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_gsf_seq"} 0 0 0
327 0 return $self->{'_gsf_seq'};
328 }
329  
330  
331 =head2 seqname
332  
333 Title : seqname
334 Usage : $obj->seq_id($newval)
335 Function: There are many cases when you make a feature that you
336 do know the sequence name, but do not know its actual
337 sequence. This is an attribute such that you can store
338 the seqname.
339  
340 This attribute should *not* be used in GFF dumping, as
341 that should come from the collection in which the seq
342 feature was found.
343 Returns : value of seqname
344 Args : newvalue (optional)
345  
346 =cut
347  
348 0 ▶sub seqname {
Subroutine seqname: not called CC=2 SCAR=17.9
Pod documented
349 0 my ($obj,$value) = @_;
350 0 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
351 0 $obj->{'_gsf_seqname'} = $value;
352 }
353 0 return $obj->{'_gsf_seqname'};
354 }
355  
356  
357 =head2 Proxies
358  
359 These functions chain back to the parent for all non sequence related stuff.
360  
361 =cut
362  
363 =head2 primary_tag
364  
365 Title : primary_tag
366 Usage : $tag = $feat->primary_tag()
367 Function: Returns the primary tag for a feature,
368 eg 'exon'
369 Returns : a string
370 Args : none
371  
372 =cut
373  
374 0 ▶sub primary_tag {
Subroutine primary_tag: not called CC=1 SCAR=6.9
Pod documented
375 0 my ($self,@args) = @_;
376  
377 0 return $self->parent->primary_tag();
378 }
379  
380  
381 =head2 source_tag
382  
383 Title : source_tag
384 Usage : $tag = $feat->source_tag()
385 Function: Returns the source tag for a feature,
386 eg, 'genscan'
387 Returns : a string
388 Args : none
389  
390 =cut
391  
392 0 ▶sub source_tag {
Subroutine source_tag: not called CC=1 SCAR=6.9
Pod documented
393 0 my ($self) = @_;
394  
395 0 return $self->parent->source_tag();
396 }
397  
398  
399 =head2 has_tag
400  
401 Title : has_tag
402 Usage : $tag_exists = $self->has_tag('some_tag')
403 Function:
404 Returns : TRUE if the specified tag exists, and FALSE otherwise
405 Args :
406  
407 =cut
408  
409 0 ▶sub has_tag {
Subroutine has_tag: not called CC=1 SCAR=6.9
Pod documented
410 0 my ($self,$tag) = @_;
411  
412 0 return $self->parent->has_tag($tag);
413 }
414  
415  
416 =head2 get_tag_values
417  
418 Title : get_tag_values
419 Usage : @values = $self->get_tag_values('some_tag')
420 Function:
421 Returns : An array comprising the values of the specified tag.
422 Args :
423  
424 =cut
425  
426 1 *each_tag_value = \&get_tag_values;
427  
428 0 ▶sub get_tag_values {
Subroutine get_tag_values: not called CC=1 SCAR=6.9
Pod documented
429 0 my ($self,$tag) = @_;
430  
431 0 return $self->parent->get_tag_values($tag);
432 }
433  
434  
435 =head2 get_all_tags
436  
437 Title : get_all_tags
438 Usage : @tags = $feat->get_all_tags()
439 Function: gives all tags for this feature
440 Returns : an array of strings
441 Args : none
442  
443 =cut
444  
445 1 *all_tags = \&get_all_tags;
446  
447 0 ▶sub get_all_tags {
Subroutine get_all_tags: not called CC=1 SCAR=6.9
Pod documented
448 0 my ($self) = @_;
449  
450 0 return $self->parent->all_tags();
451 }
452  
453 1 1;
« Bio/Search/Hit/PullHitI.pm ↑ Summary Bio/Root/Test.pm »