Loci involved in local adaptation can potentially be identified by an unusual correlation between allele frequencies and important ecological variables, or by extreme allele frequency differences between geographic regions. However, such comparisons are complicated by differences in sample sizes and the neutral correlation of allele frequencies across populations due to shared history and gene flow. To overcome these difficulties, we have developed a Bayesian method that estimates the empirical pattern of covariance in allele frequencies between populations from a set of markers, and then uses this as a null model for a test at individual SNPs. I developed this method in collaboration with David Witonsky, Anna Di Rienzo and Jonathan Pritchard. The method is described in a paper in Genetics.

The method was further developed by Torsten Günther and myself, as described in this Genetics article. The newest version of the method is called Bayenv 2, and it maintains the full functionality of the original Bayenv.

The code is maintained by Torsten here. The tarballs/zips of the executable, example datasets, and a manual are given there.

When using bayenv please make sure that you have recently downloaded the program, to avoid old bugs. Please email Torsten ( for the code, or for versions compiled for other types of machine.

From the original paper:
The matrices for the HGDP data
The Bayes factors for the European and Western Eurasia Bayes Factors used in the paper, stored as R objects.

6 Responses to Bayenv

  1. Pingback: Bayenv - Identify Loci Underlying Local Adaptation

  2. Pingback: Homo sapiens: the unsung model species of molecular ecology | The Molecular Ecologist

  3. Qiu T says:

    Dear professor,
    I am not sure if the Bayenv can be used to analyze the AFLP data since I am worried about Bayenv which is only applied to SNPs data. Thank you very much.
    And I cannot find the software of Bayenv. Could you please help me to tell me where I can download it ? Thank you so much.

  4. Jacob Alsdurf says:

    I am having problems with Bayenv2.0 and would appreciate guidance from you.

    The following works:
    26 populations
    6597 SNPs
    1,000,000 iterations
    Random seed 1021

    When I regroup my samples into smaller strata (regional groupings) Bayenv2.0 stops.
    4 populations
    6597 SNPs
    Attempting 1,000,000 iterations
    Random seed 1021

    Bayenv2.0 stops at 258,500 iterations every time.
    Error code:
    bayenv2(23636,0xa181b1a8) malloc: *** mach_vm_map(size=1048576) failed (error code=3)
    *** error: can’t allocate region
    *** set a breakpoint in malloc_error_break to debug
    Numerical Recipes run-time error…
    allocation failure in dvector()
    …now exiting to system…

    I have tried this on multiple OS X computers with 8 GB memory.

    Any suggestions?

    Thank you for your time,

    • trstngnthr says:

      Hi Jacob,
      What happens if you change the seed? It could be some memory allocation issue only happening with some number drawn using that particular seed in combination with your data.
      Unfortunately, I can’t check it since I don’t have a Mac. I would generally recommend to use the Linux 64bit version of bayenv since it’s the only version actually receiving updates.
      Let me know if the issue also occurs with other seeds.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s