-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiprb.pl~
executable file
·75 lines (60 loc) · 1.7 KB
/
iprb.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
#!/usr/bin/perl
use strictures;
# note, this is a brute force script
# it is possible to come up with a simpler formula
# open file
my ($file) = @ARGV;
open FILE, '<', $file;
# load parameters k, m and n
my ($k,$m,$n) = split ' ', <FILE>;
# compute population size p
my $p = $k + $m + $n;
# state all possible genotypes
my @genotypes = ('AA', 'aA', 'aa');
# store probabilities of presence of dominant allele
# per genotype combination
my %pr_dom = (
'AAAA' => 1,
'AAaA' => 1,
'AAaa' => 1,
'aAAA' => 1,
'aAaA' => 0.75,
'aAaa' => 0.5,
'aaAA' => 1,
'aaaA' => 0.5,
'aaaa' => 0
);
# set sum of all probabilities of presence dominant allele
my $pr_sum = 0;
# loop over all genotype combinations
foreach my $gt1 (@genotypes) {
# set number of individuals y with genotype 1
my $y;
$y = $k if ($gt1 eq 'AA');
$y = $m if ($gt1 eq 'aA');
$y = $n if ($gt1 eq 'aa');
foreach my $gt2 (@genotypes) {
# set number of individuals x with genotype 2
my $x;
$x = $k if ($gt2 eq 'AA');
$x = $m if ($gt2 eq 'aA');
$x = $n if ($gt2 eq 'aa');
# calculate probability pr of presence dominant allele
# in offspring of this genotype1-genotype2 combination
my $pr;
# if genotype1 equals genotype2,
# population with genotype2 decrease by 1
if ($gt1 eq $gt2) {
$pr = ( $y/$p ) * ( ($x-1)/($p-1) ) * $pr_dom{$gt1 . $gt2};
}
# if genotype1 is not equal to genotype 2
# population with genotype 2 is not affected
elsif ($gt1 ne $gt2) {
$pr = ( $y/$p ) * ( $x/($p-1) ) * $pr_dom{$gt1 . $gt2};
}
# add probability to sum of all probabilities
$pr_sum += $pr;
}
}
# report final sum of probabilities of presence dominante allele
print $pr_sum, "\n";