-
Notifications
You must be signed in to change notification settings - Fork 5
/
callGenotypes.pl
executable file
·63 lines (54 loc) · 1.28 KB
/
callGenotypes.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
#!/usr/bin/perl
## Call genotypes from impute2 output.
## Note that sites should be filterd beforehand to remove low quality imputations.
##
## Author: Peter Humburg, 2012
use warnings;
use strict;
use File::Basename;
use IO::Zlib;
use Getopt::Long;
sub usage{
print STDERR basename($0) . " [options] <files>\n";
print STDERR " files: List of impute2 output files.\n";
print STDERR " Options:\n";
print STDERR " --dosage | -d: Output dosage estimates rather than calls.\n";
exit;
}
my ($status, $dosage);
$status = GetOptions("dosage|d" => \$dosage);
if(not @ARGV){
usage();
}
my (@entry, $call);
for my $file (@ARGV){
if($file =~ /\.gz$/){
tie *IN, 'IO::Zlib', $file, 'rb' or (warn("Unable to read $file: $!") and next);
}
else{
open IN, $file or (warn("Unable to read $file: $!") and next);
}
while(<IN>){
chomp;
@entry = split /\s/;
if($entry[0] =~ /(\d+):\d+/){
$entry[0] = $1;
}
print join(" ", @entry[0..4]);
for(my $i = 5; $i < @entry; $i += 3){
$call = 0;
if($dosage){
$call = $entry[$i+1] + 2*$entry[$i+2];
}
elsif($entry[$i+1] > $entry[$i] and $entry[$i+1] > $entry[$i+2]){
$call = 1;
}
elsif($entry[$i+2] > $entry[$i] and $entry[$i+2] > $entry[$i+1]){
$call = 2;
}
print " $call";
}
print "\n";
}
close IN;
}