File S3 #!/usr/bin/perl # Created by Danny Miller (dem shift

advertisement
File S3
#!/usr/bin/perl
# Created by Danny Miller (dem shift-2 stowers dot org)
# This model assumes a random # of B chromosomes are sent
# to an egg or a sperm each generation and then randomly
# fertilize each other to create the next generation.
# 1,000 males and 1,000 females are chosen each generation
# to continue.
#
# This produces a large amount of data, which is saved as
# a .csv file in ./BChromosomeModel.csv
#
# This work is licensed under a Creative Commons Attribution 3.0
# Unported License<http://creativecommons.org/licenses/by/3.0/>
use strict;
# Modifiable variables
my $totalB = 6;
my $maxBchromosomes = 3; # This limits the # of B's that survive to
# $totalB * $maxBchromosomes
my $totalGenerations = 1000; # Total num of generations to model
my $flyCountPerGeneration = 1000; # x2 to get the total progeny per generation
my $maxOffspring = 20;
# Max # of offspring a single fly can have
# Global storage variables
my %perGeneration;
my $output;
# Populate the %perGeneration hash with the beginning num
# of B chromosomes
foreach my $fly (1..$flyCountPerGeneration) {
$perGeneration{'male'}{$fly} = $totalB;
$perGeneration{'female'}{$fly} = $totalB;
}
# Print out a header, comment out if you don't want it
print "B chromosomes per generation\n";
print "| generation | males | females ";
$output .= "generation,males,females,";
foreach (0..20) {
printf "| %2d ", $_;
$output .= "$_,";
}
print "|\n";
$output .= "\n";
# Iterate over each generation
foreach my $generation (1..$totalGenerations) {
my %flies;
printf "|
%3d |", $generation;
$output .= "$generation,";
foreach my $fly (1..$flyCountPerGeneration) {
# Choose the # of offspring for this mating
my $offspring = int(rand($maxOffspring));
1
Bauerly et al.
my $maleB = $perGeneration{'male'}{$fly};
my $femaleB = $perGeneration{'female'}{$fly};
foreach my $offspringNum (1..$offspring) {
# $seed is a bit confusing, basically, we'll choose some num
# of progeny to continue to the next generation from this
# number
my $seed = int(rand(10000000));
my($maleLeft,$femaleLeft,$maleRight,$femaleRight) = (0,0,0,0);
# Send a random # of B's to either the 'left' or 'right' pole
foreach (1..$maleB) {
my $num = int(rand(2));
$maleLeft++ if $num == 0;
$maleRight++ if $num == 1;
}
# Send a random # of B's to either the 'left' or 'right' pole
foreach (1..$femaleB) {
my $num = int(rand(2));
$femaleLeft++ if $num == 0;
$femaleRight++ if $num == 1;
}
# will the offspring be male or female?
my $MorF = int(rand(2));
$seed .= "|male" if $MorF == 0;
$seed .= "|female" if $MorF == 1;
my $poleChosen = int(rand(2));
$flies{$seed} = $maleLeft + $femaleLeft if $poleChosen == 0;
$flies{$seed} = $maleRight + $femaleRight if $poleChosen == 1;
$flies{$seed} = undef if $flies{$seed} >= $totalB * $maxBchromosomes;
}
}
# because $seed above is random, we can simply choose the first x flies
my(%count,%countBchromosomes);
foreach my $progeny (sort keys %flies) {
my($sex) = $progeny =~ /\|(\w+)/;
$count{$sex}++;
$perGeneration{$sex}{$count{$sex}} = $flies{$progeny};
# Tracks how many flies had $flies{$progey} B chromosomes
$countBchromosomes{$flies{$progeny}}++;
}
# Record # of males and females for this generation
printf " %6d | %6d |", $count{'male'}, $count{'female'};
$output .= "$count{'male'},$count{'female'},";
foreach (0..20) {
printf " %4d |", $countBchromosomes{$_};
$output .= "$countBchromosomes{$_},";
}
print "\n";
2
Bauerly et al.
$output .= "\n";
}
open OUTF,">BChromosomeModel.csv";
print OUTF $output;
close OUTF;
3
Bauerly et al.
Download