Intalling Shiny Server on Ubuntu 14 LTS

Intalling Shiny Server on Ubuntu 14 LTS

OK, so I just ‘found‘ shiny and it has a lot of cool stuff to it.  OK, I’ve known about it for a long time but have just had the opportunity to sit down and work it out and see how it can fit into the presentation and learning I’m trying to develop in my Applied Population Genetics online textbook.  Here is a brief overview of how I set up the shiny server on my Ubuntu box that is hosting the book (so I can embed more interactivity in the display).

Read more



The program STRUCTURE is an ubiquitous feature of many population genetic studies these days—if it is appropriate is another question. Today, while covering model based clustering in population genetics, we ran into a problem where STRUCTURE was unable to run and the OS said it was Corrupted and should be thrown away.  Jump below for our fix, it really is an easy one.

Read more

Buffers & Convex Hulls

Buffers & Convex Hulls

An analysis common to modern population genetics is that of finding ecological distances between objects on a landscape.  The estimation of pairwise distance derived from spatial data is a computationally intensive thing, one that if you are not careful will bring your laptop to its knees!  One way to mitigate this data problem is to use a minimal amount raster area so that the estimation of the underlying distance graph can be done on a smaller set of points.  This example provides a simple solution using convex hulls.  Jump below for the complete example.

Read more

Merging data frames

In R, there is often the need to merge two data.frame objects (say one with individual samples and the other with population coordinates.  The merge()  function is a pretty awesome though it may take a little getting used to.
Here are some things to remember:

  1. You need to have two data.frame objects to merge
  2. The first one in the function call will be the one merged on-to the second one is added to the first.
  3. Each will need a column to use as an index—it is a column that will be used to match rows of data.  If they are the same column names then the function will do it automagically, if no common names are found in the names()  of either  data.frame objects, you can specify the columns using the optional by.x=  and by.y=  function arguments.

Read more

Loading in Rasters

Much of the work in my laboratory uses spatial data in some context.  As such it is important to try to be able to grab and use spatial data to in an easy fashion.  At present, R is probably the best way to grab, visualize, and analyze spatial data. For this example, I went to and downloaded the elevation (altitude) for tile 13 (eastern North America) as a GeoTiff.  A GeoTiff is a specific type of image format that has spatial data contained within it.  The tile data has a pixel resolution of 30 arc seconds which puts us in the general area of ~ 1km.   First, we need to get things set up to work.

Read more

Compiling the GSL Library for OSX

Compiling the GSL Library for OSX

I’ve been working on integrating the Swift language into my analysis workflow but much of what I do involves the GNU Scientific Libraries for matrix analysis and other tools.  Here is a quick tutorial on how to install the GSL library on a clean OSX platform.

  1. It is easiest if you have XCode installed.  You can get this from the App Store for free.  Go download it and install it.
  2. Download the latest version of the GSL libraries.  You can grab them by:
    1. Looking for your nearest mirror site listed at and connecting to it.
    2. Open the directory gsl/ where all the versions will be listed.  Scroll down and grab gsl-latest.tar.gz.
  3. Open the terminal (Utilities -> and type:  cd ~/Downloads
  4. Unpack the archive by:  tar zxvf gsl-latest.tar.gz then cd gsl-1.16/ (or whatever the version actually was, it will probably be some number larger than 1.16).
  5. Inside that folder will be a README file (which you probably won’t read) and an INSTALL file (which you should read).  In that folder it will tell you to:  ./configure then  make then sudo make install. This last command will require you to type in your password as it is going to install something into the base system.
  6. All the libraries and header files will be installed into the /usr/local/ directory.

Install rgeos on OSX

There seems to be some nefarious conspiracy against packaging spatial R packages on the mac platform. Don’t quite understand it but it sucks.  Here is how to install the rgeos package.

If you try the normal way, you get the following error:

which is not very helpful.   Read more

Turning In Assignments via Google Sharing

If you use Google Docs for your writing, there are several cool tricks you can use to increase your efficiency.  Here is one thing that has made it much easier when it comes to turning in assignments.  Previously, one would create a document in some word processor, work on it, put it on a thumb drive, take it home and work on it, take it back to school, perhaps a lab computer, maybe it is also worked on in the library, etc.  Eventually, you finish the document and then to turn it in you can either print it off (got to go find a printer or where I put that extra paper) or email it  in.  This last option is terrible if you have a large class!

If you are using Google Docs, you can just share it with the instructor.  In the sharing options, you can designate that you share with someone but only allow them to make “suggestions”.  This keeps the integrity of your document in place while allowing another person to mark it up.  Once you share it, they can open it and write in it but any and all changes to the document are indicated via a highlight color.  Since both of you are working on the document, there is no need to email it back and forth, there is only one document.

Here is a short video how that is done if you need more visual input.

Setting Up Your Site for Syndication

This quick tutorial is for how you set up your site to make it able to syndicate to a class site.  I am using the BIOL310 Genetics Online course as an example.  You are going to need the following:

  1. A category given to you by the professor to use on your site to indicate which posts should be sent over to the class site.
  2. A blog.  Here I am running WordPress as it is the supported one from VCU.  Others are available if you already have a blog going, if not got to and sign up as a VCU student and make one.  Consider it a digital portfolio for all your work.
  3. Send your professor the address of your blog.

Below is a video of the process.  It is pretty easy to do.

That should be it. Once your professor has the link and sets up syndication, your posts (when the category is applied to them) will show up on the site.

Extracting Data from Rasters

This document shows you how to extract data from rasters.


Getting The Libraries

First, I’ll load in some packages to get the ability to work with raster data and to load in the Arapatus attenuatus data set (it is part of the default gstudiopackage).


Loading and Cropping Rasters

We can load in the raster, and then crop it to just the are we need. These rasters were downloaded from [] and are much larger than the study area. This just makes it easier on the computer to not have to deal with such large areas. After cropping it, we will load in the annual precip and temperature data as well.


Getting Example Data from Araptus attenuatus

Now, lets grab the Araptus data and look at the data and plot out the locations.




Extracting Point Data

To elevation, temperature and precipitation from the rasters for each sampling location, we need to translate them into points first. I’ll first grab the coordinate data as a data.frame.


Then we can grab them using the normal functions in the sp library.



Plotting Trend lines.

Cool, lets sort this by latitude


and then plot out some values to look at what is going on.