-
Notifications
You must be signed in to change notification settings - Fork 5
/
SNPtable2cmpositions.pl
77 lines (72 loc) · 1.48 KB
/
SNPtable2cmpositions.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
71
72
73
74
75
76
77
#!/bin/perl
use warnings;
use strict;
my $map = $ARGV[0]; #lg.ALL.bronze14.path.txt
#my $snp = $ARGV[1]; #SNP file in hmp format
#SNPfile piped in
my $tmp;
my %hash;
open MAP, $map;
while(<MAP>){
chomp;
my @a = split(/\t/,$_);
if ($. ne "1"){
if ($a[2] ne "NA"){
my $chrom = $a[0];
$hash{$chrom}{$a[1]} = $a[2];
}
}
}
close MAP;
#open SNP, $snp;
#while(<SNP>){
while(<STDIN>){
chomp;
my $line = $_;
my @a = split(/\t/,$line);
if ($. eq "1"){
foreach my $i(0..1){
print "$a[$i]\t";
}
print "cM";
foreach my $i(2..$#a){
print "\t$a[$i]";
}
}else{
my $chrom = $a[0];
my $bp = $a[1];
my $previous_site;
my $before_site;
my $after_site;
my $loci_cM;
foreach my $site (sort {$a <=> $b} keys %{$hash{$chrom}}){
if ($site > $bp){
if ($previous_site){
$before_site = $previous_site;
$after_site = $site;
goto FOUNDPOS;
}else{
$loci_cM = "NA";
goto BADSITE;
}
}
$previous_site = $site;
}
$loci_cM = "NA";
goto BADSITE;
FOUNDPOS:
my $cM_range = $hash{$chrom}{$after_site} - $hash{$chrom}{$before_site};
my $bp_range = $after_site - $before_site;
my $percent_of_range = ($bp - $before_site)/$bp_range;
$loci_cM = ($percent_of_range * $cM_range) + $hash{$chrom}{$before_site};
BADSITE:
print "\n";
foreach my $i(0..1){
print "$a[$i]\t";
}
print "$loci_cM";
foreach my $i(2..$#a){
print "\t$a[$i]";
}
}
}