-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnonRefFreqFromPileup.pl
More file actions
62 lines (54 loc) · 1.32 KB
/
nonRefFreqFromPileup.pl
File metadata and controls
62 lines (54 loc) · 1.32 KB
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
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Std;
my %opt;
getopts('hb:d:', \%opt);
my $usage = <<ENDL;
perl countNonRefPileup.pl -d [min depth] -b [bin size] < [pileup]
ENDL
sub HELP_MESSAGE {
print STDERR $usage;
exit(1);
}
HELP_MESSAGE if $opt{h};
my @bases = qw/A T C G/;
my $freqThreshold = 0.001;
my $binSize = $opt{b}? $opt{b} : 0.05;
my $minDepth = $opt{d}? $opt{d} : 10;
my $lastBin = 1 / $binSize;
my %nonRefFreq;
while (<>) {
chomp;
my @F = split /\t/;
next unless $F[4];
my $depth = length($F[4]);
next if $depth < $minDepth;
next if $F[4] =~ /[-+]/;
$F[4] =~ s/[-+][ATCGNatcgn]+//g;
for my $base (@bases) {
my $count = () = $F[4] =~ /$base/i;
my $freq = $count / $depth;
$nonRefFreq{$F[2]}{$base}[int($freq / $binSize)]++ if $freq > $freqThreshold;
}
}
print "Ref\tVar";
for my $bin (0..$lastBin) {
print "\tBin$bin";
}
print "\n";
for my $refBase (@bases) {
for my $varBase (@bases) {
next if $refBase eq $varBase;
print "$refBase\t$varBase";
for my $bin (0..$lastBin) {
print "\t";;
if (defined $nonRefFreq{$refBase}{$varBase}[$bin]) {
print $nonRefFreq{$refBase}{$varBase}[$bin];
} else {
print "0";
}
}
print "\n";
}
}