Bio/LocatableSeq.pm

filter: Statementstmt 95.7% 182 / 190 Branchbran 80.8% 97 / 120 Conditioncond 66.6% 40 / 60 MC/DCmcdc 42.8% 15 / 35 Subroutinesub 100% 20 / 20 Podpod 100% 14 / 14 totaltotal 83.8% 368 / 439 CC 85 SCAR 21.4
CC
85
Cov
86%
get_nse
15.9
location_from_column
11.3
mapping
11.2
CRAP 8.5
« Bio/Search/Result/BlastResult.pm ↑ Summary Bio/Tools/FootPrinter.pm »
1 #
2 # BioPerl module for Bio::LocatableSeq
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::LocatableSeq - A Bio::PrimarySeq object with start/end points on it
17 that can be projected into a MSA or have coordinates relative to
18 another seq.
19  
20 =head1 SYNOPSIS
21  
22 use Bio::LocatableSeq;
23 my $seq = Bio::LocatableSeq->new(-seq => "CAGT-GGT",
24 -id => "seq1",
25 -start => 1,
26 -end => 7);
27  
28 # a normal sequence object
29 $locseq->seq();
30 $locseq->id();
31  
32 # has start,end points
33 $locseq->start();
34 $locseq->end();
35  
36 # inherits off RangeI, so range operations possible
37  
38 =head1 DESCRIPTION
39  
40 The LocatableSeq sequence object was developed mainly because the SimpleAlign
41 object requires this functionality, and in the rewrite of the Sequence object we
42 had to decide what to do with this.
43  
44 It is, to be honest, not well integrated with the rest of bioperl. For example,
45 the trunc() function does not return a LocatableSeq object, as some might have
46 thought. Also, the sequence is not a Bio::SeqI, so the location is simply
47 inherited from Bio::RangeI and is not stored in a Bio::Location.
48  
49 There are all sorts of nasty gotcha's about interactions between coordinate
50 systems when these sort of objects are used. Some mapping now occurs to deal
51 with HSP data, however it can probably be integrated in better and most methods
52 do not implement it correctly yet. Also, several PrimarySeqI methods (subseq(),
53 trunc(), etc.) do not behave as expected and must be used with care. Due to this,
54 LocatableSeq functionality is to be refactored in a future BioPerl release.
55 However, for alignment functionality it works adequately for the time being.
56  
57 If you do not need alignment functionality, L<Bio::SeqfeatureI>-implementing
58 modules may be a suitable alternative to L<Bio::LocatableSeq>. For example,
59 L<Bio::SeqFeature::Generic> and L<Bio::SeqFeature::Lite> provide methods to
60 attach a sequence to a specific region of a parent sequence and to set other
61 useful attributes.
62  
63 =head1 FEEDBACK
64  
65 =head2 Mailing Lists
66  
67 User feedback is an integral part of the evolution of this and other
68 Bioperl modules. Send your comments and suggestions preferably to one
69 of the Bioperl mailing lists. Your participation is much appreciated.
70  
71 bioperl-l@bioperl.org - General discussion
72 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
73  
74 =head2 Support
75  
76 Please direct usage questions or support issues to the mailing list:
77  
78 I<bioperl-l@bioperl.org>
79  
80 rather than to the module maintainer directly. Many experienced and
81 reponsive experts will be able look at the problem and quickly
82 address it. Please include a thorough description of the problem
83 with code and data examples if at all possible.
84  
85 =head2 Reporting Bugs
86  
87 Report bugs to the Bioperl bug tracking system to help us keep track
88 the bugs and their resolution. Bug reports can be submitted via the
89 web:
90  
91 https://github.com/bioperl/bioperl-live/issues
92  
93 =head1 APPENDIX
94  
95 The rest of the documentation details each of the object
96 methods. Internal methods are usually preceded with a _
97  
98 =cut
99  
100  
101  
102 package Bio::LocatableSeq;
103 274 $Bio::LocatableSeq::VERSION = '1.7.6';
104 274 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
105  
106 274 ▶use Bio::Location::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 274 ▶use Bio::Location::Fuzzy;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 274 ▶use vars qw($GAP_SYMBOLS $OTHER_SYMBOLS $FRAMESHIFT_SYMBOLS $RESIDUE_SYMBOLS $MATCHPATTERN);
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 # The following global variables contain symbols used to represent gaps,
111 # frameshifts, residues, and other valid symbols. These are set at compile-time;
112 # expect scoping errors when using 'local' and resetting $MATCHPATTERN (see
113 # LocatableSeq.t)
114  
115 274 $GAP_SYMBOLS = '\-\.=~';
116 274 $FRAMESHIFT_SYMBOLS = '\\\/';
117 274 $OTHER_SYMBOLS = '\?';
118 274 $RESIDUE_SYMBOLS = '0-9A-Za-z\*';
119 274 $MATCHPATTERN = $RESIDUE_SYMBOLS.$GAP_SYMBOLS.$FRAMESHIFT_SYMBOLS.$OTHER_SYMBOLS;
120  
121 274 ▶use base qw(Bio::PrimarySeq Bio::RangeI);
Subroutine BEGIN: called CC=1 SCAR=0.0
122  
123  
124 sub new {
125 4294 ▶ my ($class, @args) = @_;
Subroutine new: called CC=7 SCAR=19.5
Pod documented
126 4294 my $self = $class->SUPER::new(@args);
127  
128 4293 my ($start,$end,$strand, $mapping, $fs, $nse) =
129 $self->_rearrange( [qw(START
130 END
131 STRAND
132 MAPPING
133 FRAMESHIFTS
134 FORCE_NSE
135 )],
136 @args);
137
138 4293 ▶ $mapping ||= [1,1];
Condition100%2/2
$mapping ||= [1, 1]
l!l
464247
MC/DC100%1/1
$mapping ||= [1, 1]
$mapping
Truth table100%2/2
A
A= $mapping
Aresult
11
00
139 4293 $self->mapping($mapping);
140 4293 ▶ $nse || 0;
Branch: 1 branch
BranchTrueFalseTotal
$nse or '???' 4289 4 4293
141 4293 $self->force_nse($nse);
142 4293 ▶ defined $fs && $self->frameshifts($fs);
Branch: 1 branch
BranchTrueFalseTotal
defined $fs and $self->frameshifts($fs) 4 4289 4293
143 4293 ▶ defined $start && $self->start($start);
Branch: 1 branch
BranchTrueFalseTotal
defined $start and $self->start($start) 3669 624 4293
144 4293 ▶ defined $end && $self->end($end);
Branch: 1 branch
BranchTrueFalseTotal
defined $end and $self->end($end) 2752 1541 4293
145 4293 ▶ defined $strand && $self->strand($strand);
Branch: 1 branch
BranchTrueFalseTotal
defined $strand and $self->strand($strand) 417 3876 4293
146  
147 4293 return $self; # success - we hope!
148 }
149  
150  
151 =head2 start
152  
153 Title : start
154 Usage : $obj->start($newval)
155 Function: Get/set the 1-based start position of this sequence in the original
156 sequence. '0' means before the original sequence starts.
157 Returns : value of start
158 Args : newvalue (optional)
159  
160 =cut
161  
162 sub start {
163 12613 ▶ my $self = shift;
Subroutine start: called CC=4 SCAR=13.9
Pod documented
164 12613 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3825 8788 12613
165 3825 my $value = shift;
166 3825 $self->{'start'} = $value;
167 }
168 12613 ▶ return $self->{'start'} if defined $self->{'start'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"start"} 12123 490 12613
169 490 ▶ return 1 if $self->seq;
Branch: 1 branch
BranchTrueFalseTotal
if $self->seq 467 23 490
170 23 return;
171 }
172  
173  
174 =head2 end
175  
176 Title : end
177 Usage : $obj->end($newval)
178 Function: Get/set the 1-based end position of this sequence in the original
179 sequence. '0' means before the original sequence starts.
180 Returns : value of end
181 Args : newvalue (optional)
182 Note : although this is a get/set, it checks passed values against the
183 calculated end point ( derived from the sequence and based on
184 $GAP_SYMBOLS and possible frameshifts() ). If there is no match,
185 it will warn and set the proper value. Probably best used for
186 debugging proper sequence calculations.
187  
188 =cut
189  
190 sub end {
191 7349 ▶ my $self = shift;
Subroutine end: called CC=8 SCAR=21.0
Pod documented
192 7349 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2899 4450 7349
193 2899 my $value = shift;
194 2899 my $st = $self->start;
195 # start of 0 usually means the sequence is all gaps but maps to
196 # other sequences in an alignment
197 2899 ▶ if ($self->seq && $st != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->seq and $st != 0) 2826 73 2899
Condition66%2/3
$self->seq and $st != 0
!ll&&!rl&&r
7302826
MC/DC50%1/2
$self->seq and $st != 0
$self->seq $st != 0
Truth table66%2/3
A and B
A= $self->seqB= $st != 0
ABresult
0X0
100
111
198 2826 my $len = $self->_ungapped_len;
199 2826 my $calend = $st + $len - 1;
200 2826 ▶ my $id = $self->id || 'unknown';
Condition100%2/2
$self->id || 'unknown'
l!l
280818
MC/DC100%1/1
$self->id || 'unknown'
$self->id
Truth table100%2/2
A
A= $self->id
Aresult
11
00
201 2826 ▶ if ($calend != $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($calend != $value) 0 2826 2826
202 0 $self->warn("In sequence $id residue count gives end value ".
203 "$calend. \nOverriding value [$value] with value $calend for ".
204 "Bio::LocatableSeq::end().\n".$self->seq);
205 0 $value = $calend;
206 }
207 }
208 2899 $self->{'end'} = $value;
209 }
210  
211 7349 ▶ if (defined $self->{'end'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'end'}) { } 6180 1169 7349
elsif (my $len = $self->_ungapped_len) { } 1146 23 1169
212 6180 return $self->{'end'}
213 } elsif ( my $len = $self->_ungapped_len) {
214 1146 return $len + $self->start - 1;
215 } else {
216 23 return;
217 }
218 }
219  
220  
221 # changed 08.10.26 to return ungapped length, not the calculated end
222 # of the sequence
223 sub _ungapped_len {
224 3995 ▶ my $self = shift;
Subroutine _ungapped_len: called CC=3 SCAR=11.0
225 3995 ▶ return unless my $string = $self->seq;
Branch: 1 branch
BranchTrueFalseTotal
unless my $string = $self->seq 23 3972 3995
226 3972 my ($map_res, $map_coord) = $self->mapping;
227 3972 my $offset = 0;
228 3972 ▶ if (my %data = $self->frameshifts) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(%data) = $self->frameshifts) 2 3970 3972
229 2 map {$offset += $_} values %data;
230 }
231 3972 $string =~ s{[$GAP_SYMBOLS$FRAMESHIFT_SYMBOLS]+}{}g;
232 3972 return CORE::length($string)/($map_res/$map_coord) + $offset/($map_coord/$map_res);
233 }
234  
235 #sub length {
236 # my $self = shift;
237 # return unless my $string = $self->seq;
238 # $string =~ s{[$GAP_SYMBOLS$FRAMESHIFT_SYMBOLS]+}{}g;
239 # return CORE::length($string);
240 #}
241  
242  
243 =head2 strand
244  
245 Title : strand
246 Usage : $obj->strand($newval)
247 Function: return or set the strandedness
248 Returns : the value of the strandedness (-1, 0 or 1)
249 Args : the value of the strandedness (-1, 0 or 1)
250  
251 =cut
252  
253 sub strand {
254 5195 ▶ my $self = shift;
Subroutine strand: called CC=2 SCAR=6.9
Pod documented
255 5195 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 487 4708 5195
256 487 my $value = shift;
257 487 $self->{'strand'} = $value;
258 }
259 5195 return $self->{'strand'};
260 }
261  
262  
263 =head2 mapping
264  
265 Title : mapping
266 Usage : $obj->mapping($newval)
267 Function: return or set the mapping indices (indicates # symbols/positions in
268 the source string mapping to # of coordinate positions)
269 Returns : two-element array (# symbols => # coordinate pos)
270 Args : two elements (# symbols => # coordinate pos); this can also be
271 passed in as an array reference of the two elements (as might be
272 passed upon Bio::LocatableSeq instantiation, for instance).
273  
274 =cut
275  
276 sub mapping {
277 8285 ▶ my $self = shift;
Subroutine mapping: called CC=9 SCAR=24.1
Pod documented
278 8285 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4301 3984 8285
279 4301 ▶ my @mapping = (ref($_[0]) eq 'ARRAY') ? @{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 4301 0 4301
280 4301 ▶ $self->throw("Must pass two values (# residues mapped to # positions)")
Branch: 1 branch
BranchTrueFalseTotal
if @mapping != 2 0 4301 4301
281 if @mapping != 2;
282 4301 ▶ if ((grep {$_ != 1 && $_ != 3} @mapping) || ($mapping[0] == 3 && $mapping[1] == 3)) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$_ != 1 and $_ != 3;} @mapping or $mapping[0] == 3 and $mapping[1] == 3) 0 4301 4301
$_ != 1 and $_ != 3 11 8591 8602
Condition33%2/6
grep {$_ != 1 and $_ != 3;} @mapping or $mapping[0] == 3 and $mapping[1] == 3
l!l&&r!l&&!r
004301
$mapping[0] == 3 and $mapping[1] == 3
!ll&&!rl&&r
430100
MC/DC0%0/3
grep {$_ != 1 and $_ != 3;} @mapping or $mapping[0] == 3 and $mapping[1] == 3
grep {$_ != 1 and $_ != 3;} @mapping $mapping[0] == 3 $mapping[1] == 3
Truth table0%0/4
A or B and C
A= grep {$_ != 1 and $_ != 3;} @mappingB= $mapping[0] == 3C= $mapping[1] == 3
ABCresult
1XX1
0111
00X0
0100
283 0 $self->throw("Mapping values other than 1 or 3 are not currently supported")
284 }
285 4301 $self->{'_mapping'} = \@mapping;
286 }
287 8285 ▶ $self->throw('Mapping for LocatableSeq not set') if !exists $self->{'_mapping'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_mapping"} 0 8285 8285
288 8285 return @{ $self->{'_mapping'} };
289 }
290  
291  
292 =head2 frameshifts
293  
294 Title : frameshifts
295 Usage : $obj->frameshifts($newval)
296 Function: get/set the frameshift hash, which contains sequence positions as
297 keys and the shift (-2, -1, 1, 2) as the value
298 Returns : hash
299 Args : hash or hash reference
300  
301 =cut
302  
303 sub frameshifts {
304 3976 ▶ my $self = shift;
Subroutine frameshifts: called CC=5 SCAR=16.7
Pod documented
305 3976 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 3972 3976
306 4 ▶ if (ref $_[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 4 0 4
307 4 $self->{_frameshifts} = $_[0];
308 } else {
309 # assume this is a full list to be converted to a hash
310 0 $self->{_frameshifts} = \%{@_} # coerce into hash ref
311 }
312 }
313 (defined $self->{_frameshifts} && ref $self->{_frameshifts} eq 'HASH') ?
314 3976 ▶ return %{$self->{_frameshifts}} : return ();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'_frameshifts'} && ref $self->{'_frameshifts'} eq 'HASH' ? : 8 3968 3976
Condition66%2/3
defined $self->{"_frameshifts"} and ref $self->{"_frameshifts"} eq "HASH"
!ll&&!rl&&r
396808
MC/DC50%1/2
defined $self->{"_frameshifts"} and ref $self->{"_frameshifts"} eq "HASH"
defined $self->{"_frameshifts"} ref $self->{"_frameshifts"} eq "HASH"
Truth table66%2/3
A and B
A= defined $self->{"_frameshifts"}B= ref $self->{"_frameshifts"} eq "HASH"
ABresult
0X0
100
111
315 }
316  
317  
318 =head2 get_nse
319  
320 Title : get_nse
321 Usage :
322 Function: read-only name of form id/start-end
323 Example :
324 Returns :
325 Args :
326  
327 =cut
328  
329 sub get_nse {
330 4097 ▶ my ($self,$char1,$char2) = @_;
Subroutine get_nse: called CC=14 SCAR=27.7
Pod documented
331  
332 4097 ▶ $char1 ||= "/";
Condition50%1/2
$char1 ||= "/"
l!l
04097
MC/DC0%0/1
$char1 ||= "/"
$char1
Truth table50%1/2
A
A= $char1
Aresult
11
00
333 4097 ▶ $char2 ||= "-";
Condition50%1/2
$char2 ||= "-"
l!l
04097
MC/DC0%0/1
$char2 ||= "-"
$char2
Truth table50%1/2
A
A= $char2
Aresult
11
00
334
335 4097 ▶ my ($id, $st, $end, $strand) = ($self->id(), $self->start(),
Condition100%2/2
$self->strand || 0
l!l
1613936
MC/DC100%1/1
$self->strand || 0
$self->strand
Truth table100%2/2
A
A= $self->strand
Aresult
11
00
336 $self->end(), $self->strand || 0);
337
338 4097 ▶ if ($self->force_nse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->force_nse) 4 4093 4097
339 4 ▶ $id ||= '';
Condition50%1/2
$id ||= ""
l!l
04
MC/DC0%0/1
$id ||= ""
$id
Truth table50%1/2
A
A= $id
Aresult
11
00
340 4 ▶ $st ||= 0;
Condition50%1/2
$st ||= 0
l!l
40
MC/DC0%0/1
$st ||= 0
$st
Truth table50%1/2
A
A= $st
Aresult
11
00
341 4 ▶ $end ||= 0;
Condition50%1/2
$end ||= 0
l!l
40
MC/DC0%0/1
$end ||= 0
$end
Truth table50%1/2
A
A= $end
Aresult
11
00
342 }
343
344 4097 ▶ $self->throw("Attribute id not set") unless defined($id);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 0 4097 4097
345 4097 ▶ $self->throw("Attribute start not set") unless defined($st);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $st 0 4097 4097
346 4097 ▶ $self->throw("Attribute end not set") unless defined($end);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $end 0 4097 4097
347
348 4097 ▶ if ($strand && $strand == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand and $strand == -1) 29 4068 4097
Condition100%3/3
$strand and $strand == -1
!ll&&!rl&&r
393613229
MC/DC100%2/2
$strand and $strand == -1
$strand $strand == -1
Truth table100%3/3
A and B
A= $strandB= $strand == -1
ABresult
0X0
100
111
349 29 ($st, $end) = ($end, $st);
350 }
351
352 #Stockholm Rfam includes version if present so it is optional
353 4097 ▶ my $v = $self->version ? '.'.$self->version : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->version ? : 0 4097 4097
354 4097 return join('',$id, $v, $char1, $st, $char2, $end);
355 }
356  
357  
358 =head2 force_nse
359  
360 Title : force_nse
361 Usage : $ls->force_nse()
362 Function: Boolean which forces get_nse() to build an NSE, regardless
363 of whether id(), start(), or end() is set
364 Returns : Boolean value
365 Args : (optional) Boolean (1 or 0)
366 Note : This will convert any passed value evaluating as TRUE/FALSE to 1/0
367 respectively
368  
369 =cut
370  
371 sub force_nse {
372 8390 ▶ my ($self, $flag) = @_;
Subroutine force_nse: called CC=3 SCAR=11.0
Pod documented
373 8390 ▶ if (defined $flag) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $flag) 40 8350 8390
374 40 ▶ $flag ? (return $self->{'_force_nse'} = 1) : (return $self->{'_force_nse'} = 0);
Branch: 1 branch
BranchTrueFalseTotal
$flag ? : 4 36 40
375 }
376 8350 return $self->{'_force_nse'};
377 }
378  
379  
380 =head2 num_gaps
381  
382 Title : num_gaps
383 Usage :$self->num_gaps('.')
384 Function:Gets number of gaps in the sequence. The count excludes
385 leading or trailing gap characters.
386  
387 Valid bioperl sequence characters are [A-Za-z\-\.\*]. Of
388 these, '.' and '-' are counted as gap characters unless an
389 optional argument specifies one of them.
390  
391 Returns : number of internal gaps in the sequence.
392 Args : a gap character (optional)
393 Status : Stable
394 Note : replaces no_gaps
395  
396 =cut
397  
398 sub num_gaps {
399 39 ▶ my ($self,$char) = @_;
Subroutine num_gaps: called CC=5 SCAR=16.3
Pod documented
400 39 my ($seq, $count) = (undef, 0);
401  
402 # default gap characters
403 39 ▶ $char ||= $GAP_SYMBOLS;
Condition66%2/3
$char ||= $Bio::LocatableSeq::GAP_SYMBOLS
l!l&&r!l&&!r
3630
MC/DC0%0/2
$char ||= $Bio::LocatableSeq::GAP_SYMBOLS
$char $Bio::LocatableSeq::GAP_SYMBOLS
Truth table66%2/3
A ||= B
A= $charB= $Bio::LocatableSeq::GAP_SYMBOLS
ABresult
1X1
011
000
404  
405 39 ▶ $self->warn("I hope you know what you are doing setting gap to [$char]")
Branch: 1 branch
BranchTrueFalseTotal
unless $char =~ /[$Bio::LocatableSeq::GAP_SYMBOLS]/ 0 39 39
406 unless $char =~ /[$GAP_SYMBOLS]/;
407  
408 39 $seq = $self->seq;
409 39 ▶ return 0 unless $seq; # empty sequence does not have gaps
Branch: 1 branch
BranchTrueFalseTotal
unless $seq 0 39 39
410  
411 39 $seq =~ s/^([$char]+)//;
412 39 $seq =~ s/([$char]+)$//;
413 39 ▶ while ( $seq =~ /[$char]+/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq =~ /[$char]+/g) 68 39 107
414 68 $count++;
415 }
416  
417 39 return $count;
418 }
419  
420  
421 =head2 column_from_residue_number
422  
423 Title : column_from_residue_number
424 Usage : $col = $seq->column_from_residue_number($resnumber)
425 Function:
426  
427 This function gives the position in the alignment
428 (i.e. column number) of the given residue number in the
429 sequence. For example, for the sequence
430  
431 Seq1/91-97 AC..DEF.GH
432  
433 column_from_residue_number(94) returns 6.
434  
435 An exception is thrown if the residue number would lie
436 outside the length of the aligment
437 (e.g. column_from_residue_number( "Seq2", 22 )
438  
439 Returns : A column number for the position of the
440 given residue in the given sequence (1 = first column)
441 Args : A residue number in the whole sequence (not just that
442 segment of it in the alignment)
443  
444 =cut
445  
446 sub column_from_residue_number {
447 31 ▶ my ($self, $resnumber) = @_;
Subroutine column_from_residue_number: called CC=11 SCAR=24.1
Pod documented
448  
449 31 ▶ $self->throw("Residue number has to be a positive integer, not [$resnumber]")
Branch: 1 branch
BranchTrueFalseTotal
unless $resnumber =~ /^\d+$/ and $resnumber > 0 0 31 31
Condition33%1/3
$resnumber =~ /^\d+$/ and $resnumber > 0
!ll&&!rl&&r
0031
MC/DC0%0/2
$resnumber =~ /^\d+$/ and $resnumber > 0
$resnumber =~ /^\d+$/ $resnumber > 0
Truth table33%1/3
A and B
A= $resnumber =~ /^\d+$/B= $resnumber > 0
ABresult
0X0
100
111
450 unless $resnumber =~ /^\d+$/ and $resnumber > 0;
451  
452 31 ▶ if ($resnumber >= $self->start() and $resnumber <= $self->end()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resnumber >= $self->start and $resnumber <= $self->end) 30 1 31
Condition66%2/3
$resnumber >= $self->start and $resnumber <= $self->end
!ll&&!rl&&r
0130
MC/DC50%1/2
$resnumber >= $self->start and $resnumber <= $self->end
$resnumber >= $self->start $resnumber <= $self->end
Truth table66%2/3
A and B
A= $resnumber >= $self->startB= $resnumber <= $self->end
ABresult
0X0
100
111
453 30 my @chunks;
454 my $column_incr;
455 30 my $current_column;
456 30 my $current_residue = $self->start - 1;
457 30 my $seq = $self->seq;
458 30 ▶ my $strand = $self->strand || 0;
Condition100%2/2
$self->strand || 0
l!l
624
MC/DC100%1/1
$self->strand || 0
$self->strand
Truth table100%2/2
A
A= $self->strand
Aresult
11
00
459  
460 30 ▶ if ($strand == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand == -1) { } 3 27 30
461 #@chunks = reverse $seq =~ m/[^\.\-]+|[\.\-]+/go;
462 3 @chunks = reverse $seq =~ m/[$RESIDUE_SYMBOLS]+|[$GAP_SYMBOLS]+/go;
463 3 $column_incr = -1;
464 3 $current_column = (CORE::length $seq) + 1;
465 }
466 else {
467 #@chunks = $seq =~ m/[^\.\-]+|[\.\-]+/go;
468 27 @chunks = $seq =~ m/[$RESIDUE_SYMBOLS]+|[$GAP_SYMBOLS]+/go;
469 27 $column_incr = 1;
470 27 $current_column = 0;
471 }
472  
473 30 ▶ while (my $chunk = shift @chunks) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chunk = shift @chunks) 77 0 77
474 #if ($chunk =~ m|^[\.\-]|o) {
475 77 ▶ if ($chunk =~ m|^[$GAP_SYMBOLS]|o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk =~ /^[$Bio::LocatableSeq::GAP_SYMBOLS]/o) { } 25 52 77
476 25 $current_column += $column_incr * CORE::length($chunk);
477 }
478 else {
479 52 ▶ if ($current_residue + CORE::length($chunk) < $resnumber) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_residue + length($chunk) < $resnumber) { } 22 30 52
480 22 $current_column += $column_incr * CORE::length($chunk);
481 22 $current_residue += CORE::length($chunk);
482 }
483 else {
484 30 ▶ if ($strand == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand == -1) { } 3 27 30
485 3 $current_column -= $resnumber - $current_residue;
486 }
487 else {
488 27 $current_column += $resnumber - $current_residue;
489 }
490 30 return $current_column;
491 }
492 }
493 }
494 }
495  
496 1 $self->throw("Could not find residue number $resnumber");
497  
498 }
499  
500  
501 =head2 location_from_column
502  
503 Title : location_from_column
504 Usage : $loc = $ali->location_from_column($column_number)
505 Function:
506  
507 This function gives the residue number for a given position
508 in the alignment (i.e. column number) of the given. Gaps
509 complicate this process and force the output to be a
510 L<Bio::Location::Simple> where values can be undefined.
511 For example, for the sequence:
512  
513 Seq/91-96 .AC..DEF.G.
514  
515 location_from_column( 3 ) position 92
516 location_from_column( 4 ) position 92^93
517 location_from_column( 9 ) position 95^96
518 location_from_column( 1 ) position undef
519  
520 An exact position returns a Bio::Location::Simple object
521 where where location_type() returns 'EXACT', if a position
522 is between bases location_type() returns 'IN-BETWEEN'.
523 Column before the first residue returns undef. Note that if
524 the position is after the last residue in the alignment,
525 that there is no guarantee that the original sequence has
526 residues after that position.
527  
528 An exception is thrown if the column number is not within
529 the sequence.
530  
531 Returns : Bio::Location::Simple or undef
532 Args : A column number
533 Throws : If column is not within the sequence
534  
535 See L<Bio::Location::Simple> for more.
536  
537 =cut
538  
539 sub location_from_column {
540 49 ▶ my ($self, $column) = @_;
Subroutine location_from_column: called CC=11 SCAR=24.2
Pod documented
541  
542 49 ▶ $self->throw("Column number has to be a positive integer, not [$column]")
Branch: 1 branch
BranchTrueFalseTotal
unless $column =~ /^\d+$/ and $column > 0 0 49 49
Condition33%1/3
$column =~ /^\d+$/ and $column > 0
!ll&&!rl&&r
0049
MC/DC0%0/2
$column =~ /^\d+$/ and $column > 0
$column =~ /^\d+$/ $column > 0
Truth table33%1/3
A and B
A= $column =~ /^\d+$/B= $column > 0
ABresult
0X0
100
111
543 unless $column =~ /^\d+$/ and $column > 0;
544 49 ▶ $self->throw("Column number [$column] is larger than".
Branch: 1 branch
BranchTrueFalseTotal
unless $column <= $self->length 0 49 49
545 " sequence length [". $self->length. "]")
546 unless $column <= $self->length;
547  
548 49 my ($loc);
549 49 my $s = $self->subseq(1,$column);
550 49 $s =~ s/[^a-zA-Z\*]//g;
551  
552 49 my $pos = CORE::length $s;
553  
554 49 ▶ my $start = $self->start || 0 ;
Condition50%1/2
$self->start || 0
l!l
490
MC/DC0%0/1
$self->start || 0
$self->start
Truth table50%1/2
A
A= $self->start
Aresult
11
00
555 49 ▶ my $strand = $self->strand() || 1;
Condition100%2/2
$self->strand || 1
l!l
1237
MC/DC100%1/1
$self->strand || 1
$self->strand
Truth table100%2/2
A
A= $self->strand
Aresult
11
00
556 49 ▶ my $relative_pos = ($strand == -1)
Branch: 1 branch
BranchTrueFalseTotal
$strand == -1 ? : 5 44 49
557 ? ($self->end - $pos + 1)
558 : ($pos + $start - 1);
559 49 ▶ if ($self->subseq($column, $column) =~ /[a-zA-Z\*]/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->subseq($column, $column) =~ /[a-zA-Z\*]/) { } 43 6 49
elsif ($pos == 0 and $self->start == 1) { } 2 4 6
560 43 $loc = Bio::Location::Simple->new
561 (-start => $relative_pos,
562 -end => $relative_pos,
563 -strand => 1,
564 );
565 ▶ } elsif ($pos == 0 and $self->start == 1) {
Condition100%3/3
$pos == 0 and $self->start == 1
!ll&&!rl&&r
312
MC/DC100%2/2
$pos == 0 and $self->start == 1
$pos == 0 $self->start == 1
Truth table100%3/3
A and B
A= $pos == 0B= $self->start == 1
ABresult
0X0
100
111
566 } else {
567 4 my ($start,$end) = ($relative_pos, $relative_pos + $strand);
568 4 ▶ if ($strand == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand == -1) 1 3 4
569 1 ($start,$end) = ($end,$start);
570 }
571 4 $loc = Bio::Location::Simple->new
572 (-start => $start,
573 -end => $end,
574 -strand => 1,
575 -location_type => 'IN-BETWEEN'
576 );
577 }
578 49 return $loc;
579 }
580  
581  
582 =head2 revcom
583  
584 Title : revcom
585 Usage : $rev = $seq->revcom()
586 Function: Produces a new Bio::LocatableSeq object which
587 has the reversed complement of the sequence. For protein
588 sequences this throws an exception of "Sequence is a
589 protein. Cannot revcom"
590  
591 Returns : A new Bio::LocatableSeq object
592 Args : none
593  
594 =cut
595  
596 sub revcom {
597 12 ▶ my ($self) = @_;
Subroutine revcom: called CC=5 SCAR=17.1
Pod documented
598 # since we don't know whether sequences without 1 => 1 correlation can be
599 # revcom'd, kick back
600 12 ▶ if (grep {$_ != 1} $self->mapping) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ != 1;} $self->mapping) 0 12 12
601 0 $self->warn('revcom() not supported for sequences with mapped values of > 1');
602 0 return;
603 }
604 12 my $new = $self->SUPER::revcom;
605 12 ▶ $new->strand($self->strand * -1) if $self->strand;
Branch: 1 branch
BranchTrueFalseTotal
if $self->strand 6 6 12
606 12 ▶ $new->start($self->start) if $self->start;
Branch: 1 branch
BranchTrueFalseTotal
if $self->start 12 0 12
607 12 ▶ $new->end($self->end) if $self->end;
Branch: 1 branch
BranchTrueFalseTotal
if $self->end 12 0 12
608 12 return $new;
609 }
610  
611  
612 =head2 trunc
613  
614 Title : trunc
615 Usage : $subseq = $myseq->trunc(10,100);
616 Function: Provides a truncation of a sequence,
617 Returns : a fresh Bio::PrimarySeqI implementing object
618 Args : Two integers denoting first and last columns of the
619 sequence to be included into sub-sequence.
620  
621 =cut
622  
623 sub trunc {
624 40 ▶ my ($self, $start, $end) = @_;
Subroutine trunc: called CC=5 SCAR=16.4
Pod documented
625 40 my $new = $self->SUPER::trunc($start, $end);
626 40 $new->strand($self->strand);
627  
628 # end will be automatically calculated
629 40 ▶ $start = $end if $self->strand && $self->strand == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->strand and $self->strand == -1 3 37 40
Condition66%2/3
$self->strand and $self->strand == -1
!ll&&!rl&&r
3703
MC/DC50%1/2
$self->strand and $self->strand == -1
$self->strand $self->strand == -1
Truth table66%2/3
A and B
A= $self->strandB= $self->strand == -1
ABresult
0X0
100
111
630  
631 40 $start = $self->location_from_column($start);
632 40 ▶ $start ? ($start = $start->end) : ($start = 1);
Branch: 1 branch
BranchTrueFalseTotal
$start ? : 40 0 40
633 40 ▶ $new->start($start) if $start;
Branch: 1 branch
BranchTrueFalseTotal
if $start 40 0 40
634  
635 40 return $new;
636 }
637  
638  
639 =head2 validate_seq
640  
641 Title : validate_seq
642 Usage : if(! $seqobj->validate_seq($seq_str) ) {
643 print "sequence $seq_str is not valid for an object of
644 alphabet ",$seqobj->alphabet, "\n";
645 }
646 Function: Test that the given sequence is valid, i.e. contains only valid
647 characters. The allowed characters are all letters (A-Z) and '-','.',
648 '*','?','=' and '~'. Spaces are not valid. Note that this
649 implementation does not take alphabet() into account.
650 Returns : 1 if the supplied sequence string is valid, 0 otherwise.
651 Args : - Sequence string to be validated
652 - Boolean to throw an error if the sequence is invalid
653  
654 =cut
655  
656 sub validate_seq {
657 4763 ▶ my ($self, $seqstr, $throw) = @_;
Subroutine validate_seq: called CC=7 SCAR=19.9
Pod documented
658 4763 ▶ $seqstr = '' if not defined $seqstr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seqstr 0 4763 4763
659 4763 ▶ $throw = 0 if not defined $throw ; # 0 for backward compatibility
Branch: 1 branch
BranchTrueFalseTotal
unless defined $throw 8 4755 4763
660 4763 ▶ if ( (CORE::length $seqstr > 0 ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (length $seqstr > 0 and not $seqstr =~ /^([$Bio::LocatableSeq::MATCHPATTERN]+)$/) 1 4762 4763
Condition100%3/3
length $seqstr > 0 and not $seqstr =~ /^([$Bio::LocatableSeq::MATCHPATTERN]+)$/
!ll&&!rl&&r
447581
MC/DC100%2/2
length $seqstr > 0 and not $seqstr =~ /^([$Bio::LocatableSeq::MATCHPATTERN]+)$/
length $seqstr > 0 not $seqstr =~ /^([$Bio::LocatableSeq::MATCHPATTERN]+)$/
Truth table100%3/3
A and not(B)
A= length $seqstr > 0B= not $seqstr =~ /^([$Bio::LocatableSeq::MATCHPATTERN]+)$/
ABresult
0X0
100
111
661 ($seqstr !~ /^([$MATCHPATTERN]+)$/) ) {
662 1 ▶ if ($throw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($throw) 1 0 1
663 1 ▶ $self->throw("Failed validation of sequence '".(defined($self->id) ||
Condition50%1/2
defined $self->id || '[unidentified sequence]'
l!l
01
MC/DC0%0/1
defined $self->id || '[unidentified sequence]'
defined $self->id
Truth table50%1/2
A
A= defined $self->id
Aresult
11
00
664 '[unidentified sequence]')."'. Invalid characters were: " .
665 join('',($seqstr =~ /([^$MATCHPATTERN]+)/g)));
666 }
667 0 return 0;
668 }
669 4762 return 1;
670 }
671  
672 274 1;
« Bio/Search/Result/BlastResult.pm ↑ Summary Bio/Tools/FootPrinter.pm »