blib/lib/MEME/Alphabet.pm

filter: Statementstmt 57.3% 474 / 826 Branchbran 43.0% 167 / 388 Conditioncond 56.0% 70 / 125 MC/DCmcdc 33.7% 26 / 77 Subroutinesub 53.3% 32 / 60 Podpod 0.0% 0 / 42 totaltotal 50.6% 769 / 1518 SCAR 87.9
CC
248
Cov
53%
to_text
380.0
_symobj_cmp
343.3
to_json
110.0
CRAP 6593.1
↑ Summary
1 =pod
2  
3 =head1 NAME
4  
5 MEME::Alphabet - Provides nucleobase alphabet capabilities for Perl code.
6  
7 =head1 AUTHORS
8  
9 James Johnson and Timothy L. Bailey.
10  
11 =head1 LICENSE
12  
13 Copyright
14 (1994 - 2017) The Regents of the University of California.
15 All Rights Reserved.
16  
17 Permission to use, copy, modify, and distribute any part of
18 this software for educational, research and non-profit purposes,
19 without fee, and without a written agreement is hereby granted,
20 provided that the above copyright notice, this paragraph and
21 the following three paragraphs appear in all copies.
22  
23 Those desiring to incorporate this software into commercial
24 products or use for commercial purposes should contact the
25 Technology Transfer Office, University of California, San Diego,
26 9500 Gilman Drive, La Jolla, California, 92093-0910,
27 Ph: (619) 534 5815.
28  
29 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO
30 ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
31 CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF
32 THE USE OF THIS SOFTWARE, EVEN IF THE UNIVERSITY OF CALIFORNIA
33 HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  
35 THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
36 UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE
37 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
38 THE UNIVERSITY OF CALIFORNIA MAKES NO REPRESENTATIONS AND
39 EXTENDS NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
40 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
41 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, OR THAT
42 THE USE OF THE MATERIAL WILL NOT INFRINGE ANY PATENT,
43 TRADEMARK OR OTHER RIGHTS.
44  
45 =cut
46  
47 package MEME::Alphabet;
48  
49 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 2 ▶use feature 'unicode_strings';
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 2 ▶use Fcntl qw(O_RDONLY);
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 # pinned to the latest MEME Suite version (x.yy.z), and then versioned from there
57 2 ▶use version; our $VERSION = version->declare("v4.12.0.1.2");
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 2 require Exporter;
60 2 our @ISA = qw(Exporter);
61 2 our @EXPORT_OK = qw(rna dna moddna protein);
62  
63 2 my $SYM_RE = qr/[A-Za-z0-9\?\.\*\-]/;
64 2 my $COLOUR_RE = qr/[0-9A-Fa-f]{6}/;
65 2 my $NAME_RE = qr/"((?:[^\\"]+|\\["\/bfnrt]|\\u[0-9A-Fa-f]{4})*)"/;
66 2 my $CORE_RE = qr/($SYM_RE)(?:\s+$NAME_RE)?(?:\s+($COLOUR_RE))?/;
67 2 my $COMMENT_RE = qr/^(\s*(?:[^#](?:[^"#]*|"(?:\\.|[^"\\]*)*")*)?)#.*$/;
68 2 my $HEADER_RE = qr/^\s*ALPHABET(?:\s+v1)?(?:\s+$NAME_RE)?(?:\s+(RNA|DNA|PROTEIN)-LIKE)?\s*$/;
69 2 my $CORE_SINGLE_RE = qr/^\s*$CORE_RE\s*$/;
70 2 my $CORE_PAIR_RE = qr/^\s*$CORE_RE\s*~\s*$CORE_RE\s*$/;
71 2 my $AMBIG_RE = qr/^\s*$CORE_RE\s*=\s*($SYM_RE*)\s*$/;
72  
73 sub new {
74 5 ▶ my $classname = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
75 5 my $self = {};
76 5 bless($self, $classname);
77 5 $self->_init(@_);
78 5 return $self;
79 }
80  
81 sub _init {
82 5 ▶ my $self = shift;
Subroutine _init: called CC=4 SCAR=15.7
83 5 my ($file) = @_;
84 5 $self->{errors} = [];
85 5 $self->{file_name} = undef;
86 5 $self->{line_no} = 0;
87 5 $self->{seen_header} = 0; #FALSE
88 5 $self->{seen_symbol} = 0; #FALSE
89 5 $self->{seen_ambig} = 0; #FALSE
90 5 $self->{seen_lc} = 0; #FALSE
91 5 $self->{seen_uc} = 0; #FALSE
92 5 $self->{name} = undef;
93 5 $self->{sym_lookup} = {};
94 5 $self->{core_syms} = [];
95 5 $self->{ambig_syms} = [];
96 5 $self->{parsed} = 0; #FALSE
97 5 ▶ if (defined($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 5 5
98 0 $self->parse_file($file);
99 0 ▶ if (@{$self->{errors}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"errors"};}) 0 0 0
100 0 foreach my $error ( @{$self->{errors}} ) {
101 0 warn($error);
102 }
103 0 croak("Invalid alphabet file \"$file\"\n");
104 }
105 }
106 }
107  
108 sub _error {
109 0 ▶ my $self = shift;
Subroutine _error: not called CC=3 SCAR=24.8
110 0 my ($reason) = @_;
111 0 my $line_info = '';
112 0 my $file_info = '';
113 0 ▶ $line_info = 'on line ' . $self->{line_no} . ' ' if ($self->{line_no});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"line_no"} 0 0 0
114 0 ▶ $file_info = 'file "' . $self->{file_name} . '"' if ($self->{file_name});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"file_name"} 0 0 0
115 0 push(@{$self->{errors}}, "Invalid alphabet $file_info- $line_info$reason\n");
116 }
117  
118 sub parse_header {
119 4 ▶ my $self = shift;
Subroutine parse_header: called CC=7 SCAR=21.5
Pod undocumented
120 4 my ($name, $like) = @_;
121 4 ▶ die("Already finished parsing") if $self->{parsed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parsed"} 0 4 4
122 4 ▶ $self->_error('repeated header') if ($self->{seen_header});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"seen_header"} 0 4 4
123 4 ▶ $self->_error('header after symbol') if ($self->{seen_symbol});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"seen_symbol"} 0 4 4
124 4 ▶ $self->_error('like must be "DNA", "RNA" or "PROTEIN" (ignoring case)') if ($like && $like !~ m/^(RNA|DNA|PROTEIN)$/i);
Branch: 1 branch
BranchTrueFalseTotal
if $like and not $like =~ /^(RNA|DNA|PROTEIN)$/iu 0 4 4
Condition33%1/3
$like and not $like =~ /^(RNA|DNA|PROTEIN)$/iu
!ll&&!rl&&r
040
MC/DC0%0/2
$like and not $like =~ /^(RNA|DNA|PROTEIN)$/iu
$like not $like =~ /^(RNA|DNA|PROTEIN)$/iu
Truth table33%1/3
A and not(B)
A= $likeB= not $like =~ /^(RNA|DNA|PROTEIN)$/iu
ABresult
0X0
100
111
125 4 $self->{name} = $name;
126 4 ▶ $self->{like} = ($like ? uc($like) : '');
Branch: 1 branch
BranchTrueFalseTotal
$like ? : 4 0 4
127 4 $self->{seen_header} = 1; #TRUE
128 }
129  
130 sub uniq {
131 60 ▶ my %seen;
Subroutine uniq: called CC=1 SCAR=0.0
Pod undocumented
132 60 grep !$seen{$_}++, @_;
133 }
134  
135 sub parse_symbol {
136 92 ▶ my $self = shift;
Subroutine parse_symbol: called CC=18 SCAR=31.6
Pod undocumented
137 92 my ($sym, $name, $colour, $complement, $comprise, $aliases) = @_;
138 92 ▶ die("Already finished parsing") if $self->{parsed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parsed"} 0 92 92
139 92 ▶ $self->_error('expected header but found symbol') unless ($self->{seen_header} || $self->{seen_symbol});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"seen_header"} or $self->{"seen_symbol"} 0 92 92
Condition33%1/3
$self->{"seen_header"} or $self->{"seen_symbol"}
l!l&&r!l&&!r
9200
MC/DC0%0/2
$self->{"seen_header"} or $self->{"seen_symbol"}
$self->{"seen_header"} $self->{"seen_symbol"}
Truth table33%1/3
A or B
A= $self->{"seen_header"}B= $self->{"seen_symbol"}
ABresult
1X1
011
000
140 92 ▶ if (defined($self->{sym_lookup}->{$sym})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"sym_lookup"}{$sym}) 0 92 92
141 0 $self->_error("symbol $sym is already used");
142 0 return; # can't really proceed with a duplicate
143 }
144 92 ▶ $self->{seen_lc} = 1 if ($sym ge 'a' && $sym le 'z');
Branch: 1 branch
BranchTrueFalseTotal
if $sym ge "a" and $sym le "z" 16 76 92
Condition66%2/3
$sym ge "a" and $sym le "z"
!ll&&!rl&&r
76016
MC/DC50%1/2
$sym ge "a" and $sym le "z"
$sym ge "a" $sym le "z"
Truth table66%2/3
A and B
A= $sym ge "a"B= $sym le "z"
ABresult
0X0
100
111
145 92 ▶ $self->{seen_uc} = 1 if ($sym ge 'A' && $sym le 'Z');
Branch: 1 branch
BranchTrueFalseTotal
if $sym ge "A" and $sym le "Z" 60 32 92
Condition100%3/3
$sym ge "A" and $sym le "Z"
!ll&&!rl&&r
161660
MC/DC100%2/2
$sym ge "A" and $sym le "Z"
$sym ge "A" $sym le "Z"
Truth table100%3/3
A and B
A= $sym ge "A"B= $sym le "Z"
ABresult
0X0
100
111
146 92 my $symbol = {sym => $sym, aliases => [], name => $name, colour => $colour};
147 92 ▶ if (defined($aliases)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $aliases) 8 84 92
148 8 push(@{$symbol->{aliases}}, split(//, $aliases));
149 }
150 92 ▶ if (defined($comprise)) { # ambiguous symbol
Branch: 1 branch
BranchTrueFalseTotal
if (defined $comprise) { } 60 32 92
151 60 my @equals = split //, $comprise;
152 60 @equals = sort _symbol_cmp @equals;
153 60 @equals = &uniq(@equals);
154 60 ▶ for (my $i = 0; $i < scalar(@equals); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @equals) 160 60 220
155 160 my $csym = $self->{sym_lookup}->{$equals[$i]};
156 160 ▶ if (!defined($csym)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $csym) { } 0 160 160
elsif (defined $csym->{'comprise'}) { } 0 160 160
157 0 $self->_error('referenced symbol ' . $equals[$i] . ' is unknown');
158 } elsif (defined($csym->{comprise})) {
159 0 $self->_error('referenced symbol ' . $equals[$i] . ' is ambiguous');
160 }
161 }
162 60 $symbol->{comprise} = join('', @equals);
163 60 push(@{$self->{ambig_syms}}, $symbol);
164 60 $self->{seen_ambig} = 1;
165 60 ▶ if ($sym eq '?' && length($symbol->{comprise}) < scalar(@{$self->{core_syms}})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sym eq "?" and length $symbol->{"comprise"} < scalar @{$self->{"core_syms"};}) 0 60 60
Condition33%1/3
$sym eq "?" and length $symbol->{"comprise"} < scalar @{$self->{"core_syms"};}
!ll&&!rl&&r
6000
MC/DC0%0/2
$sym eq "?" and length $symbol->{"comprise"} < scalar @{$self->{"core_syms"};}
$sym eq "?" length $symbol->{"comprise"} < scalar @{$self->{"core_syms"};}
Truth table33%1/3
A and B
A= $sym eq "?"B= length $symbol->{"comprise"} < scalar @{$self->{"core_syms"};}
ABresult
0X0
100
111
166 0 $self->_error('symbol ? is reserved as a wildcard');
167 }
168 } else { # core symbol
169 32 ▶ $self->_error('symbol ? is reserved as a wildcard') if ($sym eq '?');
Branch: 1 branch
BranchTrueFalseTotal
if $sym eq "?" 0 32 32
170 32 ▶ $self->_error('unexpected core symbol (as ambiguous symbols seen)') if ($self->{seen_ambig});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"seen_ambig"} 0 32 32
171 32 $symbol->{complement} = $complement;
172 32 push(@{$self->{core_syms}}, $symbol);
173 }
174 92 $self->{sym_lookup}->{$sym} = $symbol;
175 92 $self->{seen_symbol} = 1;
176 }
177  
178 sub parse_line {
179 0 ▶ my $self = shift;
Subroutine parse_line: not called CC=7 SCAR=40.3
Pod undocumented
180 0 ▶ die("Already finished parsing") if $self->{parsed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parsed"} 0 0 0
181 0 my ($line) = @_;
182 0 $self->{line_no} += 1;
183 0 $line =~ s/$COMMENT_RE/$1/;
184 0 ▶ return unless ($line =~ m/\S/); # skip empty lines
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/u 0 0 0
185 0 ▶ if ($line =~ m/$HEADER_RE/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($line =~ /$HEADER_RE/u) { } 0 0 0
elsif ($line =~ /$CORE_PAIR_RE/u) { } 0 0 0
elsif ($line =~ /$CORE_SINGLE_RE/u) { } 0 0 0
elsif ($line =~ /$AMBIG_RE/u) { } 0 0 0
186 0 $self->parse_header($1, $2);
187 } elsif ($line =~ m/$CORE_PAIR_RE/) {
188 0 $self->parse_symbol($1, &_decode_JSON_string($2), &_decode_colour($3), $4);
189 0 $self->parse_symbol($4, &_decode_JSON_string($5), &_decode_colour($6), $1);
190 } elsif ($line =~ m/$CORE_SINGLE_RE/) {
191 0 $self->parse_symbol($1, &_decode_JSON_string($2), &_decode_colour($3));
192 } elsif ($line =~ m/$AMBIG_RE/) {
193 0 $self->parse_symbol($1, &_decode_JSON_string($2), &_decode_colour($3), undef, $4);
194 } else {
195 0 $self->_error('unrecognised pattern');
196 }
197 }
198  
199 sub _add_lookup {
200 106 ▶ my ($lookup, $target, $character, $both_case) = @_;
Subroutine _add_lookup: called CC=6 SCAR=19.1
201 106 $lookup->{$character} = $target;
202 106 ▶ if ($both_case) {
Branch: 1 branch
BranchTrueFalseTotal
if ($both_case) 36 70 106
203 36 ▶ if ($character ge 'A' && $character le 'Z') {
Branch: 2 branches
BranchTrueFalseTotal
if ($character ge 'A' and $character le 'Z') { } 34 2 36
elsif ($character ge 'a' and $character le 'z') { } 0 4 4
Condition66%2/3
$character ge "A" and $character le "Z"
!ll&&!rl&&r
2034
MC/DC50%1/2
$character ge "A" and $character le "Z"
$character ge "A" $character le "Z"
Truth table66%2/3
A and B
A= $character ge "A"B= $character le "Z"
ABresult
0X0
100
111
204 34 $lookup->{chr(ord($character) + 32)} = $target;
205 ▶ } elsif ($character ge 'a' && $character le 'z') {
Condition33%1/3
$character ge "a" and $character le "z"
!ll&&!rl&&r
200
MC/DC0%0/2
$character ge "a" and $character le "z"
$character ge "a" $character le "z"
Truth table33%1/3
A and B
A= $character ge "a"B= $character le "z"
ABresult
0X0
100
111
206 0 $lookup->{chr(ord($character) - 32)} = $target;
207 }
208 }
209 }
210  
211 sub parse_done {
212 4 ▶ my $self = shift;
Subroutine parse_done: called CC=60 SCAR=41.9
Pod undocumented
213 4 ▶ die("Already finished parsing") if $self->{parsed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parsed"} 0 4 4
214 # now sort the symbols
215 4 @{$self->{core_syms}} = sort _symobj_cmp @{$self->{core_syms}};
216 4 @{$self->{ambig_syms}} = sort _symobj_cmp @{$self->{ambig_syms}};
217 # check if there is a wildcard
218 4 ▶ if (scalar(@{$self->{ambig_syms}}) == 0 || length($self->{ambig_syms}->[0]->{comprise}) != scalar(@{$self->{core_syms}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{"ambig_syms"};} == 0 or length $self->{"ambig_syms"}[0]{"comprise"} != scalar @{$self->{"core_syms"};}) 2 2 4
Condition66%2/3
scalar @{$self->{"ambig_syms"};} == 0 or length $self->{"ambig_syms"}[0]{"comprise"} != scalar @{$self->{"core_syms"};}
l!l&&r!l&&!r
022
MC/DC50%1/2
scalar @{$self->{"ambig_syms"};} == 0 or length $self->{"ambig_syms"}[0]{"comprise"} != scalar @{$self->{"core_syms"};}
scalar @{$self->{"ambig_syms"};} == 0 length $self->{"ambig_syms"}[0]{"comprise"} != scalar @{$self->{"core_syms"};}
Truth table66%2/3
A or B
A= scalar @{$self->{"ambig_syms"};} == 0B= length $self->{"ambig_syms"}[0]{"comprise"} != scalar @{$self->{"core_syms"};}
ABresult
1X1
011
000
219 #warn("Warning: wildcard symbol automatically generated\n");
220 2 my $wildcard_comprise = '';
221 2 ▶ for (my $i = 0; $i < scalar(@{$self->{core_syms}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"core_syms"};}) 24 2 26
222 24 $wildcard_comprise .= $self->{core_syms}->[$i]->{sym};
223 }
224 2 unshift(@{$self->{ambig_syms}}, {sym => '?', aliases => [], comprise => $wildcard_comprise});
225 }
226 # create the final list of symbols and determine aliases
227 4 my %comprise_lookup = ();
228 4 $self->{ncore} = scalar(@{$self->{core_syms}});
229 4 $self->{syms} = [];
230 4 ▶ for (my $i = 0; $i < $self->{ncore}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"ncore"}) 32 4 36
231 32 my $sym = $self->{core_syms}->[$i];
232 32 $comprise_lookup{$sym->{sym}} = $sym;
233 32 $sym->{index} = scalar(@{$self->{syms}});
234 32 push(@{$self->{syms}}, $sym);
235 }
236 4 ▶ for (my $i = 0; $i < scalar(@{$self->{ambig_syms}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"ambig_syms"};}) 62 4 66
237 62 my $sym = $self->{ambig_syms}->[$i];
238 62 my $real = $comprise_lookup{$sym->{comprise}};
239 62 ▶ if (defined($real)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $real) { } 0 62 62
240 0 push(@{$real->{aliases}}, $sym->{sym});
241 } else {
242 62 $comprise_lookup{$sym->{comprise}} = $sym;
243 62 $sym->{index} = scalar(@{$self->{syms}});
244 62 push(@{$self->{syms}}, $sym);
245 }
246 }
247 # cleanup some entries we don't need
248 4 delete $self->{sym_lookup};
249 4 delete $self->{core_syms};
250 4 delete $self->{ambig_syms};
251 # map comprising characters to objects
252 4 ▶ for (my $i = $self->{ncore}; $i < scalar(@{$self->{syms}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"syms"};}) 62 4 66
253 62 my $sym = $self->{syms}->[$i];
254 62 my @list = map { $comprise_lookup{$_} } split(//, $sym->{comprise});
255 62 $sym->{comprise} = \@list;
256 }
257 #determine complements
258 4 my $fully_complementable = 1;
259 4 ▶ for (my $i = 0; $i < $self->{ncore}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"ncore"}) 32 4 36
260 32 my $sym = $self->{syms}->[$i];
261 32 ▶ unless (defined($sym->{complement})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sym->{"complement"}) 0 32 32
262 0 $fully_complementable = 0;
263 0 next;
264 }
265 32 $sym->{complement} = $comprise_lookup{$sym->{complement}};
266 }
267 4 ▶ AMBIG: for (my $i = $self->{ncore}; $i < scalar(@{$self->{syms}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"syms"};}) 62 4 66
268 62 my $sym = $self->{syms}->[$i];
269 62 my @complements = ();
270 62 ▶ for (my $j = 0; $j < scalar(@{$sym->{comprise}}); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$sym->{"comprise"};}) 184 62 246
271 184 my $target = $sym->{comprise}->[$j]->{complement};
272 184 ▶ next AMBIG unless defined $target;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target 0 184 184
273 184 push(@complements, $target->{sym});
274 }
275 62 @complements = sort _symbol_cmp @complements;
276 62 my $complement = $comprise_lookup{join('', @complements)};
277 62 ▶ next AMBIG unless defined $complement;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $complement 0 62 62
278 62 $sym->{complement} = $complement;
279 }
280 # create lookup
281 4 my $both_case = ($self->{seen_lc} != $self->{seen_uc});
282 4 $self->{lookup} = {};
283 4 ▶ for (my $i = 0; $i < scalar(@{$self->{syms}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"syms"};}) 94 4 98
284 94 my $sym = $self->{syms}->[$i];
285 94 &_add_lookup($self->{lookup}, $sym, $sym->{sym}, $both_case);
286 94 ▶ for (my $j = 0; $j < scalar(@{$sym->{aliases}}); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$sym->{"aliases"};}) 12 94 106
287 12 &_add_lookup($self->{lookup}, $sym, $sym->{aliases}->[$j], $both_case);
288 }
289 }
290 4 $self->{comprise_lookup} = \%comprise_lookup;
291 4 $self->{fully_complementable} = $fully_complementable;
292 # create regular expressions to match something that isn't a valid symbol
293 4 my $all_symbols = quotemeta(join('', (keys %{$self->{lookup}})));
294 4 $self->{re_not_valid} = qr/[^$all_symbols]/;
295 4 my $ambig_symbols = '';
296 4 ▶ for (my $i = $self->{ncore}; $i < scalar(@{$self->{syms}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"syms"};}) 62 4 66
297 62 my $entry = $self->{syms}->[$i];
298 62 my $prime_sym = $entry->{sym};
299 62 $ambig_symbols .= $prime_sym;
300 62 ▶ if ($both_case && $prime_sym =~ m/^[A-Za-z]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($both_case and $prime_sym =~ /^[A-Za-z]$/u) 22 40 62
Condition66%2/3
$both_case and $prime_sym =~ /^[A-Za-z]$/u
!ll&&!rl&&r
40022
MC/DC50%1/2
$both_case and $prime_sym =~ /^[A-Za-z]$/u
$both_case $prime_sym =~ /^[A-Za-z]$/u
Truth table66%2/3
A and B
A= $both_caseB= $prime_sym =~ /^[A-Za-z]$/u
ABresult
0X0
100
111
301 22 my $prime_sym_copy = $prime_sym; # copy
302 22 $prime_sym_copy =~ tr/A-Za-z/a-zA-Z/; # swap case
303 22 $ambig_symbols .= $prime_sym_copy;
304 }
305 62 foreach my $alias_sym (@{$entry->{aliases}}) {
306 8 $ambig_symbols .= $alias_sym;
307 8 ▶ if ($both_case && $alias_sym =~ m/^[A-Za-z]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($both_case and $alias_sym =~ /^[A-Za-z]$/u) 2 6 8
Condition100%3/3
$both_case and $alias_sym =~ /^[A-Za-z]$/u
!ll&&!rl&&r
422
MC/DC100%2/2
$both_case and $alias_sym =~ /^[A-Za-z]$/u
$both_case $alias_sym =~ /^[A-Za-z]$/u
Truth table100%3/3
A and B
A= $both_caseB= $alias_sym =~ /^[A-Za-z]$/u
ABresult
0X0
100
111
308 2 my $alias_sym_copy = $alias_sym; # copy
309 2 $alias_sym_copy =~ tr/A-Za-z/a-zA-Z/; # swap case
310 2 $ambig_symbols .= $alias_sym_copy;
311 }
312 }
313 }
314 4 $self->{re_ambig} = qr/[\Q$ambig_symbols\E]/;
315 4 $self->{re_ambig_only} = qr/^[\Q$ambig_symbols\E]*$/;
316 #$ambig_symbols = quotemeta($ambig_symbols);
317 #$self->{re_ambig} = qr/[$ambig_symbols]/;
318 #$self->{re_ambig_only} = qr/^[$ambig_symbols]*$/;
319  
320 # create translatation strings
321 # Strings to translate aliases of core symbols to prime representation
322 4 my ($tr_src_core_alias_to_prime, $tr_dst_core_alias_to_prime) = ('', '');
323 4 ▶ for (my $i = 0; $i < $self->{ncore}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"ncore"}) 32 4 36
324 32 my $entry = $self->{syms}->[$i];
325 32 my $prime_sym = $entry->{sym};
326 # alternate case of primary symbol?
327 32 ▶ if ($both_case && $prime_sym =~ m/^[A-Za-z]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($both_case and $prime_sym =~ /^[A-Za-z]$/u) 8 24 32
Condition66%2/3
$both_case and $prime_sym =~ /^[A-Za-z]$/u
!ll&&!rl&&r
2408
MC/DC50%1/2
$both_case and $prime_sym =~ /^[A-Za-z]$/u
$both_case $prime_sym =~ /^[A-Za-z]$/u
Truth table66%2/3
A and B
A= $both_caseB= $prime_sym =~ /^[A-Za-z]$/u
ABresult
0X0
100
111
328 8 my $prime_sym_copy = $prime_sym; # copy
329 8 $prime_sym_copy =~ tr/A-Za-z/a-zA-Z/; # swap case
330 8 $tr_src_core_alias_to_prime .= $prime_sym_copy;
331 8 $tr_dst_core_alias_to_prime .= $prime_sym;
332 }
333 # alias symbols
334 32 foreach my $alias_sym (@{$entry->{aliases}}) {
335 4 $tr_src_core_alias_to_prime .= $alias_sym;
336 4 $tr_dst_core_alias_to_prime .= $prime_sym;
337 # alternate case of alias symbol?
338 4 ▶ if ($both_case && $alias_sym =~ m/^[A-Za-z]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($both_case and $alias_sym =~ /^[A-Za-z]$/u) 2 2 4
Condition66%2/3
$both_case and $alias_sym =~ /^[A-Za-z]$/u
!ll&&!rl&&r
202
MC/DC50%1/2
$both_case and $alias_sym =~ /^[A-Za-z]$/u
$both_case $alias_sym =~ /^[A-Za-z]$/u
Truth table66%2/3
A and B
A= $both_caseB= $alias_sym =~ /^[A-Za-z]$/u
ABresult
0X0
100
111
339 2 my $alias_sym_copy = $alias_sym; # copy
340 2 $alias_sym_copy =~ tr/A-Za-z/a-zA-Z/; # swap case
341 2 $tr_src_core_alias_to_prime .= $alias_sym_copy;
342 2 $tr_dst_core_alias_to_prime .= $prime_sym;
343 }
344 }
345 }
346 4 $tr_src_core_alias_to_prime =~ s/([\/\-])/\\$1/g; # escape forward slash and dash
347 4 $tr_dst_core_alias_to_prime =~ s/([\/\-])/\\$1/g; # escape forward slash and dash
348 4 $self->{tr_src_core_alias_to_prime} = $tr_src_core_alias_to_prime;
349 4 $self->{tr_dst_core_alias_to_prime} = $tr_dst_core_alias_to_prime;
350 # Strings to translate aliases of ambiguous symbols to prime representation
351 4 my ($tr_src_ambig_alias_to_prime, $tr_dst_ambig_alias_to_prime) = ('', '');
352 4 ▶ for (my $i = $self->{ncore}; $i < scalar(@{$self->{syms}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"syms"};}) 62 4 66
353 62 my $entry = $self->{syms}->[$i];
354 62 my $prime_sym = $entry->{sym};
355 # alternate case of primary symbol?
356 62 ▶ if ($both_case && $prime_sym =~ m/^[A-Za-z]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($both_case and $prime_sym =~ /^[A-Za-z]$/u) 22 40 62
Condition66%2/3
$both_case and $prime_sym =~ /^[A-Za-z]$/u
!ll&&!rl&&r
40022
MC/DC50%1/2
$both_case and $prime_sym =~ /^[A-Za-z]$/u
$both_case $prime_sym =~ /^[A-Za-z]$/u
Truth table66%2/3
A and B
A= $both_caseB= $prime_sym =~ /^[A-Za-z]$/u
ABresult
0X0
100
111
357 22 my $prime_sym_copy = $prime_sym; # copy
358 22 $prime_sym_copy =~ tr/A-Za-z/a-zA-Z/; # swap case
359 22 $tr_src_ambig_alias_to_prime .= $prime_sym_copy;
360 22 $tr_dst_ambig_alias_to_prime .= $prime_sym;
361 }
362 # alias symbols
363 62 foreach my $alias_sym (@{$entry->{aliases}}) {
364 8 $tr_src_ambig_alias_to_prime .= $alias_sym;
365 8 $tr_dst_ambig_alias_to_prime .= $prime_sym;
366 # alternate case of alias symbol?
367 8 ▶ if ($both_case && $alias_sym =~ m/^[A-Za-z]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($both_case and $alias_sym =~ /^[A-Za-z]$/u) 2 6 8
Condition100%3/3
$both_case and $alias_sym =~ /^[A-Za-z]$/u
!ll&&!rl&&r
422
MC/DC100%2/2
$both_case and $alias_sym =~ /^[A-Za-z]$/u
$both_case $alias_sym =~ /^[A-Za-z]$/u
Truth table100%3/3
A and B
A= $both_caseB= $alias_sym =~ /^[A-Za-z]$/u
ABresult
0X0
100
111
368 2 my $alias_sym_copy = $alias_sym;
369 2 $alias_sym_copy =~ tr/A-Za-z/a-zA-Z/;
370 2 $tr_src_ambig_alias_to_prime .= $alias_sym_copy;
371 2 $tr_dst_ambig_alias_to_prime .= $prime_sym;
372 }
373 }
374 }
375 4 $tr_src_ambig_alias_to_prime =~ s/([\/\-])/\\$1/g; # escape forward slash and dash
376 4 $tr_dst_ambig_alias_to_prime =~ s/([\/\-])/\\$1/g; # escape forward slash and dash
377 4 $self->{tr_src_ambig_alias_to_prime} = $tr_src_ambig_alias_to_prime;
378 4 $self->{tr_dst_ambig_alias_to_prime} = $tr_dst_ambig_alias_to_prime;
379 # Strings to translate ambiguous symbols and their aliases to the wildcard
380 4 my ($tr_src_ambig_to_wild, $tr_dst_ambig_to_wild) = ('', '');
381 4 my $wildcard = $self->{syms}->[$self->{ncore}]->{sym};
382 4 ▶ for (my $i = $self->{ncore}; $i < scalar(@{$self->{syms}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"syms"};}) 62 4 66
383 62 my $entry = $self->{syms}->[$i];
384 62 my $prime_sym = $entry->{sym};
385 # primary symbol to wildcard (unless it is the wildcard)
386 62 ▶ if ($i != $self->{ncore}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i != $self->{"ncore"}) 58 4 62
387 58 $tr_src_ambig_to_wild .= $prime_sym;
388 58 $tr_dst_ambig_to_wild .= $wildcard;
389 }
390 # alternate case of primary symbol?
391 62 ▶ if ($both_case && $prime_sym =~ m/^[A-Za-z]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($both_case and $prime_sym =~ /^[A-Za-z]$/u) 22 40 62
Condition66%2/3
$both_case and $prime_sym =~ /^[A-Za-z]$/u
!ll&&!rl&&r
40022
MC/DC50%1/2
$both_case and $prime_sym =~ /^[A-Za-z]$/u
$both_case $prime_sym =~ /^[A-Za-z]$/u
Truth table66%2/3
A and B
A= $both_caseB= $prime_sym =~ /^[A-Za-z]$/u
ABresult
0X0
100
111
392 22 my $prime_sym_copy = $prime_sym;
393 22 $prime_sym_copy =~ tr/A-Za-z/a-zA-Z/;
394 22 $tr_src_ambig_to_wild .= $prime_sym_copy;
395 22 $tr_dst_ambig_to_wild .= $wildcard;
396 }
397 # alias symbols
398 62 foreach my $alias_sym (@{$entry->{aliases}}) {
399 8 $tr_src_ambig_to_wild .= $alias_sym;
400 8 $tr_dst_ambig_to_wild .= $wildcard;
401 # alternate case of alias symbol?
402 8 ▶ if ($both_case && $alias_sym =~ m/^[A-Za-z]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($both_case and $alias_sym =~ /^[A-Za-z]$/u) 2 6 8
Condition100%3/3
$both_case and $alias_sym =~ /^[A-Za-z]$/u
!ll&&!rl&&r
422
MC/DC100%2/2
$both_case and $alias_sym =~ /^[A-Za-z]$/u
$both_case $alias_sym =~ /^[A-Za-z]$/u
Truth table100%3/3
A and B
A= $both_caseB= $alias_sym =~ /^[A-Za-z]$/u
ABresult
0X0
100
111
403 2 my $alias_sym_copy = $alias_sym;
404 2 $alias_sym_copy =~ tr/A-Za-z/a-zA-Z/;
405 2 $tr_src_ambig_to_wild .= $alias_sym_copy;
406 2 $tr_dst_ambig_to_wild .= $wildcard;
407 }
408 }
409 }
410 4 $tr_src_ambig_to_wild =~ s/([\/\-])/\\$1/g; # escape forward slash and dash
411 4 $tr_dst_ambig_to_wild =~ s/([\/\-])/\\$1/g; # escape forward slash and dash
412 4 $self->{tr_src_ambig_to_wild} = $tr_src_ambig_to_wild;
413 4 $self->{tr_dst_ambig_to_wild} = $tr_dst_ambig_to_wild;
414 # Strings to translate unknown symbols to the wildcard
415 4 my ($tr_src_unknown_to_wild, $tr_dst_unknown_to_wild) = ('', '');
416 4 my $range_start = 0;
417 4 ▶ for (my $i = 33; $i <= 126; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= 126) 376 4 380
418 376 ▶ if (defined($self->{lookup}->{chr($i)})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"lookup"}{chr $i}) 140 236 376
419 140 ▶ if ($i > ($range_start + 1)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i > $range_start + 1) { } 38 102 140
elsif ($i == $range_start + 1) { } 12 90 102
420 38 $tr_src_unknown_to_wild .= sprintf("\\%03o-\\%03o", $range_start, $i - 1);
421 } elsif ($i == ($range_start + 1)) {
422 12 $tr_src_unknown_to_wild .= sprintf("\\%03o", $range_start);
423 }
424 140 $range_start = $i + 1;
425 }
426 }
427 4 $tr_src_unknown_to_wild .= sprintf("\\%03o-\\377", $range_start);
428 4 ▶ $tr_dst_unknown_to_wild = ($wildcard eq '-' || $wildcard eq '/' ? "\\" : "") .$wildcard; # tr will extend using the last character
Branch: 1 branch
BranchTrueFalseTotal
$wildcard eq '-' || $wildcard eq '/' ? : 0 4 4
Condition33%1/3
$wildcard eq "-" or $wildcard eq "/"
l!l&&r!l&&!r
004
MC/DC0%0/2
$wildcard eq "-" or $wildcard eq "/"
$wildcard eq "-" $wildcard eq "/"
Truth table33%1/3
A or B
A= $wildcard eq "-"B= $wildcard eq "/"
ABresult
1X1
011
000
429 4 $self->{tr_src_unknown_to_wild} = $tr_src_unknown_to_wild;
430 4 $self->{tr_dst_unknown_to_wild} = $tr_dst_unknown_to_wild;
431 # check 'like' a standard alphabet
432 4 ▶ if ($self->{like}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"like"}) 4 0 4
433 4 my ($req_core, $req_comp, $name);
434 4 ▶ if ($self->{like} eq 'RNA') {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'like'} eq 'RNA') { } 0 4 4
elsif ($self->{'like'} eq 'DNA') { } 4 0 4
elsif ($self->{'like'} eq 'PROTEIN') { } 0 0 0
435 0 $req_core = 'ACGU';
436 0 $name = 'RNA';
437 } elsif ($self->{like} eq 'DNA') {
438 4 $req_core = 'ACGT';
439 4 $req_comp = 'TGCA';
440 4 $name = 'DNA';
441 } elsif ($self->{like} eq 'PROTEIN') {
442 0 $req_core = 'ACDEFGHIKLMNPQRSTVWY';
443 0 $name = 'protein';
444 }
445 4 ▶ if (defined $req_core) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req_core) 4 0 4
446 4 ▶ for (my $i = 0; $i < length($req_core); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $req_core) 16 4 20
447 16 my $sym = substr($req_core, $i, 1);
448 16 my $symobj = $self->{lookup}->{$sym};
449 16 ▶ unless (defined $symobj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $symobj) 0 16 16
450 0 $self->_error("not $name like - expected symbol '$sym'");
451 }
452 16 ▶ unless ($symobj->{index} < $self->{ncore}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($symobj->{"index"} < $self->{"ncore"}) 0 16 16
453 0 $self->_error("not $name like - symbol '$sym' must be a core symbol");
454 }
455 16 ▶ if (defined $req_comp) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req_comp) { } 16 0 16
456 16 my $comp = substr($req_comp, $i, 1);
457 16 my $compobj = $self->{lookup}->{$comp};
458 16 ▶ if (not defined $compobj || not defined $symobj->{complement} || $symobj->{complement} != $compobj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $compobj or not defined $symobj->{"complement"} || $symobj->{"complement"} != $compobj) 0 16 16
Condition16%1/6
defined $compobj or not defined $symobj->{"complement"} || $symobj->{"complement"} != $compobj
l!l&&r!l&&!r
1600
defined $symobj->{'complement'} || $symobj->{'complement'} != $compobj
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $compobj or not defined $symobj->{"complement"} || $symobj->{"complement"} != $compobj
defined $compobj defined $symobj->{'complement'} $symobj->{'complement'} != $compobj
Truth table25%1/4
A or not(B || C)
A= defined $compobjB= defined $symobj->{'complement'}C= $symobj->{'complement'} != $compobj
ABCresult
1XX1
0001
01X0
0010
459 0 $self->_error("not $name like - symbol '$sym' complement must be '$comp'");
460 }
461 } else {
462 #if (defined $symobj->{complement}) {
463 # $self->_error("not $name like - symbol '$sym' must not have complement");
464 #}
465 }
466 }
467 }
468 }
469 # done
470 4 $self->{parsed} = 1; # TRUE
471 }
472  
473 sub parse_file {
474 0 ▶ my $self = shift;
Subroutine parse_file: not called CC=3 SCAR=24.8
Pod undocumented
475 0 ▶ die("Already finished parsing") if $self->{parsed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parsed"} 0 0 0
476 0 my ($file) = @_;
477 0 $self->{file_name} = $file;
478 0 my ($fh, $line);
479 0 sysopen($fh, $file, O_RDONLY);
480 0 ▶ while($line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $fh)) 0 0 0
481 0 chomp($line);
482 0 $self->parse_line($line);
483 }
484 0 close($fh);
485 0 $self->parse_done();
486 }
487  
488 sub _sym_to_text {
489 0 ▶ my ($sym) = @_;
Subroutine _sym_to_text: not called CC=3 SCAR=24.8
490 0 my $name_info = '';
491 0 ▶ if (defined($sym->{name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sym->{"name"}) 0 0 0
492 0 $name_info = ' "' . &_encode_JSON_string($sym->{name}) . '"';
493 }
494 0 my $colour_info = '';
495 0 ▶ if (defined($sym->{colour})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sym->{"colour"}) 0 0 0
496 0 $colour_info = sprintf(" %.06X", $sym->{colour});
497 }
498 0 return $sym->{sym} . $name_info . $colour_info;
499 }
500  
501 sub to_text {
502 0 ▶ my $self = shift;
Subroutine to_text: not called CC=19 SCAR=59.4
Pod undocumented
503 0 my %options = @_;
504 0 my $out = '';
505 0 my $gap = undef;
506 # set option defaults
507 0 ▶ $options{print_header} = 1 unless defined $options{print_header};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"print_header"} 0 0 0
508 0 ▶ $options{print_footer} = 1 unless defined $options{print_footer};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"print_footer"} 0 0 0
509 # output header
510 0 ▶ if ($options{print_header}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"print_header"}) 0 0 0
511 $out .= "ALPHABET " . $self->name(1) .
512 0 ▶ ($self->{like} ? ' ' . $self->{like} . '-LIKE' : '') . "\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'like'} ? : 0 0 0
513 }
514 # output all paired core symbols
515 0 ▶ for (my $i = 0; $i < $self->{ncore}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"ncore"}) 0 0 0
516 0 my $sym = $self->{syms}->[$i];
517 0 my $csym = $sym->{complement};
518 0 ▶ if (defined($csym) && $sym->{index} < $csym->{index}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $csym and $sym->{"index"} < $csym->{"index"}) 0 0 0
Condition0%0/3
defined $csym and $sym->{"index"} < $csym->{"index"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $csym and $sym->{"index"} < $csym->{"index"}
defined $csym $sym->{"index"} < $csym->{"index"}
Truth table0%0/3
A and B
A= defined $csymB= $sym->{"index"} < $csym->{"index"}
ABresult
0X0
100
111
519 0 $out .= &_sym_to_text($sym) . ' ~ ' . &_sym_to_text($csym) . "\n";
520 }
521 }
522 # output all unpared core symbols
523 0 ▶ for (my $i = 0; $i < $self->{ncore}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"ncore"}) 0 0 0
524 0 my $sym = $self->{syms}->[$i];
525 0 ▶ if (!defined($sym->{complement})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sym->{"complement"}) 0 0 0
526 0 $out .= &_sym_to_text($sym) . "\n";
527 }
528 }
529 # output ambiguous symbols
530 0 ▶ for (my $i = $self->{ncore}; $i < scalar(@{$self->{syms}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"syms"};}) 0 0 0
531 0 my $sym = $self->{syms}->[$i];
532 0 ▶ if (scalar(@{$sym->{comprise}}) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$sym->{"comprise"};} == 0) 0 0 0
533 0 $gap = $sym;
534 0 next;
535 }
536 0 my $comprise = '';
537 0 ▶ for (my $j = 0; $j < scalar(@{$sym->{comprise}}); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$sym->{"comprise"};}) 0 0 0
538 0 $comprise .= $sym->{comprise}->[$j]->{sym};
539 }
540 0 $out .= &_sym_to_text($sym) . ' = ' . $comprise . "\n";
541 0 ▶ for (my $j = 0; $j < scalar(@{$sym->{aliases}}); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$sym->{"aliases"};}) 0 0 0
542 0 $out .= $sym->{aliases}->[$j] . ' = ' . $comprise . "\n";
543 }
544 }
545 # output core symbol aliases
546 0 ▶ for (my $i = 0; $i < $self->{ncore}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"ncore"}) 0 0 0
547 0 my $sym = $self->{syms}->[$i];
548 0 ▶ for (my $j = 0; $j < scalar(@{$sym->{aliases}}); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$sym->{"aliases"};}) 0 0 0
549 0 $out .= $sym->{aliases}->[$j] . ' = ' . $sym->{sym} . "\n";
550 }
551 }
552 # output gap symbol and aliases
553 0 ▶ if ($gap) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gap) 0 0 0
554 0 $out .= &_sym_to_text($gap) . " =\n";
555 0 ▶ for (my $j = 0; $j < scalar(@{$gap->{aliases}}); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$gap->{"aliases"};}) 0 0 0
556 0 $out .= $gap->{aliases}->[$j] . " =\n";
557 }
558 }
559 # output footer
560 0 ▶ if ($options{print_footer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"print_footer"}) 0 0 0
561 0 $out .= "END ALPHABET\n";
562 }
563 0 return $out;
564 }
565  
566 sub to_json() {
567 0 ▶ my $self = shift;
Subroutine to_json: not called CC=10 SCAR=47.0
Pod undocumented
568 0 my ($jw) = @_;
569 0 $jw->start_object_value();
570 0 $jw->str_prop("name", $self->{name});
571 0 ▶ $jw->str_prop("like", lc($self->{like})) if ($self->{like});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"like"} 0 0 0
572 0 $jw->num_prop("ncore", $self->{ncore});
573 0 $jw->property("symbols");
574 0 $jw->start_array_value();
575 0 ▶ for (my $i = 0; $i < scalar(@{$self->{syms}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->{"syms"};}) 0 0 0
576 0 my $sym = $self->{syms}->[$i];
577 0 $jw->start_object_value();
578 0 $jw->str_prop("symbol", $sym->{sym});
579 0 ▶ $jw->str_prop("aliases", join("", @{$sym->{aliases}})) if (scalar(@{$sym->{aliases}}) > 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$sym->{"aliases"};} > 0 0 0 0
580 0 ▶ $jw->str_prop("name", $sym->{name}) if (defined($sym->{name}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $sym->{"name"} 0 0 0
581 0 ▶ $jw->str_prop("colour", sprintf("%06X", $sym->{colour})) if (defined($sym->{colour}) && $sym->{colour} > 0);
Branch: 1 branch
BranchTrueFalseTotal
if defined $sym->{"colour"} and $sym->{"colour"} > 0 0 0 0
Condition0%0/3
defined $sym->{"colour"} and $sym->{"colour"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $sym->{"colour"} and $sym->{"colour"} > 0
defined $sym->{"colour"} $sym->{"colour"} > 0
Truth table0%0/3
A and B
A= defined $sym->{"colour"}B= $sym->{"colour"} > 0
ABresult
0X0
100
111
582 0 ▶ if ($i < $self->{ncore}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{'ncore'}) { } 0 0 0
583 0 ▶ $jw->str_prop("complement", $sym->{complement}->{sym}) if (defined($sym->{complement}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $sym->{"complement"} 0 0 0
584 } else {
585 0 my $comprise = '';
586 0 ▶ for (my $j = 0; $j < scalar(@{$sym->{comprise}}); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$sym->{"comprise"};}) 0 0 0
587 0 $comprise .= $sym->{comprise}->[$j]->{sym};
588 }
589 0 $jw->str_prop("equals", $comprise);
590 }
591 0 $jw->end_object_value();
592 }
593 0 $jw->end_array_value();
594 0 $jw->end_object_value();
595 }
596  
597 sub has_errors {
598 4 ▶ my $self = shift;
Subroutine has_errors: called CC=1 SCAR=0.0
Pod undocumented
599 4 return scalar(@{$self->{errors}});
600 }
601  
602 sub get_errors {
603 0 ▶ my $self = shift;
Subroutine get_errors: not called CC=1 SCAR=6.9
Pod undocumented
604 0 return @{$self->{errors}};
605 }
606  
607 sub name {
608 0 ▶ my $self = shift;
Subroutine name: not called CC=2 SCAR=17.9
Pod undocumented
609 0 my ($should_encode) = @_;
610 0 ▶ if ($should_encode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($should_encode) { } 0 0 0
611 0 return '"' . &_encode_JSON_string($self->{name}) . '"';
612 } else {
613 0 return $self->{name};
614 }
615 }
616  
617 sub has_complement {
618 5 ▶ my $self = shift;
Subroutine has_complement: called CC=2 SCAR=7.1
Pod undocumented
619 5 ▶ die("Not finished parsing") unless $self->{parsed};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parsed"} 0 5 5
620 5 return $self->{fully_complementable};
621 }
622  
623 sub size_core {
624 8 ▶ my $self = shift;
Subroutine size_core: called CC=1 SCAR=0.0
Pod undocumented
625 8 return $self->{ncore};
626 }
627  
628 sub size_full {
629 8 ▶ my $self = shift;
Subroutine size_full: called CC=1 SCAR=0.0
Pod undocumented
630 8 return scalar(@{$self->{syms}});
631 }
632  
633 #
634 # Return the input list in list context
635 # and the flattened list in scalar context.
636 #
637 sub _flatten_list_in_scalar_context {
638 6 ▶ if (wantarray) {
Subroutine _flatten_list_in_scalar_context: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 5 1 6
639 5 return @_;
640 } else {
641 1 return join('' , @_);
642 }
643 }
644  
645 #
646 # Returns the concatenation of all the
647 # possible ambiguity codes of the alphabet.
648 # Returns a list in list context, otherwise a scalar.
649 #
650 sub get_ambig_syms {
651 0 ▶ my $self = shift;
Subroutine get_ambig_syms: not called CC=3 SCAR=24.8
Pod undocumented
652 0 my @ambig_syms;
653  
654 0 foreach my $sym ($self->get_syms()) {
655 0 ▶ unless ($self->is_core($sym)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_core($sym)) 0 0 0
656 0 push(@ambig_syms, $sym);
657 }
658 }
659  
660 0 return _flatten_list_in_scalar_context(@ambig_syms);
661 }
662  
663 #
664 # Returns the concatenation of all the possible symbols
665 # of the alphabet.
666 # Returns a list in list context, otherwise a scalar.
667 #
668 sub get_syms {
669 3 ▶ my $self = shift;
Subroutine get_syms: called CC=2 SCAR=6.9
Pod undocumented
670 3 my @syms;
671  
672 3 foreach my $symbol (@{$self->{syms}}) {
673 62 push(@syms, $symbol->{sym});
674 }
675  
676 3 return _flatten_list_in_scalar_context(@syms);
677 }
678  
679 #
680 # Returns the concatenation of all the core symbols
681 # of the alphabet.
682 # Returns a list in list context, otherwise a scalar.
683 #
684 sub get_core {
685 3 ▶ my $self = shift;
Subroutine get_core: called CC=3 SCAR=11.0
Pod undocumented
686 3 my @core_syms;
687  
688 3 foreach my $sym ($self->get_syms()) {
689 62 ▶ if ($self->is_core($sym)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_core($sym)) 20 42 62
690 20 push(@core_syms, $sym);
691 }
692 }
693  
694 3 return _flatten_list_in_scalar_context(@core_syms);
695 }
696  
697 #
698 # Returns a dictionary containing the core symbols that
699 # each ambiguity code of the alphabet is composed of.
700 #
701 sub get_alternates_dict {
702 0 ▶ my $self = shift;
Subroutine get_alternates_dict: not called CC=2 SCAR=17.9
Pod undocumented
703 0 my %alternates;
704 0 foreach my $ambig_base (split(//, $self->get_ambig_syms())) {
705 0 %alternates = (%alternates, %{$self->comprise($ambig_base)});
706 }
707 0 return %alternates;
708 }
709  
710 #
711 # Is the symbol part of the core alphabet.
712 #
713 sub is_core {
714 62 ▶ my $self = shift;
Subroutine is_core: called CC=2 SCAR=7.0
Pod undocumented
715 62 my ($letter) = @_;
716 62 my $sym = $self->{lookup}->{$letter};
717 62 ▶ return defined($sym) && $sym->{index} < $self->{ncore};
Condition66%2/3
defined $sym && $sym->{'index'} < $self->{'ncore'}
!ll&&!rl&&r
04220
MC/DC50%1/2
defined $sym && $sym->{'index'} < $self->{'ncore'}
defined $sym $sym->{'index'} < $self->{'ncore'}
Truth table66%2/3
A && B
A= defined $symB= $sym->{'index'} < $self->{'ncore'}
ABresult
0X0
100
111
718 }
719  
720 #
721 # Is the symbol part of the alphabet.
722 #
723 sub is_known {
724 0 ▶ my $self = shift;
Subroutine is_known: not called CC=1 SCAR=6.9
Pod undocumented
725 0 my ($letter) = @_;
726 0 my $sym = $self->{lookup}->{$letter};
727 0 return defined($sym);
728 }
729  
730 #
731 # Does the sequence only contain ambiguous symbols.
732 # This might be useful if you want to throw away something containing only
733 # ambiguous symbols as that has no real useful information.
734 #
735 sub is_ambig_seq {
736 0 ▶ my $self = shift;
Subroutine is_ambig_seq: not called CC=1 SCAR=6.9
Pod undocumented
737 0 my ($seq) = @_;
738 0 my $ambig_only_re = $self->{re_ambig_only};
739  
740 0 return scalar($seq =~ m/$ambig_only_re/);
741 }
742  
743 #
744 # Does the sequence contain ambiguous symbols.
745 #
746 sub is_part_ambig_seq {
747 0 ▶ my $self = shift;
Subroutine is_part_ambig_seq: not called CC=1 SCAR=6.9
Pod undocumented
748 0 my ($seq) = @_;
749 0 my $ambig_re = $self->{re_ambig};
750  
751 0 return scalar($seq =~ m/$ambig_re/);
752 }
753  
754 sub char {
755 0 ▶ my $self = shift;
Subroutine char: not called CC=3 SCAR=24.8
Pod undocumented
756 0 my ($index) = @_;
757  
758 0 ▶ return if ($index < 0 || $index > scalar(@{$self->{syms}}));
Branch: 1 branch
BranchTrueFalseTotal
if $index < 0 or $index > scalar @{$self->{"syms"};} 0 0 0
Condition0%0/3
$index < 0 or $index > scalar @{$self->{"syms"};}
l!l&&r!l&&!r
000
MC/DC0%0/2
$index < 0 or $index > scalar @{$self->{"syms"};}
$index < 0 $index > scalar @{$self->{"syms"};}
Truth table0%0/3
A or B
A= $index < 0B= $index > scalar @{$self->{"syms"};}
ABresult
1X1
011
000
759  
760 0 return $self->{syms}->[$index]->{sym};
761 }
762  
763 #
764 # Converts a symbol into the index in the alphabet.
765 #
766 sub index {
767 0 ▶ my $self = shift;
Subroutine index: not called CC=2 SCAR=17.9
Pod undocumented
768 0 my ($letter) = @_;
769 0 my $sym = $self->{lookup}->{$letter};
770  
771 0 ▶ return unless defined $sym;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sym 0 0 0
772  
773 0 return $sym->{index};
774 }
775  
776 #
777 # Converts a symbol that could be an alias into the primary symbol.
778 #
779 sub encode {
780 0 ▶ my $self = shift;
Subroutine encode: not called CC=2 SCAR=17.9
Pod undocumented
781 0 my ($letter) = @_;
782 0 my $sym = $self->{lookup}->{$letter};
783  
784 0 ▶ return unless defined $sym;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sym 0 0 0
785 0 return $sym->{sym};
786 }
787  
788 #
789 # Takes a letter and returns the set of comprising core symbols.
790 #
791 sub comprise {
792 0 ▶ my $self = shift;
Subroutine comprise: not called CC=3 SCAR=24.8
Pod undocumented
793 0 my ($letter) = @_;
794 0 my $sym = $self->{lookup}->{$letter};
795 0 my %set = ();
796 0 ▶ if (defined($sym->{comprise})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sym->{'comprise'}) { } 0 0 0
797 0 ▶ for (my $i = 0; $i < scalar(@{$sym->{comprise}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$sym->{"comprise"};}) 0 0 0
798 0 $set{$sym->{comprise}->[$i]->{sym}} = 1;
799 }
800 } else {
801 0 $set{$sym->{sym}} = 1;
802 }
803 0 return \%set;
804 }
805  
806 #
807 # Converts a set of core symbols into either a matching ambigous symbol or
808 # a group of core symbols.
809 #
810 sub regex {
811 0 ▶ my $self = shift;
Subroutine regex: not called CC=2 SCAR=17.9
Pod undocumented
812 0 my ($set) = @_;
813 0 my $key = join('', sort _symbol_cmp keys %{$set});
814 0 my $sym = $self->{comprise_lookup}->{$key};
815 0 ▶ if (defined($sym)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sym) { } 0 0 0
816 0 return $sym->{sym};
817 } else {
818 0 return '['.$key.']';
819 }
820 }
821  
822 #
823 # Takes a set of core symbols and creates a set containing the other core symbols.
824 #
825 sub negate_set {
826 0 ▶ my $self = shift;
Subroutine negate_set: not called CC=3 SCAR=24.8
Pod undocumented
827 0 my ($set) = @_;
828 0 my %negated_set = ();
829  
830 0 ▶ for (my $i = 0; $i < $self->{ncore}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"ncore"}) 0 0 0
831 0 my $a = $self->{syms}->[$i]->{sym};
832 0 ▶ if (!($set->{$a})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($set->{$a}) 0 0 0
833 0 $negated_set{$a} = 1;
834 }
835 }
836  
837 0 return \%negated_set;
838 }
839  
840 #
841 # Finds the first unknown symbol.
842 #
843 sub find_unknown {
844 0 ▶ my $self = shift;
Subroutine find_unknown: not called CC=2 SCAR=17.9
Pod undocumented
845 0 my ($seq) = @_;
846 0 my $not_valid = $self->{re_not_valid};
847  
848 0 ▶ if ($seq =~ m/($not_valid)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq =~ /($not_valid)/u) { } 0 0 0
849 0 return ($-[1], $1);
850 } else {
851 0 return;
852 }
853 }
854  
855 #
856 # Reverse complements a sequence using the alphabet.
857 #
858 sub rc_seq {
859 1 ▶ my $self = shift;
Subroutine rc_seq: called CC=2 SCAR=7.0
Pod undocumented
860 1 ▶ croak("Alphabet does not allow complementing.") unless $self->has_complement();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_complement 0 1 1
861 1 my ($sequence) = @_;
862 1 my @seq = split //, $sequence;
863  
864 1 @seq = reverse @seq;
865 1 @seq = map { $self->{lookup}->{$_}->{complement}->{sym} } @seq;
866  
867 1 return join('', @seq);
868 }
869  
870 #
871 # Translate a sequence using the alphabet.
872 #
873 # NO_ALIASES Convert any alias symbols into the main symbol.
874 # NO_AMBIGS Convert any ambiguous symbols into the main wildcard symbol.
875 # NO_UNKNOWN Convert any unknown symbols into the main wildcard symbol.
876 #
877 sub translate_seq {
878 0 ▶ my $self = shift;
Subroutine translate_seq: not called CC=8 SCAR=42.8
Pod undocumented
879 0 my ($sequence, %options) = @_;
880 0 ▶ my $no_aliases = (defined($options{NO_ALIASES}) ? $options{NO_ALIASES} : 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $options{'NO_ALIASES'} ? : 0 0 0
881 0 ▶ my $no_ambigs = (defined($options{NO_AMBIGS}) ? $options{NO_AMBIGS} : 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $options{'NO_AMBIGS'} ? : 0 0 0
882 0 ▶ my $no_unknown = (defined($options{NO_UNKNOWN}) ? $options{NO_UNKNOWN} : 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $options{'NO_UNKNOWN'} ? : 0 0 0
883 0 my ($src, $dst) = ('', '');
884 0 ▶ if ($no_aliases) {
Branch: 2 branches
BranchTrueFalseTotal
if ($no_aliases) { } 0 0 0
elsif ($no_ambigs) { } 0 0 0
885 0 $src .= $self->{tr_src_core_alias_to_prime};
886 0 $dst .= $self->{tr_dst_core_alias_to_prime};
887 0 ▶ if ($no_ambigs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($no_ambigs) { } 0 0 0
888 0 $src .= $self->{tr_src_ambig_to_wild};
889 0 $dst .= $self->{tr_dst_ambig_to_wild};
890 } else {
891 0 $src .= $self->{tr_src_ambig_alias_to_prime};
892 0 $dst .= $self->{tr_dst_ambig_alias_to_prime};
893 }
894 } elsif ($no_ambigs) {
895 0 $src .= $self->{tr_src_ambig_to_wild};
896 0 $dst .= $self->{tr_dst_ambig_to_wild};
897 }
898 0 ▶ if ($no_unknown) {
Branch: 1 branch
BranchTrueFalseTotal
if ($no_unknown) 0 0 0
899 0 $src .= $self->{tr_src_unknown_to_wild};
900 0 $dst .= $self->{tr_dst_unknown_to_wild};
901 }
902  
903 0 eval {$sequence =~ tr/$src/$dst/};
904  
905 0 return $sequence;
906 }
907  
908 #
909 # Returns a scalar of Weblogo 3 colour arguments:
910 # --color COLOR SYMBOLS DESCRIPTION ...
911 # Currently only operates over core symbols.
912 sub get_Weblogo_colour_args {
913 1 ▶ my $self = shift;
Subroutine get_Weblogo_colour_args: called CC=2 SCAR=6.9
Pod undocumented
914  
915 1 my $arg_string = "";
916  
917 1 foreach my $letter ($self->get_core()) {
918 12 my $sym = $self->{lookup}->{$letter};
919  
920 # convert back from decoded hex, adding '#' prefix
921 12 my $HTML_colour = sprintf("#%X", $sym->{colour});
922  
923 12 $arg_string .= "--color '$HTML_colour' '$sym->{sym}' '$sym->{name}' ";
924 }
925  
926 1 return $arg_string;
927 }
928  
929 #
930 # Compare 2 different alphabet objects for equality
931 #
932 sub equals {
933 2 ▶ my $self = shift;
Subroutine equals: called CC=30 SCAR=37.0
Pod undocumented
934 2 my ($other) = @_;
935 2 ▶ return 0 if ($self->size_core() != $other->size_core());
Branch: 1 branch
BranchTrueFalseTotal
if $self->size_core != $other->size_core 0 2 2
936 2 ▶ return 0 if ($self->size_full() != $other->size_full());
Branch: 1 branch
BranchTrueFalseTotal
if $self->size_full != $other->size_full 0 2 2
937 2 ▶ return 0 if ($self->has_complement() != $other->has_complement());
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_complement != $other->has_complement 0 2 2
938 2 ▶ return 0 if (defined($self->{name}) != defined($other->{name}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"name"} != defined $other->{"name"} 0 2 2
939 2 ▶ if (defined($self->{name}) && defined($other->{name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"name"} and defined $other->{"name"}) 2 0 2
Condition33%1/3
defined $self->{"name"} and defined $other->{"name"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $self->{"name"} and defined $other->{"name"}
defined $self->{"name"} defined $other->{"name"}
Truth table33%1/3
A and B
A= defined $self->{"name"}B= defined $other->{"name"}
ABresult
0X0
100
111
940 2 ▶ return 0 if ($self->{name} ne $other->{name});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"name"} ne $other->{"name"} 0 2 2
941 }
942 2 my $nsyms = $self->size_full();
943 2 ▶ for (my $i = 0; $i < $nsyms; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $nsyms) 47 2 49
944 47 my $self_sym = $self->{syms}->[$i];
945 47 my $other_sym = $other->{syms}->[$i];
946 47 ▶ return 0 if ($self_sym->{sym} ne $other_sym->{sym});
Branch: 1 branch
BranchTrueFalseTotal
if $self_sym->{"sym"} ne $other_sym->{"sym"} 0 47 47
947 47 ▶ return 0 if (defined($self_sym->{name}) != defined($other_sym->{name}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self_sym->{"name"} != defined $other_sym->{"name"} 0 47 47
948 47 ▶ if (defined($self_sym->{name}) && defined($other_sym->{name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self_sym->{"name"} and defined $other_sym->{"name"}) 46 1 47
Condition66%2/3
defined $self_sym->{"name"} and defined $other_sym->{"name"}
!ll&&!rl&&r
1046
MC/DC50%1/2
defined $self_sym->{"name"} and defined $other_sym->{"name"}
defined $self_sym->{"name"} defined $other_sym->{"name"}
Truth table66%2/3
A and B
A= defined $self_sym->{"name"}B= defined $other_sym->{"name"}
ABresult
0X0
100
111
949 46 ▶ return 0 if ($self_sym->{name} ne $other_sym->{name});
Branch: 1 branch
BranchTrueFalseTotal
if $self_sym->{"name"} ne $other_sym->{"name"} 0 46 46
950 }
951 47 ▶ return 0 if (defined($self_sym->{colour}) != defined($other_sym->{colour}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self_sym->{"colour"} != defined $other_sym->{"colour"} 0 47 47
952 47 ▶ if (defined($self_sym->{colour}) && defined($other_sym->{colour})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self_sym->{"colour"} and defined $other_sym->{"colour"}) 16 31 47
Condition66%2/3
defined $self_sym->{"colour"} and defined $other_sym->{"colour"}
!ll&&!rl&&r
31016
MC/DC50%1/2
defined $self_sym->{"colour"} and defined $other_sym->{"colour"}
defined $self_sym->{"colour"} defined $other_sym->{"colour"}
Truth table66%2/3
A and B
A= defined $self_sym->{"colour"}B= defined $other_sym->{"colour"}
ABresult
0X0
100
111
953 16 ▶ return 0 if ($self_sym->{colour} != $other_sym->{colour});
Branch: 1 branch
BranchTrueFalseTotal
if $self_sym->{"colour"} != $other_sym->{"colour"} 0 16 16
954 }
955 47 ▶ return 0 if (scalar(@{$self_sym->{aliases}}) != scalar(@{$other_sym->{aliases}}));
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$self_sym->{"aliases"};} != scalar @{$other_sym->{"aliases"};} 0 47 47
956 47 my $naliases = scalar(@{$self_sym->{aliases}});
957 47 ▶ for (my $j = 0; $j < $naliases; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $naliases) 6 47 53
958 6 ▶ return 0 if ($self_sym->{aliases}->[$j] ne $other_sym->{aliases}->[$j]);
Branch: 1 branch
BranchTrueFalseTotal
if $self_sym->{"aliases"}[$j] ne $other_sym->{"aliases"}[$j] 0 6 6
959 }
960 }
961 2 $nsyms = $self->size_core();
962 2 ▶ for (my $i = 0; $i < $nsyms; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $nsyms) 16 2 18
963 16 my $self_sym = $self->{syms}->[$i];
964 16 my $other_sym = $other->{syms}->[$i];
965 16 ▶ return 0 if (defined($self_sym->{complement}) != defined($other_sym->{complement}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self_sym->{"complement"} != defined $other_sym->{"complement"} 0 16 16
966 16 ▶ if (defined($self_sym->{complement}) && defined($other_sym->{complement})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self_sym->{"complement"} and defined $other_sym->{"complement"}) 16 0 16
Condition33%1/3
defined $self_sym->{"complement"} and defined $other_sym->{"complement"}
!ll&&!rl&&r
0016
MC/DC0%0/2
defined $self_sym->{"complement"} and defined $other_sym->{"complement"}
defined $self_sym->{"complement"} defined $other_sym->{"complement"}
Truth table33%1/3
A and B
A= defined $self_sym->{"complement"}B= defined $other_sym->{"complement"}
ABresult
0X0
100
111
967 16 ▶ return 0 if ($self_sym->{complement}->{sym} ne $other_sym->{complement}->{sym});
Branch: 1 branch
BranchTrueFalseTotal
if $self_sym->{"complement"}{"sym"} ne $other_sym->{"complement"}{"sym"} 0 16 16
968 }
969 }
970 2 $nsyms = $self->size_full();
971 2 ▶ for (my $i = $self->size_core(); $i < $nsyms; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $nsyms) 31 2 33
972 31 my $self_sym = $self->{syms}->[$i];
973 31 my $other_sym = $other->{syms}->[$i];
974 31 ▶ return 0 if (scalar(@{$self_sym->{comprise}}) != scalar(@{$other_sym->{comprise}}));
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$self_sym->{"comprise"};} != scalar @{$other_sym->{"comprise"};} 0 31 31
975 31 ▶ for (my $j = 0; $j < scalar(@{$self_sym->{comprise}}); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$self_sym->{"comprise"};}) 92 31 123
976 92 ▶ return 0 if ($self_sym->{comprise}->[$j]->{sym} ne $other_sym->{comprise}->[$j]->{sym});
Branch: 1 branch
BranchTrueFalseTotal
if $self_sym->{"comprise"}[$j]{"sym"} ne $other_sym->{"comprise"}[$j]{"sym"} 0 92 92
977 }
978 }
979 2 return 1;
980 }
981  
982 sub is_dna {
983 1 ▶ my $self = shift;
Subroutine is_dna: called CC=2 SCAR=7.1
Pod undocumented
984 1 ▶ $self->{cached_is_dna} = $self->equals(&dna()) unless defined $self->{cached_is_dna};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"cached_is_dna"} 1 0 1
985 1 return $self->{cached_is_dna};
986 }
987  
988 sub is_moddna {
989 1 ▶ my $self = shift;
Subroutine is_moddna: called CC=2 SCAR=7.1
Pod undocumented
990 1 ▶ $self->{cached_is_moddna} = $self->equals(&moddna()) unless defined $self->{cached_is_moddna};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"cached_is_moddna"} 1 0 1
991 1 return $self->{cached_is_moddna};
992 }
993  
994 sub is_rna {
995 0 ▶ my $self = shift;
Subroutine is_rna: not called CC=2 SCAR=17.9
Pod undocumented
996 0 ▶ $self->{cached_is_rna} = $self->equals(&rna()) unless defined $self->{cached_is_rna};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"cached_is_rna"} 0 0 0
997 0 return $self->{cached_is_rna};
998 }
999  
1000 sub is_protein {
1001 0 ▶ my $self = shift;
Subroutine is_protein: not called CC=2 SCAR=17.9
Pod undocumented
1002 0 ▶ $self->{cached_is_protein} = $self->equals(&protein()) unless defined $self->{cached_is_protein};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"cached_is_protein"} 0 0 0
1003 0 return $self->{cached_is_protein};
1004 }
1005  
1006 #
1007 # Helper function to decode a string encoded using the method defined in the JSON specification.
1008 #
1009 sub _decode_JSON_string {
1010 0 ▶ my ($text) = @_;
Subroutine _decode_JSON_string: not called CC=2 SCAR=17.9
1011  
1012 0 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 0 0
1013  
1014 0 $text =~ s/\\(["\\\/])/$1/g;
1015 0 $text =~ s/\\b/\x{8}/g;
1016 0 $text =~ s/\\f/\x{C}/g;
1017 0 $text =~ s/\\n/\x{A}/g;
1018 0 $text =~ s/\\r/\x{D}/g;
1019 0 $text =~ s/\\t/\x{9}/g;
1020 0 $text =~ s/\\u([0-9A-Fa-f]{4})/chr(hex($1))/ge;
1021  
1022 0 return $text;
1023 }
1024  
1025 #
1026 # Helper function to encode a string using the method defined in the JSON specification.
1027 #
1028 sub _encode_JSON_string {
1029 0 ▶ my ($text) = @_;
Subroutine _encode_JSON_string: not called CC=1 SCAR=6.9
1030  
1031 0 $text =~ s/(["\\\/])/\\$1/g;
1032 0 $text =~ s/\x{8}/\\b/g;
1033 0 $text =~ s/\x{C}/\\f/g;
1034 0 $text =~ s/\x{A}/\\n/g;
1035 0 $text =~ s/\x{D}/\\r/g;
1036 0 $text =~ s/\x{9}/\\t/g;
1037 0 $text =~ s/([\x{0}-\x{1F}\x{7F}-\x{9F}\x{2028}\x{2029}])/sprintf("\\u%.04X",ord($1))/ge;
1038  
1039 0 return $text;
1040 }
1041  
1042 #
1043 # Helper function to convert the colour into a number.
1044 #
1045 sub _decode_colour {
1046 0 ▶ my ($text) = @_;
Subroutine _decode_colour: not called CC=2 SCAR=17.9
1047  
1048 0 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 0 0
1049  
1050 0 return hex($text);
1051 }
1052  
1053 # _symbol_cmp
1054 # Sorts so letters are before numbers which are before symbols.
1055 # Otherwise sorts using normal string comparison.
1056 sub _symbol_cmp($$) { ## no critic
1057 526 ▶ my ($a, $b) = @_;
Subroutine _symbol_cmp: called CC=24 SCAR=35.3
1058  
1059 526 ▶ if (length($a) == length($b)) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $a == length $b) { } 470 56 526
elsif (length $a > length $b) { } 14 42 56
1060 470 ▶ for (my $i = 0; $i < length($a); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $a) 504 0 504
1061 504 my ($sym_a, $sym_b);
1062 504 $sym_a = ord(substr($a, $i, 1));
1063 504 $sym_b = ord(substr($b, $i, 1));
1064 # check to see if either is a letter
1065 504 my ($is_letter_a, $is_letter_b);
1066 504 ▶ $is_letter_a = (($sym_a >= ord('A') && $sym_a <= ord('Z')) || ($sym_a >= ord('a') && $sym_a <= ord('z')));
Condition88%8/9
$sym_a >= 65 && $sym_a <= 90 || $sym_a >= 97 && $sym_a <= 122
l!l&&r!l&&!r
3409866
$sym_a >= 65 and $sym_a <= 90
!ll&&!rl&&r
6698340
$sym_a >= 97 and $sym_a <= 122
!ll&&!rl&&r
66098
MC/DC25%1/4
$sym_a >= 65 && $sym_a <= 90 || $sym_a >= 97 && $sym_a <= 122
$sym_a >= 65 $sym_a <= 90 $sym_a >= 97 $sym_a <= 122
Truth table42%3/7
A and B || C and D
A= $sym_a >= 65B= $sym_a <= 90C= $sym_a >= 97D= $sym_a <= 122
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1067 504 ▶ $is_letter_b = (($sym_b >= ord('A') && $sym_b <= ord('Z')) || ($sym_b >= ord('a') && $sym_b <= ord('z')));
Condition88%8/9
$sym_b >= 65 && $sym_b <= 90 || $sym_b >= 97 && $sym_b <= 122
l!l&&r!l&&!r
3229092
$sym_b >= 65 and $sym_b <= 90
!ll&&!rl&&r
9290322
$sym_b >= 97 and $sym_b <= 122
!ll&&!rl&&r
92090
MC/DC25%1/4
$sym_b >= 65 && $sym_b <= 90 || $sym_b >= 97 && $sym_b <= 122
$sym_b >= 65 $sym_b <= 90 $sym_b >= 97 $sym_b <= 122
Truth table42%3/7
A and B || C and D
A= $sym_b >= 65B= $sym_b <= 90C= $sym_b >= 97D= $sym_b <= 122
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1068 504 ▶ if ($is_letter_a) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_letter_a) { } 438 66 504
elsif ($is_letter_b) { } 18 48 66
1069 438 ▶ if ($is_letter_b) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_letter_b) { } 394 44 438
1070 394 ▶ if ($sym_a < $sym_b) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sym_a < $sym_b) { } 168 226 394
elsif ($sym_b < $sym_a) { } 192 34 226
1071 168 return -1;
1072 } elsif ($sym_b < $sym_a) {
1073 192 return 1;
1074 }
1075 34 next;
1076 } else {
1077 44 return -1;
1078 }
1079 } elsif ($is_letter_b) {
1080 18 return 1;
1081 }
1082  
1083 # check to see if either is a number
1084 48 my ($is_num_a, $is_num_b);
1085 48 ▶ $is_num_a = ($sym_a ge '0' && $sym_a le '9');
Condition33%1/3
$sym_a ge '0' && $sym_a le '9'
!ll&&!rl&&r
0048
MC/DC0%0/2
$sym_a ge '0' && $sym_a le '9'
$sym_a ge '0' $sym_a le '9'
Truth table33%1/3
A && B
A= $sym_a ge '0'B= $sym_a le '9'
ABresult
0X0
100
111
1086 48 ▶ $is_num_b = ($sym_b ge '0' && $sym_b le '9');
Condition33%1/3
$sym_b ge '0' && $sym_b le '9'
!ll&&!rl&&r
0048
MC/DC0%0/2
$sym_b ge '0' && $sym_b le '9'
$sym_b ge '0' $sym_b le '9'
Truth table33%1/3
A && B
A= $sym_b ge '0'B= $sym_b le '9'
ABresult
0X0
100
111
1087 48 ▶ if ($is_num_a) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_num_a) { } 48 0 48
elsif ($is_num_b) { } 0 0 0
1088 48 ▶ if ($is_num_b) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_num_b) { } 48 0 48
1089 48 ▶ if ($sym_a < $sym_b) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sym_a < $sym_b) { } 16 32 48
elsif ($sym_b < $sym_a) { } 32 0 32
1090 16 return -1;
1091 } elsif ($sym_b < $sym_a) {
1092 32 return 1;
1093 }
1094 0 next;
1095 } else {
1096 0 return -1;
1097 }
1098 } elsif ($is_num_b) {
1099 0 return 1;
1100 }
1101  
1102 # both must be symbols
1103 0 ▶ if ($sym_a < $sym_b) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sym_a < $sym_b) { } 0 0 0
elsif ($sym_b < $sym_a) { } 0 0 0
1104 0 return -1;
1105 } elsif ($sym_b < $sym_a) {
1106 0 return 1;
1107 }
1108 }
1109  
1110 0 return 0;
1111 } elsif (length($a) > length($b)) {
1112 14 return -1;
1113 } else {
1114 42 return 1;
1115 }
1116 }
1117  
1118 sub _symobj_cmp($$) { ## no critic
1119 216 ▶ my ($sym1, $sym2) = @_;
Subroutine _symobj_cmp: called CC=24 SCAR=58.4
1120 216 my $ret;
1121  
1122 # compare comprise
1123 216 ▶ if (defined($sym1->{comprise}) && defined($sym2->{comprise})) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $sym1->{'comprise'} and defined $sym2->{'comprise'}) { } 150 66 216
elsif (defined $sym1->{'comprise'}) { } 0 66 66
elsif (defined $sym2->{'comprise'}) { } 0 66 66
Condition66%2/3
defined $sym1->{"comprise"} and defined $sym2->{"comprise"}
!ll&&!rl&&r
660150
MC/DC50%1/2
defined $sym1->{"comprise"} and defined $sym2->{"comprise"}
defined $sym1->{"comprise"} defined $sym2->{"comprise"}
Truth table66%2/3
A and B
A= defined $sym1->{"comprise"}B= defined $sym2->{"comprise"}
ABresult
0X0
100
111
1124 150 $ret = _symbol_cmp($sym1->{comprise}, $sym2->{comprise});
1125 150 ▶ return $ret if $ret != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ret != 0 150 0 150
1126 } elsif (defined($sym1->{comprise})) {
1127 0 return 1; # sym2 first because it is a core symbol
1128 } elsif (defined($sym2->{comprise})) {
1129 0 return -1; # sym1 first because it is a core symbol
1130 }
1131  
1132 # compare symbol
1133 66 $ret = _symbol_cmp($sym1->{sym}, $sym2->{sym});
1134 66 ▶ return $ret if $ret != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ret != 0 66 0 66
1135  
1136 # compare complement
1137 0 ▶ if (defined($sym1->{complement}) && defined($sym2->{complement})) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $sym1->{'complement'} and defined $sym2->{'complement'}) { } 0 0 0
elsif (defined $sym1->{'complement'}) { } 0 0 0
elsif (defined $sym2->{'complement'}) { } 0 0 0
Condition0%0/3
defined $sym1->{"complement"} and defined $sym2->{"complement"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $sym1->{"complement"} and defined $sym2->{"complement"}
defined $sym1->{"complement"} defined $sym2->{"complement"}
Truth table0%0/3
A and B
A= defined $sym1->{"complement"}B= defined $sym2->{"complement"}
ABresult
0X0
100
111
1138 0 $ret = _symbol_cmp($sym1->{complement}, $sym2->{complement});
1139 0 ▶ return $ret if $ret != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ret != 0 0 0 0
1140 } elsif (defined($sym1->{complement})) {
1141 0 return 1;
1142 } elsif (defined($sym2->{complement})) {
1143 0 return -1;
1144 }
1145  
1146 # compare aliases
1147 0 ▶ if (scalar(@{$sym1->{aliases}}) != scalar(@{$sym2->{aliases}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$sym1->{"aliases"};} != scalar @{$sym2->{"aliases"};}) 0 0 0
1148 # sort length decending
1149 0 return scalar(@{$sym2->{aliases}}) <=> scalar(@{$sym1->{aliases}});
1150 }
1151 0 ▶ for (my $i = 0; $i < scalar(@{$sym1->{aliases}}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$sym1->{"aliases"};}) 0 0 0
1152 0 $ret = _symbol_cmp($sym1->{aliases}->[$i], $sym2->{aliases}->[$i]);
1153 0 ▶ return $ret if $ret != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ret != 0 0 0 0
1154 }
1155  
1156 # compare name
1157 0 ▶ if (defined($sym1->{name}) && defined($sym2->{name})) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $sym1->{'name'} and defined $sym2->{'name'}) { } 0 0 0
elsif (defined $sym1->{'name'}) { } 0 0 0
elsif (defined $sym2->{'name'}) { } 0 0 0
Condition0%0/3
defined $sym1->{"name"} and defined $sym2->{"name"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $sym1->{"name"} and defined $sym2->{"name"}
defined $sym1->{"name"} defined $sym2->{"name"}
Truth table0%0/3
A and B
A= defined $sym1->{"name"}B= defined $sym2->{"name"}
ABresult
0X0
100
111
1158 0 $ret = $sym1->{name} cmp $sym2->{name};
1159 0 ▶ return $ret if $ret != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ret != 0 0 0 0
1160 } elsif (defined($sym1->{name})) {
1161 0 return 1;
1162 } elsif (defined($sym2->{name})) {
1163 0 return -1;
1164 }
1165  
1166 # compare colour
1167 0 ▶ if (defined($sym1->{colour}) && defined($sym2->{colour})) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $sym1->{'colour'} and defined $sym2->{'colour'}) { } 0 0 0
elsif (defined $sym1->{'colour'}) { } 0 0 0
elsif (defined $sym2->{'colour'}) { } 0 0 0
Condition0%0/3
defined $sym1->{"colour"} and defined $sym2->{"colour"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $sym1->{"colour"} and defined $sym2->{"colour"}
defined $sym1->{"colour"} defined $sym2->{"colour"}
Truth table0%0/3
A and B
A= defined $sym1->{"colour"}B= defined $sym2->{"colour"}
ABresult
0X0
100
111
1168 0 return $sym1->{colour} <=> $sym2->{colour};
1169 } elsif (defined($sym1->{colour})) {
1170 0 return 1;
1171 } elsif (defined($sym2->{colour})) {
1172 0 return -1;
1173 }
1174 0 return 0;
1175 }
1176  
1177 #
1178 # Return the RNA alphabet.
1179 #
1180 sub rna {
1181 0 ▶ my $alph = new __PACKAGE__;
Subroutine rna: not called CC=2 SCAR=17.9
Pod undocumented
1182  
1183 0 $alph->parse_header('RNA', 'RNA');
1184  
1185 # core symbols
1186 0 $alph->parse_symbol('A', 'Adenine', 0xCC0000);
1187 0 $alph->parse_symbol('C', 'Cytosine', 0x0000CC);
1188 0 $alph->parse_symbol('G', 'Guanine', 0xFFB300);
1189 0 $alph->parse_symbol('U', 'Uracil', 0x008000, undef, undef, 'T');
1190 # ambiguous symbols
1191 0 $alph->parse_symbol('W', 'Weak', undef, undef, 'AU');
1192 0 $alph->parse_symbol('S', 'Strong', undef, undef, 'CG');
1193 0 $alph->parse_symbol('M', 'Amino', undef, undef, 'AC');
1194 0 $alph->parse_symbol('K', 'Keto', undef, undef, 'GU');
1195 0 $alph->parse_symbol('R', 'Purine', undef, undef, 'AG');
1196 0 $alph->parse_symbol('Y', 'Pyrimidine', undef, undef, 'CU');
1197 0 $alph->parse_symbol('B', 'Not A', undef, undef, 'CGU');
1198 0 $alph->parse_symbol('D', 'Not C', undef, undef, 'AGU');
1199 0 $alph->parse_symbol('H', 'Not G', undef, undef, 'ACU');
1200 0 $alph->parse_symbol('V', 'Not U', undef, undef, 'ACG');
1201 0 $alph->parse_symbol('N', 'Any base', undef, undef, 'ACGU', 'X.');
1202 # for now treat '.' (gap) as a wildcard
1203  
1204 # process
1205 0 $alph->parse_done();
1206  
1207 # error check
1208 0 ▶ die("Uhoh, this shouldn't happen:\n" + join("\n", $alph->get_errors())) if ($alph->has_errors());
Branch: 1 branch
BranchTrueFalseTotal
if $alph->has_errors 0 0 0
1209  
1210 0 return $alph;
1211 }
1212  
1213 #
1214 # Parse core symbols in the DNA alphabet.
1215 # This is done separately, to ease expansion.
1216 # All core symbols must be parsed before any ambiguous symbols.
1217 # Optionally accepts arguments to set colours (alphabetical order).
1218 #
1219 sub _parse_core_DNA_symbols {
1220 4 ▶ my $alph = shift;
Subroutine _parse_core_DNA_symbols: called CC=5 SCAR=16.1
1221  
1222 4 ▶ $$alph->parse_symbol('A', 'Adenine', shift || 0xCC0000, 'T');
Condition100%2/2
shift() || 13369344
l!l
22
MC/DC100%1/1
shift() || 13369344
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1223 4 ▶ $$alph->parse_symbol('C', 'Cytosine', shift || 0x0000CC, 'G');
Condition100%2/2
shift() || 204
l!l
22
MC/DC100%1/1
shift() || 204
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1224 4 ▶ $$alph->parse_symbol('G', 'Guanine', shift || 0xFFB300, 'C');
Condition100%2/2
shift() || 16757504
l!l
22
MC/DC100%1/1
shift() || 16757504
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1225 4 ▶ $$alph->parse_symbol('T', 'Thymine', shift || 0x008000, 'A', undef, 'U');
Condition100%2/2
shift() || 32768
l!l
22
MC/DC100%1/1
shift() || 32768
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1226 }
1227  
1228 #
1229 # Parse ambiguous symbols in the DNA alphabet.
1230 # This is done separately, to ease expansion.
1231 #
1232 sub _parse_ambiguous_DNA_symbols {
1233 4 ▶ my $alph = shift;
Subroutine _parse_ambiguous_DNA_symbols: called CC=1 SCAR=0.0
1234  
1235 4 $$alph->parse_symbol('W', 'Weak', undef, undef, 'AT');
1236 4 $$alph->parse_symbol('S', 'Strong', undef, undef, 'CG');
1237 4 $$alph->parse_symbol('M', 'Amino', undef, undef, 'AC');
1238 4 $$alph->parse_symbol('K', 'Keto', undef, undef, 'GT');
1239 4 $$alph->parse_symbol('R', 'Purine', undef, undef, 'AG');
1240 4 $$alph->parse_symbol('Y', 'Pyrimidine', undef, undef, 'CT');
1241 4 $$alph->parse_symbol('B', 'Not A', undef, undef, 'CGT');
1242 4 $$alph->parse_symbol('D', 'Not C', undef, undef, 'AGT');
1243 4 $$alph->parse_symbol('H', 'Not G', undef, undef, 'ACT');
1244 4 $$alph->parse_symbol('V', 'Not T', undef, undef, 'ACG');
1245 4 $$alph->parse_symbol('N', 'Any base', undef, undef, 'ACGT', 'X.');
1246 }
1247  
1248 #
1249 # Return the DNA alphabet.
1250 #
1251 sub dna {
1252 2 ▶ my $alph = new __PACKAGE__;
Subroutine dna: called CC=2 SCAR=7.0
Pod undocumented
1253  
1254 2 $alph->parse_header('DNA', 'DNA');
1255  
1256 2 _parse_core_DNA_symbols(\$alph);
1257 2 _parse_ambiguous_DNA_symbols(\$alph);
1258  
1259 # for now treat '.' (gap) as a wildcard
1260 # process
1261 2 $alph->parse_done();
1262  
1263 2 ▶ die("Uhoh, this shouldn't happen:\n" + join("\n", $alph->get_errors())) if ($alph->has_errors());
Branch: 1 branch
BranchTrueFalseTotal
if $alph->has_errors 0 2 2
1264  
1265 2 return $alph;
1266 }
1267  
1268 #
1269 # Return the DNA with cytosine modifications alphabet.
1270 #
1271 sub moddna {
1272 2 ▶ my $alph = new __PACKAGE__;
Subroutine moddna: called CC=2 SCAR=6.9
Pod undocumented
1273  
1274 2 $alph->parse_header('modDNA', 'DNA');
1275  
1276 2 _parse_core_DNA_symbols(\$alph, 0x8510A8, 0xA50026, 0x313695, 0xA89610);
1277  
1278 # additional core symbols
1279 2 $alph->parse_symbol('m', '5-Methylcytosine', 0xD73027, '1');
1280 2 $alph->parse_symbol('1', 'Guanine:5-Methylcytosine', 0x4575B4, 'm');
1281 2 $alph->parse_symbol('h', '5-Hydroxymethylcytosine', 0xF46D43, '2');
1282 2 $alph->parse_symbol('2', 'Guanine:5-Hydroxymethylcytosine', 0x74ADD1, 'h');
1283 2 $alph->parse_symbol('f', '5-Formylcytosine', 0xFDAE61, '3');
1284 2 $alph->parse_symbol('3', 'Guanine:5-Formylcytosine', 0xABD9E9, 'f');
1285 2 $alph->parse_symbol('c', '5-Carboxylcytosine', 0xFEE090, '4');
1286 2 $alph->parse_symbol('4', 'Guanine:5-Carboxylcytosine', 0xE0F3F8, 'c');
1287  
1288 2 _parse_ambiguous_DNA_symbols(\$alph);
1289  
1290 # additional ambiguous symbols
1291 2 $alph->parse_symbol('z', 'Any C mod', undef, undef, 'Cmhfc');
1292 2 $alph->parse_symbol('9', 'Guanine:any C mod', undef, undef, 'G1234');
1293 2 $alph->parse_symbol('y', 'C, not (hydroxy)methylcytosine', undef, undef, 'Cfc');
1294 2 $alph->parse_symbol('8', 'Guanine:C, not (hydroxy)methylcytosine', undef, undef, 'G34');
1295 2 $alph->parse_symbol('x', '(Hydroxy)methylcytosine', undef, undef, 'mh');
1296 2 $alph->parse_symbol('7', 'Guanine:(hydroxy)methylcytosine', undef, undef, '12');
1297 2 $alph->parse_symbol('w', '(Formyl/carboxyl)cytosine', undef, undef, 'fc');
1298 2 $alph->parse_symbol('6', 'Guanine:(formyl/carboxyl)cytosine', undef, undef, '34');
1299  
1300 # process
1301 2 $alph->parse_done();
1302  
1303 2 ▶ die("Uhoh, this shouldn't happen:\n" + join("\n", $alph->get_errors())) if ($alph->has_errors());
Branch: 1 branch
BranchTrueFalseTotal
if $alph->has_errors 0 2 2
1304  
1305 2 return $alph;
1306 }
1307  
1308 #
1309 # Return the Protein alphabet.
1310 #
1311 sub protein {
1312 0 ▶ my $alph = new __PACKAGE__;
Subroutine protein: not called CC=2 SCAR=17.9
Pod undocumented
1313  
1314 0 $alph->parse_header('Protein', 'PROTEIN');
1315  
1316 # core symbols
1317 0 $alph->parse_symbol('A', 'Alanine', 0x0000CC);
1318 0 $alph->parse_symbol('R', 'Arginine', 0xCC0000);
1319 0 $alph->parse_symbol('N', 'Asparagine', 0x008000);
1320 0 $alph->parse_symbol('D', 'Aspartic acid', 0xFF00FF);
1321 0 $alph->parse_symbol('C', 'Cysteine', 0x0000CC);
1322 0 $alph->parse_symbol('E', 'Glutamic acid', 0xFF00FF);
1323 0 $alph->parse_symbol('Q', 'Glutamine', 0x008000);
1324 0 $alph->parse_symbol('G', 'Glycine', 0xFFB300);
1325 0 $alph->parse_symbol('H', 'Histidine', 0xFFCCCC);
1326 0 $alph->parse_symbol('I', 'Isoleucine', 0x0000CC);
1327 0 $alph->parse_symbol('L', 'Leucine', 0x0000CC);
1328 0 $alph->parse_symbol('K', 'Lysine', 0xCC0000);
1329 0 $alph->parse_symbol('M', 'Methionine', 0x0000CC);
1330 0 $alph->parse_symbol('F', 'Phenylalanine', 0x0000CC);
1331 0 $alph->parse_symbol('P', 'Proline', 0xFFFF00);
1332 0 $alph->parse_symbol('S', 'Serine', 0x008000);
1333 0 $alph->parse_symbol('T', 'Threonine', 0x008000);
1334 0 $alph->parse_symbol('W', 'Tryptophan', 0x0000CC);
1335 0 $alph->parse_symbol('Y', 'Tyrosine', 0x33E6CC);
1336 0 $alph->parse_symbol('V', 'Valine', 0x0000CC);
1337 # ambiguous symbols
1338 0 $alph->parse_symbol('B', 'Asparagine or Aspartic acid', undef, undef, 'ND');
1339 0 $alph->parse_symbol('Z', 'Glutamine or Glutamic acid', undef, undef, 'QE');
1340 0 $alph->parse_symbol('J', 'Leucine or Isoleucine', undef, undef, 'LI');
1341 0 $alph->parse_symbol('X', 'Any amino acid', undef, undef, 'ARNDCEQGHILKMFPSTWYV', '*.');
1342 # for now treat '*' (stop codon) and '.' (gap) as a wildcard
1343  
1344 # process
1345 0 $alph->parse_done();
1346  
1347 # error check
1348 0 ▶ die("Uhoh, this shouldn't happen:\n" + join("\n", $alph->get_errors())) if ($alph->has_errors());
Branch: 1 branch
BranchTrueFalseTotal
if $alph->has_errors 0 0 0
1349  
1350 0 return $alph;
1351 }
1352  
1353 2 1;
1354 __END__
↑ Summary