lib/FASTX/Seq.pm

filter: Statementstmt 94.5% 206 / 218 Branchbran 73.6% 81 / 110 Conditioncond 62.5% 35 / 56 MC/DCmcdc 29.4% 10 / 34 Subroutinesub 94.4% 34 / 36 Podpod 100% 29 / 29 totaltotal 81.7% 395 / 483 CC 78 SCAR 21.4
CC
78
Cov
84%
new
26.4
asfastq
8.1
string
6.0
CRAP 8.5
« lib/FASTX/ScriptHelper.pm ↑ Summary script/fqlen.pl »
1 package FASTX::Seq;
2 #ABSTRACT: A class for representing a sequence for FASTX::Reader
3  
4 46 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 46 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 46 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 46 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 46 $Data::Dumper::Sortkeys = 1;
9 46 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 46 $FASTX::Seq::VERSION = $FASTX::Reader::VERSION;
12 46 $FASTX::Seq::DEFAULT_QUALITY = 'I';
13 46 $FASTX::Seq::DEFAULT_LINE_LEN = 0;
14 46 $FASTX::Seq::DEFAULT_OFFSET = 33;
15 46 ▶$FASTX::Seq::QUIET = $ENV{'FASTX_QUIET'} // 0;
Condition50%1/2
$ENV{"FASTX_QUIET"} // 0
l!l
046
MC/DC0%0/1
$ENV{"FASTX_QUIET"} // 0
$ENV{"FASTX_QUIET"}
Truth table50%1/2
A
A= $ENV{"FASTX_QUIET"}
Aresult
11
00
16 46 require Exporter;
17 46 our @ISA = qw(Exporter);
18  
19  
20  
21 81 ▶sub new {
Subroutine new: called CC=24 SCAR=32.7
Pod documented
22 81 my $class = shift @_;
23 81 my ($seq, $name, $comment, $qual, $offset, $line_len, $default_quality);
24 81 ▶ if (not defined $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 1 80 81
25 1 confess "ERROR FASTX::Seq: Sequence missing, record cannot be created.\n";
26 }
27 # Descriptive instantiation with parameters -param => value
28 80 ▶ if (substr($_[0], 0, 1) eq '-') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($_[0], 0, 1) eq '-') { } 15 65 80
elsif (not defined $seq) { } 65 0 65
29 15 my %data = @_;
30 # Try parsing
31 15 for my $i (keys %data) {
32 53 ▶ if ($i =~ /^-(seq|sequence)/) {
Branch: 7 branches
BranchTrueFalseTotal
if ($i =~ /^-(seq|sequence)/u) { } 15 38 53
elsif ($i =~ /^-(name|id)/u) { } 12 26 38
elsif ($i =~ /^-(comment|desc|description)/u) { } 7 19 26
elsif ($i =~ /^-qual(ity)?/u) { } 13 6 19
elsif ($i =~ /^-offset/u) { } 3 3 6
elsif ($i =~ /^-line_len/u) { } 2 1 3
elsif ($i =~ /^-default_quality/u) { } 0 1 1
33 15 $seq = $data{$i};
34 } elsif ($i =~ /^-(name|id)/) {
35 12 $name = $data{$i};
36 } elsif ($i =~ /^-(comment|desc|description)/) {
37 7 $comment = $data{$i};
38 } elsif ($i =~ /^-qual(ity)?/) {
39 13 $qual = $data{$i};
40 } elsif ($i =~ /^-offset/) {
41 3 $offset = $data{$i};
42 } elsif ($i =~ /^-line_len/) {
43 2 $line_len = $data{$i};
44 } elsif ($i =~ /^-default_quality/) {
45 0 $default_quality = $data{$i};
46 } else {
47 1 confess "ERROR FASTX::Seq: Unknown parameter $i\n";
48 }
49 }
50 } elsif (not defined $seq) {
51 # Positional instantiation
52 # check number of arguments
53 65 ▶ confess "ERROR FASTX::Seq: Wrong number of arguments\n" if (scalar(@_) < 1 || scalar(@_) > 4);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ < 1 or scalar @_ > 4 0 65 65
Condition33%1/3
scalar @_ < 1 or scalar @_ > 4
l!l&&r!l&&!r
0065
MC/DC0%0/2
scalar @_ < 1 or scalar @_ > 4
scalar @_ < 1 scalar @_ > 4
Truth table33%1/3
A or B
A= scalar @_ < 1B= scalar @_ > 4
ABresult
1X1
011
000
54 65 ($seq, $name, $comment, $qual) = @_;
55 }
56
57 # Required NOT empty
58 79 ▶ if (not defined $seq) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $seq) 0 79 79
59 0 confess "ERROR FASTX::Seq: Sequence missing, record cannot be created\n";
60 }
61  
62 # If quality is provided, must match sequence length
63 79 ▶ if ( defined $seq && defined $qual
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seq and defined $qual and length $seq != length $qual) 2 77 79
Condition83%5/6
defined $seq and defined $qual and length $seq != length $qual
!ll&&!rl&&r
39382
defined $seq and defined $qual
!ll&&!rl&&r
03940
MC/DC66%2/3
defined $seq and defined $qual and length $seq != length $qual
defined $seq defined $qual length $seq != length $qual
Truth table75%3/4
A and B and C
A= defined $seqB= defined $qualC= length $seq != length $qual
ABCresult
0XX0
10X0
1100
1111
64 && (length($seq) != length($qual))) {
65 2 confess "Sequence/quality length mismatch";
66 }
67
68 77 my $self = bless {}, $class;
69
70  
71 77 ▶ $self->{name} = $name // undef;
Condition100%2/2
$name // undef
l!l
689
MC/DC100%1/1
$name // undef
$name
Truth table100%2/2
A
A= $name
Aresult
11
00
72 77 $self->{seq} = $seq;
73 77 ▶ $self->{comment} = $comment // undef;
Condition100%2/2
$comment // undef
l!l
4235
MC/DC100%1/1
$comment // undef
$comment
Truth table100%2/2
A
A= $comment
Aresult
11
00
74 77 ▶ $self->{qual} = $qual // undef;
Condition100%2/2
$qual // undef
l!l
3839
MC/DC100%1/1
$qual // undef
$qual
Truth table100%2/2
A
A= $qual
Aresult
11
00
75
76 # Store defaults
77 77 ▶ $self->{default_quality} = $default_quality // $FASTX::Seq::DEFAULT_QUALITY;
Condition33%1/3
$default_quality // $FASTX::Seq::DEFAULT_QUALITY
l!l&&r!l&&!r
0770
MC/DC0%0/2
$default_quality // $FASTX::Seq::DEFAULT_QUALITY
$default_quality $FASTX::Seq::DEFAULT_QUALITY
Truth table33%1/3
A // B
A= $default_qualityB= $FASTX::Seq::DEFAULT_QUALITY
ABresult
1X1
011
000
78 77 ▶ $self->{line_len} = $line_len // $FASTX::Seq::DEFAULT_LINE_LEN;
Condition66%2/3
$line_len // $FASTX::Seq::DEFAULT_LINE_LEN
l!l&&r!l&&!r
2750
MC/DC0%0/2
$line_len // $FASTX::Seq::DEFAULT_LINE_LEN
$line_len $FASTX::Seq::DEFAULT_LINE_LEN
Truth table66%2/3
A // B
A= $line_lenB= $FASTX::Seq::DEFAULT_LINE_LEN
ABresult
1X1
011
000
79 77 ▶ $self->{offset} = $offset // $FASTX::Seq::DEFAULT_OFFSET;
Condition66%2/3
$offset // $FASTX::Seq::DEFAULT_OFFSET
l!l&&r!l&&!r
3740
MC/DC0%0/2
$offset // $FASTX::Seq::DEFAULT_OFFSET
$offset $FASTX::Seq::DEFAULT_OFFSET
Truth table66%2/3
A // B
A= $offsetB= $FASTX::Seq::DEFAULT_OFFSET
ABresult
1X1
011
000
80
81 77 return $self;
82
83 }
84  
85  
86 10 ▶sub copy {
Subroutine copy: called CC=1 SCAR=0.0
Pod documented
87 10 my ($self) = @_;
88 10 my $copy = __PACKAGE__->new($self->seq, $self->name, $self->comment, $self->qual);
89 10 $copy->{default_quality} = $self->default_quality;
90 10 $copy->line_len = $self->line_len;
91 10 $copy->offset = $self->offset;
92 10 return $copy;
93 }
94  
95  
96 93 ▶sub seq : lvalue {
Subroutine seq: called CC=2 SCAR=6.9
Pod documented
97 # Update sequence
98 93 my ($self, $new_val) = @_;
99 93 ▶ $self->{seq} = $new_val if (defined $new_val);
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val 5 88 93
100 93 return $self->{seq};
101 }
102  
103  
104  
105 14 ▶sub name : lvalue {
Subroutine name: called CC=2 SCAR=7.1
Pod documented
106 # Update name
107 14 my ($self, $new_val) = @_;
108 14 ▶ $self->{seq} = $new_val if (defined $new_val);
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val 0 14 14
109 14 return $self->{name};
110 }
111  
112  
113  
114 56 ▶sub qual : lvalue {
Subroutine qual: called CC=2 SCAR=7.1
Pod documented
115 # Update quality
116 56 my ($self, $new_val) = @_;
117 56 ▶ $self->{qual} = $new_val if (defined $new_val);
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val 0 56 56
118 56 return $self->{qual};
119 }
120  
121  
122 11 ▶sub comment : lvalue {
Subroutine comment: called CC=2 SCAR=7.1
Pod documented
123 # Update comment
124 11 my ($self, $new_val) = @_;
125 11 ▶ $self->{comment} = $new_val if (defined $new_val);
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val 0 11 11
126 11 return $self->{comment};
127 }
128  
129  
130 29 ▶sub offset : lvalue {
Subroutine offset: called CC=4 SCAR=14.1
Pod documented
131 # Update offset
132 29 my ($self, $new_val) = @_;
133 29 ▶ confess "ERROR FASTX::Seq: offset must be a positive integer" if (defined $new_val && $new_val !~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val and not $new_val =~ /^\d+$/u 0 29 29
Condition66%2/3
defined $new_val and not $new_val =~ /^\d+$/u
!ll&&!rl&&r
2810
MC/DC0%0/2
defined $new_val and not $new_val =~ /^\d+$/u
defined $new_val not $new_val =~ /^\d+$/u
Truth table66%2/3
A and not(B)
A= defined $new_valB= not $new_val =~ /^\d+$/u
ABresult
0X0
100
111
134 29 ▶ $self->{offset} = $new_val if (defined $new_val);
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val 1 28 29
135 29 return $self->{offset};
136 }
137  
138  
139 20 ▶sub line_len : lvalue {
Subroutine line_len: called CC=4 SCAR=15.6
Pod documented
140 # Update line_len
141 20 my ($self, $new_val) = @_;
142 20 ▶ confess "ERROR FASTX::Seq: line_len must be a positive integer" if (defined $new_val && $new_val !~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val and not $new_val =~ /^\d+$/u 0 20 20
Condition33%1/3
defined $new_val and not $new_val =~ /^\d+$/u
!ll&&!rl&&r
2000
MC/DC0%0/2
defined $new_val and not $new_val =~ /^\d+$/u
defined $new_val not $new_val =~ /^\d+$/u
Truth table33%1/3
A and not(B)
A= defined $new_valB= not $new_val =~ /^\d+$/u
ABresult
0X0
100
111
143 20 ▶ $self->{line_len} = $new_val if (defined $new_val);
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val 0 20 20
144 20 return $self->{line_len};
145 }
146  
147  
148 10 ▶sub default_quality : lvalue {
Subroutine default_quality: called CC=4 SCAR=15.6
Pod documented
149 # Update default_quality
150 10 my ($self, $new_val) = @_;
151 10 ▶ confess "ERROR FASTX::Seq: default_quality must be a single character" if (defined $new_val && length($new_val) != 1);
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val and length $new_val != 1 0 10 10
Condition33%1/3
defined $new_val and length $new_val != 1
!ll&&!rl&&r
1000
MC/DC0%0/2
defined $new_val and length $new_val != 1
defined $new_val length $new_val != 1
Truth table33%1/3
A and B
A= defined $new_valB= length $new_val != 1
ABresult
0X0
100
111
152 10 ▶ $self->{default_quality} = $new_val if (defined $new_val);
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val 0 10 10
153 10 return $self->{default_quality};
154 }
155  
156  
157 23 ▶sub len {
Subroutine len: called CC=1 SCAR=0.0
Pod documented
158 # Update comment
159 23 my ($self) = @_;
160 23 return length($self->{seq});
161 }
162  
163  
164  
165  
166  
167 2 ▶sub rev {
Subroutine rev: called CC=2 SCAR=7.0
Pod documented
168 # Update comment
169 2 my ($self) = @_;
170 2 $self->{seq} = reverse($self->{seq});
171 2 ▶ $self->{qual} = reverse($self->{qual}) if (defined reverse($self->{qual}));
Branch: 1 branch
BranchTrueFalseTotal
if defined reverse($self->{"qual"}) 2 0 2
172 2 return $self;
173 }
174  
175  
176  
177 1 ▶sub rc {
Subroutine rc: called CC=2 SCAR=7.2
Pod documented
178 # Update comment
179 1 my ($self) = @_;
180 1 $self->rev();
181 1 ▶ if ($self->{seq} =~ /U/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'seq'} =~ /U/iu) { } 0 1 1
182 0 $self->{seq} =~ tr/ACGURYSWKMBDHVacguryswkmbdhv/UGCAYRSWMKVHDBugcayrswmkvhdb/;
183 } else {
184 1 $self->{seq} =~ tr/ACGTRYSWKMBDHVacgtryswkmbdhv/TGCAYRSWMKVHDBtgcayrswmkvhdb/;
185 }
186 #$self->{qual} = reverse($self->{qual}) if (defined reverse($self->{qual}));
187 1 return $self;
188 }
189  
190  
191 7 ▶sub slice {
Subroutine slice: called CC=4 SCAR=13.9
Pod documented
192 # Update comment
193 7 my ($self, $from, $len) = @_;
194 7 my $new_seq;
195 my $new_qual;
196 7 ▶ if (defined($len)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $len) { } 4 3 7
197 4 $new_seq = substr($self->{seq}, $from, $len);
198 4 ▶ $new_qual = defined($self->{qual}) ? substr($self->{qual}, $from, $len) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'qual'} ? : 1 3 4
199 } else {
200 3 $new_seq = substr($self->{seq}, $from);
201 3 ▶ $new_qual = defined($self->{qual}) ? substr($self->{qual}, $from) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'qual'} ? : 1 2 3
202 }
203 7 return __PACKAGE__->new($new_seq, $self->{name}, $self->{comment}, $new_qual);
204 }
205  
206  
207 42 ▶sub char2qual {
Subroutine char2qual: called CC=3 SCAR=11.4
Pod documented
208 42 my ($self, $quality_encoded, $offset) = @_;
209 # Check quality_encoded is a single character
210 42 ▶ confess "Quality encoded character must be a single character" if (length($quality_encoded) != 1);
Branch: 1 branch
BranchTrueFalseTotal
if length $quality_encoded != 1 0 42 42
211 42 ▶ $offset = defined $offset ? $offset : $FASTX::Seq::DEFAULT_OFFSET;
Branch: 1 branch
BranchTrueFalseTotal
defined $offset ? : 42 0 42
212 42 return unpack("C*", $quality_encoded) - $offset;
213 }
214  
215  
216 2 ▶sub qual2char {
Subroutine qual2char: called CC=3 SCAR=11.4
Pod documented
217 2 my ($self, $quality_integer, $offset) = @_;
218 2 ▶ confess "Quality integer must be an integer value" if ($quality_integer !~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $quality_integer =~ /^\d+$/u 0 2 2
219 2 ▶ $offset = defined $offset ? $offset : $FASTX::Seq::DEFAULT_OFFSET;
Branch: 1 branch
BranchTrueFalseTotal
defined $offset ? : 2 0 2
220 2 return chr($quality_integer + $offset);
221 }
222  
223  
224  
225 5 ▶sub qualities {
Subroutine qualities: called CC=3 SCAR=11.0
Pod documented
226 5 my ($self) = @_;
227 5 my @qualities;
228 5 ▶ if (defined $self->{qual}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"qual"}) 5 0 5
229 5 ▶ for (my $i = 0; $i < length($self->{qual}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $self->{"qual"}) 40 5 45
230 40 push @qualities, $self->char2qual(substr($self->{qual}, $i, 1), $self->{offset});
231 }
232 }
233 5 return @qualities;
234 }
235  
236  
237 1 ▶sub min_qual {
Subroutine min_qual: called CC=1 SCAR=0.0
Pod documented
238 1 my ($self) = @_;
239 1 my @qualities = $self->qualities();
240 # Calculate minimum quality
241 1 @qualities = sort {$a <=> $b} @qualities;
242 1 return $qualities[0];
243 }
244  
245  
246  
247 1 ▶sub max_qual {
Subroutine max_qual: called CC=1 SCAR=0.0
Pod documented
248 1 my ($self) = @_;
249 1 my @qualities = $self->qualities();
250 # Calculate minimum quality
251 1 @qualities = sort {$b <=> $a} @qualities;
252 1 return $qualities[0];
253 }
254  
255  
256 1 ▶sub trim_after : lvalue {
Subroutine trim_after: called CC=4 SCAR=13.9
Pod documented
257 1 my ($self, $qual_value) = @_;
258 1 ▶ confess "Quality integer must be an integer value" if ($qual_value !~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $qual_value =~ /^\d+$/u 0 1 1
259 # Detect first base with quality lower or equal than $qual_value
260 1 my $i = 0;
261 1 my @qualities = $self->qualities();
262 1 ▶ for ($i = 0; $i < scalar(@qualities); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @qualities) 7 0 7
263 7 ▶ if ($qualities[$i] <= $qual_value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qualities[$i] <= $qual_value) 1 6 7
264 1 last;
265 }
266 }
267 # Trim sequence and quality
268 1 my $slice = $self->slice(0, $i);
269 1 $self->{seq} = $slice->{seq};
270 1 $self->{qual} = $slice->{qual};
271 1 return $self;
272 }
273  
274  
275  
276 1 ▶sub trim_until : lvalue {
Subroutine trim_until: called CC=4 SCAR=13.9
Pod documented
277 1 my ($self, $qual_value) = @_;
278 1 ▶ confess "Quality integer must be an integer value" if ($qual_value !~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $qual_value =~ /^\d+$/u 0 1 1
279 # Detect first base with quality lower or equal than $qual_value
280 1 my $i = 0;
281 1 my @qualities = $self->qualities();
282 1 ▶ for ($i = 0; $i < scalar(@qualities); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @qualities) 3 0 3
283 3 ▶ if ($qualities[$i] >= $qual_value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qualities[$i] >= $qual_value) 1 2 3
284 1 last;
285 }
286 }
287 # Trim sequence and quality
288 1 my $slice = $self->slice($i);
289 1 $self->{seq} = $slice->{seq};
290 1 $self->{qual} = $slice->{qual};
291
292 1 return $self;
293 }
294  
295 22 ▶sub _kmer2num {
Subroutine _kmer2num: called CC=3 SCAR=11.3
296 22 my ($kmer) = @_;
297  
298 22 my %baseVal = ('T' => 0, 'C' => 1, 'A' => 2, 'G' => 3, 'U' => 0);
299 22 my $klen = length($kmer);
300 22 my $num = 0;
301  
302 22 for my $i (0..($klen - 1)) {
303 66 ▶ if (exists $baseVal{substr($kmer, $i, 1)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $baseVal{substr $kmer, $i, 1}) { } 66 0 66
304 66 my $p = 4 ** ($klen - 1 - $i);
305 66 $num += $p * $baseVal{substr($kmer, $i, 1)};
306 } else {
307 0 $num = -1;
308 0 last;
309 }
310 }
311  
312 22 return $num;
313 }
314  
315  
316 5 ▶sub translate {
Subroutine translate: called CC=5 SCAR=16.3
Pod documented
317 5 my ($self, $code_number) = @_;
318  
319 5 my $record = $self->copy();
320 # Default genetic code if not specified
321 5 ▶ $code_number //= 11;
Condition50%1/2
$code_number //= 11
l!l
50
MC/DC0%0/1
$code_number //= 11
$code_number
Truth table50%1/2
A
A= $code_number
Aresult
11
00
322
323 5 my @code_map = (
324 "FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG", #1
325 "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG",
326 "FFLLSSSSYY**CCWWTTTTPPPPHHQQRRRRIIMMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
327 "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
328 "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSSSVVVVAAAADDEEGGGG",
329 "FFLLSSSSYYQQCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
330 "",
331 "",
332 "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
333 "FFLLSSSSYY**CCCWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
334 "FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG", #11 Bact, Ar and Plant Plast
335 "FFLLSSSSYY**CC*WLLLSPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
336 "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSGGVVVVAAAADDEEGGGG",
337 "FFLLSSSSYYY*CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
338 "FFLLSSSSYY*QCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG", #15
339 "FFLLSSSSYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
340 "", "", "", "",
341 "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
342 "FFLLSS*SYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
343 "FF*LSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
344 "FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSSKVVVVAAAADDEEGGGG",
345 "FFLLSSSSYY**CCGWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
346 "FFLLSSSSYY**CC*WLLLAPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
347 "FFLLSSSSYYQQCCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
348 "FFLLSSSSYYQQCCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
349 "FFLLSSSSYYYYCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
350 "FFLLSSSSYYEECC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
351 "FFLLSSSSYYEECCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG"
352 );
353
354 5 my $code = $code_map[$code_number - 1];
355 # Check sequence is nucleotidic or RNA
356 5 ▶ confess "ERROR FASTX::Seq: Sequence must be nucleotidic" if ($self->{seq} !~ /^[ACGTU]+$/i);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"seq"} =~ /^[ACGTU]+$/iu 0 5 5
357 5 my @nucleotides = split //, $self->seq;
358 5 my @translated_sequence;
359
360 5 ▶ for (my $i = 0; $i < scalar(@nucleotides) - 2; $i += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar(@nucleotides) - 2) 22 5 27
361 22 my $codon = $nucleotides[$i] . $nucleotides[$i+1] . $nucleotides[$i+2];
362 22 my $num = _kmer2num($codon); # You need to define this function
363 22 ▶ if ($num != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num != -1) { } 22 0 22
364 22 push @translated_sequence, substr($code, $num, 1);
365
366 } else {
367 0 push @translated_sequence, '-';
368
369 }
370 }
371
372 5 my $translated_seq = join('', @translated_sequence);
373
374 5 $record->seq($translated_seq);
375 # Remove qual if present
376 5 $record->qual(undef);
377 5 return $record;
378 }
379  
380  
381 0 ▶sub string {
Subroutine string: not called CC=2 SCAR=17.9
Pod documented
382 # Update comment
383 0 my ($self, @args) = @_;
384 0 ▶ if (defined $self->{qual}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'qual'}) { } 0 0 0
385 0 return $self->asfastq(@args);
386 } else {
387 0 return $self->asfasta(@args);
388 }
389
390 }
391  
392  
393 0 ▶sub as_string {
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
394 # Update comment
395 0 my ($self) = @_;
396 0 return $self->string();
397 }
398  
399  
400  
401 15 ▶sub asfasta {
Subroutine asfasta: called CC=4 SCAR=14.1
Pod documented
402 # Update comment
403 15 my ($self, $len) = @_;
404
405 15 ▶ my $name = $self->{name} // "sequence";
Condition50%1/2
$self->{"name"} // "sequence"
l!l
150
MC/DC0%0/1
$self->{"name"} // "sequence"
$self->{"name"}
Truth table50%1/2
A
A= $self->{"name"}
Aresult
11
00
406 15 ▶ my $comment = (defined $self->{comment} and length($self->{comment}) > 0) ? " " . $self->{comment} : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'comment'} && length $self->{'comment'} > 0 ? : 6 9 15
Condition66%2/3
defined $self->{"comment"} and length $self->{"comment"} > 0
!ll&&!rl&&r
096
MC/DC50%1/2
defined $self->{"comment"} and length $self->{"comment"} > 0
defined $self->{"comment"} length $self->{"comment"} > 0
Truth table66%2/3
A and B
A= defined $self->{"comment"}B= length $self->{"comment"} > 0
ABresult
0X0
100
111
407 15 return ">" . $name . $comment . "\n" . _split_string($self->{seq}, $len) . "\n";
408 }
409  
410  
411 25 ▶sub asfastq {
Subroutine asfastq: called CC=8 SCAR=20.9
Pod documented
412 # Update comment
413 25 my ($self, $user_quality) = @_;
414 25 my $quality = $self->{qual};
415  
416 25 ▶ if (defined $user_quality) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $user_quality) { } 15 10 25
elsif (not defined $quality) { } 6 4 10
417 # User requests new quality
418 15 ▶ if (length($user_quality) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $user_quality == 1) { } 10 5 15
419 # And it's valid!
420 10 $quality = $user_quality x length($self->{seq});
421 } else {
422 5 ▶ if (not $FASTX::Seq::QUIET) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($FASTX::Seq::QUIET) 5 0 5
423 5 say STDERR "[WARNING] FASTX::Seq->as_fastq(): Provide a _char_ as quality, not a value (", $user_quality,"): defaulting to $FASTX::Seq::DEFAULT_QUALITY";
424 }
425 5 $quality = $FASTX::Seq::DEFAULT_QUALITY x length($self->{seq});
426 }
427 } elsif (not defined $quality) {
428 6 $quality = $FASTX::Seq::DEFAULT_QUALITY x length($self->{seq});
429 }
430
431
432 25 ▶ my $name = $self->{name} // "sequence";
Condition50%1/2
$self->{"name"} // "sequence"
l!l
250
MC/DC0%0/1
$self->{"name"} // "sequence"
$self->{"name"}
Truth table50%1/2
A
A= $self->{"name"}
Aresult
11
00
433 25 ▶ my $comment = (defined $self->{comment} and length($self->{comment}) > 0) ? " " . $self->{comment} : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'comment'} && length $self->{'comment'} > 0 ? : 10 15 25
Condition66%2/3
defined $self->{"comment"} and length $self->{"comment"} > 0
!ll&&!rl&&r
01510
MC/DC50%1/2
defined $self->{"comment"} and length $self->{"comment"} > 0
defined $self->{"comment"} length $self->{"comment"} > 0
Truth table66%2/3
A and B
A= defined $self->{"comment"}B= length $self->{"comment"} > 0
ABresult
0X0
100
111
434
435 25 return "@" . $name . $comment . "\n" . $self->{seq} . "\n+\n" . $quality . "\n";
436 }
437  
438  
439  
440  
441 5 ▶sub as_fasta {
Subroutine as_fasta: called CC=1 SCAR=0.0
Pod documented
442 # Update comment
443 5 my ($self, @args) = @_;
444 5 return $self->asfasta(@args);
445 }
446  
447  
448 10 ▶sub as_fastq {
Subroutine as_fastq: called CC=1 SCAR=0.0
Pod documented
449 # Update comment
450 10 my ($self, @args) = @_;
451 10 return $self->asfastq(@args);
452 }
453  
454  
455 13 ▶sub is_fasta {
Subroutine is_fasta: called CC=3 SCAR=11.1
Pod documented
456 # Return true if record has no quality
457 13 my ($self) = @_;
458 13 ▶ return ((defined $self->{qual}) > 0 and length($self->{qual}) == length($self->{seq})) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'qual'} > 0 && length $self->{'qual'} == length $self->{'seq'} ? : 6 7 13
Condition66%2/3
defined $self->{"qual"} > 0 and length $self->{"qual"} == length $self->{"seq"}
!ll&&!rl&&r
706
MC/DC50%1/2
defined $self->{"qual"} > 0 and length $self->{"qual"} == length $self->{"seq"}
defined $self->{"qual"} > 0 length $self->{"qual"} == length $self->{"seq"}
Truth table66%2/3
A and B
A= defined $self->{"qual"} > 0B= length $self->{"qual"} == length $self->{"seq"}
ABresult
0X0
100
111
459 }
460  
461  
462 7 ▶sub is_fastq {
Subroutine is_fastq: called CC=3 SCAR=11.1
Pod documented
463 # Update comment
464 7 my ($self) = @_;
465 7 ▶ return ((defined $self->{qual}) > 0 and length($self->{qual}) == length($self->{seq})) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'qual'} > 0 && length $self->{'qual'} == length $self->{'seq'} ? : 4 3 7
Condition66%2/3
defined $self->{"qual"} > 0 and length $self->{"qual"} == length $self->{"seq"}
!ll&&!rl&&r
304
MC/DC50%1/2
defined $self->{"qual"} > 0 and length $self->{"qual"} == length $self->{"seq"}
defined $self->{"qual"} > 0 length $self->{"qual"} == length $self->{"seq"}
Truth table66%2/3
A and B
A= defined $self->{"qual"} > 0B= length $self->{"qual"} == length $self->{"seq"}
ABresult
0X0
100
111
466 }
467  
468  
469 15 ▶sub _split_string {
Subroutine _split_string: called CC=4 SCAR=13.9
470 15 my ($string, $width) = @_;
471 15 ▶ if (not defined $width or $width == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $width or $width == 0) 10 5 15
Condition66%2/3
not defined $width or $width == 0
l!l&&r!l&&!r
1005
MC/DC50%1/2
not defined $width or $width == 0
not defined $width $width == 0
Truth table66%2/3
not(A) or B
A= not defined $widthB= $width == 0
ABresult
1X1
011
000
472 10 return "$string";
473 }
474  
475 5 my $output_string;
476 5 ▶ for (my $i=0; $i<length($string); $i+=$width) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $string) 74 5 79
477 74 my $frag = substr($string, $i, $width);
478 74 $output_string.=$frag."\n";
479 }
480 5 chomp($output_string);
481 5 return $output_string;
482 }
483  
484 46 1;
485  
486 __END__
« lib/FASTX/ScriptHelper.pm ↑ Summary script/fqlen.pl »