| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Sandy::Quality; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Class to simulate quality entries |
|
3
|
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
958
|
use App::Sandy::Base 'class'; |
|
|
6
|
|
|
|
|
16
|
|
|
|
6
|
|
|
|
|
37
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'App::Sandy::Role::Counter'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.25'; # VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'quality_profile' => ( |
|
11
|
|
|
|
|
|
|
is => 'ro', |
|
12
|
|
|
|
|
|
|
isa => 'My:QualityP', |
|
13
|
|
|
|
|
|
|
required => 1, |
|
14
|
|
|
|
|
|
|
coerce => 1 |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has '_quality_by_system' => ( |
|
18
|
|
|
|
|
|
|
traits => ['Hash'], |
|
19
|
|
|
|
|
|
|
is => 'ro', |
|
20
|
|
|
|
|
|
|
isa => 'My:QualityH', |
|
21
|
|
|
|
|
|
|
builder => '_build_quality_by_system', |
|
22
|
|
|
|
|
|
|
lazy_build => 1, |
|
23
|
|
|
|
|
|
|
handles => { |
|
24
|
|
|
|
|
|
|
_get_quality_by_system => 'get' |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has '_gen_quality' => ( |
|
29
|
|
|
|
|
|
|
traits => ['Code'], |
|
30
|
|
|
|
|
|
|
is => 'ro', |
|
31
|
|
|
|
|
|
|
isa => 'CodeRef', |
|
32
|
|
|
|
|
|
|
builder => '_build_gen_quality', |
|
33
|
|
|
|
|
|
|
lazy_build => 1, |
|
34
|
|
|
|
|
|
|
handles => { |
|
35
|
|
|
|
|
|
|
gen_quality => 'execute' |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has '_phred_score' => ( |
|
40
|
|
|
|
|
|
|
traits => ['Array'], |
|
41
|
|
|
|
|
|
|
isa => 'ro', |
|
42
|
|
|
|
|
|
|
isa => 'ArrayRef', |
|
43
|
|
|
|
|
|
|
builder => '_build_phred_score', |
|
44
|
|
|
|
|
|
|
handles => { |
|
45
|
|
|
|
|
|
|
_count_phred_score => 'count', |
|
46
|
|
|
|
|
|
|
_get_phred_score => 'get' |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub BUILD { |
|
51
|
30
|
|
|
30
|
0
|
72
|
my $self = shift; |
|
52
|
|
|
|
|
|
|
## Just to ensure that the lazy attributes are built before &new returns |
|
53
|
30
|
50
|
|
|
|
883
|
$self->_quality_by_system if $self->quality_profile ne 'poisson'; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _build_gen_quality { |
|
57
|
7
|
|
|
7
|
|
18
|
my $self = shift; |
|
58
|
7
|
|
|
|
|
13
|
my $fun; |
|
59
|
|
|
|
|
|
|
|
|
60
|
7
|
50
|
|
|
|
313
|
if ($self->quality_profile eq 'poisson') { |
|
61
|
7
|
|
|
9136
|
|
175
|
$fun = sub { $self->_gen_quality_by_poisson_dist(@_) }; |
|
|
9136
|
|
|
|
|
23837
|
|
|
62
|
|
|
|
|
|
|
} else { |
|
63
|
0
|
|
|
0
|
|
0
|
$fun = sub { $self->_gen_quality_by_system(@_) }; |
|
|
0
|
|
|
|
|
0
|
|
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
7
|
|
|
|
|
358
|
return $fun; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _build_phred_score { |
|
70
|
30
|
|
|
30
|
|
65
|
my $self = shift; |
|
71
|
|
|
|
|
|
|
|
|
72
|
30
|
|
|
|
|
636
|
my @phred_score = ( |
|
73
|
|
|
|
|
|
|
{ |
|
74
|
|
|
|
|
|
|
score => ['I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A', '@', '?'], |
|
75
|
|
|
|
|
|
|
size => 11, |
|
76
|
|
|
|
|
|
|
ratio => 1.5 |
|
77
|
|
|
|
|
|
|
}, |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
|
|
|
|
|
|
score => ['>', '=', '<', ';', ':', '9', '8', '7', '6', '5'], |
|
80
|
|
|
|
|
|
|
size => 10, |
|
81
|
|
|
|
|
|
|
ratio => 2 |
|
82
|
|
|
|
|
|
|
}, |
|
83
|
|
|
|
|
|
|
{ |
|
84
|
|
|
|
|
|
|
score => ['4', '3', '2', '1', '0', '/', '.', '-', ',', '+'], |
|
85
|
|
|
|
|
|
|
size => 10, |
|
86
|
|
|
|
|
|
|
ratio => 2 |
|
87
|
|
|
|
|
|
|
}, |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
|
|
|
|
|
|
score => ['*', ')', '(', '\'', '&', '%', '$', '#', '"', '!'], |
|
90
|
|
|
|
|
|
|
size => 10, |
|
91
|
|
|
|
|
|
|
ratio => 1 |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
); |
|
94
|
|
|
|
|
|
|
|
|
95
|
30
|
|
|
|
|
987
|
return \@phred_score; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _build_quality_by_system { |
|
99
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
100
|
0
|
|
|
|
|
0
|
my $db = App::Sandy::DB::Handle::Quality->new; |
|
101
|
0
|
|
|
|
|
0
|
my ($matrix, $deepth, $partil) = $db->retrievedb($self->quality_profile); |
|
102
|
|
|
|
|
|
|
return { |
|
103
|
0
|
|
|
|
|
0
|
matrix => $matrix, |
|
104
|
|
|
|
|
|
|
deepth => $deepth, |
|
105
|
|
|
|
|
|
|
partil => $partil |
|
106
|
|
|
|
|
|
|
}; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _gen_quality_by_system { |
|
110
|
0
|
|
|
0
|
|
0
|
my ($self, $read_size, $rng) = @_; |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
my ($matrix, $deepth, $partil) = $self->_get_quality_by_system( |
|
113
|
|
|
|
|
|
|
qw/matrix deepth partil/ |
|
114
|
|
|
|
|
|
|
); |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
0
|
my ($bin, $left); |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# To make this routine more robust. |
|
119
|
|
|
|
|
|
|
# It is necessary to work on reads |
|
120
|
|
|
|
|
|
|
# lesser than read_size |
|
121
|
0
|
0
|
|
|
|
0
|
if ($read_size < $partil) { |
|
122
|
0
|
|
|
|
|
0
|
$partil = $read_size; |
|
123
|
0
|
|
|
|
|
0
|
$bin = 1; |
|
124
|
0
|
|
|
|
|
0
|
$left = 0; |
|
125
|
|
|
|
|
|
|
} else { |
|
126
|
0
|
|
|
|
|
0
|
$bin = int($read_size / $partil); |
|
127
|
0
|
|
|
|
|
0
|
$left = $read_size % $partil; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
0
|
my $pick_again = $self->with_make_counter($read_size - $left, $left, $rng); |
|
131
|
0
|
|
|
|
|
0
|
my $quality; |
|
132
|
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
0
|
for (my $i = 0; $i < $partil; $i++) { |
|
134
|
0
|
|
|
|
|
0
|
for (my $j = 0; $j < $bin; $j++) { |
|
135
|
0
|
|
|
|
|
0
|
$quality .= $matrix->[$i][$rng->get_n($deepth)]; |
|
136
|
0
|
0
|
|
|
|
0
|
if ($pick_again->()) { |
|
137
|
0
|
|
|
|
|
0
|
$quality .= $matrix->[$i][$rng->get_n($deepth)]; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
0
|
return \$quality; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub _gen_quality_by_poisson_dist { |
|
146
|
9136
|
|
|
9136
|
|
17967
|
my ($self, $read_size, $rng) = @_; |
|
147
|
9136
|
|
|
|
|
12564
|
my $quality; |
|
148
|
9136
|
|
|
|
|
309938
|
return $self->_poisson_dist(\$quality, $read_size, $self->_count_phred_score, $rng); |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _poisson_dist { |
|
152
|
45680
|
|
|
45680
|
|
82567
|
my ($self, $quality_ref, $size, $countdown, $rng) = @_; |
|
153
|
45680
|
100
|
|
|
|
109842
|
return $quality_ref if not $countdown; |
|
154
|
|
|
|
|
|
|
|
|
155
|
36544
|
|
|
|
|
1240307
|
my $phred_score = $self->_get_phred_score($self->_count_phred_score - $countdown); |
|
156
|
36544
|
|
|
|
|
93606
|
my $part = int($size / $phred_score->{ratio}) + ($size % $phred_score->{ratio}); |
|
157
|
|
|
|
|
|
|
|
|
158
|
36544
|
|
|
|
|
75344
|
for (my $i = 0; $i < $part; $i++) { |
|
159
|
91360
|
|
|
|
|
306746
|
$$quality_ref .= $phred_score->{score}[$rng->get_n($phred_score->{size})]; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
36544
|
|
|
|
|
85259
|
return $self->_poisson_dist($quality_ref, $size - $part, $countdown - 1, $rng); |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__END__ |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=pod |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=encoding UTF-8 |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 NAME |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
App::Sandy::Quality - Class to simulate quality entries |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 VERSION |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
version 0.25 |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 AUTHORS |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over 4 |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Thiago L. A. Miller <tmiller@mochsl.org.br> |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
J. Leonel Buzzo <lbuzzo@mochsl.org.br> |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Felipe R. C. dos Santos <fsantos@mochsl.org.br> |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Helena B. Conceição <hconceicao@mochsl.org.br> |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item * |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Rodrigo Barreiro <rbarreiro@mochsl.org.br> |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item * |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Gabriela Guardia <gguardia@mochsl.org.br> |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item * |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Fernanda Orpinelli <forpinelli@mochsl.org.br> |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item * |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Rafael Mercuri <rmercuri@mochsl.org.br> |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item * |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Rodrigo Barreiro <rbarreiro@mochsl.org.br> |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item * |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Pedro A. F. Galante <pgalante@mochsl.org.br> |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=back |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This software is Copyright (c) 2023 by Teaching and Research Institute from Sírio-Libanês Hospital. |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
This is free software, licensed under: |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut |