-
Notifications
You must be signed in to change notification settings - Fork 0
/
estimate_cm.pl
executable file
·98 lines (86 loc) · 2.4 KB
/
estimate_cm.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/perl
#A script to estimate cM from a map based on physicial position of markers
#inputvariables tab delimited marker file and map file
#marker file only uses first column for marker names
#map file layout (tab delimited)
## Marker Chr cM bp
use strict;
use Getopt::Std;
use Data::Dumper;
#reading options
our ($opt_i, $opt_m);
getopts('i:m:');
if (!$opt_i) {
print STDERR "\nInput marker file (-i) required\n\n\n";
}
if (!$opt_m) {
print STDERR "\nInput map file (-m) required\n\n\n";
}
my @markers;
my @mapmarkers;
my %markerchr;
my %markerpos;
my %markercm;
my $firstline = 1;
open INFILE, "<", $opt_i or die "No such input file $opt_i";
while (<INFILE>) {
chomp $_;
if ($firstline == 1) {
$firstline = 0;
next;
}
my @row = split('\t', $_);
my $marker = $row[0];
push @markers, $marker;
my @markerinfo = split('_',$marker);
my $chr = $markerinfo[0];
$chr =~ s/\D//g;
$markerchr{$marker} = $chr;
$markerpos{$marker} = $markerinfo[1];
}
close INFILE;
$firstline = 1;
open MAPFILE, "<", $opt_m or die "No such input file $opt_i";
while (<MAPFILE>) {
chomp $_;
if ($firstline == 1) {
$firstline = 0;
next;
}
my @row = split('\t', $_);
my $marker = $row[0];
push @mapmarkers, $marker;
$markerchr{$marker} = $row[1];
$markercm{$marker} = $row[2];
$markerpos{$marker} = $row[3];
}
close MAPFILE;
print "Marker\tChr\tcM\tbp\n";
foreach my $marker (@markers) {
my $startmarker;
my $endmarker;
foreach my $mapmarker (@mapmarkers) {
#print "c1:".$markerchr{$marker}."c2:".$markerchr{$mapmarker};
if ($markerchr{$marker} ne $markerchr{$mapmarker}) {
next;
}
if ($markerpos{$mapmarker} >= $markerpos{$marker}) {
$endmarker = $mapmarker;
last;
}
$startmarker = $mapmarker;
}
my $markercm;
unless ($startmarker) {
$markercm = $markerpos{$marker} * ($markercm{$endmarker}/$markerpos{$endmarker});
}
unless ($endmarker) {
$markercm = $markerpos{$marker} * ($markercm{$startmarker}/$markerpos{$startmarker});
}
#print "st:$startmarker\n";
unless ($markercm) {
my $cm_per_bp = ($markercm{$endmarker} - $markercm{$startmarker}) / ($markerpos{$endmarker} - $markerpos{$startmarker} + 1);
$markercm = $markercm{$startmarker} + (($markerpos{$marker} - $markerpos{$startmarker}) * $cm_per_bp);
}
print "$marker\t".$markerchr{$marker}."\t".$markercm."\t".$markerpos{$marker}."\n";
}