| 1 | package Acme::BloodType; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 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 | 2 | 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 | 2 | my $alleles = [ "O", "A", "B" ]; | |||||||||||||||||||||||||||||||
| 36 | 2 | my $phenotypes = [ "O", "A", "B", "AB" ]; | |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 2 | 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 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 57 | 0 | my ($class, $init) = @_; | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 0 | my $self = {}; | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if (defined $init && defined $init->{'genotype'}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $init and defined $init->{"genotype"}
MC/DC0%0/2
defined $init and defined $init->{"genotype"}
defined $init
defined $init->{"genotype"}
Truth table0%0/3
A and B
A= defined $initB= defined $init->{"genotype"}
| |||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return undef unless $geno_pheno->{ $init->{'genotype'} }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 0 | $self->{'genotype'} = $init->{'genotype'}; | |||||||||||||||||||||||||||||||
| 64 | ▶ | } elsif (defined $init && defined $init->{'phenotype'}) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $init and defined $init->{"phenotype"}
MC/DC0%0/2
defined $init and defined $init->{"phenotype"}
defined $init
defined $init->{"phenotype"}
Truth table0%0/3
A and B
A= defined $initB= defined $init->{"phenotype"}
| |||||||||||||||||||||||||||||||||
| 65 | 0 | my @possible = grep { $geno_pheno->{$_} eq $init->{'phenotype'} } keys %$geno_pheno; | |||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return undef unless @possible; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub get_bloodtype { | ||||||||||||||||||||||||||||||
|
Subroutine
get_bloodtype: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 83 | 0 | 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 | 0 | ▶ | sub get_genotype { | ||||||||||||||||||||||||||||||
|
Subroutine
get_genotype: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 96 | 0 | 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 | 0 | ▶ | sub cross { | ||||||||||||||||||||||||||||||
|
Subroutine
cross: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 108 | 0 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | die "Uh?" unless $other->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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<< <ARODLAND at cpan.org> >> | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | =head1 BUGS | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||||||
| 125 | C<bug-acme-bloodtype at rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||||||
| 126 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Acme-BloodType>. | ||||||||||||||||||||||||||||||||
| 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<http://annocpan.org/dist/Acme-BloodType> | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | L<http://cpanratings.perl.org/d/Acme-BloodType> | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Acme-BloodType> | ||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | =item * Search CPAN | ||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | L<http://search.cpan.org/dist/Acme-BloodType> | ||||||||||||||||||||||||||||||||
| 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 | 2 | 1; # End of Acme::BloodType | |||||||||||||||||||||||||||||||