Bio/SeqFeatureI.pm

filter: Statementstmt 63.7% 123 / 193 Branchbran 53.0% 53 / 100 Conditioncond 48.7% 20 / 41 MC/DCmcdc 18.1% 4 / 22 Subroutinesub 40.0% 10 / 25 Podpod 94.4% 17 / 18 totaltotal 56.8% 227 / 399 CC 67 SCAR 48.4
CC
67
Cov
59%
spliced_seq
214.9
primary_id
12.0
phase
10.1
CRAP 127.1
« Bio/DB/GenericWebAgent.pm ↑ Summary Bio/Root/RootI.pm »
1 #
2 # BioPerl module for Bio::SeqFeatureI
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::SeqFeatureI - Abstract interface of a Sequence Feature
17  
18 =head1 SYNOPSIS
19  
20 # get a seqfeature somehow, eg, from a Sequence with Features attached
21  
22 foreach $feat ( $seq->get_SeqFeatures() ) {
23 print "Feature from ", $feat->start, "to ",
24 $feat->end, " Primary tag ", $feat->primary_tag,
25 ", produced by ", $feat->source_tag(), "\n";
26  
27 if ( $feat->strand == 0 ) {
28 print "Feature applicable to either strand\n";
29 }
30 else {
31 print "Feature on strand ", $feat->strand,"\n"; # -1,1
32 }
33  
34 print "feature location is ",$feat->start, "..",
35 $feat->end, " on strand ", $feat->strand, "\n";
36 print "easy utility to print locations in GenBank/EMBL way ",
37 $feat->location->to_FTstring(), "\n";
38  
39 foreach $tag ( $feat->get_all_tags() ) {
40 print "Feature has tag ", $tag, " with values, ",
41 join(' ',$feat->get_tag_values($tag)), "\n";
42 }
43 print "new feature\n" if $feat->has_tag('new');
44 # features can have sub features
45 my @subfeat = $feat->get_SeqFeatures();
46 }
47  
48 =head1 DESCRIPTION
49  
50 This interface is the functions one can expect for any Sequence
51 Feature, whatever its implementation or whether it is a more complex
52 type (eg, a Gene). This object does not actually provide any
53 implementation, it just provides the definitions of what methods one can
54 call. See Bio::SeqFeature::Generic for a good standard implementation
55 of this object
56  
57 =head1 FEEDBACK
58  
59 User feedback is an integral part of the evolution of this and other
60 Bioperl modules. Send your comments and suggestions preferably to one
61 of the Bioperl mailing lists. Your participation is much appreciated.
62  
63 bioperl-l@bioperl.org - General discussion
64 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
65  
66 =head2 Support
67  
68 Please direct usage questions or support issues to the mailing list:
69  
70 I<bioperl-l@bioperl.org>
71  
72 rather than to the module maintainer directly. Many experienced and
73 reponsive experts will be able look at the problem and quickly
74 address it. Please include a thorough description of the problem
75 with code and data examples if at all possible.
76  
77 =head2 Reporting Bugs
78  
79 Report bugs to the Bioperl bug tracking system to help us keep track
80 the bugs and their resolution. Bug reports can be submitted via the
81 web:
82  
83 https://github.com/bioperl/bioperl-live/issues
84  
85 =head1 APPENDIX
86  
87 The rest of the documentation details each of the object
88 methods. Internal methods are usually preceded with a _
89  
90 =cut
91  
92  
93 # Let the code begin...
94  
95  
96 package Bio::SeqFeatureI;
97 245 $Bio::SeqFeatureI::VERSION = '1.7.8';
98 245 ▶use vars qw($HasInMemory);
Subroutine BEGIN: called CC=1 SCAR=0.0
99 245 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 245 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.4
101 245 eval { require Bio::DB::InMemoryCache };
102 0 ▶ if( $@ ) { $HasInMemory = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 245 245
103 245 else { $HasInMemory = 1 }
104 }
105  
106 245 ▶use Bio::Seq;
Subroutine BEGIN: called CC=1 SCAR=0.0
107  
108 245 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 245 ▶use base qw(Bio::RangeI);
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 =head1 Bio::SeqFeatureI specific methods
113  
114 New method interfaces.
115  
116 =cut
117  
118 =head2 get_SeqFeatures
119  
120 Title : get_SeqFeatures
121 Usage : @feats = $feat->get_SeqFeatures();
122 Function: Returns an array of sub Sequence Features
123 Returns : An array
124 Args : none
125  
126 =cut
127  
128 0 ▶sub get_SeqFeatures{
Subroutine get_SeqFeatures: not called CC=1 SCAR=6.9
Pod documented
129 0 my ($self,@args) = @_;
130  
131 0 $self->throw_not_implemented();
132 }
133  
134 =head2 display_name
135  
136 Title : display_name
137 Usage : $name = $feat->display_name()
138 Function: Returns the human-readable name of the feature for displays.
139 Returns : a string
140 Args : none
141  
142 =cut
143  
144 0 ▶sub display_name {
Subroutine display_name: not called CC=1 SCAR=6.9
Pod documented
145 0 shift->throw_not_implemented();
146 }
147  
148 =head2 primary_tag
149  
150 Title : primary_tag
151 Usage : $tag = $feat->primary_tag()
152 Function: Returns the primary tag for a feature,
153 eg 'exon'
154 Returns : a string
155 Args : none
156  
157  
158 =cut
159  
160 0 ▶sub primary_tag{
Subroutine primary_tag: not called CC=1 SCAR=6.9
Pod documented
161 0 my ($self,@args) = @_;
162  
163 0 $self->throw_not_implemented();
164  
165 }
166  
167 =head2 source_tag
168  
169 Title : source_tag
170 Usage : $tag = $feat->source_tag()
171 Function: Returns the source tag for a feature,
172 eg, 'genscan'
173 Returns : a string
174 Args : none
175  
176  
177 =cut
178  
179 0 ▶sub source_tag{
Subroutine source_tag: not called CC=1 SCAR=6.9
Pod documented
180 0 my ($self,@args) = @_;
181  
182 0 $self->throw_not_implemented();
183 }
184  
185 =head2 has_tag
186  
187 Title : has_tag
188 Usage : $tag_exists = $self->has_tag('some_tag')
189 Function:
190 Returns : TRUE if the specified tag exists, and FALSE otherwise
191 Args :
192  
193 =cut
194  
195 0 ▶sub has_tag{
Subroutine has_tag: not called CC=1 SCAR=6.9
Pod documented
196 0 my ($self,@args) = @_;
197  
198 0 $self->throw_not_implemented();
199  
200 }
201  
202 =head2 get_tag_values
203  
204 Title : get_tag_values
205 Usage : @values = $self->get_tag_values('some_tag')
206 Function:
207 Returns : An array comprising the values of the specified tag.
208 Args : a string
209  
210 throws an exception if there is no such tag
211  
212 =cut
213  
214 0 ▶sub get_tag_values {
Subroutine get_tag_values: not called CC=1 SCAR=6.9
Pod documented
215 0 shift->throw_not_implemented();
216 }
217  
218 =head2 get_tagset_values
219  
220 Title : get_tagset_values
221 Usage : @values = $self->get_tagset_values(qw(label transcript_id product))
222 Function:
223 Returns : An array comprising the values of the specified tags, in order of tags
224 Args : An array of strings
225  
226 does NOT throw an exception if none of the tags are not present
227  
228 this method is useful for getting a human-readable label for a
229 SeqFeatureI; not all tags can be assumed to be present, so a list of
230 possible tags in preferential order is provided
231  
232 =cut
233  
234 # interface + abstract method
235 4 ▶sub get_tagset_values {
Subroutine get_tagset_values: called CC=3 SCAR=11.0
Pod documented
236 4 my ($self, @args) = @_;
237 4 my @vals = ();
238 4 foreach my $arg (@args) {
239 5 ▶ if ($self->has_tag($arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_tag($arg)) 5 0 5
240 5 push(@vals, $self->get_tag_values($arg));
241 }
242 }
243 4 return @vals;
244 }
245  
246 =head2 get_all_tags
247  
248 Title : get_all_tags
249 Usage : @tags = $feat->get_all_tags()
250 Function: gives all tags for this feature
251 Returns : an array of strings
252 Args : none
253  
254  
255 =cut
256  
257 0 ▶sub get_all_tags{
Subroutine get_all_tags: not called CC=1 SCAR=6.9
Pod documented
258 0 shift->throw_not_implemented();
259 }
260  
261 =head2 attach_seq
262  
263 Title : attach_seq
264 Usage : $sf->attach_seq($seq)
265 Function: Attaches a Bio::Seq object to this feature. This
266 Bio::Seq object is for the *entire* sequence: ie
267 from 1 to 10000
268  
269 Note that it is not guaranteed that if you obtain a feature from
270 an object in bioperl, it will have a sequence attached. Also,
271 implementors of this interface can choose to provide an empty
272 implementation of this method. I.e., there is also no guarantee
273 that if you do attach a sequence, seq() or entire_seq() will not
274 return undef.
275  
276 The reason that this method is here on the interface is to enable
277 you to call it on every SeqFeatureI compliant object, and
278 that it will be implemented in a useful way and set to a useful
279 value for the great majority of use cases. Implementors who choose
280 to ignore the call are encouraged to specifically state this in
281 their documentation.
282  
283 Example :
284 Returns : TRUE on success
285 Args : a Bio::PrimarySeqI compliant object
286  
287  
288 =cut
289  
290 0 ▶sub attach_seq {
Subroutine attach_seq: not called CC=1 SCAR=6.9
Pod documented
291 0 shift->throw_not_implemented();
292 }
293  
294 =head2 seq
295  
296 Title : seq
297 Usage : $tseq = $sf->seq()
298 Function: returns the truncated sequence (if there is a sequence attached)
299 for this feature
300 Example :
301 Returns : sub seq (a Bio::PrimarySeqI compliant object) on attached sequence
302 bounded by start & end, or undef if there is no sequence attached.
303 If the strand is defined and set to -1, the returned sequence is
304 the reverse-complement of the region
305 Args : none
306  
307  
308 =cut
309  
310 0 ▶sub seq {
Subroutine seq: not called CC=1 SCAR=6.9
Pod documented
311 0 shift->throw_not_implemented();
312 }
313  
314 =head2 entire_seq
315  
316 Title : entire_seq
317 Usage : $whole_seq = $sf->entire_seq()
318 Function: gives the entire sequence that this seqfeature is attached to
319 Example :
320 Returns : a Bio::PrimarySeqI compliant object, or undef if there is no
321 sequence attached
322 Args : none
323  
324  
325 =cut
326  
327 0 ▶sub entire_seq {
Subroutine entire_seq: not called CC=1 SCAR=6.9
Pod documented
328 0 shift->throw_not_implemented();
329 }
330  
331  
332 =head2 seq_id
333  
334 Title : seq_id
335 Usage : $obj->seq_id($newval)
336 Function: There are many cases when you make a feature that you
337 do know the sequence name, but do not know its actual
338 sequence. This is an attribute such that you can store
339 the ID (e.g., display_id) of the sequence.
340  
341 This attribute should *not* be used in GFF dumping, as
342 that should come from the collection in which the seq
343 feature was found.
344 Returns : value of seq_id
345 Args : newvalue (optional)
346  
347  
348 =cut
349  
350 0 ▶sub seq_id {
Subroutine seq_id: not called CC=1 SCAR=6.9
Pod documented
351 0 shift->throw_not_implemented();
352 }
353  
354 =head2 gff_string
355  
356 Title : gff_string
357 Usage : $str = $feat->gff_string;
358 $str = $feat->gff_string($gff_formatter);
359 Function: Provides the feature information in GFF format.
360  
361 The implementation provided here returns GFF2 by default. If you
362 want a different version, supply an object implementing a method
363 gff_string() accepting a SeqFeatureI object as argument. E.g., to
364 obtain GFF1 format, do the following:
365  
366 my $gffio = Bio::Tools::GFF->new(-gff_version => 1);
367 $gff1str = $feat->gff_string($gff1io);
368  
369 Returns : A string
370 Args : Optionally, an object implementing gff_string().
371  
372  
373 =cut
374  
375 0 ▶sub gff_string{
Subroutine gff_string: not called CC=2 SCAR=17.9
Pod documented
376 0 my ($self,$formatter) = @_;
377  
378 0 ▶ $formatter = $self->_static_gff_formatter unless $formatter;
Branch: 1 branch
BranchTrueFalseTotal
unless $formatter 0 0 0
379 0 return $formatter->gff_string($self);
380 }
381  
382 245 my $static_gff_formatter = undef;
383  
384 =head2 _static_gff_formatter
385  
386 Title : _static_gff_formatter
387 Usage :
388 Function:
389 Example :
390 Returns :
391 Args :
392  
393  
394 =cut
395  
396 1 ▶sub _static_gff_formatter{
Subroutine _static_gff_formatter: called CC=2 SCAR=7.0
397 1 my ($self,@args) = @_;
398 1 require Bio::Tools::GFF; # on the fly inclusion -- is this better?
399 1 ▶ if( !defined $static_gff_formatter ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $static_gff_formatter) 1 0 1
400 1 $static_gff_formatter = Bio::Tools::GFF->new('-gff_version' => 2);
401 }
402 1 return $static_gff_formatter;
403 }
404  
405  
406 =head1 Decorating methods
407  
408 These methods have an implementation provided by Bio::SeqFeatureI,
409 but can be validly overwritten by subclasses
410  
411 =head2 spliced_seq
412  
413 Title : spliced_seq
414  
415 Usage : $seq = $feature->spliced_seq()
416 $seq = $feature_with_remote_locations->spliced_seq($db_for_seqs)
417  
418 Function: Provides a sequence of the feature which is the most
419 semantically "relevant" feature for this sequence. A default
420 implementation is provided which for simple cases returns just
421 the sequence, but for split cases, loops over the split location
422 to return the sequence. In the case of split locations with
423 remote locations, eg
424  
425 join(AB000123:5567-5589,80..1144)
426  
427 in the case when a database object is passed in, it will attempt
428 to retrieve the sequence from the database object, and "Do the right thing",
429 however if no database object is provided, it will generate the correct
430 number of N's (DNA) or X's (protein, though this is unlikely).
431  
432 This function is deliberately "magical" attempting to second guess
433 what a user wants as "the" sequence for this feature.
434  
435 Implementing classes are free to override this method with their
436 own magic if they have a better idea what the user wants.
437  
438 Args : [optional]
439 -db A L<Bio::DB::RandomAccessI> compliant object if
440 one needs to retrieve remote seqs.
441 -nosort boolean if the locations should not be sorted
442 by start location. This may occur, for instance,
443 in a circular sequence where a gene span starts
444 before the end of the sequence and ends after the
445 sequence start. Example : join(15685..16260,1..207)
446 (default = if sequence is_circular(), 1, otherwise 0)
447 -phase truncates the returned sequence based on the
448 intron phase (0,1,2).
449  
450 Returns : A L<Bio::PrimarySeqI> object
451  
452 =cut
453  
454 132 ▶sub spliced_seq {
Subroutine spliced_seq: called CC=53 SCAR=53.7
Pod documented
455 132 my $self = shift;
456 132 my @args = @_;
457 132 my ($db, $nosort, $phase) =
458 $self->_rearrange([qw(DB NOSORT PHASE)], @args);
459  
460 # set no_sort based on the parent sequence status
461 132 ▶ if ($self->entire_seq->is_circular) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->entire_seq->is_circular) 118 14 132
462 118 $nosort = 1;
463 }
464  
465 # (added 7/7/06 to allow use old API (with warnings)
466 132 ▶ my $old_api = (!(grep {$_ =~ /(?:nosort|db|phase)/} @args)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!grep({$_ =~ /(?:nosort|db|phase)/;} @args) ? : 1 131 132
467 132 ▶ if (@args && $old_api) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args and $old_api) 0 132 132
Condition66%2/3
@args and $old_api
!ll&&!rl&&r
11310
MC/DC0%0/2
@args and $old_api
@args $old_api
Truth table66%2/3
A and B
A= @argsB= $old_api
ABresult
0X0
100
111
468 0 $self->warn( q(API has changed; please use '-db' or '-nosort' )
469 . qq(for args. See POD for more details.));
470 0 ▶ $db = shift @args if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
471 0 ▶ $nosort = shift @args if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
472 0 ▶ $phase = shift @args if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
473 };
474  
475 132 ▶ if (defined($phase) && ($phase < 0 || $phase > 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $phase and $phase < 0 || $phase > 2) 2 130 132
Condition100%6/6
defined $phase and $phase < 0 || $phase > 2
!ll&&!rl&&r
12732
$phase < 0 or $phase > 2
l!l&&r!l&&!r
113
MC/DC100%3/3
defined $phase and $phase < 0 || $phase > 2
defined $phase $phase < 0 $phase > 2
Truth table100%4/4
A and B or C
A= defined $phaseB= $phase < 0C= $phase > 2
ABCresult
0XX0
1000
11X1
1011
476 2 $self->warn("Phase must be 0,1, or 2. Setting phase to 0...");
477 2 $phase = 0;
478 }
479  
480 132 ▶ if ( $db && ref($db) && ! $db->isa('Bio::DB::RandomAccessI') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($db and ref $db and not $db->isa('Bio::DB::RandomAccessI')) { } 0 132 132
elsif (defined $db and $Bio::SeqFeatureI::HasInMemory and $db->isa('Bio::DB::InMemoryCache')) { } 0 264 264
Condition33%2/6
$db and ref $db and not $db->isa("Bio::DB::RandomAccessI")
!ll&&!rl&&r
13200
$db and ref $db
!ll&&!rl&&r
13200
MC/DC0%0/3
$db and ref $db and not $db->isa("Bio::DB::RandomAccessI")
$db ref $db not $db->isa("Bio::DB::RandomAccessI")
Truth table25%1/4
A and B and not(C)
A= $dbB= ref $dbC= not $db->isa("Bio::DB::RandomAccessI")
ABCresult
0XX0
10X0
1100
1111
481 0 $self->warn( "Must pass in a valid Bio::DB::RandomAccessI object"
482 . " for access to remote locations for spliced_seq");
483 0 $db = undef;
484 }
485 ▶ elsif ( defined $db && $HasInMemory && $db->isa('Bio::DB::InMemoryCache') ) {
Condition33%2/6
defined $db and $Bio::SeqFeatureI::HasInMemory and $db->isa("Bio::DB::InMemoryCache")
!ll&&!rl&&r
13200
defined $db and $Bio::SeqFeatureI::HasInMemory
!ll&&!rl&&r
13200
MC/DC0%0/3
defined $db and $Bio::SeqFeatureI::HasInMemory and $db->isa("Bio::DB::InMemoryCache")
defined $db $Bio::SeqFeatureI::HasInMemory $db->isa("Bio::DB::InMemoryCache")
Truth table25%1/4
A and B and C
A= defined $dbB= $Bio::SeqFeatureI::HasInMemoryC= $db->isa("Bio::DB::InMemoryCache")
ABCresult
0XX0
10X0
1100
1111
486 0 $db = Bio::DB::InMemoryCache->new(-seqdb => $db);
487 }
488  
489 132 ▶ if ( not $self->location->isa("Bio::Location::SplitLocationI") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->location->isa("Bio::Location::SplitLocationI")) 113 19 132
490 113 ▶ if ($phase) {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase) { } 2 111 113
491 2 $self->debug("Subseq start: ",$phase+1,"\tend: ",$self->end,"\n");
492 2 my $seqstr = substr($self->seq->seq, $phase);
493 2 my $out = Bio::Seq->new( -id => $self->entire_seq->display_id
494 . "_spliced_feat",
495 -seq => $seqstr);
496 2 return $out;
497 }
498 else {
499 111 return $self->seq(); # nice and easy!
500 }
501 }
502  
503 # redundant test, but the above ISA is probably not ideal.
504 19 ▶ if ( not $self->location->isa("Bio::Location::SplitLocationI") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->location->isa("Bio::Location::SplitLocationI")) 0 19 19
505 0 $self->throw("not atomic, not split, yikes, in trouble!");
506 }
507  
508 19 my $seqstr = '';
509 19 my $seqid = $self->entire_seq->display_id;
510 # This is to deal with reverse strand features
511 # so we are really sorting features 5' -> 3' on their strand
512 # i.e. rev strand features will be sorted largest to smallest
513 # as this how revcom CDSes seem to be annotated in genbank.
514 # Might need to eventually allow this to be programable?
515 # (can I mention how much fun this is NOT! --jason)
516  
517 19 my ($mixed,$mixedloc, $fstrand) = (0);
518  
519 19 ▶ if ( $self->isa('Bio::Das::SegmentI') and not $self->absolute ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa("Bio::Das::SegmentI") and not $self->absolute) 0 19 19
Condition33%1/3
$self->isa("Bio::Das::SegmentI") and not $self->absolute
!ll&&!rl&&r
1900
MC/DC0%0/2
$self->isa("Bio::Das::SegmentI") and not $self->absolute
$self->isa("Bio::Das::SegmentI") not $self->absolute
Truth table33%1/3
A and not(B)
A= $self->isa("Bio::Das::SegmentI")B= not $self->absolute
ABresult
0X0
100
111
520 0 $self->warn( "Calling spliced_seq with a Bio::Das::SegmentI which "
521 . "does have absolute set to 1 -- be warned you may not "
522 . "be getting things on the correct strand");
523 }
524  
525 19 my @locset = $self->location->each_Location;
526 19 my @locs;
527 19 ▶ if ( not $nosort ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $nosort) { } 1 18 19
528 # @locs = map { $_->[0] }
529 # sort so that most negative is first basically to order
530 # the features on the opposite strand 5'->3' on their strand
531 # rather than they way most are input which is on the fwd strand
532  
533 # sort { $a->[1] <=> $b->[1] } # Yes Tim, Schwartzian transformation
534 my @proc_locs =
535 map {
536 1 ▶ $fstrand = $_->strand unless defined $fstrand;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fstrand 1 2 3
537 3 ▶ $mixed = 1 if defined $_->strand && $fstrand != $_->strand;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_->strand and $fstrand != $_->strand 0 3 3
Condition33%1/3
defined $_->strand and $fstrand != $_->strand
!ll&&!rl&&r
030
MC/DC0%0/2
defined $_->strand and $fstrand != $_->strand
defined $_->strand $fstrand != $_->strand
Truth table33%1/3
A and B
A= defined $_->strandB= $fstrand != $_->strand
ABresult
0X0
100
111
538  
539 3 ▶ if( defined $_->seq_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_->seq_id) 3 0 3
540 3 ▶ $mixedloc = 1 if( $_->seq_id ne $seqid );
Branch: 1 branch
BranchTrueFalseTotal
if $_->seq_id ne $seqid 2 1 3
541 }
542 3 ▶ [ $_, $_->start * ($_->strand || 1) ];
Condition50%1/2
$_->strand || 1
l!l
30
MC/DC0%0/1
$_->strand || 1
$_->strand
Truth table50%1/2
A
A= $_->strand
Aresult
11
00
543 } @locset;
544  
545 1 my @sort_locs;
546 1 ▶ if ( $fstrand == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fstrand == 1) { } 1 0 1
elsif ($fstrand == -1) { } 0 0 0
547 1 @sort_locs = sort { $a->[1] <=> $b->[1] } @proc_locs; # Yes Tim, Schwartzian transformation
548 }elsif ( $fstrand == -1 ){
549 0 @sort_locs = sort { $b->[1] <=> $a->[1] } @proc_locs; # Yes Tim, Schwartzian transformation
550 } else {
551 0 @sort_locs = @proc_locs;
552 }
553 1 @locs = map { $_->[0] } @sort_locs;
554  
555 1 ▶ if ( $mixed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mixed) 0 1 1
556 0 $self->warn( "Mixed strand locations, spliced seq using the "
557 . "input order rather than trying to sort");
558 0 @locs = @locset;
559 }
560 }
561 else {
562 # use the original order instead of trying to sort
563 18 @locs = @locset;
564 18 $fstrand = $locs[0]->strand;
565 }
566  
567  
568 19 my $last_id = undef;
569 19 my $called_seq = undef;
570 # This will be left as undefined if 1) db is remote or 2)seq_id is undefined.
571 # In that case, old code is used to make exon sequence
572 19 my $called_seq_seq = undef;
573 19 my $called_seq_len = undef;
574  
575 19 foreach my $loc ( @locs ) {
576 97 ▶ if ( not $loc->isa("Bio::Location::Atomic") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($loc->isa("Bio::Location::Atomic")) 0 97 97
577 0 $self->throw("Can only deal with one level deep locations");
578 }
579  
580 97 ▶ if ( $fstrand != $loc->strand ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fstrand != $loc->strand) 0 97 97
581 0 $self->warn("feature strand is different from location strand!");
582 }
583  
584 97 my $loc_seq_id;
585 97 ▶ if ( defined $loc->seq_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $loc->seq_id) { } 97 0 97
586 97 $loc_seq_id = $loc->seq_id;
587  
588 # deal with remote sequences
589 97 ▶ if ($loc_seq_id ne $seqid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loc_seq_id ne $seqid) { } 2 95 97
590 # might be too big to download whole sequence
591 2 $called_seq_seq = undef;
592  
593 2 ▶ if ( defined $db ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $db) { } 0 2 2
594 0 my $sid = $loc_seq_id;
595 0 $sid =~ s/\.\d+$//g;
596 0 eval {
597 0 $called_seq = $db->get_Seq_by_acc($sid);
598 };
599 0 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
600 0 $self->warn( "In attempting to join a remote location, sequence $sid "
601 . "was not in database. Will provide padding N's. Full exception \n\n$@");
602 0 $called_seq = undef;
603 }
604 }
605 else {
606 2 $self->warn( "cannot get remote location for ".$loc_seq_id ." without a valid "
607 . "Bio::DB::RandomAccessI database handle (like Bio::DB::GenBank)");
608 2 $called_seq = undef;
609 }
610 2 ▶ if ( !defined $called_seq ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $called_seq) 2 0 2
611 2 $seqstr .= 'N' x $loc->length;
612 2 next;
613 }
614 }
615 # have local sequence available
616 else {
617 # don't have to pull out source sequence again if it's local unless
618 # it's the first exon or different from previous exon
619 95 ▶ unless (defined(($last_id) && $last_id eq $loc_seq_id )){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($last_id && $last_id eq $loc_seq_id)) 19 76 95
Condition66%2/3
$last_id && $last_id eq $loc_seq_id
!ll&&!rl&&r
19076
MC/DC50%1/2
$last_id && $last_id eq $loc_seq_id
$last_id $last_id eq $loc_seq_id
Truth table66%2/3
A && B
A= $last_idB= $last_id eq $loc_seq_id
ABresult
0X0
100
111
620 19 $called_seq = $self->entire_seq;
621 19 $called_seq_seq = $called_seq->seq(); # this is slow
622 }
623 }
624 }
625 #undefined $loc->seq->id
626 else {
627 0 $called_seq = $self->entire_seq;
628 0 $called_seq_seq = undef;
629 }
630  
631 95 my ($start,$end) = ($loc->start,$loc->end);
632  
633 # does the called sequence make sense? Bug 1780
634 95 my $called_seq_len;
635  
636 # can avoid a seq() call on called_seq
637 95 ▶ if (defined($called_seq_seq)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $called_seq_seq) { } 95 0 95
638 95 $called_seq_len = length($called_seq_seq);
639 }
640 # can't avoid a seq() call on called_seq
641 else {
642 0 $called_seq_len = $called_seq->length # this is slow
643 }
644  
645 95 ▶ if ($called_seq_len < $loc->end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($called_seq_len < $loc->end) 0 95 95
646 0 my $accession = $called_seq->accession;
647 0 my $orig_id = $self->seq_id; # originating sequence
648 0 my ($locus) = $self->get_tagset_values("locus_tag");
649 0 $self->throw( "Location end ($end) exceeds length ($called_seq_len) of "
650 . "called sequence $accession.\nCheck sequence version used in "
651 . "$locus locus-tagged SeqFeature in $orig_id.");
652 }
653  
654 95 ▶ if ( $self->isa('Bio::Das::SegmentI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa('Bio::Das::SegmentI')) { } 0 95 95
655 # $called_seq is Bio::DB::GFF::RelSegment, as well as its subseq();
656 # Bio::DB::GFF::RelSegment::seq() returns a Bio::PrimarySeq, and using seq()
657 # in turn returns a string. Confused?
658 0 $seqstr .= $called_seq->subseq($start,$end)->seq()->seq(); # this is slow
659 }
660 else {
661 95 my $exon_seq;
662 95 ▶ if (defined ($called_seq_seq)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $called_seq_seq) { } 95 0 95
663 95 $exon_seq = substr($called_seq_seq, $start-1, $end-$start+1); # this is quick
664 }
665 else {
666 0 $exon_seq = $called_seq->subseq($loc->start,$loc->end); # this is slow
667 }
668  
669 # If guide_strand is defined, assemble the sequence first and revcom later if needed,
670 # if its not defined, apply revcom immediately to proper locations
671 95 ▶ if (defined $self->location->guide_strand) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->location->guide_strand) { } 95 0 95
672 95 $seqstr .= $exon_seq;
673 }
674 else {
675 0 ▶ my $strand = defined ($loc->strand) ? ($loc->strand) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $loc->strand ? : 0 0 0
676  
677 # revcomp $exon_seq
678 0 ▶ if ($strand == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand == -1) { } 0 0 0
679 0 $exon_seq = reverse($exon_seq);
680 0 $exon_seq =~ tr/ABCDGHKMNRSTUVWXYabcdghkmnrstuvwxy/TVGHCDMKNYSAABWXRtvghcdmknysaabwxr/;
681 0 $seqstr .= $exon_seq;
682 }
683 else {
684 0 $seqstr .= $exon_seq;
685 }
686 }
687 }
688  
689 95 ▶ $last_id = $loc_seq_id if (defined($loc_seq_id));
Branch: 1 branch
BranchTrueFalseTotal
if defined $loc_seq_id 95 0 95
690 } #next $loc
691  
692 # Use revcom only after the whole sequence has been assembled
693 19 ▶ my $guide_strand = defined ($self->location->guide_strand) ? ($self->location->guide_strand) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->location->guide_strand ? : 19 0 19
694 19 ▶ if ($guide_strand == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guide_strand == -1) 10 9 19
695 10 my $seqstr_obj = Bio::Seq->new(-seq => $seqstr);
696 10 $seqstr = $seqstr_obj->revcom->seq;
697 }
698  
699 19 ▶ if (defined($phase)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $phase) 0 19 19
700 0 $seqstr = substr($seqstr, $phase);
701 }
702  
703 19 my $out = Bio::Seq->new( -id => $self->entire_seq->display_id
704 . "_spliced_feat",
705 -seq => $seqstr);
706  
707 19 return $out;
708 }
709  
710 =head2 location
711  
712 Title : location
713 Usage : my $location = $seqfeature->location()
714 Function: returns a location object suitable for identifying location
715 of feature on sequence or parent feature
716 Returns : Bio::LocationI object
717 Args : none
718  
719  
720 =cut
721  
722 0 ▶sub location {
Subroutine location: not called CC=1 SCAR=6.9
Pod documented
723 0 my ($self) = @_;
724  
725 0 $self->throw_not_implemented();
726 }
727  
728  
729 =head2 primary_id
730  
731 Title : primary_id
732 Usage : $obj->primary_id($newval)
733 Function:
734 Example :
735 Returns : value of primary_id (a scalar)
736 Args : on set, new value (a scalar or undef, optional)
737  
738 Primary ID is a synonym for the tag 'ID'
739  
740 =cut
741  
742 0 ▶sub primary_id{
Subroutine primary_id: not called CC=3 SCAR=24.8
Pod documented
743 0 my $self = shift;
744 # note from cjm@fruitfly.org:
745 # I have commented out the following 2 lines:
746  
747 #return $self->{'primary_id'} = shift if @_;
748 #return $self->{'primary_id'};
749  
750 #... and replaced it with the following; see
751 # http://bioperl.org/pipermail/bioperl-l/2003-December/014150.html
752 # for the discussion that lead to this change
753  
754 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
755 0 ▶ if ($self->has_tag('ID')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_tag("ID")) 0 0 0
756 0 $self->remove_tag('ID');
757 }
758 0 $self->add_tag_value('ID', shift);
759 }
760 0 my ($id) = $self->get_tagset_values('ID');
761 0 return $id;
762 }
763  
764 0 ▶sub generate_unique_persistent_id {
Subroutine generate_unique_persistent_id: not called CC=1 SCAR=6.9
Pod undocumented
765 # DEPRECATED - us IDHandler
766 0 my $self = shift;
767 0 require Bio::SeqFeature::Tools::IDHandler;
768 0 Bio::SeqFeature::Tools::IDHandler->new->generate_unique_persistent_id($self);
769 }
770  
771  
772 =head2 phase
773  
774 Title : phase
775 Usage : $obj->phase($newval)
776 Function: get/set this feature's phase.
777 Example :
778 Returns : undef if no phase is set,
779 otherwise 0, 1, or 2 (the only valid values for phase)
780 Args : on set, the new value
781  
782 Most features do not have or need a defined phase.
783  
784 For features representing a CDS, the phase indicates where the feature
785 begins with reference to the reading frame. The phase is one of the
786 integers 0, 1, or 2, indicating the number of bases that should be
787 removed from the beginning of this feature to reach the first base of
788 the next codon. In other words, a phase of "0" indicates that the next
789 codon begins at the first base of the region described by the current
790 line, a phase of "1" indicates that the next codon begins at the
791 second base of this region, and a phase of "2" indicates that the
792 codon begins at the third base of this region. This is NOT to be
793 confused with the frame, which is simply start modulo 3.
794  
795 For forward strand features, phase is counted from the start
796 field. For reverse strand features, phase is counted from the end
797 field.
798  
799 =cut
800  
801 6 ▶sub phase {
Subroutine phase: called CC=8 SCAR=23.1
Pod documented
802 6 my $self = shift;
803 6 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 3 6
804 3 ▶ $self->remove_tag('phase') if $self->has_tag('phase');
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_tag("phase") 0 3 3
805 3 my $newphase = shift;
806 3 ▶ $self->throw("illegal phase value '$newphase', phase must be either undef, 0, 1, or 2")
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $newphase or $newphase == 0 or $newphase == 1 or $newphase == 2 0 3 3
Condition33%3/9
not defined $newphase or $newphase == 0 or $newphase == 1 or $newphase == 2
l!l&&r!l&&!r
300
not defined $newphase or $newphase == 0 or $newphase == 1
l!l&&r!l&&!r
030
not defined $newphase or $newphase == 0
l!l&&r!l&&!r
003
MC/DC0%0/4
not defined $newphase or $newphase == 0 or $newphase == 1 or $newphase == 2
not defined $newphase $newphase == 0 $newphase == 1 $newphase == 2
Truth table20%1/5
not(A) or B or C or D
A= not defined $newphaseB= $newphase == 0C= $newphase == 1D= $newphase == 2
ABCDresult
1XXX1
01XX1
001X1
00011
00000
807 unless !defined $newphase || $newphase == 0 || $newphase == 1 || $newphase == 2;
808 3 $self->add_tag_value('phase', $newphase );
809 3 return $newphase;
810 }
811  
812 3 ▶ return $self->has_tag('phase') ? ($self->get_tag_values('phase'))[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_tag('phase') ? : 2 1 3
813 }
814  
815  
816 =head1 Bio::RangeI methods
817  
818 These methods are inherited from RangeI and can be used
819 directly from a SeqFeatureI interface. Remember that a
820 SeqFeature is-a RangeI, and so wherever you see RangeI you
821 can use a feature ($r in the below documentation).
822  
823 =cut
824  
825 =head2 start()
826  
827 See L<Bio::RangeI>
828  
829 =head2 end()
830  
831 See L<Bio::RangeI>
832  
833 =head2 strand()
834  
835 See L<Bio::RangeI>
836  
837 =head2 overlaps()
838  
839 See L<Bio::RangeI>
840  
841 =head2 contains()
842  
843 See L<Bio::RangeI>
844  
845 =head2 equals()
846  
847 See L<Bio::RangeI>
848  
849 =head2 intersection()
850  
851 See L<Bio::RangeI>
852  
853 =head2 union()
854  
855 See L<Bio::RangeI>
856  
857 =cut
858  
859 245 1;
« Bio/DB/GenericWebAgent.pm ↑ Summary Bio/Root/RootI.pm »