Class Bion

java.lang.Object
  extended byBion

public class Bion
extends java.lang.Object

The individual reactive biological thingy. Diploid hermaphrodite version, with one recombination modifier locus at the end of the chromosome. I have coded 4 different versions of Bion with different speed and flexibility tradeoffs:

BionBits
Each chromosome is a single long int which means that the total number of loci is 64, including the locus of the recombination modifier. This is the fastest implementation, partly because bit-masking is used in generating recombinant chromosomes. Restricted to two alleles per locus.
BionArray
Each chromosome is an array of integers. This is the least refined of the versions. I gave up on it early when I saw how slow it was going to be, and how much memory it gobbles up. I tried it because of the potential flexibility: any number of loci, and any number of alleles per locus.
BionList
Each chromosome is a linked list of nodes, one node for each "different" allele. The idea here was to cut down on the amount of storage needed by only keeping track of the nodes with information. In the two-allele case I am dealing with, near mutation-selection balance, I keep track of only the deleterious alleles, since they are relatively rare. For example, at a mut-sel balance of 0.1, chromosomes are only a tenth of the size they would be if they had to store all loci. Although storage requirements were indeed dimminished, the processes of recombination and mutation are more complex. That complexity plus the overhead of the linked lists both cost in speed.
BionPlus
In a final rewrite, I coded each chromosome as an array of long integers. Although all alleles are stored all the time, each locus is just a bit, rather than one whole node on a linked list. Bit masking can be used to speed recombination (in 64-locus chunks), and there is no built-in limit to the number of loci that can be represented. This runs at more than twice the speed of BionList, and requires much less memory. This is the best written code, since I put more time into it once I saw its speed potential. This is the version documented here.
Bions are instantiated by Deme, and Loci is the class that runs the whole simulation. I use MersenneTwisterFast.


Field Summary
private  double benMutRate
           
private  int chunks
           
 int del
           
 int delleft
           
private  double delMutRate
           
 int delright
           
private  Deme deme
           
 double fit
           
private  boolean[] isHit
           
 int lab
           
private  long[] left
           
private  double minRecRate
           
private  double modRecRate
           
private  int nAttribs
           
 int rab
           
private  MersenneTwisterFast rand
           
 int rec
           
private  int recloc
           
private  long recMask
           
private  long[] right
           
 int tab
           
 int taB
           
 int tAb
           
 int tAB
           
 
Constructor Summary
Bion(Deme deme)
           
 
Method Summary
private  long[] getGamete(Bion bion)
          Do recombination, and then mutation to generate a gamete.
 int getNumEvents(int n, double p)
          Choose the appropriate means, pre-computed or not, of generating the number of random events and then return the appropriate value.
 void getRec()
          Calculates how many recombination modifiers are present.
 void init()
          Build initial left and right chromosomes and set info fields.
 Bion mateWith(Bion other)
          grab a gamete from each parent, and set info fields
private  void mutateBen(long[] chromo, double mutRate)
          uses the global (all-loci) benMutRate
private  void mutateDel(long[] chromo, double mutRate)
          uses the global (all-loci) delMutRate
 int poisson(double lambda)
          found Poisson recipe somewhere: [Calculate exponential.] Set p = exp(-mu), n = 0, q = 1.
private  void sumAB()
          Calculate bits of information having to do with allele correlation and match-up.
private  void sumDel()
          Calculate number of deleterious alleles on each chromosome, and the total.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nAttribs

private final int nAttribs

chunks

private final int chunks

left

private long[] left

right

private long[] right

recloc

private final int recloc

recMask

private final long recMask

delMutRate

private final double delMutRate

benMutRate

private final double benMutRate

minRecRate

private final double minRecRate

modRecRate

private final double modRecRate

fit

public double fit

del

public int del

rec

public int rec

delleft

public int delleft

delright

public int delright

tAB

public int tAB

tAb

public int tAb

taB

public int taB

tab

public int tab

lab

public int lab

rab

public int rab

deme

private Deme deme

rand

private final MersenneTwisterFast rand

isHit

private boolean[] isHit
Constructor Detail

Bion

public Bion(Deme deme)
Method Detail

init

public void init()
Build initial left and right chromosomes and set info fields. All subsequent chromosomes originate from parents.


getNumEvents

public int getNumEvents(int n,
                        double p)
Choose the appropriate means, pre-computed or not, of generating the number of random events and then return the appropriate value. For trials n >= 50 Poisson or Normal approximations to the Binomial are used, depending on p, otherwise exact Bionomial distribution is used.


poisson

public int poisson(double lambda)
found Poisson recipe somewhere:
  1. [Calculate exponential.] Set p = exp(-mu), n = 0, q = 1.
  2. [Get uniform variable.] Generate a random variable u, uniformly distributed between 0 and 1.
  3. [Multiply.] Set q = q*u.
  4. [Test against the exponential.] If q is greater than or equal to p, set N = N + 1 and return to step 2.


getGamete

private long[] getGamete(Bion bion)
Do recombination, and then mutation to generate a gamete.


mutateDel

private void mutateDel(long[] chromo,
                       double mutRate)
uses the global (all-loci) delMutRate


mutateBen

private void mutateBen(long[] chromo,
                       double mutRate)
uses the global (all-loci) benMutRate


mateWith

public Bion mateWith(Bion other)
grab a gamete from each parent, and set info fields


toString

public java.lang.String toString()

sumDel

private void sumDel()
Calculate number of deleterious alleles on each chromosome, and the total. This is the information used to calculate fitness.


sumAB

private void sumAB()
Calculate bits of information having to do with allele correlation and match-up.


getRec

public void getRec()
Calculates how many recombination modifiers are present. used for warping the basal minRecRate