forked from molgenis/ngs-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_BeagleR2.pl
70 lines (55 loc) · 1.73 KB
/
filter_BeagleR2.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
#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
use Getopt::Long;
my ($help, $input, $output, $filtervalue);
my $count = 0;
#### get options
GetOptions(
"h" => \$help,
"inputBeagleR2file=s" => \$input,
"outputSnpIDfile=s" => \$output,
"R2threshold=s" => \$filtervalue
);
usage() and exit(1) if $help;
# mandatory args
usage() and exit(1) unless $input;
usage() and exit(1) unless $output;
usage() and exit(1) unless $filtervalue;
open (INPUT, "<", $input) or die $!;
open (OUTPUT, ">", $output) or die $!;
print "\nStarting filtering..\n\n";
my $lines;
while ($lines = <INPUT>){
chomp $lines;
my @array = split("\t", $lines);
my $snpID = $array[1];
my $pos = $array[2];
my $refall = $array[3];
my $altall = $array[4];
my $r2value = $array[5];
$r2value =~ s/NaN/0.00/g;
if ($r2value >= $filtervalue){
print OUTPUT "$snpID\n";
$count++;
}
}
print "Filtering finished!\n";
print "Number of SNPs left: $count\n";
close(INPUT);
close(OUTPUT);
sub usage {
print <<EOF;
#########################################################################################
filter_BeagleR2 (version 1)
This script filters a beagleR2 file on user specified R2 value. Output is a file
containing a list of snpIDs.
#########################################################################################
Usage: ./convert_snpIDs.pl
\t-inputBeagleR2file Input beagleR2 file to filter
\t-outputSnpIDfile Output file
\t-R2threshold R2 threshold value to filter on (>=)
#########################################################################################
EOF
}