forked from Axolotl233/Simple_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculate.dadi.res.pl
51 lines (49 loc) · 1.18 KB
/
Calculate.dadi.res.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
#! perl
use warnings;
use strict;
my $f = shift or die "need file\n";
my $w = shift;
my $length = shift;
$w //= 0;
$length //= 243560759;
#$length //= 86145070;
my $mu = shift;
my $gen_time = shift;
$mu //= 6e-9;
$gen_time = 1;
open IN,'<',$f;
my @head = split/\t/,(readline IN);
$head[-1] =~ s/.*\((.*)\)/$1/;
$head[-1] =~ s/\s//g;
my %o;
my $c = 0;
while(<IN>){
next if /^Model/;
my @l = split/\s+/;
$o{$c} = [$l[2],$l[3],$l[5],$l[6]];
$c += 1;
}
my @type = split/,/,$head[-1];
print "$head[2]\t$head[3]\t$head[5]\tn_theta\tn_ref\t$head[6]\n";
for my $k (sort {${$o{$a}}[1] <=> ${$o{$b}}[1]}keys %o){
my @a = @{$o{$k}};
my @p = split/,/,$a[-1];
die "error format\n" if scalar @p ne scalar @type;
my $ntheta=$a[2]/$length;
my $nref=$ntheta/(4*$mu);
print "$a[0]\t$a[1]\t$a[2]\t$ntheta\t$nref\t";
for(my $i = 0;$i < @type;$i += 1){
if($type[$i] =~ /^n/i){
$p[$i] = $p[$i] * $nref;
}elsif($type[$i] =~ /^t/i){
$p[$i] = $p[$i] * 2 * $gen_time* $nref;
}elsif($type[$i] =~ /^m/i){
$p[$i] = $p[$i] / (2 * $nref);
}
}
print join",",@p;
print "\n";
if($w == 0){
last;
}
}