Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 796acdce9a
Fetching contributors…

Cannot retrieve contributors at this time

executable file 160 lines (151 sloc) 4.588 kb
use Mojolicious::Lite;
use gen_drift;
get '/' => sub {
my $self = shift;
return $self->render('gen_drift');
};
get '/gen_drift_results' => sub {
my $self = shift;
my $pops = $self->param('pops');
my $size = $self->param('size');
my $generations = $self->param('generations');
my $frequency = $self->param('frequency');
if ( $pops < 1
or $pops > 100
or $size < 1
or $size > 10_000_000
or $generations < 1
or $generations > 1_000
or $frequency < 0
or $frequency > 1
or $pops =~ m/[^0-9]/
or $size =~ m/[^0-9]/
or $generations =~ m/[^0-9]/
or $frequency =~ m/[^0-9.]/ )
{
my $invalid = "Invalid parameter!";
$invalid .= " Number of populations must be an integer from 1 to 100."
if $pops < 1
or $pops > 100
or $pops =~ m/[^0-9]/;
$invalid .= " Number of individuals must be an integer from 1 to 10,000,000."
if $size < 1
or $size > 10_000_000
or $size =~ m/[^0-9]/;
$invalid .= " Number of generations must be an integer from 1 to 1,000."
if $generations < 1
or $generations > 1_000
or $generations =~ m/[^0-9]/;
$invalid .= " Starting allele frequency must be from 0 to 1."
if $frequency < 0
or $frequency > 1
or $frequency =~ m/[^0-9.]/;
$self->flash( message => $invalid );
$self->redirect_to('/');
}
else{
my $out = join "",
"p", $pops,
"s", $size,
"g", $generations,
"f", $frequency;
my $gen_drift = gen_drift->new(
pops => $pops,
size => $size,
generations => $generations,
frequency => $frequency,
out => $out,
);
$self->stash(
rplot => "$out/gen_drift.png",
results => "$out/gen_drift.tsv",
);
$gen_drift->simulate;
$self->render('gen_drift_results');
}
};
app->start;
__DATA__
@@ gen_drift.html.ep
% layout 'default';
% if (my $message = flash 'message') {
<b><%= $message %></b><br>
% }
%= form_for gen_drift_results => begin
<table>
<tr>
<td align=right>
Number of populations to simulate:
<td>
%= text_field 'pops'
<td align>
[1 - 100]
<tr>
<td align=right>
Number of individuals in each population:
<td>
%= text_field 'size'
<td align>
[1 - 10,000,000]
<tr>
<td align=right>
Number of generations:
<td>
%= text_field 'generations'
<td align>
[1 - 1,000]
<tr>
<td align=right>
Starting allele frequency:
<td>
%= text_field 'frequency'
<td align>
[0 - 1]
<tr>
<td>
<td>
%= submit_button 'Simulate genetic drift'
</table>
% end
@@ gen_drift_results.html.ep
% layout 'default';
<iframe src="<%= $rplot %>" style="width:480px; height:480px;" frameborder="0"></iframe><br>
Results (right-click to save):
<a href="<%= $rplot %>">Figure</a>
<a href="<%= $results %>">Table</a><br><br>
<a href="/gen_drift_results?pops=<%= param('pops') %>&size=<%= param('size') %>&generations=<%= param('generations') %>&frequency=<%= param('frequency') %>">
<%= submit_button 'RE-RUN SIMULATION (SAME PARAMETERS)' %></a>
<a href="/">
<%= submit_button 'RUN SIMULATION WITH NEW PARAMETERS' %></a><br>
<table>
<tr>
<td align=right>
Number of populations to simulate:
<td>
%= param('pops')
<tr>
<td align=right>
Number of individuals in each population:
<td>
%= param('size')
<tr>
<td align=right>
Number of generations:
<td>
%= param('generations')
<tr>
<td align=right>
Starting allele frequency:
<td>
%= param('frequency')
</table>
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title>Genetic Drift Simulator</title></head>
<h2>Genetic Drift Simulator</h2>
<h3>This web app will simulate genetic drift in allele frequency for a single polymorphism with two alleles.
<br>Simulation is done under a Wright-Fisher model, using the binomial distribution.</h3>
<body><%= content %></body>
<a href="https://github.com/mfcovington/genetic_drift"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub"></a>
</html>
Jump to Line
Something went wrong with that request. Please try again.