Formatting Microsatellite Data for PCA in EIGENSOFT

At this point, who hasn’t read Patterson et al 2006 about population structure and eigenvector analysis?  It’s a great paper as it introduced the EIGENSOFT package for analyzing genomic data using principal components analysis (PCA).  PCA is a great way to identify both population structure and admixture relationships.  For anyone that works with microsatellites, you no doubt noticed the paragraph that says you can use microsatellite data as the PCA input.  However, the input format is not all that clear for how to convert your data.  This post provides an in-eloquent way of doing the format conversion using Excel tables.

Let’s start with our data in double column format (e.g.- STRUCTURE format).
Let’s call this Tab1:

MicroData

Note that Sample2 is missing data at Locus1.

You need to convert your data so that each allele of a microsatellite in your dataset has its own column.  In the toy example there are four alleles for Locus1, and three alleles for Locus2.  In Excel, I set up a new tab with the paired locus and allele information.  Also remember that it is important to keep the sample order the same as in the two column format.

The next step is to populate the new table with the number of alleles (0, 1, or 2) that each sample has for each locus_allele combination.  While this may be simple enough to do my hand for toy datasets, it is much easier (and less error prone) to use formulas in Excel to populate the new table.  I used an if/then statement.  Specifically, if the allele in the first column for the locus of interest was equal to the allele in the header row, then populate that cell with the value of 1; if the values in Tab 1 and Tab 2 are not equal, then populate the cell with a 0.

Write formulas for each locus_allele combination for the first sample, making sure to lock the right hand of the equation (allele value to compare the data to) using dollar signs before the row and column identifiers.

One_Allele

Once formulas have been written for the first sample, you can drag the equations down to populate the full table.

You should have noticed that when you do this, you are only accounting for the first allele.  Therefore, you can add (+) an additional if/then statement to account for the second allele in the second column, like this:

Two_Alleles

Yay!  There are now counts for all of the alleles.  However, we still have to account for the missing data.  To do this, we can still use the same idea as before by adding another if/then statement, but this time it will evaluate if the cell in the original data (Tab 1) is blank.  Blank cells can be coded in Excel as empty quotes (e.g. “”).  Since missing data should be missing in both columns in the original double column data (Tab 1), we only need to evaluate the first column, and assign it a value of 9 if it fulfills the if/then statement.

Two_Alleles_Missing

Now we see that Locus1 of Sample2 has been coded as missing data (9) at all alleles.

Finally, you need to make the three files (.eigenstratgeno, .snp, and .ind) that serve as input in EIGENSOFT.  To make the .eigenstratgeno file, copy your Excel table, then paste the values to remove the formulas.  (If you want to reference the formulas in the future, paste the values in a new tab.)  Now copy the table (with values not formulas) again and use the transpose function.  The toy data now looks like this:

EigenstratgenoFormat

Copy just the values (no sample or locus names) and paste into a text file, then remove the tabs between each column that Excel inserts.

FinalData

Finally, you may be asking why go through all of this trouble to use EIGENSOFT for PCA when you could also make one using the R package adegenet?  I like EIGENSOFT because you can analyze the output with Tracy-Widom statistics (within the EIGENSOFT package) to identify which principal components are significant versus less rigorous ways such as observing the plateau of eigenvalues.

Script for ChromoPainter

I’m new to Perl so this may not be the most elegant script. The script converts fastPHASE output into a ChromoPainter input file. The for loop makes an input file for each scaffold for which my data maps to (in my case 284 scaffolds of the polar bear genome).

#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
my($infile, $phasefile, $Chromofile, $constant, $i);
foreach my $chr (1..284){ #1 to 284 b/c my data maps to scaffolds that are named numerically and range from 1 to 284, non exclusive)
$constant = "0 0\n";
$infile="batch_1.scaffold".$chr.".phase.inp"; #Exported fastPHASE input file (.inp) for each scaffold from STACKS
$phasefile="Scaf".$chr."._hapguess_switch.out"; #_hapguess_switch.out is output from fastPHASE
$Chromofile="Scaf".$chr.".phase";
if (-e $infile && $phasefile) { #Using -e flag on infile and phasefile names to skip over any scaffold numbers (between 1-284) where my data does not map to; ex: no data on scaffold 100
open (INFILE, '+<', "$infile");
open (PHASEFILE, '+<', "$phasefile"); open (CHROMOFILE, '>>', "$Chromofile");
print CHROMOFILE ($constant); #Prints a 0 on the first line of the Chromofile, then moves to next line
my @infile = ;
my @phasefile = ;
print CHROMOFILE @infile[0..3]; #Prints first four lines of fastPHASE input file (num samples, num loci, loci bp position on scaffold, and a row of "S" * num loci)
print CHROMOFILE @phasefile[0..187]; #I have 94 samples (diploid); therefore, 188 haplotype lines when -Z flag used in fastPHASE. This prints all lines of the file fastPHASE output to ChromoPainter input file.
close INFILE;
close PHASEFILE;
close CHROMOFILE;
}
}

