forked from gringer/bioinfscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtcounts2MAF.pl
executable file
·49 lines (44 loc) · 1.04 KB
/
gtcounts2MAF.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
#!/usr/bin/perl
use warnings;
use strict;
use List::Util;
sub processCounts{
my ($marker, $countRef) = @_;
if($marker eq ""){
return;
}
#print(STDERR "Processing $marker\n");
foreach my $sex (keys(%{$countRef})){
my %tCounts = %{$countRef->{$sex}};
my $total = 0;
my $minA = "0";
my $minC = undef;
while(my ($a, $b) = each %tCounts) {
if(!defined($minC) || ($b < $minC)){
$minC = $b;
$minA = $a;
}
$total += $b;
}
my $minF = ($total > 0) ? $minC / $total : 0;
printf("%s,%s,%s,%0.4f\n", $marker, $sex, $minA, $minF);
}
}
my $lastMarker = "";
my $counts = {};
while(<>){
chomp;
#print $_."\n";
my ($marker, $sex, $type, $bases, $count) = split(/,/);
if($marker ne $lastMarker){
processCounts($lastMarker, $counts);
$counts = {"m" => {}, "f" => {}, "a" => {}};
$lastMarker = $marker;
}
#print(join(";",%{$counts})."\n");
if(($type ne "a") || ($bases eq "0")){
next;
}
$counts->{$sex}->{$bases} = $count;
}
processCounts($lastMarker, $counts);