| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Acme::BloodType; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25060
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
493
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Acme::BloodType - For those obsessed with celebrities' blood types |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.01 |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Allows you to model people with different blood-types and see what would |
|
21
|
|
|
|
|
|
|
happen if they had a kid. Alpha version handles ABO only for now. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Acme::BloodType; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Hooray for gene sequencers |
|
26
|
|
|
|
|
|
|
$mary = Acme::BloodType->new({ genotype => "AA" }); |
|
27
|
|
|
|
|
|
|
$bill = Acme::BloodType->new({ phenotype => "O" }); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$baby = $mary->cross($bill); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
print "It's a ", $baby->get_bloodtype, "!\n"; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $alleles = [ "O", "A", "B" ]; |
|
36
|
|
|
|
|
|
|
my $phenotypes = [ "O", "A", "B", "AB" ]; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $geno_pheno = { |
|
39
|
|
|
|
|
|
|
"OO" => "O", |
|
40
|
|
|
|
|
|
|
"OA" => "A", "AO" => "A", "AA" => "A", |
|
41
|
|
|
|
|
|
|
"OB" => "B", "BO" => "B", "BB" => "B", |
|
42
|
|
|
|
|
|
|
"AB" => "AB", "BA" => "AB" |
|
43
|
|
|
|
|
|
|
}; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 METHODS |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 Acme::BloodType->new(\%specifier) |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Create an Acme::Bloodtype object representing a person. You may specify |
|
50
|
|
|
|
|
|
|
genotype, phenotype (in which case a genotype is chosen at random), or nothing, |
|
51
|
|
|
|
|
|
|
in which case it's all random. Probabilities don't (yet) model real-world |
|
52
|
|
|
|
|
|
|
distributions. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub new { |
|
57
|
0
|
|
|
0
|
1
|
|
my ($class, $init) = @_; |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $self = {}; |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
0
|
0
|
|
|
|
if (defined $init && defined $init->{'genotype'}) { |
|
|
|
0
|
0
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
return undef unless $geno_pheno->{ $init->{'genotype'} }; |
|
63
|
0
|
|
|
|
|
|
$self->{'genotype'} = $init->{'genotype'}; |
|
64
|
|
|
|
|
|
|
} elsif (defined $init && defined $init->{'phenotype'}) { |
|
65
|
0
|
|
|
|
|
|
my @possible = grep { $geno_pheno->{$_} eq $init->{'phenotype'} } keys %$geno_pheno; |
|
|
0
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
return undef unless @possible; |
|
67
|
0
|
|
|
|
|
|
$self->{'genotype'} = $possible[rand @possible]; |
|
68
|
|
|
|
|
|
|
} else { |
|
69
|
0
|
|
|
|
|
|
my @possible = keys %$geno_pheno; |
|
70
|
0
|
|
|
|
|
|
$self->{'genotype'} = $possible[rand @possible]; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return bless $self, $class; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 $bt->get_bloodtype |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Get the bloodtype (phenotype) of this person. Returns "A", "B", "AB", or "O". |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub get_bloodtype { |
|
83
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $geno_pheno->{ $self->{'genotype'} }; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 $bt->get_genotype |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Get the genotype of this person. Returns a string of two characters, which |
|
91
|
|
|
|
|
|
|
may be "A", "B", or "O". |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub get_genotype { |
|
96
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
97
|
0
|
|
|
|
|
|
return $self->{'genotype'}; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 $bt1->cross($bt2) |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
"Mate" one person with the other, producing a result chosen randomly in the |
|
103
|
|
|
|
|
|
|
style of Mendel. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub cross { |
|
108
|
0
|
|
|
0
|
1
|
|
my ($self, $other) = @_; |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
die "Uh?" unless $other->isa(__PACKAGE__); |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $from_self = substr $self->get_genotype, int rand 2, 1; |
|
113
|
0
|
|
|
|
|
|
my $from_other = substr $other->get_genotype, int rand 2, 1; |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
return __PACKAGE__->new({ genotype => $from_self . $from_other }); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Andrew Rodland, C<< >> |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 BUGS |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
125
|
|
|
|
|
|
|
C, or through the web interface at |
|
126
|
|
|
|
|
|
|
L. |
|
127
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
128
|
|
|
|
|
|
|
your bug as I make changes. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 SUPPORT |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
perldoc Acme::BloodType |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
You can also look for information at: |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=over 4 |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * Search CPAN |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Copyright 2006 Andrew Rodland, all rights reserved. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
165
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; # End of Acme::BloodType |