-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQV_run_assessment.pl
397 lines (345 loc) · 9.6 KB
/
QV_run_assessment.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Getopt::Long;
# Written by Ariella Sasson, Rutgers University, version 1, Nov 1, 2009
# This script provides an analysis of the SOLiD QV file. It samples 20% of the data available to speed up runtime and gives consistant results with a full analysis of the data.
$0 =~ s-.*/--g;
my ($inputF,$tLen,$negQV,$outputFile);
#input output option
GetOptions('i|input=s' => \$inputF,
't|trunc:i' => \$tLen,
'm|misCall_sig:s' => \$negQV,
'o|output=s' => \$outputFile,
);
my @assign;
my $acnt;
@assign=&AssignInputs();
$acnt=@assign;
if ($acnt > 0){
my $trash = join('',@assign);
print "\n$trash";
usage();
}
{
open (iFP,$inputF) or die "Can not open $inputF.\n";
my $output=">".$outputFile;
open (oFP,$output) or die "Can not open $output.\n";
my $counter=0;
my $Scounter=0;
my @matrix;
my $pic=0;
my @rmNeg;
my @avg20;
my @p1_eoff;
my @p3_eoff;
my @p5_eoff;
my @p1_e3;
my @p1_e5;
my @p5_e0;
my @holdID;
#change these 2 loops to increase the matrix size
for my $i ( 0 .. 55 ) {
for my $j ( 0 .. 50 ) {
$matrix[$i][$j]=0;
$rmNeg[$i][$j]=0;
$avg20[$i][$j]=0;
$p1_eoff[$i][$j]=0;
$p3_eoff[$i][$j]=0;
$p5_eoff[$i][$j]=0;
$p1_e3[$i][$j]=0;
$p1_e5[$i][$j]=0;
$p5_e0[$i][$j]=0;
}
}
#reading line by line. The bead numbers are ignored.
while (<iFP>) {
chomp;
$b=">";
if (/^($b)|^\#/) {
next;
}
my $qv = $_;
$counter++;
$pic++;
if ($pic!=5){
next;
}
else{
$pic=0;
$Scounter++;
my @F3_arr=split (/\s/,$qv);
my $test=@F3_arr;
if ($tLen == -20){
$tLen=$test;
}
elsif ($tLen > $test) {
$tLen=$test;
}
# Set up for p & e analysis
for my $m ( 0 .. 2) {
for my $n ( 0 .. $test-1 ) {
$holdID[$m][$n]=0;
}
}
# Full QV analysis No truncation
for (0..$test-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$matrix[$_][$a]++;
if ($a >= 26){
$holdID[0][$_]=1;
}
if ($a <= 11){
$holdID[1][$_]=1;
}
if ($a == 0) {
$holdID[2][$_]=1;
}
}
# Average QV analysis min Score 20
my $sum = 0;
my $negInd=0;
for (0 .. $tLen-1){
$sum=$sum + $F3_arr[$_];
if (($F3_arr[$_] < 0) && ($negQV eq 'y')){
$negInd=1;
}
}
my $avg_sc = $sum/$tLen;
if ((($negQV eq 'y') && ($negInd == 0)) || ($negQV eq 'n')){
if ($avg_sc >= 20) {
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$avg20[$_][$a]++;
}
}
}
# p & e analysis
my $psum = 0;
my $esum = 0;
my $negsum = 0;
my $holdL = 9;
if ($tLen -1 < 9){
$holdL = $tLen -1;
}
for (0 .. $holdL){
$psum = $psum + $holdID[0][$_];
}
for (0 .. $tLen-1){
$esum = $esum + $holdID[1][$_];
$negsum = $negsum + $holdID[2][$_];
}
# Removal of miscalls
if ($negsum ==0){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$rmNeg[$_][$a]++;
}
}
# p1 e off
if ($negQV eq 'y'){
if (($negsum ==0) && ($psum >=1)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p1_eoff[$_][$a]++;
}
}
} else {
if (($psum >=1)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p1_eoff[$_][$a]++;
}
}
}
# p3 e off
if ($negQV eq 'y'){
if (($negsum ==0) && ($psum >=3)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p3_eoff[$_][$a]++;
}
}
} else {
if (($psum >=3)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p3_eoff[$_][$a]++;
}
}
}
# p5 e off
if ($negQV eq 'y'){
if (($negsum ==0) && ($psum >=5)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p5_eoff[$_][$a]++;
}
}
} else {
if (($psum >=5)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p5_eoff[$_][$a]++;
}
}
}
#p1 e5
if ($negQV eq 'y'){
if (($negsum ==0) && ($psum >=1) && ($esum <= 5)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p1_e5[$_][$a]++;
}
}
} else {
if (($psum >=1) && ($esum <= 5)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p1_e5[$_][$a]++;
}
}
}
#p1 e3
if ($negQV eq 'y'){
if (($negsum ==0) && ($psum >=1) && ($esum <= 3)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p1_e3[$_][$a]++;
}
}
} else {
if (($psum >=1) && ($esum <= 3)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p1_e3[$_][$a]++;
}
}
}
#p5 e0
if ($negQV eq 'y'){
if (($negsum ==0) && ($psum >=5) && ($esum == 0)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p5_e0[$_][$a]++;
}
}
} else {
if (($psum >=5) && ($esum == 0)){
for (0..$tLen-1){
my $a = $F3_arr[$_];
$a = $a + 1;
$p5_e0[$_][$a]++;
}
}
}
}
}
close(iFP);
print oFP "Total Count of reads - $counter \n";
print oFP "Total COunt of reads sampled - $Scounter \n";
print oFP "\n\n";
print oFP "Full QV Analysis\n";
for my $i ( 0 .. $#matrix) {
print oFP "@{$matrix[$i]}\n";
}
print oFP "\n\n";
print oFP "Removal of miscalls\n";
for my $i ( 0 .. $#rmNeg) {
print oFP "@{$rmNeg[$i]}\n";
}
print oFP "\n\n";
print oFP "Reads where the mean >=20 \n";
for my $i ( 0 .. $#avg20) {
print oFP "@{$avg20[$i]}\n";
}
print oFP "\n\n";
print oFP "Reads where p=1 e=off \n";
for my $i ( 0 .. $#p1_eoff) {
print oFP "@{$p1_eoff[$i]}\n";
}
print oFP "\n\n";
print oFP "Reads where p=3 e=off \n";
for my $i ( 0 .. $#p3_eoff) {
print oFP "@{$p3_eoff[$i]}\n";
}
print oFP "\n\n";
print oFP "Reads where p=5 e=off \n";
for my $i ( 0 .. $#p5_eoff) {
print oFP "@{$p5_eoff[$i]}\n";
}
print oFP "\n\n";
print oFP "Reads where p=1 e=5 \n";
for my $i ( 0 .. $#p1_e5) {
print oFP "@{$p1_e5[$i]}\n";
}
print oFP "\n\n";
print oFP "Reads where p=1 e=3 \n";
for my $i ( 0 .. $#p1_e3) {
print oFP "@{$p1_e3[$i]}\n";
}
print oFP "\n\n";
print oFP "Reads where p=5 e=0 \n";
for my $i ( 0 .. $#p5_e0) {
print oFP "@{$p5_e0[$i]}\n";
}
print oFP "\n\n";
close(oFP);
}
sub AssignInputs{
my @err;
if ((!defined($inputF)) || ($inputF eq '')) {
push(@err, "Error 1: Input File not defined\n");
}
#------------------------------
if ((!defined($negQV)) || ($negQV eq '') || ($negQV eq 'off') || ($negQV eq 'n')||($negQV eq 'no')){
$negQV = 'n';
print "Removal of Reads containing a miscall - $negQV\n";
}
elsif (($negQV eq 'on')||($negQV eq 'y')||($negQV eq 'yes')) {
$negQV = 'y';
print "Removal of reads containing a miscall - $negQV\n";
}
else {
push(@err,"Error 2: Removal of reads with negative quality scores can either be 'on' or 'off'. The default is off.\n");
}
#------------------------------
if ((!defined($tLen)) || ($tLen eq '')){
$tLen = -20;
print "No truncation desired\n";
}
elsif ($tLen > 0) {
$tLen = $tLen;
print "Truncation length - $tLen\n";
}
else {
push(@err,"Error 3: Improper truncation length. Truncation must be turned on and the length must be greater than 0.\n");
}
#--------------------------------------------------------------
if ((!defined($outputFile)) || ($outputFile eq '')) {
push(@err,"Error 3: Output File not defined\n");
}
return @err;
}
sub usage {
print "\nusage: $0 \n[-i SOLiD QV file you want to analyze\n -t the length of desired read \n -m remove from analysis any reads that contain a miscall (.) \n -o output file name]\n\n";
print "outputs a series of matrices that represent QV analyses for various filtering parameters. The rows represent the positions and the columns represent the quality scores. ";
print "The numbers represented in the matrix are the counts of that score at that positions.\n\n";
print "example: $0 -i Frag.qual -t 35 -m y -o Frag_QV_analysis.txt\n\n";
exit;
}