Population Genetics, Part III: Data Wrangling and Analyses

So some good news!- My population genetics study on the two herbivorous biological control agents of water hyacinth: Neochetina bruchi and N. eichhorniae, was finally accepted for publication w/ minor revisions in Evolutionary Applications. I will certainly post it once it is In Press! This was one of the projects I did for my Delta Science Postdoctoral Fellowship research 

So with that, I will fulfill my promise on posting Part III of my ‘how-to’ series for population genetics using microsatellites.  To recap, Part I of this series explained what microsatellites are, and how to develop microsatellite markers, and Part II was on how to amplify and genotype these markers (the cheap way with universal fluorescent labeled tails, and multiplex pcr).

Part III (right here!) is my attempt to guide you through the jungle of population genetic analyses. I will discuss the main programs and analyses I used and how to properly format your data to make these packages and programs work!

STRUCTURE analysis of N. bruchi across eight populations and eight loci

I am not going to go into nitty-gritty detail because the tutorial for the ‘poppr’ package in R, does a FANTASTIC job on guiding newbies (including my former self) through the process of how to import data into R, exploring the data, and then how to conduct some basic and advanced analyses. The link is here  http://grunwaldlab.github.io/Population_Genetics_in_R/index.html

Honestly- this is how I started learning how to conduct population genetic analyses in R.. I kid you not. I literally followed the above tutorial step by step and did almost all of the analyses just to get a feel for the data and how to run population genetic stats.

So- Where to start you ask?

Well, one of my collaborator/coauthors (Dr. Ruth Hufbauer-CSU) emphasized that before you analyze the data, a good first step is to know what your question is, and why you are asking those questions. Then you should base your analyses on those questions.

Here are some example questions:

  • Where did these samples/individuals originate from?
  • How many populations are there?
  • What is the genetic diversity in these populations, and are some populations more diverse than others? Genetic diversity is often based on one or more of the following: heterozygosity, allelic richness and diversity indices such as the Shannon, Simpson, or Nei)
  • Are there population genetic bottlenecks?
  • Is there inbreeding?
  • Are there hybrids (crosses between two species)?

Then of course you have to report some general marker- and population-based stats (Deviation from HWE- Hardy Weinberg Equilibrium, Linkage Disequilibrium (LD), overall expected and observed heterozygosity, (He and Ho), null alleles..etc).

Load the Data: Before you do anything, you have to load the data in a format that the programs recognize!

  •  GenAlex- Excel Based Program-useful to check data formatting, and reformat data for import into R or other programs. However the main thing I found useful was understanding just what your dataframe should look like, which the Poppr tutorial emphasizes nicely: here
  • Adegenet package in R- (Jombart et al., 2010) Converts any type of data frame or matrix or txt file to a format that you need for a specific type of analysis
    • For most of my data analyses, I used the following two formats, converting my csv to data that the packages could recognize, or that I could convert further:
      1. newdataname <- read.genalex(“datafile.csv”,genclone = FALSE)
        • you can convert this to a genepop format with the following code-
      2. newdataname2=read.genalex(“datafile.csv”)
        • #need genclone for gytpes conversion, hence don’t use genclone=FALSE
          • gtypesdata=genind2gtypes(newdataname2)
Screenshot 2018-12-08 12.48.53.png
Example dataframe for import and analysis with the Poppr R package. Areas selected in blue represent the Loci, Samples and Populations, see poppr tutorial for further examples

Basic and Advanced Stats- I suggest to use:

  • Poppr– (Kamvar et al., 2015; Kamvar et al., 2014) this package depends on loading a lot of other packages and guides you through analyses in the tutorial. One example- is as a wrapper for the ‘vegan’ package- poppr calculates genotype accumulation curve (see if you sampled enough loci and individuals),
  • Pegas-(Paradis, 2010) -calculate Linkage Disequilibrium (LD) and HWE across populations for each locus
  • PopGenReport-(Adamack et al., 2014)- calculate null-allele frequencies pairwise FST and Jost’s D analyses, compare total and average allelic richness (accounting for sample size) and the number of private alleles among populations
  • diveRsity– (Keenan et al., 2013)-Estimate the average observed (Ho) and expected (He) heterozygosity, deviations from HWE (exact test) and the average ‘inbreeding coefficient’ (FIS) for each population across all loci.  In my paper I distinguish FIS as a measure of increases in homozygosity due to genetic drift caused by a larger population being separated into sub populations, rather than due to consanguineous mating (Crow, 2010)
  • InbreedR- (Stoffel et al., 2016)-calculate g2 as a measure of inbreeding.

Hypothesis testing: 

  • Linear Mixed Models, or Generalized (GLMMs) depending on which is more suitable for your data- with the lmer function in the lme4 package (Bates et al., 2015): I used this to test for the effects of population (collection site) on genetic diversity. Implementing an LMM accounts for the variability of the microsatellite loci by modeling locus as a random effect, and collection site as a fixed effect with allelic richness or expected heterozygosity as the response variables in separate models. Stepwise model simplification (Crawley, 2013) can be performed using likelihood ratio tests. Differences across collection sites can be compared, based on 95% CI, using Tukey’s post-hoc test in the ‘multcomp’ package (Hothorn et al., 2008). Read more about mixed models here. 

Analyses of Population Structure

I suggest using several programs to see how they compare. I used:

  • STRUCTURE -as it is one of the most popular programs-(Pritchard et al., 2000). I used Clumpak (Kopelman, Mayzel, Jakobsson, Rosenberg, & Mayrose, 2015) to analyze the Best K, and to visualize and produce plots based on all of the runs from STRUCTURE outputs. Please see data-wrangling section below for more details on how to get your data into STRUCTURE, and also into Clumpak.
  • FLOCK- great program in excel (Duchesne & Turgeon, 2012), to see which populations are genetic sources for other populations, as well as determining ‘K’ the number of genetic clusters within a given population or site (useful to compare to output ‘K’s from STRUCTURE
  • ‘adegenet’– to conduct Discriminant Analysis of Principal Components (DAPC) (Jombart, Devillard, & Balloux, 2010). There is a great tutorial here:
DAPC analysis on microsatellite data (eight loci) from eight populations of N. bruchi
Used the Adegenet package in R, and the Adegenet DAPC tutorial

Of course life is never easy.. especially when you have a MacOSX and for some reason the world revolves around PCs.

Here are some Data-wrangling tips for getting data into STRUCTURE and ClumpaK 

  • To get my data into the STRUCTURE format, I used the function ‘genind2structure’ that I found online here. Then in R, I used: genind2structure(inputdata, file=”outputdata.txt”, pops=TRUE).
  • Following this , you will need to:
    • RUN PERL SCRIPT Below..
    • since I have a MacOSX, I had to convert from DOS to UNIX with terminal program before loading in STRUCTURE by using similar code to this: while($_ = <>){s/\r\n|\n|\r/\n/g;print “$_\n”;}
      and you can find more info here .
    • To get my files into the Clumpak web processor, I had to use a different zip-program (Zipfiles4PC) than what the MacOSx does, as for some reason Clumpak couldn’t process- Mac-zipped files.

Ok.. I think that is enough for now.. but really.. If I can emphasize one thing it is to go through the whole Poppr tutorial to get a handle of how to analyze data in R, and a feel for YOUR data!



One thought on “Population Genetics, Part III: Data Wrangling and Analyses

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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