Dance Your PhD 2014 Submission

I wanted to enter the Dance Your PhD contest since before I was accepted into a PhD program!  Although never formally trained in dance, I did dance on my high school’s team and generally enjoyed the process.  So Dance Your PhD seemed totally up my alley combining art and science.

I had the vision for my dance mapped out in the second year of my PhD program.  While preparing an NSF DDIG and really thinking about both my hypotheses and the conservation implications of my work, the dance simply story-boarded out in my mind.  Specifically, I would combine my dissertation chapters on American black bear (Ursus americanus) phylogeography with its implications for wildlife trade.  Black bears experience a low amount of trade for traditional Asian medicine where the gallbladders and paws are thought to be medicinally useful.  By understanding genetic diversity throughout the range (as informed by the evolution of bear lineages), we can predict where an illegal sample came from, since the sample should have a genetic signature similar to its natal population. Even though I had the story mapped out, I didn’t want to dance my hypothses, I wanted to dance my data. So I sat on my dance until this year as I’m finishing up my dissertation.

Knowing the parts of my dissertation I wanted to convey led easily into the story of the interpretive dance. In the first scene, a bear (that’s me) is illegally hunted. In the second scene, I show the results of the phylogeography study. The appearance of the bears on screen signifies their speciation in North America. Over time the species expands its range and population size, all the while accumulating genetic variation which you can see slow emerge between the dancers in the east (stage right) and west (stage left). The bears are pushed south into glacial refugia. The group dance is meant to convey how even though genetic differentiation has already accumulated, they are still a single species. As the third scene begins, we come back to our illegally hunted bear who dances her genetic signature to try to find which broad region she belongs. After that broad lineage is identified, she is finally able to find her natal area within the whole species range.

The title of the piece, “No Way Home,” is a reference to Dave Wilcove’s book of the same name. The book describes multiple ways in which human induced landscape changes have affected animal migration routes. I use the title two ways. First, to recognize the impact of ongoing habitat fragmentation in limiting dispersal and gene flow in many species, not just bears. Second, to tie in the use of natal origin identification for wildlife trade application; although we can use genetics in this way, an illegally harvested animal no longer contributes it’s genes to the population. Therefore, through habitat fragmentation or illegal harvest, there is, “No Way Home” for many animals.

I first heard “Wapsuk,” by Kathleen Edwards when she opened for Bon Iver in 2011. She told the audience the story of being an artist invited on an expedition to Wapsuk National Park in Manitoba, Canada where she saw polar bears (Ursus maritimus) for the first time. Immediately, I sat up and took note, because it was a song about bears! Two hours later as I walked to the car (after an amazing set by Bon Iver), I started singing Wapsuk, and that’s when I knew that it HAD to be the song for my Dance Your PhD submission.

A final note about my dance: I dedicated it to the staff (past, present, and future) of the UNCG All Arts and Sciences Camp and specifically to camp’s long time Executive Director Bob Prout. That was the summer camp I attended then worked at when I was younger. Camp was my absolutely favorite thing/place/week that I looked forward to all year long. The dedication is just my tiny way of saying thank you for all you do to create fun and formative experiences for us art and science nerds. I can not fully express how very much camp means to me, still to this day.

Evolution2014 Talk- The talk that should have been

I organize a lot of things.  Like A LOT of things!  I chaired my department’s seminar organizing committee for three years.  I’ve organized the rangewide sampling effort for my dissertation project with 32 organizations. I founded and organize schedules for a blog.  The list goes on; I’m organized.

So imagine my surprise when I opened the Evolution2014 program and didn’t find my name. Apparently, the one thing I didn’t organize this year (and perhaps the most important since I’m looking for a postdoc) was signing up to give a talk. I have memories of signing up for a talk so can only imagine I got distracted and closed out without finishing; I truly thought I signed up.

Since life handed me lemons, I decided to make lemonade. Where the “lemonade” was really just making the slides for the talk I would have given. Feel free to download as a pdf: PuckettEvol2014; then find me at the meeting or tweet to me, as I’m happy to discuss further!

I’m on the postdoc market

I created this website in large part because I am looking for postdoctoral research opportunities.  I anticipate graduating in May 2015 and starting a new position shortly thereafter.  My current research interests are below; additionally, you can find links to my publications here. I would be happy to discuss project ideas or university specific fellowship opportunities that may fund my time in your lab.  Please contact me: EEPuckett at mizzou dot edu, or via Twitter.

Research Interests
I am broadly interested in both the spatial and temporal distribution of genetic variation in functional and neutral loci. Regarding the spatial distribution, I am interested in geographic barriers leading to within species lineage diversification and range expansion processes, particularly the adaptive potential of range expansion for widespread species. Regarding the temporal distribution, I am interested in both the timing of either de novo mutations or changes in standing allele frequency variation as an adaptive response to climatic change. I am also interested in incomplete lineage sorting.