Bio/SeqUtils.pm

filter: Statementstmt 29.8% 136 / 455 Branchbran 17.5% 47 / 268 Conditioncond 5.8% 7 / 120 MC/DCmcdc 3.9% 3 / 76 Subroutinesub 50.0% 14 / 28 Podpod 100% 13 / 13 totaltotal 22.9% 220 / 960 CC 226 SCAR 58.6
CC
226
Cov
23%
insert
1056.0
_coord_adjust_deletion
992.0
_coord_adjust_insertion
420.0
CRAP 350.1
« Bio/AlignIO/proda.pm ↑ Summary Bio/SearchIO/infernal.pm »
1 # BioPerl module for Bio::SeqUtils
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by Heikki Lehvaslaiho <heikki-at-bioperl-dot-org>
6 #
7 # Copyright Heikki Lehvaslaiho
8 #
9 # You may distribute this module under the same terms as perl itself
10  
11 # POD documentation - main docs before the code
12  
13 =head1 NAME
14  
15 Bio::SeqUtils - Additional methods for PrimarySeq objects
16  
17 =head1 SYNOPSIS
18  
19 use Bio::SeqUtils;
20 # get a Bio::PrimarySeqI compliant object, $seq, somehow
21 $util = Bio::SeqUtils->new();
22 $polypeptide_3char = $util->seq3($seq);
23 # or
24 $polypeptide_3char = Bio::SeqUtils->seq3($seq);
25  
26 # set the sequence string (stored in one char code in the object)
27 Bio::SeqUtils->seq3($seq, $polypeptide_3char);
28  
29 # translate a sequence in all six frames
30 @seqs = Bio::SeqUtils->translate_6frames($seq);
31  
32 # inplace editing of the sequence
33 Bio::SeqUtils->mutate($seq,
34 Bio::LiveSeq::Mutation->new(-seq => 'c',
35 -pos => 3
36 ));
37 # mutate a sequence to desired similarity%
38 $newseq = Bio::SeqUtils-> evolve
39 ($seq, $similarity, $transition_transversion_rate);
40  
41 # concatenate two or more sequences with annotations and features,
42 # the first sequence will be modified
43 Bio::SeqUtils->cat(@seqs);
44 my $catseq=$seqs[0];
45  
46 # truncate a sequence, retaining features and adjusting their
47 # coordinates if necessary
48 my $truncseq = Bio::SeqUtils->trunc_with_features($seq, 100, 200);
49  
50 # reverse complement a sequence and its features
51 my $revcomseq = Bio::SeqUtils->revcom_with_features($seq);
52  
53 # simulate cloning of a fragment into a vector. Cut the vector at
54 # positions 1000 and 1100 (deleting positions 1001 to 1099) and
55 # "ligate" a fragment into the sites. The fragment is
56 # reverse-complemented in this example (option "flip").
57 # All features of the vector and fragment are preserved and
58 # features that are affected by the deletion/insertion are
59 # modified accordingly.
60 # $vector and $fragment must be Bio::SeqI compliant objects
61 my $new_molecule = Bio::Sequtils->ligate(
62 -vector => $vector,
63 -fragment => $fragment,
64 -left => 1000,
65 -right => 1100,
66 -flip => 1
67 );
68  
69 # delete a segment of a sequence (from pos 1000 to 1100, inclusive),
70 # again preserving features and annotations
71 my $new_molecule = Bio::SeqUtils->cut( $seq, 1000, 1100 );
72  
73 # insert a fragment into a recipient between positions 1000 and
74 # 1001. $recipient is a Bio::SeqI compliant object
75 my $new_molecule = Bio::SeqUtils::PbrTools->insert(
76 $recipient_seq,
77 $fragment_seq,
78 1000
79 );
80  
81 =head1 DESCRIPTION
82  
83 This class is a holder of methods that work on Bio::PrimarySeqI-
84 compliant sequence objects, e.g. Bio::PrimarySeq and
85 Bio::Seq. These methods are not part of the Bio::PrimarySeqI
86 interface and should in general not be essential to the primary function
87 of sequence objects. If you are thinking of adding essential
88 functions, it might be better to create your own sequence class.
89 See L<Bio::PrimarySeqI>, L<Bio::PrimarySeq>, and L<Bio::Seq> for more.
90  
91 The methods take as their first argument a sequence object. It is
92 possible to use methods without first creating a SeqUtils object,
93 i.e. use it as an anonymous hash.
94  
95 The first two methods, seq3() and seq3in(), give out or read in protein
96 sequences coded in three letter IUPAC amino acid codes.
97  
98 The next two methods, translate_3frames() and translate_6frames(), wrap
99 around the standard translate method to give back an array of three
100 forward or all six frame translations.
101  
102 The mutate() method mutates the sequence string with a mutation
103 description object.
104  
105 The cat() method concatenates two or more sequences. The first sequence
106 is modified by addition of the remaining sequences. All annotations and
107 sequence features will be transferred.
108  
109 The revcom_with_features() and trunc_with_features() methods are similar
110 to the revcom() and trunc() methods from Bio::Seq, but also adjust any
111 features associated with the sequence as appropriate.
112  
113 There are also methods that simulate molecular cloning with rich
114 sequence objects.
115 The delete() method cuts a segment out of a sequence and re-joins the
116 left and right fragments (like splicing or digesting and re-ligating a
117 molecule). Positions (and types) of sequence features are adjusted
118 accordingly:
119 Features that span the deleted segment are converted to split featuress
120 to indicate the disruption. (Sub)Features that extend into the deleted
121 segment are truncated.
122 A new molecule is created and returned.
123  
124 The insert() method inserts a fragment (which can be a rich Bio::Seq
125 object) into another sequence object adding all annotations and
126 features to the final product.
127 Features that span the insertion site are converted to split features
128 to indicate the disruption.
129 A new feature is added to indicate the inserted fragment itself.
130 A new molecule is created and returned.
131  
132 The ligate() method simulates digesting a recipient (vector) and
133 ligating a fragment into it, which can also be flipped if needed. It
134 is simply a combination of a deletion and an insertion step and
135 returns a new molecule. The rules for modifying feature locations
136 outlined above are also used here, e.g. features that span the cut
137 sites are converted to split features with truncated sub-locations.
138  
139  
140 =head1 FEEDBACK
141  
142 =head2 Mailing Lists
143  
144 User feedback is an integral part of the evolution of this and other
145 Bioperl modules. Send your comments and suggestions preferably to one
146 of the Bioperl mailing lists. Your participation is much appreciated.
147  
148 bioperl-l@bioperl.org - General discussion
149 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
150  
151 =head2 Support
152  
153 Please direct usage questions or support issues to the mailing list:
154  
155 I<bioperl-l@bioperl.org>
156  
157 rather than to the module maintainer directly. Many experienced and
158 reponsive experts will be able look at the problem and quickly
159 address it. Please include a thorough description of the problem
160 with code and data examples if at all possible.
161  
162 =head2 Reporting Bugs
163  
164 Report bugs to the Bioperl bug tracking system to help us keep track
165 the bugs and their resolution. Bug reports can be submitted via the
166 web:
167  
168 https://github.com/bioperl/bioperl-live/issues
169  
170 =head1 AUTHOR - Heikki Lehvaslaiho
171  
172 Email: heikki-at-bioperl-dot-org
173  
174 =head1 CONTRIBUTORS
175  
176 Roy R. Chaudhuri - roy.chaudhuri at gmail.com
177 Frank Schwach - frank.schwach@sanger.ac.uk
178  
179 =head1 APPENDIX
180  
181 The rest of the documentation details each of the object
182 methods. Internal methods are usually preceded with a _
183  
184 =cut
185  
186 # Let the code begin...
187  
188 package Bio::SeqUtils;
189 344 $Bio::SeqUtils::VERSION = '1.7.8';
190 344 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
191 344 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
192 344 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
193 344 ▶use parent qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
194  
195 # new inherited from RootI
196  
197 344 our %ONECODE = (
198 'Ala' => 'A',
199 'Asx' => 'B',
200 'Cys' => 'C',
201 'Asp' => 'D',
202 'Glu' => 'E',
203 'Phe' => 'F',
204 'Gly' => 'G',
205 'His' => 'H',
206 'Ile' => 'I',
207 'Lys' => 'K',
208 'Leu' => 'L',
209 'Met' => 'M',
210 'Asn' => 'N',
211 'Pro' => 'P',
212 'Gln' => 'Q',
213 'Arg' => 'R',
214 'Ser' => 'S',
215 'Thr' => 'T',
216 'Val' => 'V',
217 'Trp' => 'W',
218 'Xaa' => 'X',
219 'Tyr' => 'Y',
220 'Glx' => 'Z',
221 'Ter' => '*',
222 'Sec' => 'U',
223 'Pyl' => 'O',
224 'Xle' => 'J'
225 );
226  
227 344 our %THREECODE = (
228 'A' => 'Ala',
229 'B' => 'Asx',
230 'C' => 'Cys',
231 'D' => 'Asp',
232 'E' => 'Glu',
233 'F' => 'Phe',
234 'G' => 'Gly',
235 'H' => 'His',
236 'I' => 'Ile',
237 'K' => 'Lys',
238 'L' => 'Leu',
239 'M' => 'Met',
240 'N' => 'Asn',
241 'P' => 'Pro',
242 'Q' => 'Gln',
243 'R' => 'Arg',
244 'S' => 'Ser',
245 'T' => 'Thr',
246 'V' => 'Val',
247 'W' => 'Trp',
248 'Y' => 'Tyr',
249 'Z' => 'Glx',
250 'X' => 'Xaa',
251 '*' => 'Ter',
252 'U' => 'Sec',
253 'O' => 'Pyl',
254 'J' => 'Xle'
255 );
256  
257 =head2 seq3
258  
259 Title : seq3
260 Usage : $string = Bio::SeqUtils->seq3($seq)
261 Function: Read only method that returns the amino acid sequence as a
262 string of three letter codes. alphabet has to be
263 'protein'. Output follows the IUPAC standard plus 'Ter' for
264 terminator. Any unknown character, including the default
265 unknown character 'X', is changed into 'Xaa'. A noncoded
266 aminoacid selenocystein is recognized (Sec, U).
267  
268 Returns : A scalar
269 Args : character used for stop in the protein sequence optional,
270 defaults to '*' string used to separate the output amino
271 acid codes, optional, defaults to ''
272  
273 =cut
274  
275 4 ▶sub seq3 {
Subroutine seq3: called CC=9 SCAR=22.5
Pod documented
276 4 my ( $self, $seq, $stop, $sep ) = @_;
277  
278 4 ▶ $seq->isa('Bio::PrimarySeqI')
Branch: 1 branch
BranchTrueFalseTotal
$seq->isa("Bio::PrimarySeqI") or $self->throw("Not a Bio::PrimarySeqI object but [\$self]") 4 0 4
279 || $self->throw('Not a Bio::PrimarySeqI object but [$self]');
280 4 ▶ $seq->alphabet eq 'protein'
Branch: 1 branch
BranchTrueFalseTotal
$seq->alphabet eq "protein" or $self->throw("Not a protein sequence") 4 0 4
281 || $self->throw('Not a protein sequence');
282  
283 4 ▶ if ( defined $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stop) 1 3 4
284 1 ▶ length $stop != 1
Branch: 1 branch
BranchTrueFalseTotal
length $stop != 1 and $self->throw("One character stop needed, not [\$stop]") 0 1 1
285 and $self->throw('One character stop needed, not [$stop]');
286 1 $THREECODE{$stop} = "Ter";
287 }
288 4 ▶ $sep ||= '';
Condition100%2/2
$sep ||= ""
l!l
22
MC/DC100%1/1
$sep ||= ""
$sep
Truth table100%2/2
A
A= $sep
Aresult
11
00
289  
290 4 my $aa3s;
291 4 foreach my $aa ( split //, uc $seq->seq ) {
292 87 ▶ $THREECODE{$aa} and $aa3s .= $THREECODE{$aa} . $sep, next;
Branch: 1 branch
BranchTrueFalseTotal
$Bio::SeqUtils::THREECODE{$aa} and $aa3s .= $Bio::SeqUtils::THREECODE{$aa} . $sep, next 87 0 87
293 0 $aa3s .= 'Xaa' . $sep;
294 }
295 4 ▶ $sep and substr( $aa3s, -( length $sep ), length $sep ) = '';
Branch: 1 branch
BranchTrueFalseTotal
$sep and substr($aa3s, -length($sep), length $sep) = "" 2 2 4
296 4 return $aa3s;
297 }
298  
299 =head2 seq3in
300  
301 Title : seq3in
302 Usage : $seq = Bio::SeqUtils->seq3in($seq, 'MetGlyTer')
303 Function: Method for changing of the sequence of a
304 Bio::PrimarySeqI sequence object. The three letter amino
305 acid input string is converted into one letter code. Any
306 unknown character triplet, including the default 'Xaa', is
307 converted into 'X'.
308  
309 Returns : Bio::PrimarySeq object
310 Args : sequence string
311 optional character to be used for stop in the protein sequence,
312 defaults to '*'
313 optional character to be used for unknown in the protein sequence,
314 defaults to 'X'
315  
316 =cut
317  
318 2 ▶sub seq3in {
Subroutine seq3in: called CC=9 SCAR=25.3
Pod documented
319 2 my ( $self, $seq, $string, $stop, $unknown ) = @_;
320  
321 2 ▶ $seq->isa('Bio::PrimarySeqI')
Branch: 1 branch
BranchTrueFalseTotal
$seq->isa("Bio::PrimarySeqI") or $self->throw("Not a Bio::PrimarySeqI object but [$self]") 2 0 2
322 || $self->throw("Not a Bio::PrimarySeqI object but [$self]");
323 2 ▶ $seq->alphabet eq 'protein'
Branch: 1 branch
BranchTrueFalseTotal
$seq->alphabet eq "protein" or $self->throw("Not a protein sequence") 2 0 2
324 || $self->throw('Not a protein sequence');
325  
326 2 ▶ if ( defined $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stop) 0 2 2
327 0 ▶ length $stop != 1
Branch: 1 branch
BranchTrueFalseTotal
length $stop != 1 and $self->throw("One character stop needed, not [$stop]") 0 0 0
328 and $self->throw("One character stop needed, not [$stop]");
329 0 $ONECODE{'Ter'} = $stop;
330 }
331 2 ▶ if ( defined $unknown ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $unknown) 0 2 2
332 0 ▶ length $unknown != 1
Branch: 1 branch
BranchTrueFalseTotal
length $unknown != 1 and $self->throw("One character stop needed, not [$unknown]") 0 0 0
333 and $self->throw("One character stop needed, not [$unknown]");
334 0 $ONECODE{'Xaa'} = $unknown;
335 }
336  
337 2 my ( $aas, $aa3 );
338 2 my $length = ( length $string ) - 2;
339 2 ▶ for ( my $i = 0 ; $i < $length ; $i += 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $length) 31 2 33
340 31 $aa3 = substr( $string, $i, 3 );
341 31 $aa3 = ucfirst( lc($aa3) );
342 31 ▶ $ONECODE{$aa3} and $aas .= $ONECODE{$aa3}, next;
Branch: 1 branch
BranchTrueFalseTotal
$Bio::SeqUtils::ONECODE{$aa3} and $aas .= $Bio::SeqUtils::ONECODE{$aa3}, next 30 1 31
343 1 $aas .= $ONECODE{'Xaa'};
344 }
345 2 $seq->seq($aas);
346 2 return $seq;
347 }
348  
349 =head2 translate_3frames
350  
351 Title : translate_3frames
352 Usage : @prots = Bio::SeqUtils->translate_3frames($seq)
353 Function: Translate a nucleotide sequence in three forward frames.
354 The IDs of the sequences are appended with '-0F', '-1F', '-2F'.
355 Returns : An array of seq objects
356 Args : sequence object
357 same arguments as to Bio::PrimarySeqI::translate
358  
359 =cut
360  
361 3 ▶sub translate_3frames {
Subroutine translate_3frames: called CC=3 SCAR=11.0
Pod documented
362 3 my ( $self, $seq, @args ) = @_;
363  
364 3 ▶ $self->throw( 'Object [$seq] '
Branch: 1 branch
BranchTrueFalseTotal
unless $seq->can("translate") 0 3 3
365 . 'of class ['
366 . ref($seq)
367 . '] can not be translated.' )
368 unless $seq->can('translate');
369  
370 3 my ( $stop, $unknown, $frame, $tableid, $fullCDS, $throw ) = @args;
371 3 my @seqs;
372 3 my $f = 0;
373 3 ▶ while ( $f != 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f != 3) 9 3 12
374 9 my $translation =
375 $seq->translate( $stop, $unknown, $f, $tableid, $fullCDS, $throw );
376 9 $translation->id( $seq->id . "-" . $f . "F" );
377 9 push @seqs, $translation;
378 9 $f++;
379 }
380  
381 3 return @seqs;
382 }
383  
384 =head2 translate_6frames
385  
386 Title : translate_6frames
387 Usage : @prots = Bio::SeqUtils->translate_6frames($seq)
388 Function: translate a nucleotide sequence in all six frames
389 The IDs of the sequences are appended with '-0F', '-1F', '-2F',
390 '-0R', '-1R', '-2R'.
391 Returns : An array of seq objects
392 Args : sequence object
393 same arguments as to Bio::PrimarySeqI::translate
394  
395 =cut
396  
397 1 ▶sub translate_6frames {
Subroutine translate_6frames: called CC=2 SCAR=6.9
Pod documented
398 1 my ( $self, $seq, @args ) = @_;
399  
400 1 my @seqs = $self->translate_3frames( $seq, @args );
401 1 my @seqs2 = $self->translate_3frames( $seq->revcom, @args );
402 1 foreach my $seq2 (@seqs2) {
403 3 my ($tmp) = $seq2->id;
404 3 $tmp =~ s/F$/R/g;
405 3 $seq2->id($tmp);
406 }
407 1 return @seqs, @seqs2;
408 }
409  
410 =head2 valid_aa
411  
412 Title : valid_aa
413 Usage : my @aa = $table->valid_aa
414 Function: Retrieves a list of the valid amino acid codes.
415 The list is ordered so that first 21 codes are for unique
416 amino acids. The rest are ['B', 'Z', 'X', '*'].
417 Returns : array of all the valid amino acid codes
418 Args : [optional] $code => [0 -> return list of 1 letter aa codes,
419 1 -> return list of 3 letter aa codes,
420 2 -> return associative array of both ]
421  
422 =cut
423  
424 689 ▶sub valid_aa {
Subroutine valid_aa: called CC=9 SCAR=22.1
Pod documented
425 689 my ( $self, $code ) = @_;
426  
427 689 ▶ if ( !$code ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $code) { } 344 345 689
elsif ($code == 1) { } 1 344 345
elsif ($code == 2) { } 344 0 344
428 344 my @codes;
429 344 foreach my $c ( sort values %ONECODE ) {
430 9288 ▶ push @codes, $c unless ( $c =~ /[BZX\*]/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $c =~ /[BZX\*]/ 7912 1376 9288
431 }
432 344 push @codes, qw(B Z X *); # so they are in correct order ?
433 344 return @codes;
434 }
435 elsif ( $code == 1 ) {
436 1 my @codes;
437 1 foreach my $c ( sort keys %ONECODE ) {
438 27 ▶ push @codes, $c unless ( $c =~ /(Asx|Glx|Xaa|Ter)/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $c =~ /(Asx|Glx|Xaa|Ter)/ 23 4 27
439 }
440 1 push @codes, ( 'Asx', 'Glx', 'Xaa', 'Ter' );
441 1 return @codes;
442 }
443 elsif ( $code == 2 ) {
444 344 my %codes = %ONECODE;
445 344 foreach my $c ( keys %ONECODE ) {
446 9288 my $aa = $ONECODE{$c};
447 9288 $codes{$aa} = $c;
448 }
449 344 return %codes;
450 }
451 else {
452 0 $self->warn(
453 "unrecognized code in " . ref($self) . " method valid_aa()" );
454 0 return ();
455 }
456 }
457  
458 =head2 mutate
459  
460 Title : mutate
461 Usage : Bio::SeqUtils->mutate($seq,$mutation1, $mutation2);
462 Function: Inplace editing of the sequence.
463  
464 The second argument can be a Bio::LiveSeq::Mutation object
465 or an array of them. The mutations are applied sequentially
466 checking only that their position is within the current
467 sequence. Insertions are inserted before the given
468 position.
469  
470 Returns : boolean
471 Args : sequence object
472 mutation, a Bio::LiveSeq::Mutation object, or an array of them
473  
474 See L<Bio::LiveSeq::Mutation>.
475  
476 =cut
477  
478 0 ▶sub mutate {
Subroutine mutate: not called CC=5 SCAR=34.0
Pod documented
479 0 my ( $self, $seq, @mutations ) = @_;
480  
481 0 ▶ $self->throw( 'Object [$seq] '
Branch: 1 branch
BranchTrueFalseTotal
unless $seq->isa("Bio::PrimarySeqI") 0 0 0
482 . 'of class ['
483 . ref($seq)
484 . '] should be a Bio::PrimarySeqI ' )
485 unless $seq->isa('Bio::PrimarySeqI');
486 0 ▶ $self->throw( 'Object [$mutations[0]] '
Branch: 1 branch
BranchTrueFalseTotal
unless $mutations[0]->isa("Bio::LiveSeq::Mutation") 0 0 0
487 . 'of class ['
488 . ref( $mutations[0] )
489 . '] should be a Bio::LiveSeq::Mutation' )
490 unless $mutations[0]->isa('Bio::LiveSeq::Mutation');
491  
492 0 foreach my $mutation (@mutations) {
493 0 ▶ $self->throw('Attempting to mutate sequence beyond its length')
Branch: 1 branch
BranchTrueFalseTotal
unless $mutation->pos - 1 <= $seq->length 0 0 0
494 unless $mutation->pos - 1 <= $seq->length;
495  
496 0 my $string = $seq->seq;
497 0 substr $string, $mutation->pos - 1, $mutation->len, $mutation->seq;
498 0 $seq->seq($string);
499 }
500 0 1;
501 }
502  
503 =head2 cat
504  
505 Title : cat
506 Usage : Bio::SeqUtils->cat(@seqs);
507 my $catseq=$seqs[0];
508 Function: Concatenates a list of Bio::Seq objects, adding them all on to the
509 end of the first sequence. Annotations and sequence features are
510 copied over from any additional objects, and the coordinates of any
511 copied features are adjusted appropriately.
512 Returns : a boolean
513 Args : array of sequence objects
514  
515 Note that annotations have no sequence locations. If you concatenate
516 sequences with the same annotations they will all be added.
517  
518 =cut
519  
520 3 ▶sub cat {
Subroutine cat: called CC=12 SCAR=25.3
Pod documented
521 3 my ( $self, $seq, @seqs ) = @_;
522 3 ▶ $self->throw( 'Object [$seq] '
Branch: 1 branch
BranchTrueFalseTotal
unless $seq->isa("Bio::PrimarySeqI") 0 3 3
523 . 'of class ['
524 . ref($seq)
525 . '] should be a Bio::PrimarySeqI ' )
526 unless $seq->isa('Bio::PrimarySeqI');
527  
528 3 for my $catseq (@seqs) {
529 4 ▶ $self->throw( 'Object [$catseq] '
Branch: 1 branch
BranchTrueFalseTotal
unless $catseq->isa("Bio::PrimarySeqI") 0 4 4
530 . 'of class ['
531 . ref($catseq)
532 . '] should be a Bio::PrimarySeqI ' )
533 unless $catseq->isa('Bio::PrimarySeqI');
534  
535 4 ▶ $self->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $catseq->alphabet eq $seq->alphabet 0 4 4
536 'Trying to concatenate sequences with different alphabets: '
537 . $seq->display_id . '('
538 . $seq->alphabet
539 . ') and '
540 . $catseq->display_id . '('
541 . $catseq->alphabet
542 . ')' )
543 unless $catseq->alphabet eq $seq->alphabet;
544  
545 4 my $length = $seq->length;
546 4 $seq->seq( $seq->seq . $catseq->seq );
547  
548 # move annotations
549 4 ▶ if ( $seq->isa("Bio::AnnotatableI")
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->isa("Bio::AnnotatableI") and $catseq->isa("Bio::AnnotatableI")) 3 1 4
Condition66%2/3
$seq->isa("Bio::AnnotatableI") and $catseq->isa("Bio::AnnotatableI")
!ll&&!rl&&r
103
MC/DC50%1/2
$seq->isa("Bio::AnnotatableI") and $catseq->isa("Bio::AnnotatableI")
$seq->isa("Bio::AnnotatableI") $catseq->isa("Bio::AnnotatableI")
Truth table66%2/3
A and B
A= $seq->isa("Bio::AnnotatableI")B= $catseq->isa("Bio::AnnotatableI")
ABresult
0X0
100
111
550 and $catseq->isa("Bio::AnnotatableI") )
551 {
552 3 foreach my $key ( $catseq->annotation->get_all_annotation_keys() ) {
553  
554 3 foreach my $value ( $catseq->annotation->get_Annotations($key) )
555 {
556 5 $seq->annotation->add_Annotation( $key, $value );
557 }
558 }
559 }
560  
561 # move SeqFeatures
562 4 ▶ if ( $seq->isa('Bio::SeqI') and $catseq->isa('Bio::SeqI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->isa("Bio::SeqI") and $catseq->isa("Bio::SeqI")) 3 1 4
Condition66%2/3
$seq->isa("Bio::SeqI") and $catseq->isa("Bio::SeqI")
!ll&&!rl&&r
103
MC/DC50%1/2
$seq->isa("Bio::SeqI") and $catseq->isa("Bio::SeqI")
$seq->isa("Bio::SeqI") $catseq->isa("Bio::SeqI")
Truth table66%2/3
A and B
A= $seq->isa("Bio::SeqI")B= $catseq->isa("Bio::SeqI")
ABresult
0X0
100
111
563 3 for my $feat ( $catseq->get_SeqFeatures ) {
564 2 $seq->add_SeqFeature( $self->_coord_adjust( $feat, $length ) );
565 }
566 }
567  
568 }
569 3 1;
570 }
571  
572 =head2 trunc_with_features
573  
574 Title : trunc_with_features
575 Usage : $trunc=Bio::SeqUtils->trunc_with_features($seq, $start, $end);
576 Function: Like Bio::Seq::trunc, but keeps features (adjusting coordinates
577 where necessary. Features that partially overlap the region have
578 their location changed to a Bio::Location::Fuzzy.
579 Returns : A new sequence object
580 Args : A sequence object, start coordinate, end coordinate (inclusive)
581  
582  
583 =cut
584  
585 0 ▶sub trunc_with_features {
Subroutine trunc_with_features: not called CC=6 SCAR=33.4
Pod documented
586 344 ▶ use Bio::Range;
Subroutine BEGIN: called CC=1 SCAR=0.0
587 0 my ( $self, $seq, $start, $end ) = @_;
588 0 ▶ $self->throw( 'Object [$seq] '
Branch: 1 branch
BranchTrueFalseTotal
unless $seq->isa("Bio::SeqI") 0 0 0
589 . 'of class ['
590 . ref($seq)
591 . '] should be a Bio::SeqI ' )
592 unless $seq->isa('Bio::SeqI');
593 0 my $trunc = $seq->trunc( $start, $end );
594 0 my $truncrange =
595 Bio::Range->new( -start => $start, -end => $end, -strand => 0 );
596  
597 # make sure that there is no annotation or features in $trunc
598 # (->trunc() now clone objects except for Bio::Seq::LargePrimarySeq)
599 0 $trunc->annotation->remove_Annotations;
600 0 $trunc->remove_SeqFeatures;
601  
602 # move annotations
603 0 foreach my $key ( $seq->annotation->get_all_annotation_keys() ) {
604 0 foreach my $value ( $seq->annotation->get_Annotations($key) ) {
605 0 $trunc->annotation->add_Annotation( $key, $value );
606 }
607 }
608  
609 # move features
610 0 foreach (
611 grep {
612 0 ▶ $_ = $self->_coord_adjust( $_, 1 - $start, $end + 1 - $start )
Branch: 1 branch
BranchTrueFalseTotal
if $_->overlaps($truncrange) 0 0 0
613 if $_->overlaps($truncrange)
614 } $seq->get_SeqFeatures
615 )
616 {
617 0 $trunc->add_SeqFeature($_);
618 }
619 0 return $trunc;
620 }
621  
622 =head2 delete
623
624 Title : delete
625 Function: cuts a segment out of a sequence and re-joins the left and right fragments
626 (like splicing or digesting and re-ligating a molecule).
627 Positions (and types) of sequence features are adjusted accordingly:
628 Features that span the cut site are converted to split featuress to
629 indicate the disruption.
630 Features that extend into the cut-out fragment are truncated.
631 A new molecule is created and returned.
632 Usage : my $cutseq = Bio::SeqUtils::PbrTools->cut( $seq, 1000, 1100 );
633 Args : a Bio::PrimarySeqI compliant object to cut,
634 first nt of the segment to be deleted
635 last nt of the segment to be deleted
636 optional:
637 hash-ref of options:
638 clone_obj: if true, clone the input sequence object rather
639 than calling "new" on the object's class
640  
641 Returns : a new Bio::Seq object
642  
643 =cut
644  
645 0 ▶sub delete {
Subroutine delete: not called CC=14 SCAR=53.5
Pod documented
646 0 my $self = shift;
647 0 my ( $seq, $left, $right, $opts_ref ) = @_;
648 0 ▶ $self->throw( 'was expecting 3-4 paramters but got ' . @_ )
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 or @_ == 4 0 0 0
Condition0%0/3
@_ == 3 or @_ == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 3 or @_ == 4
@_ == 3 @_ == 4
Truth table0%0/3
A or B
A= @_ == 3B= @_ == 4
ABresult
1X1
011
000
649 unless @_ == 3 || @_ == 4;
650  
651 0 ▶ $self->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($seq) and $seq->isa("Bio::PrimarySeqI") 0 0 0
Condition0%0/3
builtin::blessed($seq) and $seq->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($seq) and $seq->isa("Bio::PrimarySeqI")
builtin::blessed($seq) $seq->isa("Bio::PrimarySeqI")
Truth table0%0/3
A and B
A= builtin::blessed($seq)B= $seq->isa("Bio::PrimarySeqI")
ABresult
0X0
100
111
652 'Object of class [' . ref($seq) . '] should be a Bio::PrimarySeqI ' )
653 unless blessed($seq) && $seq->isa('Bio::PrimarySeqI');
654  
655 0 ▶ $self->throw("Left coordinate ($left) must be >= 1") if $left < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $left < 1 0 0 0
656 0 ▶ if ( $right > $seq->length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($right > $seq->length) 0 0 0
657 0 $self->throw( "Right coordinate ($right) must be less than "
658 . 'sequence length ('
659 . $seq->length
660 . ')' );
661 }
662  
663 # piece together the sequence string of the remaining fragments
664 0 my $left_seq = $seq->subseq( 1, $left - 1 );
665 0 my $right_seq = $seq->subseq( $right + 1, $seq->length );
666 0 ▶ if ( !$left_seq || !$right_seq ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($left_seq and $right_seq) 0 0 0
Condition0%0/3
$left_seq and $right_seq
!ll&&!rl&&r
000
MC/DC0%0/2
$left_seq and $right_seq
$left_seq $right_seq
Truth table0%0/3
A and B
A= $left_seqB= $right_seq
ABresult
0X0
100
111
667 0 $self->throw(
668 'could not assemble sequences. At least one of the fragments is empty'
669 );
670 }
671 0 my $seq_str = $left_seq . $right_seq;
672  
673 # create the new seq object with the same class as the recipient
674 # or (if requested), make a clone of the existing object. In the
675 # latter case we need to remove sequence features from the cloned
676 # object instead of copying them
677 0 my $product;
678 0 ▶ if ( $opts_ref->{clone_obj} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts_ref->{'clone_obj'}) { } 0 0 0
679 0 $product = $self->_new_seq_via_clone( $seq, $seq_str );
680 }
681 else {
682 0 $product = $self->_new_seq_from_old( $seq, { seq => $seq_str } );
683 }
684  
685 # move sequence features
686 0 ▶ if ( $product->isa('Bio::SeqI') && $seq->isa('Bio::SeqI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($product->isa("Bio::SeqI") and $seq->isa("Bio::SeqI")) 0 0 0
Condition0%0/3
$product->isa("Bio::SeqI") and $seq->isa("Bio::SeqI")
!ll&&!rl&&r
000
MC/DC0%0/2
$product->isa("Bio::SeqI") and $seq->isa("Bio::SeqI")
$product->isa("Bio::SeqI") $seq->isa("Bio::SeqI")
Truth table0%0/3
A and B
A= $product->isa("Bio::SeqI")B= $seq->isa("Bio::SeqI")
ABresult
0X0
100
111
687 0 for my $feat ( $seq->get_SeqFeatures ) {
688 0 my $adjfeat = $self->_coord_adjust_deletion( $feat, $left, $right );
689 0 ▶ $product->add_SeqFeature($adjfeat) if $adjfeat;
Branch: 1 branch
BranchTrueFalseTotal
if $adjfeat 0 0 0
690 }
691 }
692  
693 # add a feature to annotatde the deletion
694 0 my $deletion_feature = Bio::SeqFeature::Generic->new(
695 -primary_tag => 'misc_feature',
696 -tag => { note => 'deletion of ' . ( $right - $left + 1 ) . 'bp' },
697 -location => Bio::Location::Simple->new(
698 -start => $left - 1,
699 -end => $left,
700 -location_type => 'IN-BETWEEN'
701 )
702 );
703 0 $product->add_SeqFeature($deletion_feature);
704 0 return $product;
705 }
706  
707 =head2 insert
708
709 Title : insert
710 Function: inserts a fragment (a Bio::Seq object) into a nother sequence object
711 adding all annotations and features to the final product.
712 Features that span the insertion site are converted to split
713 features to indicate the disruption.
714 A new feature is added to indicate the inserted fragment itself.
715 A new molecule is created and returned.
716 Usage : # insert a fragment after pos 1000
717 my $insert_seq = Bio::SeqUtils::PbrTools->insert(
718 $recipient_seq,
719 $fragment_seq,
720 1000
721 );
722 Args : recipient sequence (a Bio::PrimarySeqI compliant object),
723 a fragmetn to insert (Bio::PrimarySeqI compliant object),
724 insertion position (fragment is inserted to the right of this pos)
725 pos=0 will prepend the fragment to the recipient
726 optional:
727 hash-ref of options:
728 clone_obj: if true, clone the input sequence object rather
729 than calling "new" on the object's class
730 Returns : a new Bio::Seq object
731  
732 =cut
733  
734 0 ▶sub insert {
Subroutine insert: not called CC=32 SCAR=69.6
Pod documented
735 0 my $self = shift;
736 0 my ( $recipient, $fragment, $insert_pos, $opts_ref ) = @_;
737 0 ▶ $self->throw( 'was expecting 3-4 paramters but got ' . @_ )
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 or @_ == 4 0 0 0
Condition0%0/3
@_ == 3 or @_ == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 3 or @_ == 4
@_ == 3 @_ == 4
Truth table0%0/3
A or B
A= @_ == 3B= @_ == 4
ABresult
1X1
011
000
738 unless @_ == 3 || @_ == 4;
739  
740 0 ▶ $self->throw( 'Recipient object of class ['
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($recipient) and $recipient->isa("Bio::PrimarySeqI") 0 0 0
Condition0%0/3
builtin::blessed($recipient) and $recipient->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($recipient) and $recipient->isa("Bio::PrimarySeqI")
builtin::blessed($recipient) $recipient->isa("Bio::PrimarySeqI")
Truth table0%0/3
A and B
A= builtin::blessed($recipient)B= $recipient->isa("Bio::PrimarySeqI")
ABresult
0X0
100
111
741 . ref($recipient)
742 . '] should be a Bio::PrimarySeqI ' )
743 unless blessed($recipient) && $recipient->isa('Bio::PrimarySeqI');
744  
745 0 ▶ $self->throw( 'Fragment object of class ['
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($fragment) and $fragment->isa("Bio::PrimarySeqI") 0 0 0
Condition0%0/3
builtin::blessed($fragment) and $fragment->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($fragment) and $fragment->isa("Bio::PrimarySeqI")
builtin::blessed($fragment) $fragment->isa("Bio::PrimarySeqI")
Truth table0%0/3
A and B
A= builtin::blessed($fragment)B= $fragment->isa("Bio::PrimarySeqI")
ABresult
0X0
100
111
746 . ref($fragment)
747 . '] should be a Bio::PrimarySeqI ' )
748 unless blessed($fragment) && $fragment->isa('Bio::PrimarySeqI');
749  
750 0 ▶ $self->throw( 'Can\'t concatenate sequences with different alphabets: '
Branch: 1 branch
BranchTrueFalseTotal
unless $recipient->alphabet eq $fragment->alphabet 0 0 0
751 . 'recipient is '
752 . $recipient->alphabet
753 . ' and fragment is '
754 . $fragment->alphabet )
755 unless $recipient->alphabet eq $fragment->alphabet;
756  
757 0 ▶ if ( $insert_pos < 0 or $insert_pos > $recipient->length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($insert_pos < 0 or $insert_pos > $recipient->length) 0 0 0
Condition0%0/3
$insert_pos < 0 or $insert_pos > $recipient->length
l!l&&r!l&&!r
000
MC/DC0%0/2
$insert_pos < 0 or $insert_pos > $recipient->length
$insert_pos < 0 $insert_pos > $recipient->length
Truth table0%0/3
A or B
A= $insert_pos < 0B= $insert_pos > $recipient->length
ABresult
1X1
011
000
758 0 $self->throw( "insertion position ($insert_pos) must be between 0 and "
759 . 'recipient sequence length ('
760 . $recipient->length
761 . ')' );
762 }
763  
764 0 ▶ if ( $fragment->can('is_circular') && $fragment->is_circular ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fragment->can("is_circular") and $fragment->is_circular) 0 0 0
Condition0%0/3
$fragment->can("is_circular") and $fragment->is_circular
!ll&&!rl&&r
000
MC/DC0%0/2
$fragment->can("is_circular") and $fragment->is_circular
$fragment->can("is_circular") $fragment->is_circular
Truth table0%0/3
A and B
A= $fragment->can("is_circular")B= $fragment->is_circular
ABresult
0X0
100
111
765 0 $self->throw('Can\'t insert circular fragments');
766 }
767  
768 0 ▶ if ( !$recipient->seq ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($recipient->seq) 0 0 0
769 0 $self->throw(
770 'Recipient has no sequence, can not insert into this object');
771 }
772  
773 # construct raw sequence of the new molecule
774 0 ▶ my $left_seq =
Branch: 1 branch
BranchTrueFalseTotal
$insert_pos > 0 ? : 0 0 0
775 $insert_pos > 0
776 ? $recipient->subseq( 1, $insert_pos )
777 : '';
778 0 my $mid_seq = $fragment->seq;
779 0 ▶ my $right_seq =
Branch: 1 branch
BranchTrueFalseTotal
$insert_pos < $recipient->length ? : 0 0 0
780 $insert_pos < $recipient->length
781 ? $recipient->subseq( $insert_pos + 1, $recipient->length )
782 : '';
783 0 my $seq_str = $left_seq . $mid_seq . $right_seq;
784  
785 # create the new seq object with the same class as the recipient
786 # or (if requested), make a clone of the existing object. In the
787 # latter case we need to remove sequence features from the cloned
788 # object instead of copying them
789 0 my $product;
790 0 ▶ if ( $opts_ref->{clone_obj} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts_ref->{'clone_obj'}) { } 0 0 0
791 0 $product = $self->_new_seq_via_clone( $recipient, $seq_str );
792 }
793 else {
794 0 my @desc;
795 0 ▶ push @desc, 'Inserted fragment: ' . $fragment->desc
Branch: 1 branch
BranchTrueFalseTotal
if defined $fragment->desc 0 0 0
796 if defined $fragment->desc;
797 0 ▶ push @desc, 'Recipient: ' . $recipient->desc
Branch: 1 branch
BranchTrueFalseTotal
if defined $recipient->desc 0 0 0
798 if defined $recipient->desc;
799 0 ▶ $product = $self->_new_seq_from_old(
Condition0%0/7
$recipient->accession_number || ''
l!l
00
$recipient->verbose || $fragment->verbose
l!l&&r!l&&!r
000
$recipient->is_circular || 0
l!l
00
MC/DC0%0/1
$recipient->accession_number || ''
$recipient->accession_number
MC/DC0%0/2
$recipient->verbose || $fragment->verbose
$recipient->verbose $fragment->verbose
MC/DC0%0/1
$recipient->is_circular || 0
$recipient->is_circular
Truth table0%0/2
A
A= $recipient->accession_number
Aresult
11
00
Truth table0%0/3
A || B
A= $recipient->verboseB= $fragment->verbose
ABresult
1X1
011
000
Truth table0%0/2
A
A= $recipient->is_circular
Aresult
11
00
800 $recipient,
801 {
802 seq => $seq_str,
803 display_id => $recipient->display_id,
804 accession_number => $recipient->accession_number || '',
805 alphabet => $recipient->alphabet,
806 desc => join( '; ', @desc ),
807 verbose => $recipient->verbose || $fragment->verbose,
808 is_circular => $recipient->is_circular || 0,
809 }
810 );
811  
812 } # if clone_obj
813  
814 # move annotations from fragment to product
815 0 ▶ if ( $product->isa("Bio::AnnotatableI")
Branch: 1 branch
BranchTrueFalseTotal
if ($product->isa("Bio::AnnotatableI") and $fragment->isa("Bio::AnnotatableI")) 0 0 0
Condition0%0/3
$product->isa("Bio::AnnotatableI") and $fragment->isa("Bio::AnnotatableI")
!ll&&!rl&&r
000
MC/DC0%0/2
$product->isa("Bio::AnnotatableI") and $fragment->isa("Bio::AnnotatableI")
$product->isa("Bio::AnnotatableI") $fragment->isa("Bio::AnnotatableI")
Truth table0%0/3
A and B
A= $product->isa("Bio::AnnotatableI")B= $fragment->isa("Bio::AnnotatableI")
ABresult
0X0
100
111
816 && $fragment->isa("Bio::AnnotatableI") )
817 {
818 0 foreach my $key ( $fragment->annotation->get_all_annotation_keys ) {
819 0 foreach my $value ( $fragment->annotation->get_Annotations($key) ) {
820 0 $product->annotation->add_Annotation( $key, $value );
821 }
822 }
823 }
824  
825 # move sequence features to product with adjusted coordinates
826 0 ▶ if ( $product->isa('Bio::SeqI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($product->isa("Bio::SeqI")) 0 0 0
827  
828 # for the fragment, just shift the features to new position
829 0 ▶ if ( $fragment->isa('Bio::SeqI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fragment->isa("Bio::SeqI")) 0 0 0
830 0 for my $feat ( $fragment->get_SeqFeatures ) {
831 0 my $adjfeat = $self->_coord_adjust( $feat, $insert_pos );
832 0 ▶ $product->add_SeqFeature($adjfeat) if $adjfeat;
Branch: 1 branch
BranchTrueFalseTotal
if $adjfeat 0 0 0
833 }
834 }
835  
836 # for recipient, shift and modify features according to insertion.
837 0 ▶ if ( $recipient->isa('Bio::SeqI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipient->isa("Bio::SeqI")) 0 0 0
838 0 for my $feat ( $recipient->get_SeqFeatures ) {
839 0 my $adjfeat =
840 $self->_coord_adjust_insertion( $feat, $insert_pos,
841 $fragment->length );
842 0 ▶ $product->add_SeqFeature($adjfeat) if $adjfeat;
Branch: 1 branch
BranchTrueFalseTotal
if $adjfeat 0 0 0
843 }
844 }
845 }
846  
847 # add a feature to annotate the insertion
848 0 my $insertion_feature = Bio::SeqFeature::Generic->new(
849 -start => $insert_pos + 1,
850 -end => $insert_pos + $fragment->length,
851 -primary_tag => 'misc_feature',
852 -tag => { note => 'inserted fragment' },
853 );
854 0 $product->add_SeqFeature($insertion_feature);
855  
856 0 return $product;
857 }
858  
859 =head2 ligate
860
861 title : ligate
862 function: pastes a fragment (which can also have features) into a recipient
863 sequence between two "cut" sites, preserving features and adjusting
864 their locations.
865 This is a shortcut for deleting a segment from a sequence object followed
866 by an insertion of a fragmnet and is supposed to be used to simulate
867 in-vitro cloning where a recipient (a vector) is digested and a fragment
868 is then ligated into the recipient molecule. The fragment can be flipped
869 (reverse-complemented with all its features).
870 A new sequence object is returned to represent the product of the reaction.
871 Features and annotations are transferred from the insert to the product
872 and features on the recipient are adjusted according to the methods
873 L</"delete"> amd L</"insert">:
874 Features spanning the insertion site will be split up into two sub-locations.
875 (Sub-)features in the deleted region are themselves deleted.
876 (Sub-)features that extend into the deleted region are truncated.
877 The class of the product object depends on the class of the recipient (vector)
878 sequence object. if it is not possible to instantiate a new
879 object of that class, a Bio::Primaryseq object is created instead.
880 usage : # insert the flipped fragment between positions 1000 and 1100 of the
881 # vector, i.e. everything between these two positions is deleted and
882 # replaced by the fragment
883 my $new_molecule = Bio::Sequtils::Pbrtools->ligate(
884 -recipient => $vector,
885 -fragment => $fragment,
886 -left => 1000,
887 -right => 1100,
888 -flip => 1,
889 -clone_obj => 1
890 );
891 args : recipient: the recipient/vector molecule
892 fragment: molecule that is to be ligated into the vector
893 left: left cut site (fragment will be inserted to the right of
894 this position)
895 optional:
896 right: right cut site (fragment will be inseterted to the
897 left of this position). defaults to left+1
898 flip: boolean, if true, the fragment is reverse-complemented
899 (including features) before inserting
900 clone_obj: if true, clone the recipient object to create the product
901 instead of calling "new" on its class
902 returns : a new Bio::Seq object of the ligated fragments
903  
904 =cut
905  
906 0 ▶sub ligate {
Subroutine ligate: not called CC=12 SCAR=50.5
Pod documented
907 0 my $self = shift;
908 0 my ( $recipient, $fragment, $left, $right, $flip, $clone_obj ) =
909 $self->_rearrange( [qw(RECIPIENT FRAGMENT LEFT RIGHT FLIP CLONE_OBJ )],
910 @_ );
911 0 ▶ $self->throw("missing required parameter 'recipient'") unless $recipient;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipient 0 0 0
912 0 ▶ $self->throw("missing required parameter 'fragment'") unless $fragment;
Branch: 1 branch
BranchTrueFalseTotal
unless $fragment 0 0 0
913 0 ▶ $self->throw("missing required parameter 'left'") unless defined $left;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $left 0 0 0
914  
915 0 ▶ $right ||= $left + 1;
Condition0%0/3
$right ||= $left + 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$right ||= $left + 1
$right $left + 1
Truth table0%0/3
A ||= B
A= $rightB= $left + 1
ABresult
1X1
011
000
916  
917 0 ▶ $self->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($fragment) and $fragment->isa("Bio::PrimarySeqI") 0 0 0
Condition0%0/3
builtin::blessed($fragment) and $fragment->isa("Bio::PrimarySeqI")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($fragment) and $fragment->isa("Bio::PrimarySeqI")
builtin::blessed($fragment) $fragment->isa("Bio::PrimarySeqI")
Truth table0%0/3
A and B
A= builtin::blessed($fragment)B= $fragment->isa("Bio::PrimarySeqI")
ABresult
0X0
100
111
918 "Fragment must be a Bio::PrimarySeqI compliant object but it is a "
919 . ref($fragment) )
920 unless blessed($fragment) && $fragment->isa('Bio::PrimarySeqI');
921  
922 0 ▶ $fragment = $self->revcom_with_features($fragment) if $flip;
Branch: 1 branch
BranchTrueFalseTotal
if $flip 0 0 0
923  
924 0 my $opts_ref = {};
925 0 ▶ $opts_ref->{clone_obj} = 1 if $clone_obj;
Branch: 1 branch
BranchTrueFalseTotal
if $clone_obj 0 0 0
926  
927 # clone in two steps: first delete between the insertion sites,
928 # then insert the fragment. Step 1 is skipped if insert positions
929 # are adjacent (no deletion)
930 0 my ( $product1, $product2 );
931 0 eval {
932 0 ▶ if ( $right == $left + 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($right == $left + 1) { } 0 0 0
933 0 $product1 = $recipient;
934 }
935 else {
936 0 $product1 =
937 $self->delete( $recipient, $left + 1, $right - 1, $opts_ref );
938 }
939 };
940 0 ▶ $self->throw( "Failed in step 1 (cut recipient): " . $@ ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
941 0 eval { $product2 = $self->insert( $product1, $fragment, $left, $opts_ref ) };
942 0 ▶ $self->throw( "Failed in step 2 (insert fragment): " . $@ ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
943  
944 0 return $product2;
945  
946 }
947  
948 =head2 _coord_adjust_deletion
949
950 title : _coord_adjust_deletion
951 function: recursively adjusts coordinates of seqfeatures on a molecule
952 where a segment has been deleted.
953 (sub)features that span the deletion site become split features.
954 (sub)features that extend into the deletion site are truncated.
955 A note is added to the feature to inform about the size and
956 position of the deletion.
957 usage : my $adjusted_feature = Bio::Sequtils::_coord_adjust_deletion(
958 $feature,
959 $start,
960 $end
961 );
962 args : a Bio::SeqFeatureI compliant object,
963 start (inclusive) position of the deletion site,
964 end (inclusive) position of the deletion site
965 returns : a Bio::SeqFeatureI compliant object
966  
967 =cut
968  
969 0 ▶sub _coord_adjust_deletion {
Subroutine _coord_adjust_deletion: not called CC=31 SCAR=69.0
970 0 my ( $self, $feat, $left, $right ) = @_;
971  
972 0 ▶ $self->throw( 'object [$feat] '
Branch: 1 branch
BranchTrueFalseTotal
unless $feat->isa("Bio::SeqFeatureI") 0 0 0
973 . 'of class ['
974 . ref($feat)
975 . '] should be a Bio::SeqFeatureI ' )
976 unless $feat->isa('Bio::SeqFeatureI');
977 0 ▶ $self->throw('missing coordinates: need a left and a right position')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $left and defined $right 0 0 0
Condition0%0/3
defined $left and defined $right
!ll&&!rl&&r
000
MC/DC0%0/2
defined $left and defined $right
defined $left defined $right
Truth table0%0/3
A and B
A= defined $leftB= defined $right
ABresult
0X0
100
111
978 unless defined $left && defined $right;
979  
980 0 ▶ if ( $left > $right ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left > $right) 0 0 0
981 0 ▶ if ( $feat->can('is_circular') && $feat->is_circular ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feat->can('is_circular') and $feat->is_circular) { } 0 0 0
Condition0%0/3
$feat->can("is_circular") and $feat->is_circular
!ll&&!rl&&r
000
MC/DC0%0/2
$feat->can("is_circular") and $feat->is_circular
$feat->can("is_circular") $feat->is_circular
Truth table0%0/3
A and B
A= $feat->can("is_circular")B= $feat->is_circular
ABresult
0X0
100
111
982  
983 # todo handle circular molecules
984 0 $self->throw(
985 'can not yet handle deletions in circular molecules if deletion spans origin'
986 );
987 }
988 else {
989 0 $self->throw(
990 "left coordinate ($left) must be less than right ($right)"
991 . " but it was greater" );
992 }
993 }
994 0 my $deletion = Bio::Location::Simple->new(
995 -start => $left,
996 -end => $right,
997 );
998 0 my $del_length = $right - $left + 1;
999  
1000 0 my @adjsubfeat;
1001 0 for my $subfeat ( $feat->get_SeqFeatures ) {
1002 0 my $adjsubfeat =
1003 $self->_coord_adjust_deletion( $subfeat, $left, $right );
1004 0 ▶ push @adjsubfeat, $adjsubfeat if $adjsubfeat;
Branch: 1 branch
BranchTrueFalseTotal
if $adjsubfeat 0 0 0
1005 }
1006  
1007 0 my @loc;
1008 my $note;
1009 0 for ( $feat->location->each_Location ) {
1010 0 ▶ next if $deletion->contains($_); # this location will be deleted;
Branch: 1 branch
BranchTrueFalseTotal
if $deletion->contains($_) 0 0 0
1011 0 my $strand = $_->strand;
1012 0 my $type = $_->location_type;
1013 0 my $start = $_->start;
1014 0 ▶ my $start_type = $_->can('start_pos_type') ? $_->start_pos_type : undef;
Branch: 1 branch
BranchTrueFalseTotal
$_->can('start_pos_type') ? : 0 0 0
1015 0 my $end = $_->end;
1016 0 ▶ my $end_type = $_->can('end_pos_type') ? $_->end_pos_type : undef;
Branch: 1 branch
BranchTrueFalseTotal
$_->can('end_pos_type') ? : 0 0 0
1017 0 my @newcoords = ();
1018 0 ▶ if ( $start < $deletion->start && $end > $deletion->end )
Branch: 4 branches
BranchTrueFalseTotal
if ($start < $deletion->start and $end > $deletion->end) { } 0 0 0
elsif ($_->start < $deletion->start and $_->end >= $deletion->start) { } 0 0 0
elsif ($_->start <= $deletion->end and $_->end > $deletion->end) { } 0 0 0
elsif ($start >= $deletion->end) { } 0 0 0
Condition0%0/3
$start < $deletion->start and $end > $deletion->end
!ll&&!rl&&r
000
MC/DC0%0/2
$start < $deletion->start and $end > $deletion->end
$start < $deletion->start $end > $deletion->end
Truth table0%0/3
A and B
A= $start < $deletion->startB= $end > $deletion->end
ABresult
0X0
100
111
1019 { # split the feature
1020 0 @newcoords = (
1021 [ $start, ( $deletion->start - 1 ), $start_type, $end_type ],
1022 [
1023 ( $deletion->start ), $end - $del_length,
1024 $start_type, $end_type
1025 ]
1026 );
1027 0 $note =
1028 $del_length
1029 . 'bp internal deletion between pos '
1030 . ( $deletion->start - 1 ) . ' and '
1031 . $deletion->start;
1032 }
1033 ▶ elsif ( $_->start < $deletion->start && $_->end >= $deletion->start )
Condition0%0/3
$_->start < $deletion->start and $_->end >= $deletion->start
!ll&&!rl&&r
000
MC/DC0%0/2
$_->start < $deletion->start and $_->end >= $deletion->start
$_->start < $deletion->start $_->end >= $deletion->start
Truth table0%0/3
A and B
A= $_->start < $deletion->startB= $_->end >= $deletion->start
ABresult
0X0
100
111
1034 { # truncate feature end
1035 0 @newcoords =
1036 ( [ $start, ( $deletion->start - 1 ), $start_type, $end_type ] );
1037 0 $note =
1038 ( $end - $deletion->start + 1 ) . 'bp deleted from feature ';
1039 0 ▶ if ( $feat->strand ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feat->strand) 0 0 0
1040 0 ▶ $note .= $feat->strand == 1 ? "3' " : "5' ";
Branch: 1 branch
BranchTrueFalseTotal
$feat->strand == 1 ? : 0 0 0
1041 }
1042 0 $note .= 'end';
1043 }
1044 ▶ elsif ( $_->start <= $deletion->end && $_->end > $deletion->end )
Condition0%0/3
$_->start <= $deletion->end and $_->end > $deletion->end
!ll&&!rl&&r
000
MC/DC0%0/2
$_->start <= $deletion->end and $_->end > $deletion->end
$_->start <= $deletion->end $_->end > $deletion->end
Truth table0%0/3
A and B
A= $_->start <= $deletion->endB= $_->end > $deletion->end
ABresult
0X0
100
111
1045 { # truncate feature start and shift end
1046 0 @newcoords = (
1047 [
1048 ( $deletion->start ), $end - $del_length,
1049 $start_type, $end_type
1050 ]
1051 );
1052 0 $note =
1053 ( $deletion->end - $start + 1 ) . 'bp deleted from feature ';
1054 0 ▶ if ( $feat->strand ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feat->strand) { } 0 0 0
1055 0 ▶ $note .= $feat->strand == 1 ? "5' end" : "3' end";
Branch: 1 branch
BranchTrueFalseTotal
$feat->strand == 1 ? : 0 0 0
1056 }
1057 else {
1058 0 $note .= 'start';
1059 }
1060 }
1061 elsif ( $start >= $deletion->end ) { # just shift entire location
1062 0 @newcoords = (
1063 [
1064 $start - $del_length, $end - $del_length,
1065 $start_type, $end_type
1066 ]
1067 );
1068 }
1069 else { # not affected by deletion
1070 0 @newcoords = ( [ $start, $end, $start_type, $end_type ] );
1071 }
1072  
1073 # if we have no coordinates, we return nothing
1074 # the feature is deleted
1075 0 ▶ return unless @newcoords;
Branch: 1 branch
BranchTrueFalseTotal
unless @newcoords 0 0 0
1076  
1077 0 my @subloc =
1078 $self->_location_objects_from_coordinate_list( \@newcoords, $strand,
1079 $type );
1080 0 push @loc, $self->_single_loc_object_from_collection(@subloc);
1081 } # each location
1082  
1083 # create new feature based on original one and move annotation across
1084 0 my $newfeat =
1085 Bio::SeqFeature::Generic->new( -primary => $feat->primary_tag );
1086 0 foreach my $key ( $feat->annotation->get_all_annotation_keys() ) {
1087 0 foreach my $value ( $feat->annotation->get_Annotations($key) ) {
1088 0 $newfeat->annotation->add_Annotation( $key, $value );
1089 }
1090 }
1091 0 foreach my $key ( $feat->get_all_tags() ) {
1092 0 $newfeat->add_tag_value( $key, $feat->get_tag_values($key) );
1093 }
1094  
1095 # If we have a note about the deleted bases, add it
1096 0 ▶ if ($note) {
Branch: 1 branch
BranchTrueFalseTotal
if ($note) 0 0 0
1097 0 $newfeat->add_tag_value( 'note', $note );
1098 }
1099  
1100 # set modified location(s) for the new feature and
1101 # add its subfeatures if any
1102 0 my $loc = $self->_single_loc_object_from_collection(@loc);
1103 0 ▶ $loc ? $newfeat->location($loc) : return;
Branch: 1 branch
BranchTrueFalseTotal
$loc ? : 0 0 0
1104 0 $newfeat->add_SeqFeature($_) for @adjsubfeat;
1105  
1106 0 return $newfeat;
1107  
1108 }
1109  
1110 =head2 _coord_adjust_insertion
1111
1112 title : _coord_adjust_insertion
1113 function: recursively adjusts coordinates of seqfeatures on a molecule
1114 where another sequence has been inserted.
1115 (sub)features that span the insertion site become split features
1116 and a note is added about the size and positin of the insertion.
1117 Features with an IN-BETWEEN location at the insertion site
1118 are lost (such features can only exist between adjacent bases)
1119 usage : my $adjusted_feature = Bio::Sequtils::_coord_adjust_insertion(
1120 $feature,
1121 $insert_pos,
1122 $insert_length
1123 );
1124 args : a Bio::SeqFeatureI compliant object,
1125 insertion position (insert to the right of this position)
1126 length of inserted fragment
1127 returns : a Bio::SeqFeatureI compliant object
1128  
1129 =cut
1130  
1131 0 ▶sub _coord_adjust_insertion {
Subroutine _coord_adjust_insertion: not called CC=20 SCAR=60.4
1132 0 my ( $self, $feat, $insert_pos, $insert_len ) = @_;
1133  
1134 0 ▶ $self->throw( 'object [$feat] '
Branch: 1 branch
BranchTrueFalseTotal
unless $feat->isa("Bio::SeqFeatureI") 0 0 0
1135 . 'of class ['
1136 . ref($feat)
1137 . '] should be a Bio::SeqFeatureI ' )
1138 unless $feat->isa('Bio::SeqFeatureI');
1139 0 ▶ $self->throw('missing insert position') unless defined $insert_pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $insert_pos 0 0 0
1140 0 ▶ $self->throw('missing insert length') unless defined $insert_len;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $insert_len 0 0 0
1141  
1142 0 my @adjsubfeat;
1143 0 for my $subfeat ( $feat->get_SeqFeatures ) {
1144 0 push @adjsubfeat,
1145 $self->_coord_adjust_insertion( $subfeat, $insert_pos, $insert_len );
1146 }
1147  
1148 0 my @loc;
1149 my $note;
1150 0 for ( $feat->location->each_Location ) {
1151  
1152 # loose IN-BETWEEN features at the insertion site
1153 next
1154 0 ▶ if ( $_->location_type eq 'IN-BETWEEN' && $_->start == $insert_pos );
Branch: 1 branch
BranchTrueFalseTotal
if $_->location_type eq "IN-BETWEEN" and $_->start == $insert_pos 0 0 0
Condition0%0/3
$_->location_type eq "IN-BETWEEN" and $_->start == $insert_pos
!ll&&!rl&&r
000
MC/DC0%0/2
$_->location_type eq "IN-BETWEEN" and $_->start == $insert_pos
$_->location_type eq "IN-BETWEEN" $_->start == $insert_pos
Truth table0%0/3
A and B
A= $_->location_type eq "IN-BETWEEN"B= $_->start == $insert_pos
ABresult
0X0
100
111
1155 0 my $strand = $_->strand;
1156 0 my $type = $_->location_type;
1157 0 my $start = $_->start;
1158 0 ▶ my $start_type = $_->can('start_pos_type') ? $_->start_pos_type : undef;
Branch: 1 branch
BranchTrueFalseTotal
$_->can('start_pos_type') ? : 0 0 0
1159 0 my $end = $_->end;
1160 0 ▶ my $end_type = $_->can('end_pos_type') ? $_->end_pos_type : undef;
Branch: 1 branch
BranchTrueFalseTotal
$_->can('end_pos_type') ? : 0 0 0
1161 0 my @newcoords = ();
1162 0 ▶ if ( $start <= $insert_pos && $end > $insert_pos ) { # split the feature
Branch: 2 branches
BranchTrueFalseTotal
if ($start <= $insert_pos and $end > $insert_pos) { } 0 0 0
elsif ($start > $insert_pos) { } 0 0 0
Condition0%0/3
$start <= $insert_pos and $end > $insert_pos
!ll&&!rl&&r
000
MC/DC0%0/2
$start <= $insert_pos and $end > $insert_pos
$start <= $insert_pos $end > $insert_pos
Truth table0%0/3
A and B
A= $start <= $insert_posB= $end > $insert_pos
ABresult
0X0
100
111
1163 0 @newcoords = (
1164 [ $start, $insert_pos, $start_type, $end_type ],
1165 [
1166 ( $insert_pos + 1 + $insert_len ), $end + $insert_len,
1167 $start_type, $end_type
1168 ]
1169 );
1170 0 $note =
1171 $insert_len
1172 . 'bp internal insertion between pos '
1173 . $insert_pos . ' and '
1174 . ( $insert_pos + $insert_len + 1 );
1175  
1176 }
1177 elsif ( $start > $insert_pos ) { # just shift entire location
1178 0 @newcoords = (
1179 [
1180 $start + $insert_len, $end + $insert_len,
1181 $start_type, $end_type
1182 ]
1183 );
1184 }
1185 else { # not affected
1186 0 @newcoords = ( [ $start, $end, $start_type, $end_type ] );
1187 }
1188  
1189 # if we have deleted all coordinates, return nothing
1190 # (possible if all locations are IN-BETWEEN)
1191 0 ▶ return unless @newcoords;
Branch: 1 branch
BranchTrueFalseTotal
unless @newcoords 0 0 0
1192  
1193 0 my @subloc =
1194 $self->_location_objects_from_coordinate_list( \@newcoords, $strand,
1195 $type );
1196  
1197 # put together final location which could be a split now
1198 0 push @loc, $self->_single_loc_object_from_collection(@subloc);
1199 } # each location
1200  
1201 # create new feature based on original one and move annotation across
1202 0 my $newfeat =
1203 Bio::SeqFeature::Generic->new( -primary => $feat->primary_tag );
1204 0 foreach my $key ( $feat->annotation->get_all_annotation_keys() ) {
1205 0 foreach my $value ( $feat->annotation->get_Annotations($key) ) {
1206 0 $newfeat->annotation->add_Annotation( $key, $value );
1207 }
1208 }
1209 0 foreach my $key ( $feat->get_all_tags() ) {
1210 0 $newfeat->add_tag_value( $key, $feat->get_tag_values($key) );
1211 }
1212  
1213 # If we have a note about the inserted bases, add it
1214 0 ▶ if ($note) {
Branch: 1 branch
BranchTrueFalseTotal
if ($note) 0 0 0
1215 0 $newfeat->add_tag_value( 'note', $note );
1216 }
1217  
1218 # set modified location(s) for the new feature and
1219 # add its subfeatures if any
1220 0 my $loc = $self->_single_loc_object_from_collection(@loc);
1221 0 ▶ $loc ? $newfeat->location($loc) : return;
Branch: 1 branch
BranchTrueFalseTotal
$loc ? : 0 0 0
1222 0 $newfeat->add_SeqFeature($_) for @adjsubfeat;
1223  
1224 0 return $newfeat;
1225  
1226 }
1227  
1228 =head2 _single_loc_object_from_collection
1229
1230 Title : _single_loc_object_from_collection
1231 Function: takes an array of location objects. Returns either a split
1232 location object if there are more than one locations in the
1233 array or returns the single location if there is only one
1234 Usage : my $loc = _single_loc_object_from_collection( @sublocs );
1235 Args : array of Bio::Location objects
1236 Returns : a single Bio:;Location object containing all locations
1237  
1238 =cut
1239  
1240 2 ▶sub _single_loc_object_from_collection {
Subroutine _single_loc_object_from_collection: called CC=3 SCAR=12.3
1241 2 my ( $self, @locs ) = @_;
1242 2 my $loc;
1243 2 ▶ if ( @locs > 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@locs > 1) { } 0 2 2
elsif (@locs == 1) { } 2 0 2
1244 0 $loc = Bio::Location::Split->new;
1245 0 $loc->add_sub_Location(@locs);
1246 }
1247 elsif ( @locs == 1 ) {
1248 2 $loc = shift @locs;
1249 }
1250 2 return $loc;
1251 } # _single_loc_object_from_collection
1252  
1253 =head2 _location_objects_from_coordinate_list
1254
1255 Title : _location_objects_from_coordinate_list
1256 Function: takes an array-ref of start/end coordinates, a strand and a
1257 type and returns a list of Bio::Location objects (Fuzzy by
1258 default, Simple in case of in-between coordinates).
1259 If location type is not "IN-BETWEEN", individual types may be
1260 passed in for start and end location as per Bio::Location::Fuzzy
1261 documentation.
1262 Usage : my @loc_objs = $self->_location_objects_from_coordinate_list(
1263 \@coords,
1264 $strand,
1265 $type
1266 );
1267 Args : array-ref of array-refs each containing:
1268 start, end [, start-type, end-type]
1269 where types are optional. If given, must be
1270 a one of ('BEFORE', 'AFTER', 'EXACT','WITHIN', 'BETWEEN')
1271 strand (all locations must be on same strand)
1272 location-type (EXACT, IN-BETWEEN etc)
1273 Returns : list of Bio::Location objects
1274  
1275 =cut
1276  
1277 2 ▶sub _location_objects_from_coordinate_list {
Subroutine _location_objects_from_coordinate_list: called CC=7 SCAR=20.5
1278 2 my $self = shift;
1279 2 my ( $coords_ref, $strand, $type ) = @_;
1280 2 ▶ $self->throw( 'expected 3 parameters but got ' . @_ ) unless @_ == 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 2 2
1281 2 ▶ $self->throw('first argument must be an ARRAY reference#')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $coords_ref eq "ARRAY" 0 2 2
1282 unless ref($coords_ref) eq 'ARRAY';
1283  
1284 2 my @loc;
1285 2 foreach my $coords_set (@$coords_ref) {
1286 2 my ( $start, $end, $start_type, $end_type ) = @$coords_set;
1287  
1288 # taken from Bio::SeqUtils::_coord_adjust
1289 2 ▶ if ( $type ne 'IN-BETWEEN' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne 'IN-BETWEEN') { } 2 0 2
1290 2 my $loc = Bio::Location::Fuzzy->new(
1291 -start => $start,
1292 -end => $end,
1293 -strand => $strand,
1294 -location_type => $type
1295 );
1296 2 ▶ $loc->start_pos_type($start_type) if $start_type;
Branch: 1 branch
BranchTrueFalseTotal
if $start_type 0 2 2
1297 2 ▶ $loc->end_pos_type($end_type) if $end_type;
Branch: 1 branch
BranchTrueFalseTotal
if $end_type 0 2 2
1298 2 push @loc, $loc;
1299 }
1300 else {
1301 0 push @loc,
1302 Bio::Location::Simple->new(
1303 -start => $start,
1304 -end => $end,
1305 -strand => $strand,
1306 -location_type => $type
1307 );
1308 }
1309 } # each coords_set
1310 2 return @loc;
1311 } # _location_objects_from_coordinate_list
1312  
1313 =head2 _new_seq_via_clone
1314
1315 Title : _new_seq_via_clone
1316 Function: clone a sequence object using Bio::Root::Root::clone and set the new sequence string
1317 sequence features are removed.
1318 Usage : my $new_seq = $self->_new_seq_via_clone( $seq_obj, $seq_str );
1319 Args : original seq object [, new sequence string]
1320 Returns : a clone of the original sequence object, optionally with new sequence string
1321  
1322 =cut
1323  
1324 0 ▶sub _new_seq_via_clone {
Subroutine _new_seq_via_clone: not called CC=4 SCAR=30.0
1325 0 my ( $self, $in_seq_obj, $seq_str ) = @_;
1326 0 my $out_seq_obj = $in_seq_obj->clone;
1327 0 ▶ $out_seq_obj->remove_SeqFeatures if $out_seq_obj->can('remove_SeqFeatures');
Branch: 1 branch
BranchTrueFalseTotal
if $out_seq_obj->can("remove_SeqFeatures") 0 0 0
1328 0 ▶ if ( blessed $out_seq_obj->seq
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($out_seq_obj->seq) and $out_seq_obj->seq->isa('Bio::PrimarySeq')) { } 0 0 0
Condition0%0/3
builtin::blessed($out_seq_obj->seq) and $out_seq_obj->seq->isa("Bio::PrimarySeq")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($out_seq_obj->seq) and $out_seq_obj->seq->isa("Bio::PrimarySeq")
builtin::blessed($out_seq_obj->seq) $out_seq_obj->seq->isa("Bio::PrimarySeq")
Truth table0%0/3
A and B
A= builtin::blessed($out_seq_obj->seq)B= $out_seq_obj->seq->isa("Bio::PrimarySeq")
ABresult
0X0
100
111
1329 && $out_seq_obj->seq->isa('Bio::PrimarySeq') )
1330 {
1331 0 $out_seq_obj->seq->seq($seq_str);
1332 }
1333 else {
1334 0 $out_seq_obj->seq($seq_str);
1335 }
1336 0 return $out_seq_obj;
1337  
1338 } # _new_seq_via_clone
1339  
1340 =head2 _new_seq_from_old
1341
1342 Title : _new_seq_from_old
1343 Function: creates a new sequence obejct, if possible of the same class as the old and adds
1344 attributes to it. Also copies annotation across to the new object.
1345 Usage : my $new_seq = $self->_new_seq_from_old( $seq_obj, { seq => $seq_str, display_id => 'some_ID'});
1346 Args : old sequence object
1347 hashref of attributes for the new sequence (sequence string etc.)
1348 Returns : a new Bio::Seq object
1349  
1350 =cut
1351  
1352 0 ▶sub _new_seq_from_old {
Subroutine _new_seq_from_old: not called CC=16 SCAR=56.1
1353 0 my ( $self, $in_seq_obj, $attr ) = @_;
1354 0 ▶ $self->throw('attributes must be a hashref')
Branch: 1 branch
BranchTrueFalseTotal
if $attr and ref $attr ne "HASH" 0 0 0
Condition0%0/3
$attr and ref $attr ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$attr and ref $attr ne "HASH"
$attr ref $attr ne "HASH"
Truth table0%0/3
A and B
A= $attrB= ref $attr ne "HASH"
ABresult
0X0
100
111
1355 if $attr && ref($attr) ne 'HASH';
1356  
1357 0 my $seqclass;
1358 0 ▶ if ( $in_seq_obj->can_call_new ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_seq_obj->can_call_new) { } 0 0 0
1359 0 $seqclass = ref($in_seq_obj);
1360 }
1361 else {
1362 0 $seqclass = 'Bio::Primaryseq';
1363 0 $self->_attempt_to_load_seq;
1364 }
1365  
1366 my $out_seq_obj = $seqclass->new(
1367 -seq => $attr->{seq} || $in_seq_obj->seq,
1368 -display_id => $attr->{display_id} || $in_seq_obj->display_id,
1369 -accession_number => $attr->{accession_number}
1370 || $in_seq_obj->accession_number
1371 || '',
1372 -alphabet => $in_seq_obj->alphabet,
1373 -desc => $attr->{desc} || $in_seq_obj->desc,
1374 -verbose => $attr->{verbose} || $in_seq_obj->verbose,
1375 0 ▶ -is_circular => $attr->{is_circular} || $in_seq_obj->is_circular || 0,
Condition0%0/22
$attr->{'seq'} || $in_seq_obj->seq
l!l&&r!l&&!r
000
$attr->{'display_id'} || $in_seq_obj->display_id
l!l&&r!l&&!r
000
$attr->{'accession_number'} || $in_seq_obj->accession_number || ''
l!l
00
$attr->{"accession_number"} or $in_seq_obj->accession_number
l!l&&r!l&&!r
000
$attr->{'desc'} || $in_seq_obj->desc
l!l&&r!l&&!r
000
$attr->{'verbose'} || $in_seq_obj->verbose
l!l&&r!l&&!r
000
$attr->{'is_circular'} || $in_seq_obj->is_circular || 0
l!l
00
$attr->{"is_circular"} or $in_seq_obj->is_circular
l!l&&r!l&&!r
000
MC/DC0%0/2
$attr->{'seq'} || $in_seq_obj->seq
$attr->{'seq'} $in_seq_obj->seq
MC/DC0%0/2
$attr->{'display_id'} || $in_seq_obj->display_id
$attr->{'display_id'} $in_seq_obj->display_id
MC/DC0%0/2
$attr->{'accession_number'} || $in_seq_obj->accession_number || ''
$attr->{"accession_number"} $in_seq_obj->accession_number
MC/DC0%0/2
$attr->{'desc'} || $in_seq_obj->desc
$attr->{'desc'} $in_seq_obj->desc
MC/DC0%0/2
$attr->{'verbose'} || $in_seq_obj->verbose
$attr->{'verbose'} $in_seq_obj->verbose
MC/DC0%0/2
$attr->{'is_circular'} || $in_seq_obj->is_circular || 0
$attr->{"is_circular"} $in_seq_obj->is_circular
Truth table0%0/3
A || B
A= $attr->{'seq'}B= $in_seq_obj->seq
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $attr->{'display_id'}B= $in_seq_obj->display_id
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $attr->{"accession_number"}B= $in_seq_obj->accession_number
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $attr->{'desc'}B= $in_seq_obj->desc
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $attr->{'verbose'}B= $in_seq_obj->verbose
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $attr->{"is_circular"}B= $in_seq_obj->is_circular
ABresult
1X1
011
000
1376 );
1377  
1378 # move the annotation across to the product
1379 0 ▶ if ( $out_seq_obj->isa("Bio::AnnotatableI")
Branch: 1 branch
BranchTrueFalseTotal
if ($out_seq_obj->isa("Bio::AnnotatableI") and $in_seq_obj->isa("Bio::AnnotatableI")) 0 0 0
Condition0%0/3
$out_seq_obj->isa("Bio::AnnotatableI") and $in_seq_obj->isa("Bio::AnnotatableI")
!ll&&!rl&&r
000
MC/DC0%0/2
$out_seq_obj->isa("Bio::AnnotatableI") and $in_seq_obj->isa("Bio::AnnotatableI")
$out_seq_obj->isa("Bio::AnnotatableI") $in_seq_obj->isa("Bio::AnnotatableI")
Truth table0%0/3
A and B
A= $out_seq_obj->isa("Bio::AnnotatableI")B= $in_seq_obj->isa("Bio::AnnotatableI")
ABresult
0X0
100
111
1380 && $in_seq_obj->isa("Bio::AnnotatableI") )
1381 {
1382 0 foreach my $key ( $in_seq_obj->annotation->get_all_annotation_keys ) {
1383 0 foreach my $value ( $in_seq_obj->annotation->get_Annotations($key) )
1384 {
1385 0 $out_seq_obj->annotation->add_Annotation( $key, $value );
1386 }
1387 }
1388 }
1389 0 return $out_seq_obj;
1390 } # _new_seq_from_old
1391  
1392 =head2 _coord_adjust
1393  
1394 Title : _coord_adjust
1395 Usage : my $newfeat=Bio::SeqUtils->_coord_adjust($feature, 100, $seq->length);
1396 Function: Recursive subroutine to adjust the coordinates of a feature
1397 and all its subfeatures. If a sequence length is specified, then
1398 any adjusted features that have locations beyond the boundaries
1399 of the sequence are converted to Bio::Location::Fuzzy objects.
1400  
1401 Returns : A Bio::SeqFeatureI compliant object.
1402 Args : A Bio::SeqFeatureI compliant object,
1403 the number of bases to add to the coordinates
1404 (optional) the length of the parent sequence
1405  
1406  
1407 =cut
1408  
1409 2 ▶sub _coord_adjust {
Subroutine _coord_adjust: called CC=14 SCAR=29.6
1410 2 my ( $self, $feat, $add, $length ) = @_;
1411 2 ▶ $self->throw( 'Object [$feat] '
Branch: 1 branch
BranchTrueFalseTotal
unless $feat->isa("Bio::SeqFeatureI") 0 2 2
1412 . 'of class ['
1413 . ref($feat)
1414 . '] should be a Bio::SeqFeatureI ' )
1415 unless $feat->isa('Bio::SeqFeatureI');
1416 2 my @adjsubfeat;
1417 2 for my $subfeat ( $feat->get_SeqFeatures ) {
1418 0 push @adjsubfeat, $self->_coord_adjust( $subfeat, $add, $length );
1419 }
1420 2 my @loc;
1421 2 for ( $feat->location->each_Location ) {
1422 2 my @coords = ( $_->start, $_->end );
1423 2 my $strand = $_->strand;
1424 2 my $type = $_->location_type;
1425 2 foreach (@coords) {
1426 4 ▶ $self->throw("can not handle negative feature positions (got: $_)")
Branch: 1 branch
BranchTrueFalseTotal
if $_ < 0 0 4 4
1427 if $_ < 0;
1428 4 ▶ if ( $add + $_ < 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($add + $_ < 1) { } 0 4 4
elsif (defined $length and $add + $_ > $length) { } 0 4 4
1429 0 $_ = '<1';
1430 }
1431 ▶ elsif ( defined $length and $add + $_ > $length ) {
Condition33%1/3
defined $length and $add + $_ > $length
!ll&&!rl&&r
400
MC/DC0%0/2
defined $length and $add + $_ > $length
defined $length $add + $_ > $length
Truth table33%1/3
A and B
A= defined $lengthB= $add + $_ > $length
ABresult
0X0
100
111
1432 0 $_ = ">$length";
1433 }
1434 else {
1435 4 $_ = $add + $_;
1436 }
1437 }
1438 2 push @loc,
1439 $self->_location_objects_from_coordinate_list( [ \@coords ],
1440 $strand, $type );
1441 }
1442 2 my $newfeat =
1443 Bio::SeqFeature::Generic->new( -primary => $feat->primary_tag );
1444 2 foreach my $key ( $feat->annotation->get_all_annotation_keys() ) {
1445 0 foreach my $value ( $feat->annotation->get_Annotations($key) ) {
1446 0 $newfeat->annotation->add_Annotation( $key, $value );
1447 }
1448 }
1449 2 foreach my $key ( $feat->get_all_tags() ) {
1450 3 $newfeat->add_tag_value( $key, $feat->get_tag_values($key) );
1451 }
1452 2 my $loc = $self->_single_loc_object_from_collection(@loc);
1453 2 ▶ $loc ? $newfeat->location($loc) : return;
Branch: 1 branch
BranchTrueFalseTotal
$loc ? : 2 0 2
1454 2 $newfeat->add_SeqFeature($_) for @adjsubfeat;
1455 2 return $newfeat;
1456 }
1457  
1458 =head2 revcom_with_features
1459  
1460 Title : revcom_with_features
1461 Usage : $revcom=Bio::SeqUtils->revcom_with_features($seq);
1462 Function: Like Bio::Seq::revcom, but keeps features (adjusting coordinates
1463 as appropriate.
1464 Returns : A new sequence object
1465 Args : A sequence object
1466  
1467  
1468 =cut
1469  
1470 0 ▶sub revcom_with_features {
Subroutine revcom_with_features: not called CC=5 SCAR=34.0
Pod documented
1471 0 my ( $self, $seq ) = @_;
1472 0 ▶ $self->throw( 'Object [$seq] '
Branch: 1 branch
BranchTrueFalseTotal
unless $seq->isa("Bio::SeqI") 0 0 0
1473 . 'of class ['
1474 . ref($seq)
1475 . '] should be a Bio::SeqI ' )
1476 unless $seq->isa('Bio::SeqI');
1477 0 my $revcom = $seq->revcom;
1478  
1479 # make sure that there is no annotation or features in $trunc
1480 # (->revcom() now clone objects except for Bio::Seq::LargePrimarySeq)
1481 0 $revcom->annotation->remove_Annotations;
1482 0 $revcom->remove_SeqFeatures;
1483  
1484 #move annotations
1485 0 foreach my $key ( $seq->annotation->get_all_annotation_keys() ) {
1486 0 foreach my $value ( $seq->annotation->get_Annotations($key) ) {
1487 0 $revcom->annotation->add_Annotation( $key, $value );
1488 }
1489 }
1490  
1491 #move features
1492 0 for ( map { $self->_feature_revcom( $_, $seq->length ) }
1493 reverse $seq->get_SeqFeatures )
1494 {
1495 0 $revcom->add_SeqFeature($_);
1496 }
1497 0 return $revcom;
1498 }
1499  
1500 =head2 _feature_revcom
1501  
1502 Title : _feature_revcom
1503 Usage : my $newfeat=Bio::SeqUtils->_feature_revcom($feature, $seq->length);
1504 Function: Recursive subroutine to reverse complement a feature and
1505 all its subfeatures. The length of the parent sequence must be
1506 specified.
1507  
1508 Returns : A Bio::SeqFeatureI compliant object.
1509 Args : A Bio::SeqFeatureI compliant object,
1510 the length of the parent sequence
1511  
1512  
1513 =cut
1514  
1515 0 ▶sub _feature_revcom {
Subroutine _feature_revcom: not called CC=15 SCAR=54.8
1516 0 my ( $self, $feat, $length ) = @_;
1517 0 ▶ $self->throw( 'Object [$feat] '
Branch: 1 branch
BranchTrueFalseTotal
unless $feat->isa("Bio::SeqFeatureI") 0 0 0
1518 . 'of class ['
1519 . ref($feat)
1520 . '] should be a Bio::SeqFeatureI ' )
1521 unless $feat->isa('Bio::SeqFeatureI');
1522 0 my @adjsubfeat;
1523 0 for my $subfeat ( $feat->get_SeqFeatures ) {
1524 0 push @adjsubfeat, $self->_feature_revcom( $subfeat, $length );
1525 }
1526 0 my @loc;
1527 0 for ( $feat->location->each_Location ) {
1528 0 my $type = $_->location_type;
1529 0 my $strand;
1530 0 ▶ if ( $_->strand == -1 ) { $strand = 1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($_->strand == -1) { } 0 0 0
elsif ($_->strand == 1) { } 0 0 0
1531 0 elsif ( $_->strand == 1 ) { $strand = -1 }
1532 0 else { $strand = $_->strand }
1533 0 my $newend =
1534 $self->_coord_revcom( $_->start, $_->start_pos_type, $length );
1535 0 my $newstart =
1536 $self->_coord_revcom( $_->end, $_->end_pos_type, $length );
1537 0 my $newstart_type = $_->end_pos_type;
1538 0 ▶ $newstart_type = 'BEFORE' if $_->end_pos_type eq 'AFTER';
Branch: 1 branch
BranchTrueFalseTotal
if $_->end_pos_type eq "AFTER" 0 0 0
1539 0 ▶ $newstart_type = 'AFTER' if $_->end_pos_type eq 'BEFORE';
Branch: 1 branch
BranchTrueFalseTotal
if $_->end_pos_type eq "BEFORE" 0 0 0
1540 0 my $newend_type = $_->start_pos_type;
1541 0 ▶ $newend_type = 'BEFORE' if $_->start_pos_type eq 'AFTER';
Branch: 1 branch
BranchTrueFalseTotal
if $_->start_pos_type eq "AFTER" 0 0 0
1542 0 ▶ $newend_type = 'AFTER' if $_->start_pos_type eq 'BEFORE';
Branch: 1 branch
BranchTrueFalseTotal
if $_->start_pos_type eq "BEFORE" 0 0 0
1543 0 push @loc,
1544 $self->_location_objects_from_coordinate_list(
1545 [ [ $newstart, $newend, $newstart_type, $newend_type ] ],
1546 $strand, $type );
1547 }
1548 0 my $newfeat =
1549 Bio::SeqFeature::Generic->new( -primary => $feat->primary_tag );
1550 0 foreach my $key ( $feat->annotation->get_all_annotation_keys() ) {
1551 0 foreach my $value ( $feat->annotation->get_Annotations($key) ) {
1552 0 $newfeat->annotation->add_Annotation( $key, $value );
1553 }
1554 }
1555 0 foreach my $key ( $feat->get_all_tags() ) {
1556 0 $newfeat->add_tag_value( $key, $feat->get_tag_values($key) );
1557 }
1558  
1559 0 my $loc = $self->_single_loc_object_from_collection(@loc);
1560 0 ▶ $loc ? $newfeat->location($loc) : return;
Branch: 1 branch
BranchTrueFalseTotal
$loc ? : 0 0 0
1561  
1562 0 $newfeat->add_SeqFeature($_) for @adjsubfeat;
1563 0 return $newfeat;
1564 }
1565  
1566 0 ▶sub _coord_revcom {
Subroutine _coord_revcom: not called CC=7 SCAR=40.3
1567 0 my ( $self, $coord, $type, $length ) = @_;
1568 0 ▶ if ( $type eq 'BETWEEN' or $type eq 'WITHIN' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'BETWEEN' or $type eq 'WITHIN') { } 0 0 0
Condition0%0/3
$type eq "BETWEEN" or $type eq "WITHIN"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "BETWEEN" or $type eq "WITHIN"
$type eq "BETWEEN" $type eq "WITHIN"
Truth table0%0/3
A or B
A= $type eq "BETWEEN"B= $type eq "WITHIN"
ABresult
1X1
011
000
1569 0 $coord =~ s/(\d+)(\D*)(\d+)/$length+1-$3.$2.$length+1-$1/ge;
1570 }
1571 else {
1572 0 $coord =~ s/(\d+)/$length+1-$1/ge;
1573 0 $coord =~ tr/<>/></;
1574 0 ▶ $coord = '>' . $coord
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "BEFORE" and substr($coord, 0, 1) ne ">" 0 0 0
Condition0%0/3
$type eq "BEFORE" and substr($coord, 0, 1) ne ">"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "BEFORE" and substr($coord, 0, 1) ne ">"
$type eq "BEFORE" substr($coord, 0, 1) ne ">"
Truth table0%0/3
A and B
A= $type eq "BEFORE"B= substr($coord, 0, 1) ne ">"
ABresult
0X0
100
111
1575 if $type eq 'BEFORE' and substr( $coord, 0, 1 ) ne '>';
1576 0 ▶ $coord = '<' . $coord
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "AFTER" and substr($coord, 0, 1) ne "<" 0 0 0
Condition0%0/3
$type eq "AFTER" and substr($coord, 0, 1) ne "<"
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "AFTER" and substr($coord, 0, 1) ne "<"
$type eq "AFTER" substr($coord, 0, 1) ne "<"
Truth table0%0/3
A and B
A= $type eq "AFTER"B= substr($coord, 0, 1) ne "<"
ABresult
0X0
100
111
1577 if $type eq 'AFTER' and substr( $coord, 0, 1 ) ne '<';
1578 }
1579 0 return $coord;
1580 }
1581  
1582 =head2 evolve
1583  
1584 Title : evolve
1585 Usage : my $newseq = Bio::SeqUtils->
1586 evolve($seq, $similarity, $transition_transversion_rate);
1587 Function: Mutates the sequence by point mutations until the similarity of
1588 the new sequence has decreased to the required level.
1589 Transition/transversion rate is adjustable.
1590 Returns : A new Bio::PrimarySeq object
1591 Args : sequence object
1592 percentage similarity (e.g. 80)
1593 tr/tv rate, optional, defaults to 1 (= 1:1)
1594  
1595 Set the verbosity of the Bio::SeqUtils object to positive integer to
1596 see the mutations as they happen.
1597  
1598 This method works only on nucleotide sequences. It prints a warning if
1599 you set the target similarity to be less than 25%.
1600  
1601 Transition/transversion ratio is an observed attribute of an sequence
1602 comparison. We are dealing here with the transition/transversion rate
1603 that we set for our model of sequence evolution.
1604  
1605 =cut
1606  
1607 0 ▶sub evolve {
Subroutine evolve: not called CC=10 SCAR=47.0
Pod documented
1608 0 my ( $self, $seq, $sim, $rate ) = @_;
1609 0 ▶ $rate ||= 1;
Condition0%0/2
$rate ||= 1
l!l
00
MC/DC0%0/1
$rate ||= 1
$rate
Truth table0%0/2
A
A= $rate
Aresult
11
00
1610  
1611 0 ▶ $self->throw( 'Object [$seq] '
Branch: 1 branch
BranchTrueFalseTotal
unless $seq->isa("Bio::PrimarySeqI") 0 0 0
1612 . 'of class ['
1613 . ref($seq)
1614 . '] should be a Bio::PrimarySeqI ' )
1615 unless $seq->isa('Bio::PrimarySeqI');
1616  
1617 0 ▶ $self->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $sim =~ /^[+\d.]+$/ and $sim <= 100 0 0 0
Condition0%0/3
$sim =~ /^[+\d.]+$/ and $sim <= 100
!ll&&!rl&&r
000
MC/DC0%0/2
$sim =~ /^[+\d.]+$/ and $sim <= 100
$sim =~ /^[+\d.]+$/ $sim <= 100
Truth table0%0/3
A and B
A= $sim =~ /^[+\d.]+$/B= $sim <= 100
ABresult
0X0
100
111
1618 "[$sim] " . ' should be a positive integer or float under 100' )
1619 unless $sim =~ /^[+\d.]+$/ and $sim <= 100;
1620  
1621 0 ▶ $self->warn(
Branch: 1 branch
BranchTrueFalseTotal
unless $sim > 25 0 0 0
1622 "Nucleotide sequences are 25% similar by chance.
1623 Do you really want to set similarity to [$sim]%?\n"
1624 ) unless $sim > 25;
1625  
1626 0 ▶ $self->throw('Only nucleotide sequences are supported')
Branch: 1 branch
BranchTrueFalseTotal
if $seq->alphabet eq "protein" 0 0 0
1627 if $seq->alphabet eq 'protein';
1628  
1629 # arrays of possible changes have transitions as first items
1630 0 my %changes;
1631 0 $changes{'a'} = [ 't', 'c', 'g' ];
1632 0 $changes{'t'} = [ 'a', 'c', 'g' ];
1633 0 $changes{'c'} = [ 'g', 'a', 't' ];
1634 0 $changes{'g'} = [ 'c', 'a', 't' ];
1635  
1636 # given the desired rate, find out where cut off points need to be
1637 # when random numbers are generated from 0 to 100
1638 # we are ignoring identical mutations (e.g. A->A) to speed things up
1639 0 my $bin_size = 100 / ( $rate + 2 );
1640 0 my $transition = 100 - ( 2 * $bin_size );
1641 0 my $first_transversion = $transition + $bin_size;
1642  
1643 # unify the look of sequence strings
1644 0 my $string = lc $seq->seq; # lower case
1645 0 $string =~
1646 s/u/t/; # simplyfy our life; modules should deal with the change anyway
1647 # store the original sequence string
1648 0 my $oristring = $string;
1649 0 my $length = $seq->length;
1650  
1651 # stop evolving if the limit has been reached
1652 0 ▶ until ( $self->_get_similarity( $oristring, $string ) <= $sim ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_get_similarity($oristring, $string) <= $sim) 0 0 0
1653  
1654 # find the location in the string to change
1655 0 my $loc = int( rand $length ) + 1;
1656  
1657 # nucleotide to change
1658 0 my $oldnuc = substr $string, $loc - 1, 1;
1659 0 my $newnuc;
1660  
1661 # nucleotide it is changed to
1662 0 my $choose = rand(100);
1663 0 ▶ if ( $choose < $transition ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($choose < $transition) { } 0 0 0
elsif ($choose < $first_transversion) { } 0 0 0
1664 0 $newnuc = $changes{$oldnuc}[0];
1665 }
1666 elsif ( $choose < $first_transversion ) {
1667 0 $newnuc = $changes{$oldnuc}[1];
1668 }
1669 else {
1670 0 $newnuc = $changes{$oldnuc}[2];
1671 }
1672  
1673 # do the change
1674 0 substr $string, $loc - 1, 1, $newnuc;
1675  
1676 0 $self->debug("$loc$oldnuc>$newnuc\n");
1677 }
1678  
1679 0 return new Bio::PrimarySeq(
1680 -id => $seq->id . "-$sim",
1681 -description => $seq->description,
1682 -seq => $string
1683 );
1684 }
1685  
1686 0 ▶sub _get_similarity {
Subroutine _get_similarity: not called CC=3 SCAR=24.8
1687 0 my ( $self, $oriseq, $seq ) = @_;
1688  
1689 0 my $len = length($oriseq);
1690 0 my $c;
1691  
1692 0 ▶ for ( my $i = 0 ; $i < $len ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
1693 0 ▶ $c++ if substr( $oriseq, $i, 1 ) eq substr( $seq, $i, 1 );
Branch: 1 branch
BranchTrueFalseTotal
if substr($oriseq, $i, 1) eq substr($seq, $i, 1) 0 0 0
1694 }
1695 0 return 100 * $c / $len;
1696 }
1697  
1698 344 1;
« Bio/AlignIO/proda.pm ↑ Summary Bio/SearchIO/infernal.pm »