-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse_pileup_query.pl
133 lines (65 loc) · 1.93 KB
/
parse_pileup_query.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
#library to parse a pileup file line and return counts of refnuc, A, T, G, C
#parse_pileup subroutine requires a pileup line and minimum base quality as input
use strict;
sub parse_pileup {
if (@_ < 3) {
die "need to provide 2 inputs to parse_pileup: pileup line, minbasequal, base quality offset\n"
}
my @pilefields = split(/\t/, $_[0]);
my $minbasequal = int($_[1]);
my $offset = int($_[2]);
my @pileup = split(//,$pilefields[4]);
my @qualities = split(//, $pilefields[5]);
my ($acount, $tcount, $ccount, $gcount, $refnuccount) = (0,0,0,0,0);
my $indel = 0;
my $readcount = 0;
my $indelstop;
LOOP: for (my $j = 0; $j < @pileup; $j++) { #loop over each individual read and assay the nucleotide called
if ($pileup[$j] eq '^') { #ignore the read map qualities
$indel = 1;
my $indellength = 1;
$indelstop = $j + $indellength;
}
if ($indel == 0) {
if ($pileup[$j] eq '+' || $pileup[$j] eq '-') { #ignore indels
$indel = 1;
my $indellength = int($pileup[$j+1]) + 1;
if ($pileup[$j+2] =~ m/\d/) {
$indellength = (10*int($pileup[$j+1])) + int($pileup[$j+2]) + 2;
}
$indelstop = $j + $indellength;
}
}
if ($indel == 1) {
if ($j == $indelstop) {
$indel = 0;
next LOOP;
}
}
if ($indel == 0) { #count up the occurance of each nucleotide
if ($pileup[$j] ne '$') {
$readcount = $readcount + 1;
if (ord($qualities[$readcount-1]) >= ($minbasequal + $offset)) {
if ($pileup[$j] eq '.' || $pileup[$j] eq ',') {
$refnuccount = $refnuccount + 1;
}
elsif ($pileup[$j] =~ /a/i) {
$acount = $acount + 1;
}
elsif ($pileup[$j] =~ /t/i) {
$tcount = $tcount + 1;
}
elsif ($pileup[$j] =~ /c/i) {
$ccount = $ccount + 1;
}
elsif ($pileup[$j] =~ /g/i) {
$gcount = $gcount + 1;
}
}
}
}
}
my @returnarray = ($refnuccount, $acount, $tcount, $ccount, $gcount); #return counts
return @returnarray;
}
1;