PopGen Genepop

Two interfaces are supplied: A general, more complex and more efficient one (GenePopController) and a simplified, more easy to use, not complete and not so efficient version (EasyController). EasyController might not be able to handle very large files, by virtue of its interface, on the other hand it provides utility functions to compute some very simple statistics like allele counts, which are not directly available in the general interface.

The more complex interface assumes more proficient Python developers (e.g., by the use of iterators) and for now it is not documented. But even for experienced Python developers, EasyController can be convenient as long as the required functionality is exposed in EasyController and its performance is deemed acceptable.

In order for the controllers to be used, Genepop has to be installed in the system, it can be downloaded from here.

Replace your_file_here with the name and path to your file. If you get a IOError: Genepop not found then Biopython cannot find your Genepop executable. If Genepop is not on the PATH, you can add it to the constructor line, i.e.

ctrl = EasyController(your_file_here, path_to_genepop_here)

If everything is working, now we can go on and use Genepop. For the examples below, we will use the genepop file big.gen made available with the unit tests. We will also assume that there is a ctrl object initialized with the relevant file chosen.

We start by getting some basic info

pop_names, loci_names = ctrl.get_basic_info()

Returns the list of population names and loci names available on the file.

Caveat: Most existing Genepop files provide erroneous data regarding population names. In many cases that information might not be trusted. Assessing population information is, most of the times, done by the relative position of the population in the file, not the name. So the first population is the file is index 0, the second index 1, and so on...

Statistics

Heterozygosity

Lets get heterozygosity info for a certain population and a certain allele:

Will get expected and observed homozygosity and heterozygosity for population 0 and Locus2 (of the file big.gen, if you are using another file, adjust the population position and locus name accordingly).

Existing alleles

It is possible to get the list of all alleles of a certain locus in a certain population:

allele_list = ctrl.get_alleles(0,"Locus2")

allele_list will be [3, 20] (i.e., alleles 3 and 20 are on the population).

The number of alleles is simply getting len(allele_list).

It is also possible to get the list of all alleles of a certain locus for all populations:

all_allele_list = ctrl.get_alleles_all_pops("Locus2")

all_allele_list will be [3, 20].

Allele and genotype frequencies

It is possible to get the frequency of alleles in a certain population

allele_data = ctrl.get_allele_frequency(0, "Locus2")

allele_data will be (62, {3: 0.88700000000000001, 20: 0.113}). That is there are 62 genes. 88.7% are
3 and 11.3% are 20.

We can get similar information for genotypes (diploid data). Expected frequencies will also be reported:

summary_fis holds a triple with: total number of alleles, Cockerham and Weir Fis, Robertson and Hill Fis.

allele_dict holds for each allele (being each allele the key), number of repetitions of the allele, frequency and Cockerham and Weir Fis.

So, from the above results the following can be read: there are 62 genes with 2 different alleles (55 are of type 3, and 7 of type 20). 3 has frequency 0.89 and 20 0.11. All CW Fis are -0.111 and the RH Fis is -0.112.

Tests

Tests are normally computationally intensive as they are normally based on a Markov Chain algorithm. In some cases full enumeration approaches are available but those can only be applied for locus with a very low number of alleles. This means that most tests will take quite some time to complete.

For more details about Markov Chain parameters below (dememorization, batched and iterations) please consult the Genepop manual. Also consult the manual to understand when full enumeration is applicable.

Lets start by testing Hardy-Weinberg equilibrium for each loci in each population:

ctrl.test_hw(1, "excess")

The second parameter can by probability, excess or deficiency. probability is the standard Haldane HW test. Use deficiency when you are interested in heterozygote deficiency or excess if you are interested in excess.

pop_test, loc_test, all_test = ctrl.test_hw_global("deficiency")

Use deficiency when you are interested in heterozygote deficiency or excess if you are interested in excess. probability does not apply here like in test_hw.