-
Notifications
You must be signed in to change notification settings - Fork 0
/
genetic_distance_to_bim.pl
executable file
·56 lines (46 loc) · 1.36 KB
/
genetic_distance_to_bim.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
#!/usr/bin/env perl
use strict;
use warnings;
use IO::File;
my $usage = "\n\nUSAGE: perl $0 file_with_cm.map file_wo_cm.bim\n\n";
if(!$ARGV[0] || !$ARGV[1]) {
print $usage;
exit;
}
my $genetic_distance = {};
my $fh = IO::File->new("$ARGV[0]") || die "ERROR: Cannot open map file: $ARGV[0]!\n";
while(my $line = $fh->getline) {
chomp($line);
if($line !~ /^[0-9]/) {
next;
}
else {
my @lineContents = split(/\s+/, $line);
my $chromosome = $lineContents[0];
my $distance = $lineContents[2];
my $position = $lineContents[3];
my $key = $chromosome."_".$position;
$genetic_distance->{$key} = $distance;
}
}
$fh->close;
my $nh = IO::File->new("$ARGV[1]") || die "ERROR: Cannot open bim file: $ARGV[1]!\n";
while(my $line = $nh->getline) {
chomp($line);
my @lineContents = split(/\s+/, $line);
my $chromosome = $lineContents[0];
my $position = $lineContents[3];
my $key = $chromosome."_".$position;
if(exists $genetic_distance->{$key}) {
print $lineContents[0]." ";
print $lineContents[1]." ";
print $genetic_distance->{$key}." ";
print $lineContents[3]." ";
print $lineContents[4]." ";
print $lineContents[5]."\n";
}
else {
print STDERR "WARNING: No match found for: $line\n";
}
}
$nh->close;