Bio/Tools/SeqPattern.pm

filter: Statementstmt 71.5% 181 / 253 Branchbran 52.7% 38 / 72 Conditioncond 29.4% 5 / 17 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 94.4% 17 / 18 Podpod 42.8% 3 / 7 totaltotal 65.1% 245 / 376 CC 43 SCAR 22.3
CC
43
Cov
65%
_fixpat_4
35.0
alphabet_ok
12.0
_fixpat_5
11.6
CRAP 9.3
« Bio/Tools/SeqStats.pm ↑ Summary Bio/Tools/isPcr.pm »
1 #
2 # bioperl module for Bio::Tools::SeqPattern
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Steve Chervitz (sac-at-bioperl.org)
7 #
8 # Copyright Steve Chervitz
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::Tools::SeqPattern - represent a sequence pattern or motif
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Tools::SeqPattern;
21  
22 my $pat1 = 'T[GA]AA...TAAT';
23 my $pattern1 = Bio::Tools::SeqPattern->new(-SEQ =>$pat1, -TYPE =>'Dna');
24  
25 my $pat2 = '[VILM]R(GXX){3,2}...[^PG]';
26 my $pattern2 = Bio::Tools::SeqPattern->new(-SEQ =>$pat2, -TYPE =>'Amino');
27  
28 =head1 DESCRIPTION
29  
30 L<Bio::Tools::SeqPattern> module encapsulates generic data and
31 methods for manipulating regular expressions describing nucleic or
32 amino acid sequence patterns (a.k.a, "motifs"), such as the ones produced by
33 L<Bio::Tools::IUPAC>.
34  
35 L<Bio::Tools::SeqPattern> is a concrete class that inherits from L<Bio::Seq>.
36  
37 This class grew out of a need to have a standard module for doing routine
38 tasks with sequence patterns such as:
39  
40 -- Forming a reverse-complement version of a nucleotide sequence pattern
41 -- Expanding patterns containing ambiguity codes
42 -- Checking for invalid regexp characters
43 -- Untainting yet preserving special characters in the pattern
44  
45 Other features to look for in the future:
46  
47 -- Full pattern syntax checking
48 -- Conversion between expanded and condensed forms of the pattern
49  
50 =head1 MOTIVATIONS
51  
52 A key motivation for L<Bio::Tools::SeqPattern> is to have a way to
53 generate a reverse complement of a nucleotide sequence pattern.
54 This makes possible simultaneous pattern matching on both sense and
55 anti-sense strands of a query sequence.
56  
57 In principle, one could do such a search more inefficiently by testing
58 against both sense and anti-sense versions of a sequence.
59 It is entirely equivalent to test a regexp containing both sense and
60 anti-sense versions of the *pattern* against one copy of the sequence.
61 The latter approach is much more efficient since:
62  
63 1) You need only one copy of the sequence.
64 2) Only one regexp is executed.
65 3) Regexp patterns are typically much smaller than sequences.
66  
67 Patterns can be quite complex and it is often difficult to
68 generate the reverse complement pattern. The Bioperl SeqPattern.pm
69 addresses this problem, providing a convenient set of tools
70 for working with biological sequence regular expressions.
71  
72 Not all patterns have been tested. If you discover a pattern that
73 is not handled properly by Bio::Tools::SeqPattern.pm, please
74 send me some email (sac@bioperl.org). Thanks.
75  
76 =head1 OTHER FEATURES
77  
78 =head2 Extended Alphabet Support
79  
80 This module supports the same set of ambiguity codes for nucleotide
81 sequences as supported by L<Bio::Seq>. These ambiguity codes
82 define the behavior or the L<expand> method.
83  
84 ------------------------------------------
85 Symbol Meaning Nucleic Acid
86 ------------------------------------------
87 A A (A)denine
88 C C (C)ytosine
89 G G (G)uanine
90 T T (T)hymine
91 U U (U)racil
92 M A or C a(M)ino group
93 R A or G pu(R)ine
94 W A or T (W)eak bond
95 S C or G (S)trong bond
96 Y C or T p(Y)rimidine
97 K G or T (K)eto group
98 V A or C or G
99 H A or C or T
100 D A or G or T
101 B C or G or T
102 X G or A or T or C
103 N G or A or T or C
104 . G or A or T or C
105  
106  
107  
108 ------------------------------------------
109 Symbol Meaning
110 ------------------------------------------
111 A Alanine
112 C Cysteine
113 D Aspartic Acid
114 E Glutamic Acid
115 F Phenylalanine
116 G Glycine
117 H Histidine
118 I Isoleucine
119 K Lysine
120 L Leucine
121 M Methionine
122 N Asparagine
123 P Proline
124 Q Glutamine
125 R Arginine
126 S Serine
127 T Threonine
128 V Valine
129 W Tryptophan
130 Y Tyrosine
131  
132 B Aspartic Acid, Asparagine
133 Z Glutamic Acid, Glutamine
134 X Any amino acid
135 . Any amino acid
136  
137  
138 =head2 Multiple Format Support
139  
140 Ultimately, this module should be able to build SeqPattern.pm objects
141 using a variety of pattern formats such as ProSite, Blocks, Prints, GCG, etc.
142 Currently, this module only supports patterns using a grep-like syntax.
143  
144 =head1 USAGE
145  
146 A simple demo script called seq_pattern.pl is included in the examples/
147 directory of the central Bioperl distribution.
148  
149 =head1 SEE ALSO
150  
151 L<Bio::Seq> - Lightweight sequence object.
152  
153 L<Bio::Tools::IUPAC> - The IUPAC code for degenerate residues and their
154 conversion to a regular expression.
155  
156 =head1 FEEDBACK
157  
158 =head2 Mailing Lists
159  
160 User feedback is an integral part of the evolution of this and other
161 Bioperl modules. Send your comments and suggestions preferably to one
162 of the Bioperl mailing lists. Your participation is much appreciated.
163  
164 bioperl-l@bioperl.org - General discussion
165 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
166  
167 =head2 Support
168  
169 Please direct usage questions or support issues to the mailing list:
170  
171 I<bioperl-l@bioperl.org>
172  
173 rather than to the module maintainer directly. Many experienced and
174 reponsive experts will be able look at the problem and quickly
175 address it. Please include a thorough description of the problem
176 with code and data examples if at all possible.
177  
178 =head2 Reporting Bugs
179  
180 Report bugs to the Bioperl bug tracking system to help us keep track
181 the bugs and their resolution. Bug reports can be submitted via the
182 web:
183  
184 https://github.com/bioperl/bioperl-live/issues
185  
186 =head1 AUTHOR
187  
188 Steve Chervitz, sac-at-bioperl.org
189  
190 =head1 COPYRIGHT
191  
192 Copyright (c) 1997-8 Steve Chervitz. All Rights Reserved.
193 This module is free software; you can redistribute it and/or
194 modify it under the same terms as Perl itself.
195  
196 =cut
197  
198 #
199 ##
200 ###
201 #### END of main POD documentation.
202 ###
203 ##
204 #'
205 # CREATED : 28 Aug 1997
206  
207  
208 package Bio::Tools::SeqPattern;
209 4 $Bio::Tools::SeqPattern::VERSION = '1.7.8';
210 4 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
211 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
212 4 ▶use vars qw ($ID);
Subroutine BEGIN: called CC=1 SCAR=0.0
213 4 $ID = 'Bio::Tools::SeqPattern';
214  
215 ## These constants may be more appropriate in a Bio::Dictionary.pm
216 ## type of class.
217 4 my $PURINES = 'AG';
218 4 my $PYRIMIDINES = 'CT';
219 4 my $BEE = 'DN';
220 4 my $ZED = 'EQ';
221 4 my $Regexp_chars = '\w,.\*()\[\]<>\{\}^\$'; # quoted for use in regexps
222  
223 ## Package variables used in reverse complementing.
224 4 my (%Processed_braces, %Processed_asterics);
225  
226 #####################################################################################
227 ## CONSTRUCTOR ##
228 #####################################################################################
229  
230 =head1 new
231  
232 Title : new
233 Usage : my $seqpat = Bio::Tools::SeqPattern->new();
234 Purpose : Verifies that the type is correct for superclass (Bio::Seq.pm)
235 : and calls superclass constructor last.
236 Returns : n/a
237 Argument : Parameters passed to new()
238 Throws : Exception if the pattern string (seq) is empty.
239 Comments : The process of creating a new SeqPattern.pm object
240 : ensures that the pattern string is untained.
241  
242 See Also : L<Bio::Root::Root::new>,
243 L<Bio::Seq::_initialize>
244  
245 =cut
246  
247 #----------------
248 68 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
249 #----------------
250 68 my($class, %param) = @_;
251  
252 68 my $self = $class->SUPER::new(%param);
253 68 my ($seq,$type) = $self->_rearrange([qw(SEQ TYPE)], %param);
254  
255 68 ▶ $seq || $self->throw("Empty pattern.");
Branch: 1 branch
BranchTrueFalseTotal
$seq or $self->throw("Empty pattern.") 68 0 68
256 68 my $t;
257 # Get the type ready for Bio::Seq.pm
258 68 ▶ if ($type =~ /nuc|[dr]na/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /nuc|[dr]na/i) { } 66 2 68
elsif ($type =~ /amino|pep|prot/i) { } 2 0 2
259 66 $t = 'Dna';
260 } elsif ($type =~ /amino|pep|prot/i) {
261 2 $t = 'Amino';
262 }
263 68 $seq =~ tr/a-z/A-Z/; #ps 8/8/00 Canonicalize to upper case
264 68 $self->str($seq);
265 68 $self->type($t);
266  
267 68 return $self;
268 }
269  
270  
271 =head1 alphabet_ok
272  
273 Title : alphabet_ok
274 Usage : $mypat->alphabet_ok;
275 Purpose : Checks for invalid regexp characters.
276 : Overrides Bio::Seq::alphabet_ok() to allow
277 : additional regexp characters ,.*()[]<>{}^$
278 : in addition to the standard genetic alphabet.
279 : Also untaints the pattern and sets the sequence
280 : object's sequence to the untained string.
281 Returns : Boolean (1 | 0)
282 Argument : n/a
283 Throws : Exception if the pattern contains invalid characters.
284 Comments : Does not call the superclass method.
285 : Actually permits any alphanumeric, not just the
286 : standard genetic alphabet.
287  
288 =cut
289  
290 #----------------'
291 0 ▶sub alphabet_ok {
Subroutine alphabet_ok: not called CC=3 SCAR=24.8
Pod undocumented
292 #----------------
293 0 my( $self) = @_;
294  
295 0 ▶ return 1 if $self->{'_alphabet_checked'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_alphabet_checked"} 0 0 0
296  
297 0 $self->{'_alphabet_checked'} = 1;
298  
299 0 my $pat = $self->seq();
300  
301 0 ▶ if($pat =~ /[^$Regexp_chars]/io) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pat =~ /[^$Regexp_chars]/io) 0 0 0
302 0 $self->throw("Pattern contains invalid characters: $pat",
303 'Legal characters: a-z,A-Z,0-9,,.*()[]<>{}^$ ');
304 }
305  
306 # Untaint pattern (makes code taint-safe).
307 0 $pat =~ /([$Regexp_chars]+)/io;
308 0 $self->setseq(uc($1));
309 # print STDERR "\npattern ok: $pat\n";
310 0 1;
311 }
312  
313 =head1 expand
314  
315 Title : expand
316 Usage : $seqpat_object->expand();
317 Purpose : Expands the sequence pattern using special ambiguity codes.
318 Example : $pat = $seq_pat->expand();
319 Returns : String containing fully expanded sequence pattern
320 Argument : n/a
321 Throws : Exception if sequence type is not recognized
322 : (i.e., is not one of [DR]NA, Amino)
323  
324 See Also : L<Extended Alphabet Support>, L<_expand_pep>(), L<_expand_nuc>()
325  
326 =cut
327  
328 #----------
329 2 ▶sub expand {
Subroutine expand: called CC=3 SCAR=11.8
Pod undocumented
330 #----------
331 2 my $self = shift;
332  
333 2 ▶ if($self->type =~ /[DR]na/i) { $self->_expand_nuc(); }
Branch: 2 branches
BranchTrueFalseTotal
if ($self->type =~ /[DR]na/i) { } 1 1 2
elsif ($self->type =~ /Amino/i) { } 1 0 1
334 1 elsif($self->type =~ /Amino/i) { $self->_expand_pep(); }
335 else{
336 0 $self->throw("Don't know how to expand ${\$self->type} patterns.\n");
337 }
338 }
339  
340  
341 =head1 _expand_pep
342  
343 Title : _expand_pep
344 Usage : n/a; automatically called by expand()
345 Purpose : Expands peptide patterns
346 Returns : String (the expanded pattern)
347 Argument : String (the unexpanded pattern)
348 Throws : n/a
349  
350 See Also : L<expand>(), L<_expand_nuc>()
351  
352 =cut
353  
354 #----------------
355 1 ▶sub _expand_pep {
Subroutine _expand_pep: called CC=3 SCAR=12.2
356 #----------------
357 1 my ($self,$pat) = @_;
358 1 ▶ $pat ||= $self->str;
Condition33%1/3
$pat ||= $self->str
l!l&&r!l&&!r
010
MC/DC0%0/2
$pat ||= $self->str
$pat $self->str
Truth table33%1/3
A ||= B
A= $patB= $self->str
ABresult
1X1
011
000
359 1 $pat =~ s/X/./g;
360 1 $pat =~ s/^</\^/;
361 1 $pat =~ s/>$/\$/;
362  
363 ## Avoid nested situations: [bmnq] --/--> [[$ZED]mnq]
364 ## Yet correctly deal with: fze[bmnq] ---> f[$BEE]e[$ZEDmnq]
365 1 ▶ if($pat =~ /\[\w*[BZ]\w*\]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pat =~ /\[\w*[BZ]\w*\]/) { } 0 1 1
366 0 $pat =~ s/\[(\w*)B(\w*)\]/\[$1$ZED$2\]/g;
367 0 $pat =~ s/\[(\w*)Z(\w*)\]/\[$1$BEE$2\]/g;
368 0 $pat =~ s/B/\[$ZED\]/g;
369 0 $pat =~ s/Z/\[$BEE\]/g;
370 } else {
371 1 $pat =~ s/B/\[$ZED\]/g;
372 1 $pat =~ s/Z/\[$BEE\]/g;
373 }
374 1 $pat =~ s/\((.)\)/$1/g; ## Doing these last since:
375 1 $pat =~ s/\[(.)\]/$1/g; ## Pattern could contain [B] (for example)
376  
377 1 return $pat;
378 }
379  
380  
381  
382 =head1 _expand_nuc
383  
384 Title : _expand_nuc
385 Purpose : Expands nucleotide patterns
386 Returns : String (the expanded pattern)
387 Argument : String (the unexpanded pattern)
388 Throws : n/a
389  
390 See Also : L<expand>(), L<_expand_pep>()
391  
392 =cut
393  
394 #---------------
395 2 ▶sub _expand_nuc {
Subroutine _expand_nuc: called CC=3 SCAR=13.7
396 #---------------
397 2 my ($self,$pat) = @_;
398  
399 2 ▶ $pat ||= $self->str;
Condition66%2/3
$pat ||= $self->str
l!l&&r!l&&!r
110
MC/DC0%0/2
$pat ||= $self->str
$pat $self->str
Truth table66%2/3
A ||= B
A= $patB= $self->str
ABresult
1X1
011
000
400 2 $pat =~ s/N|X/./g;
401 2 $pat =~ s/pu/R/ig;
402 2 $pat =~ s/py/Y/ig;
403 2 $pat =~ s/U/T/g;
404 2 $pat =~ s/^</\^/;
405 2 $pat =~ s/>$/\$/;
406  
407 ## Avoid nested situations: [ya] --/--> [[ct]a]
408 ## Yet correctly deal with: sg[ya] ---> [gc]g[cta]
409 2 ▶ if($pat =~ /\[\w*[RYSWMK]\w*\]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pat =~ /\[\w*[RYSWMK]\w*\]/) { } 0 2 2
410 0 $pat =~ s/\[(\w*)R(\w*)\]/\[$1$PURINES$2\]/g;
411 0 $pat =~ s/\[(\w*)Y(\w*)\]/\[$1$PYRIMIDINES$2\]/g;
412 0 $pat =~ s/\[(\w*)S(\w*)\]/\[$1GC$2\]/g;
413 0 $pat =~ s/\[(\w*)W(\w*)\]/\[$1AT$2\]/g;
414 0 $pat =~ s/\[(\w*)M(\w*)\]/\[$1AC$2\]/g;
415 0 $pat =~ s/\[(\w*)K(\w*)\]/\[$1GT$2\]/g;
416 0 $pat =~ s/\[(\w*)V(\w*)\]/\[$1ACG$2\]/g;
417 0 $pat =~ s/\[(\w*)H(\w*)\]/\[$1ACT$2\]/g;
418 0 $pat =~ s/\[(\w*)D(\w*)\]/\[$1AGT$2\]/g;
419 0 $pat =~ s/\[(\w*)B(\w*)\]/\[$1CGT$2\]/g;
420 0 $pat =~ s/R/\[$PURINES\]/g;
421 0 $pat =~ s/Y/\[$PYRIMIDINES\]/g;
422 0 $pat =~ s/S/\[GC\]/g;
423 0 $pat =~ s/W/\[AT\]/g;
424 0 $pat =~ s/M/\[AC\]/g;
425 0 $pat =~ s/K/\[GT\]/g;
426 0 $pat =~ s/V/\[ACG\]/g;
427 0 $pat =~ s/H/\[ACT\]/g;
428 0 $pat =~ s/D/\[AGT\]/g;
429 0 $pat =~ s/B/\[CGT\]/g;
430 } else {
431 2 $pat =~ s/R/\[$PURINES\]/g;
432 2 $pat =~ s/Y/\[$PYRIMIDINES\]/g;
433 2 $pat =~ s/S/\[GC\]/g;
434 2 $pat =~ s/W/\[AT\]/g;
435 2 $pat =~ s/M/\[AC\]/g;
436 2 $pat =~ s/K/\[GT\]/g;
437 2 $pat =~ s/V/\[ACG\]/g;
438 2 $pat =~ s/H/\[ACT\]/g;
439 2 $pat =~ s/D/\[AGT\]/g;
440 2 $pat =~ s/B/\[CGT\]/g;
441 }
442 2 $pat =~ s/\((.)\)/$1/g; ## Doing thses last since:
443 2 $pat =~ s/\[(.)\]/$1/g; ## Pattern could contain [y] (for example)
444  
445 2 return $pat;
446 }
447  
448  
449  
450 =head1 revcom
451  
452 Title : revcom
453 Usage : revcom([1]);
454 Purpose : Forms a pattern capable of recognizing the reverse complement
455 : version of a nucleotide sequence pattern.
456 Example : $pattern_object->revcom();
457 : $pattern_object->revcom(1); ## returns expanded rev complement pattern.
458 Returns : Object reference for a new Bio::Tools::SeqPattern containing
459 : the revcom of the current pattern as its sequence.
460 Argument : (1) boolean (optional) (default= false)
461 : true : expand the pattern before rev-complementing.
462 : false: don't expand pattern before or after rev-complementing.
463 Throws : Exception if called for amino acid sequence pattern.
464 Comments : This method permits the simultaneous searching of both
465 : sense and anti-sense versions of a nucleotide pattern
466 : by means of a grep-type of functionality in which any
467 : number of patterns may be or-ed into the recognition
468 : pattern.
469 : Overrides Bio::Seq::revcom() and calls it first thing.
470 : The order of _fixpat() calls is critical.
471  
472 See Also : L<Bio::Seq::revcom>, L</_fixpat_1>, L</_fixpat_2>, L</_fixpat_3>, L</_fixpat_4>, L</_fixpat_5>
473  
474 =cut
475  
476 #-----------'
477 34 ▶sub revcom {
Subroutine revcom: called CC=4 SCAR=13.9
Pod undocumented
478 #-----------
479 34 my($self,$expand) = @_;
480  
481 34 ▶ if ($self->type !~ /Dna|Rna/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->type =~ /Dna|Rna/i) 1 33 34
482 1 $self->throw("Can't get revcom for ${\$self->type} sequence types.\n");
483 }
484 # return $self->{'_rev'} if defined $self->{'_rev'};
485  
486 33 ▶ $expand ||= 0;
Condition100%2/2
$expand ||= 0
l!l
132
MC/DC100%1/1
$expand ||= 0
$expand
Truth table100%2/2
A
A= $expand
Aresult
11
00
487 33 my $str = $self->str;
488 33 $str =~ tr/acgtrymkswhbvdnxACGTRYMKSWHBVDNX/tgcayrkmswdvbhnxTGCAYRKMSWDVBHNX/;
489 33 my $rev = CORE::reverse $str;
490 33 $rev =~ tr/[](){}<>/][)(}{></;
491  
492 33 ▶ if($expand) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expand) 1 32 33
493 1 $rev = $self->_expand_nuc($rev);
494 # print "\nExpanded: $rev\n";
495 }
496  
497 33 %Processed_braces = ();
498 33 %Processed_asterics = ();
499  
500 33 my $fixrev = _fixpat_1($rev);
501 # print "FIX 1: $fixrev";<STDIN>;
502  
503 33 $fixrev = _fixpat_2($fixrev);
504 # print "FIX 2: $fixrev";<STDIN>;
505  
506 33 $fixrev = _fixpat_3($fixrev);
507 # print "FIX 3: $fixrev";<STDIN>;
508  
509 33 $fixrev = _fixpat_4($fixrev);
510 # print "FIX 4: $fixrev";<STDIN>;
511  
512 33 $fixrev = _fixpat_5($fixrev);
513 # print "FIX 5: $fixrev";<STDIN>;
514  
515 ##### Added by ps 8/7/00 to allow non-greedy matching
516 33 $fixrev = _fixpat_6($fixrev);
517 # print "FIX 6: $fixrev";<STDIN>;
518  
519 # $self->{'_rev'} = $fixrev;
520  
521 33 return Bio::Tools::SeqPattern->new(-seq =>$fixrev, -type =>$self->type);
522 }
523  
524 =head1 backtranslate
525  
526 Title : backtranslate
527 Usage : backtranslate();
528 Purpose : Produce a degenerate oligonucleotide whose translation would produce
529 : the original protein motif.
530 Example : $pattern_object->backtranslate();
531 Returns : Object reference for a new Bio::Tools::SeqPattern containing
532 : the reverse translation of the current pattern as its sequence.
533 Throws : Exception if called for nucleotide sequence pattern.
534  
535 =cut
536  
537 1 ▶sub backtranslate {
Subroutine backtranslate: called CC=2 SCAR=7.6
Pod undocumented
538 1 my $self = shift;
539
540 # _load_module loads dynamically, caches call if successful
541 1 $self->_load_module('Bio::Tools::SeqPattern::Backtranslate');
542 1 Bio::Tools::SeqPattern::Backtranslate->import("_reverse_translate_motif");
543  
544 1 ▶ if ($self->type ne 'Amino') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type ne "Amino") 0 1 1
545 0 $self->throw(
546 0 "Can't get backtranslate for ${\$self->type} sequence types.\n"
547 );
548 }
549  
550 1 return __PACKAGE__->new(
551 -SEQ => _reverse_translate_motif($self->str),
552 -TYPE => 'Dna',
553 );
554 }
555  
556 =head1 _fixpat_1
557  
558 Title : _fixpat_1
559 Usage : n/a; called automatically by revcom()
560 Purpose : Utility method for revcom()
561 : Converts all {7,5} --> {5,7} (Part I)
562 : and [T^] --> [^T] (Part II)
563 : and *N --> N* (Part III)
564 Returns : String (the new, partially reversed pattern)
565 Argument : String (the expanded pattern)
566 Throws : n/a
567  
568 See Also : L<revcom>()
569  
570 =cut
571  
572 #--------------
573 33 ▶sub _fixpat_1 {
Subroutine _fixpat_1: called CC=7 SCAR=20.1
574 #--------------
575 33 my $pat = shift;
576  
577 ## Part I:
578 33 my (@done,@parts);
579 33 while(1) {
580 37 ▶ $pat =~ /(.*)\{(\S+?)\}(.*)/ or do{ push @done, $pat; last; };
Branch: 1 branch
BranchTrueFalseTotal
$pat =~ /(.*)\{(\S+?)\}(.*)/ or do { push @done, $pat; last } 4 33 37
581 4 $pat = $1.'#{'.reverse($2).'}'.$3;
582 # print "1: $1\n2: $2\n3: $3\n";
583 # print "modified pat: $pat";<STDIN>;
584 4 @parts = split '#', $pat;
585 4 push @done, $parts[1];
586 4 $pat = $parts[0];
587 # print "done: $parts[1]<---\nnew pat: $pat<---";<STDIN>;
588 4 ▶ last if not $pat;
Branch: 1 branch
BranchTrueFalseTotal
unless $pat 0 4 4
589 }
590 33 $pat = join('', reverse @done);
591  
592 ## Part II:
593 33 @done = ();
594 33 while(1) {
595 117 ▶ $pat =~ /(.*)\[(\S+?)\](.*)/ or do{ push @done, $pat; last; };
Branch: 1 branch
BranchTrueFalseTotal
$pat =~ /(.*)\[(\S+?)\](.*)/ or do { push @done, $pat; last } 98 19 117
596 98 $pat = $1.'#['.reverse($2).']'.$3;
597 # print "1: $1\n2: $2\n3: $3\n";
598 # print "modified pat: $pat";<STDIN>;
599 98 @parts = split '#', $pat;
600 98 push @done, $parts[1];
601 98 $pat = $parts[0];
602 # print "done: $parts[1]<---\nnew pat: $pat<---";<STDIN>;
603 98 ▶ last if not $pat;
Branch: 1 branch
BranchTrueFalseTotal
unless $pat 14 84 98
604 }
605 33 $pat = join('', reverse @done);
606  
607 ## Part III:
608 33 @done = ();
609 33 while(1) {
610 33 ▶ $pat =~ /(.*)\*([\w.])(.*)/ or do{ push @done, $pat; last; };
Branch: 1 branch
BranchTrueFalseTotal
$pat =~ /(.*)\*([\w.])(.*)/ or do { push @done, $pat; last } 0 33 33
611 0 $pat = $1.'#'.$2.'*'.$3;
612 0 $Processed_asterics{$2}++;
613 # print "1: $1\n2: $2\n3: $3\n";
614 # print "modified pat: $pat";<STDIN>;
615 0 @parts = split '#', $pat;
616 0 push @done, $parts[1];
617 0 $pat = $parts[0];
618 # print "done: $parts[1]<---\nnew pat: $pat<---";<STDIN>;
619 0 ▶ last if not $pat;
Branch: 1 branch
BranchTrueFalseTotal
unless $pat 0 0 0
620 }
621 33 return join('', reverse @done);
622  
623 }
624  
625  
626 =head1 _fixpat_2
627  
628 Title : _fixpat_2
629 Usage : n/a; called automatically by revcom()
630 Purpose : Utility method for revcom()
631 : Converts all {5,7}Y ---> Y{5,7}
632 : and {10,}. ---> .{10,}
633 Returns : String (the new, partially reversed pattern)
634 Argument : String (the expanded, partially reversed pattern)
635 Throws : n/a
636  
637 See Also : L<revcom>()
638  
639 =cut
640  
641 #--------------
642 33 ▶sub _fixpat_2 {
Subroutine _fixpat_2: called CC=3 SCAR=11.0
643 #--------------
644 33 my $pat = shift;
645  
646 33 local($^W) = 0;
647 33 my (@done,@parts,$braces);
648 33 while(1) {
649 # $pat =~ s/(.*)([^])])(\{\S+?\})([\w.])(.*)/$1$2#$4$3$5/ or do{ push @done, $pat; last; };
650 37 ▶ $pat =~ s/(.*)(\{\S+?\})([\w.])(.*)/$1#$3$2$4/ or do{ push @done, $pat; last; };
Branch: 1 branch
BranchTrueFalseTotal
$pat =~ s/(.*)(\{\S+?\})([\w.])(.*)/$1#$3$2$4/ or do { push @done, $pat; last } 4 33 37
651 4 $braces = $2;
652 4 $braces =~ s/[{}]//g;
653 4 $Processed_braces{"$3$braces"}++;
654 # print "modified pat: $pat";<STDIN>;
655 4 @parts = split '#', $pat;
656 4 push @done, $parts[1];
657 4 $pat = $parts[0];
658 # print "done: $parts[1]<---\nnew pat: $pat<---";<STDIN>;
659 4 ▶ last if not $pat;
Branch: 1 branch
BranchTrueFalseTotal
unless $pat 0 4 4
660 }
661 33 return join('', reverse @done);
662 }
663  
664  
665 =head1 _fixpat_3
666  
667 Title : _fixpat_3
668 Usage : n/a; called automatically by revcom()
669 Purpose : Utility method for revcom()
670 : Converts all {5,7}(XXX) ---> (XXX){5,7}
671 Returns : String (the new, partially reversed pattern)
672 Argument : String (the expanded, partially reversed pattern)
673 Throws : n/a
674  
675 See Also : L<revcom>()
676  
677 =cut
678  
679 #-------------
680 33 ▶sub _fixpat_3 {
Subroutine _fixpat_3: called CC=4 SCAR=14.0
681 #-------------
682 33 my $pat = shift;
683  
684 33 my (@done,@parts,$braces,$newpat,$oldpat);
685 33 while(1) {
686 # $pat =~ s/(.+)(\{\S+\})(\(\w+\))(.*)/$1#$3$2$4/ or do{ push @done, $pat; last; };
687 36 ▶ if( $pat =~ /(.*)(.)(\{\S+\})(\(\w+\))(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pat =~ /(.*)(.)(\{\S+\})(\(\w+\))(.*)/) { } 3 33 36
elsif ($pat =~ /^(\{\S+\})(\(\w+\))(.*)/) { } 0 33 33
688 3 $newpat = "$1#$2$4$3$5";
689 ##ps $oldpat = "$1#$2$3$4$5";
690 # print "1: $1\n2: $2\n3: $3\n4: $4\n5: $5\n";
691 ##ps $braces = $3;
692 ##ps $braces =~ s/[{}]//g;
693 ##ps if( exists $Processed_braces{"$2$braces"} || exists $Processed_asterics{$2}) {
694 ##ps $pat = $oldpat; # Don't change it. Already processed.
695 # print "saved pat: $pat";<STDIN>;
696 ##ps } else {
697 # print "new pat: $newpat";<STDIN>;
698 3 $pat = $newpat; # Change it.
699 ##ps }
700 } elsif( $pat =~ /^(\{\S+\})(\(\w+\))(.*)/) {
701 0 $pat = "#$2$1$3";
702 } else {
703 33 push @done, $pat; last;
704 }
705 3 @parts = split '#', $pat;
706 3 push @done, $parts[1];
707 3 $pat = $parts[0];
708 # print "done: $parts[1]<---\nnew pat: $pat<---";<STDIN>;
709 3 ▶ last if not $pat;
Branch: 1 branch
BranchTrueFalseTotal
unless $pat 0 3 3
710 }
711 33 return join('', reverse @done);
712 }
713  
714  
715 =head1 _fixpat_4
716  
717 Title : _fixpat_4
718 Usage : n/a; called automatically by revcom()
719 Purpose : Utility method for revcom()
720 : Converts all {5,7}[XXX] ---> [XXX]{5,7}
721 Returns : String (the new, partially reversed pattern)
722 Argument : String (the expanded, partially reversed pattern)
723 Throws : n/a
724  
725 See Also : L<revcom>()
726  
727 =cut
728  
729 #---------------
730 33 ▶sub _fixpat_4 {
Subroutine _fixpat_4: called CC=8 SCAR=35.6
731 #---------------
732 33 my $pat = shift;
733  
734 33 my (@done,@parts,$braces,$newpat,$oldpat);
735 33 while(1) {
736 # $pat =~ s/(.*)(\{\S+\})(\[\w+\])(.*)/$1#$3$2$4/ or do{ push @done, $pat; last; };
737 # $pat =~ s/(.*)([^\w.])(\{\S+\})(\[\w+\])(.*)/$1$2#$4$3$5/ or do{ push @done, $pat; last; };
738 33 ▶ if( $pat =~ /(.*)(.)(\{\S+\})(\[\w+\])(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pat =~ /(.*)(.)(\{\S+\})(\[\w+\])(.*)/) { } 0 33 33
elsif ($pat =~ /^(\{\S+\})(\[\w+\])(.*)/) { } 0 33 33
739 0 $newpat = "$1#$2$4$3$5";
740 0 $oldpat = "$1#$2$3$4$5";
741 # print "1: $1\n2: $2\n3: $3\n4: $4\n5: $5\n";
742 0 $braces = $3;
743 0 $braces =~ s/[{}]//g;
744 0 ▶ if( (defined $braces and defined $2) and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $braces and defined $2 and exists $Processed_braces{"$2$braces"} || exists $Processed_asterics{$2}) { } 0 0 0
Condition0%0/9
defined $braces and defined $2 and exists $Processed_braces{"$2$braces"} || exists $Processed_asterics{$2}
!ll&&!rl&&r
000
defined $braces and defined $2
!ll&&!rl&&r
000
exists $Processed_braces{"$2$braces"} or exists $Processed_asterics{$2}
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $braces and defined $2 and exists $Processed_braces{"$2$braces"} || exists $Processed_asterics{$2}
defined $braces defined $2 exists $Processed_braces{"$2$braces"} exists $Processed_asterics{$2}
Truth table0%0/5
A and B and C or D
A= defined $bracesB= defined $2C= exists $Processed_braces{"$2$braces"}D= exists $Processed_asterics{$2}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
745 exists $Processed_braces{"$2$braces"} || exists $Processed_asterics{$2}) {
746 0 $pat = $oldpat; # Don't change it. Already processed.
747 # print "saved pat: $pat";<STDIN>;
748 } else {
749 0 $pat = $newpat; # Change it.
750 # print "new pat: $pat";<STDIN>;
751 }
752 } elsif( $pat =~ /^(\{\S+\})(\[\w+\])(.*)/) {
753 0 $pat = "#$2$1$3";
754 } else {
755 33 push @done, $pat; last;
756 }
757  
758 0 @parts = split '#', $pat;
759 0 push @done, $parts[1];
760 0 $pat = $parts[0];
761 # print "done: $parts[1]<---\nnew pat: $pat<---";<STDIN>;
762 0 ▶ last if not $pat;
Branch: 1 branch
BranchTrueFalseTotal
unless $pat 0 0 0
763 }
764 33 return join('', reverse @done);
765 }
766  
767  
768 =head1 _fixpat_5
769  
770 Title : _fixpat_5
771 Usage : n/a; called automatically by revcom()
772 Purpose : Utility method for revcom()
773 : Converts all *[XXX] ---> [XXX]*
774 : and *(XXX) ---> (XXX)*
775 Returns : String (the new, partially reversed pattern)
776 Argument : String (the expanded, partially reversed pattern)
777 Throws : n/a
778  
779 See Also : L<revcom>()
780  
781 =cut
782  
783 #--------------
784 33 ▶sub _fixpat_5 {
Subroutine _fixpat_5: called CC=5 SCAR=24.5
785 #--------------
786 33 my $pat = shift;
787  
788 33 my (@done,@parts,$newpat,$oldpat);
789 33 while(1) {
790 # $pat =~ s/(.*)(\{\S+\})(\[\w+\])(.*)/$1#$3$2$4/ or do{ push @done, $pat; last; };
791 # $pat =~ s/(.*)([^\w.])(\{\S+\})(\[\w+\])(.*)/$1$2#$4$3$5/ or do{ push @done, $pat; last; };
792 33 ▶ if( $pat =~ /(.*)(.)\*(\[\w+\]|\(\w+\))(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pat =~ /(.*)(.)\*(\[\w+\]|\(\w+\))(.*)/) { } 0 33 33
elsif ($pat =~ /^\*(\[\w+\]|\(\w+\))(.*)/) { } 0 33 33
793 0 $newpat = "$1#$2$3*$4";
794 0 $oldpat = "$1#$2*$3$4";
795 # print "1: $1\n2: $2\n3: $3\n4: $4\n";
796 0 ▶ if( exists $Processed_asterics{$2}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Processed_asterics{$2}) { } 0 0 0
797 0 $pat = $oldpat; # Don't change it. Already processed.
798 # print "saved pat: $pat";<STDIN>;
799 } else {
800 0 $pat = $newpat; # Change it.
801 # print "new pat: $pat";<STDIN>;
802 }
803 } elsif( $pat =~ /^\*(\[\w+\]|\(\w+\))(.*)/) {
804 0 $pat = "#$1*$3";
805 } else {
806 33 push @done, $pat; last;
807 }
808  
809 0 @parts = split '#', $pat;
810 0 push @done, $parts[1];
811 0 $pat = $parts[0];
812 # print "done: $parts[1]<---\nnew pat: $pat<---";<STDIN>;
813 0 ▶ last if not $pat;
Branch: 1 branch
BranchTrueFalseTotal
unless $pat 0 0 0
814 }
815 33 return join('', reverse @done);
816 }
817  
818  
819  
820  
821  
822 ############################
823 #
824 # PS: Added 8/7/00 to allow non-greedy matching patterns
825 #
826 ######################################
827  
828 =head1 _fixpat_6
829  
830 Title : _fixpat_6
831 Usage : n/a; called automatically by revcom()
832 Purpose : Utility method for revcom()
833 : Converts all ?Y{5,7} ---> Y{5,7}?
834 : and ?(XXX){5,7} ---> (XXX){5,7}?
835 : and ?[XYZ]{5,7} ---> [XYZ]{5,7}?
836 Returns : String (the new, partially reversed pattern)
837 Argument : String (the expanded, partially reversed pattern)
838 Throws : n/a
839  
840 See Also : L<revcom>()
841  
842 =cut
843  
844 #--------------
845 33 ▶sub _fixpat_6 {
Subroutine _fixpat_6: called CC=4 SCAR=19.0
846 #--------------
847 33 my $pat = shift;
848 33 my (@done,@parts);
849  
850 33 @done = ();
851 33 while(1) {
852 33 ▶ $pat =~ /(.*)\?(\[\w+\]|\(\w+\)|\w)(\{\S+?\})?(.*)/ or do{ push @done, $pat; last; };
Branch: 1 branch
BranchTrueFalseTotal
$pat =~ /(.*)\?(\[\w+\]|\(\w+\)|\w)(\{\S+?\})?(.*)/ or do { push @done, $pat; last } 0 33 33
853 0 ▶ my $quantifier = $3 ? $3 : ""; # Shut up warning if no explicit quantifier
Branch: 1 branch
BranchTrueFalseTotal
$3 ? : 0 0 0
854 0 $pat = $1.'#'.$2.$quantifier.'?'.$4;
855 # $pat = $1.'#'.$2.$3.'?'.$4;
856  
857 # print "1: $1\n2: $2\n3: $3\n";
858 # print "modified pat: $pat";<STDIN>;
859 0 @parts = split '#', $pat;
860 0 push @done, $parts[1];
861 0 $pat = $parts[0];
862 # print "done: $parts[1]<---\nnew pat: $pat<---";<STDIN>;
863 0 ▶ last if not $pat;
Branch: 1 branch
BranchTrueFalseTotal
unless $pat 0 0 0
864 }
865 33 return join('', reverse @done);
866  
867 }
868  
869 =head2 str
870  
871 Title : str
872 Usage : $obj->str($newval)
873 Function:
874 Returns : value of str
875 Args : newvalue (optional)
876  
877  
878 =cut
879  
880 138 ▶sub str{
Subroutine str: called CC=2 SCAR=6.9
Pod documented
881 138 my $obj = shift;
882 138 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 68 70 138
883 68 my $value = shift;
884 68 $obj->{'str'} = $value;
885 }
886 138 return $obj->{'str'};
887  
888 }
889  
890 =head2 type
891  
892 Title : type
893 Usage : $obj->type($newval)
894 Function:
895 Returns : value of type
896 Args : newvalue (optional)
897  
898  
899 =cut
900  
901 140 ▶sub type{
Subroutine type: called CC=2 SCAR=6.9
Pod documented
902 140 my $obj = shift;
903 140 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 68 72 140
904 68 my $value = shift;
905 68 $obj->{'type'} = $value;
906 }
907 140 return $obj->{'type'};
908  
909 }
910  
911 4 1;
912  
913 __END__
« Bio/Tools/SeqStats.pm ↑ Summary Bio/Tools/isPcr.pm »