-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_chr_pos_metal.pl
executable file
·70 lines (61 loc) · 1.59 KB
/
add_chr_pos_metal.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/env perl
use strict;
use warnings;
use IO::File;
my $bim = IO::File->new("$ARGV[0]"); # BIM FILE
my $dict = {};
while(my $line = $bim->getline)
{
chomp($line);
my @lineContents = split(/\s+/, $line);
my $chromosome = $lineContents[0];
my $snp = $lineContents[1];
my $position = $lineContents[3];
$dict->{$snp}->{chr} = $chromosome;
$dict->{$snp}->{pos} = $position;
}
$bim->close;
my $nh = IO::File->new("$ARGV[1]"); # METAL OUTPUT
while(my $line = $nh->getline)
{
chomp($line);
if($line =~ /^Marker/)
{
print "CHR"."\t";
print "BP"."\t";
print "SNP"."\t";
print "A1"."\t";
print "A2"."\t";
print "FREQ"."\t";
print "BETA"."\t";
print "SE"."\t";
print "P"."\n";
next;
}
else
{
my @lineContents = split(/\s+/, $line);
my $snp = $lineContents[0];
my $a1 = uc $lineContents[1];
my $a2 = uc $lineContents[2];
my $freq = $lineContents[3];
my $beta = $lineContents[7];
my $se = $lineContents[8];
my $p = $lineContents[9];
if(!exists $dict->{$snp})
{
print STDERR "ERROR: $snp not found!\n";
exit;
}
print $dict->{$snp}->{chr}."\t";
print $dict->{$snp}->{pos}."\t";
print $snp."\t";
print $a1."\t";
print $a2."\t";
print $freq."\t";
print $beta."\t";
print $se."\t";
print $p."\n";
}
}
$nh->close;