Daily Archives: May 23, 2019

2019 R Exercise

Lecture 3.1

Marguerite Butler

An informal session to provide more R practice for those who want to improve their R skills using phylogenetic trees in R as a subject. We will start by asking for topics people would like to discuss or work on. Come with your biggest R frustrations.

R workshop materials

No preparation is required, but you can consult background material:

Background on objects is in Rboot.pdf chapter 3
Background on phylogenetic trees is in Rcomparative.pdf chapter 9 (and more in chapter 10).

Free advice on R programming

Projection

Review of Tree objects and in-session demonstration
Projection by Brian Omeara

Exercise 1 (optional): Manipulating branches on a phylogenetic tree and simulating branch lengths. An exercise in manipulating objects, editing functions, and generating simulations.

R script
Nexus file 
See also Rcomparative chapter 15.8 (but we will be using ape instead of phylobase).

Exercise 2 (optional): Gene Hunting (an exercise in string matching, abstracting, writing functions). Without using grep, write code to find all open reading frames in a  randomly generated DNA sequence.

Exercise
Code starter
Code solution (donʻt peek until youʻve tried it!)
Sample dna sequence
Sample output

Exercise 3 (optional): Verification of PGLS “by hand”. Better understand what is going on in applying a Brownian motion model by “dividing out” the phylogeny on a small phylogeny.

Chapter 1 of R_BM_OUCH_minitutorial.pdf

Exercise 4 (optional): Coding your own BM and OU simulations. To better understand the meaning of the BM and OU parameters, and also to progressively build code of increasing complexity via functions.

Chapter 2 of R_BM_OUCH_minitutorial.pdf

Code:
bmousim.R
OU.sim.branch.R   Try to get here yourself before looking
ou2drgl.R     To do 3D simulations in RGL

2019 Exercise 2.2

Lecture 2.3

Estimating a selection surface

by Stevan J. Arnold and Monique N. Simon

Exercise description

Exercise script and data file.  Open the Rmd file in RStudio.  Follow the instructions in that file about where to put the txt file.

References

 

2019 Exercise 2.1

Lecture 2.2

Using MCMCglmm in R to estimate inheritance parameters

by Patrick Carter

Before our session on Tuesday please make sure you have installed the following R packages: ggplot2, MasterBayes, MCMCglmm, Plyr

 

Before Class Tuesday please download the following 4 files; note that Model 101 output and Model 1201 output can only be read and visualized from within the R environment.

R MCMCglmm script

ASCCI data set to use with above R script

Model 101 output (Phenotype 1 Additive and Fixed nitt =1,000,000)

Model 1201 output (Phenotypes 1 and 2 Additive and Fixed nitt = 2,000,000)

 

2019 Lecture 2.1

Exercise 2.1

Estimation of inheritance with fixed and random effects

by Patrick Carter

Projections

Lecture 2.1.pdf

Notes

Readings

Villemereui MCMCglmm tutorial

Wilson_et_al-2010 Ecologists Guide to the Animal Model

Wilson et al Ecologists Guide Supplementary File 5 – Tutorial MCMCglmm

NEW REVISED – Wilson et al Supplementary File 5 – Tutorial MCMCglmm

Audio-recordings

Lecture2.1.WMA

Lecture2.1.mp3

2019 Exercise 1.2

Lecture 2.1

Multivariate inheritance: matrix algebra in R and PCP software

by Stevan J. Arnold (with thanks to Josef Uyeda, Patrick C. Phillips, & Tyler Heather)

In this class session, we will concentrate on using Patrick C. Phillips (PCP) software (h2boot) to estimate and compare G-matrices. If you are unfamiliar or out of practice with matrix algebra, do the following tutorials before class.

Matrix algebra tutorials (do them before class)

1. Overview   Readme_rev

2. Tutorial 1:    Matrix_algebra_session_rev2.Rmd     Appendix_1

3.  Tutorial 2:   Tutorial_on_direct_and_indirect_selection_rev.Rmd

Using PCP software (h2boot) to estimate G-matrices (do this in class)

1.  Overview.

The aim of this exercise is to gain some familiarity with multivariate inheritance. We will gain this familiarity by estimating and comparing genetic variances and covariances for a suite of six traits in two populations of garter snakes. You estimated heritabilities of these traits in one of these populations (inland) in Exercise 1.1

2.  Download this data file  All_females_2pops.txt and put it in a folder on your desktop.

These are data on six scale count characters for mother and offspring garter snakes sampled from two different populations (inland and coastal). Details on two of these populations and the analysis that follows can be found in Phillips & Arnold 1999 and Arnold & Phillips 1999.  Each row in this data file give the population name, family name, and then the values for six scale-count traits (body, mid, mid, ilab, slab, post).  In a set of rows with the same family name, the first row gives the counts for an adult female and the subsequent rows give the counts for her female offspring. Missing values are denoted -9999.

3.  Run the h2boot program on the PCP website.  Here is how to run h2boot on different operating systems:

a. Windows

Download h2boot.exe from this website and save it in the same folder as your data file. Then navigate to the directory containing h2boot.exe and type:

h2boot

b. MAC

(i). To run the precompiled version, download h2bootMAC from this website and place it in the same directory as your data file. Then navigate to the directory containing both h2bootMAC and the data file and type:

chmod +x h2bootMAC
h2bootMAC

(ii). To run the Windows version via WINE, you need to make sure you have updated Xcode and Xcode Command Line Tools and you need to install Macports. Go to the Macports install page and follow the quickstart guide on the top. You can make sure Macports is installed by typing the following command in a terminal:

port search wine

which should return the number of ports available (e.g., 5). Information on installing WINE can be found on the “Build Wine, the Macports way” on WINE’s build page. Type in the following command in the terminal:

sudo port install wine-devel

This command can take a little while (~45 minutes for me). Once WINE is installed, cd to the directory that contains h2boot.exe and type:

wine ./h2boot.exe

c. UBUNTU

h2boot.exe will run under WINE. If you don’t have WINE installed, you can open a terminal and type:

sudo add-apt-repository ppa:ubuntu-wine/ppa
sudo apt-get update
sudo apt-get install -y wine1.7

Then, download h2boot.exe and place it in the same directory as your data file. Navigate to the directory containing h2boot.exe and type:

wine h2boot.exe

Upon first launch some dependences may be downloaded and installed.

4. Once you see the h2boot command screen, enter the following parameter values:

Note: Initially only 10 selections will appear, but as you enter the choices below the menu will expand to 13 choices.

1) Input file name: all_females_2pops.txt
2) Trait names included in file: yes
3) Output file name: All_females_out.txt
4) Number of bootstrap runs: 1000
5) Random number seed: 1994
6) Create files for bootstrap distributions: no
7) Type of analysis: Parent-off regression w/full-sib ANOVA
8) Only use families with complete data: no
9) Analyzing multiple populations: yes
10) Make population comparisons: yes
11) Bend non-positive definite matrices: yes
12) Automatically order eigenvectors in PCP analysis: yes
enter 0) End selection and run program.

5. Your output file should look like this all_females_out,txt

6. Interpreting the h2boot output.

The following instructions show you how to graph the probability values in your output.  Open this file in RStudio:

Interpret_the_probability_values.Rmd

7. You may also want to examine and plot the bootstrap distributions produced by h2boot.

Follow the instructions in the file below.  Open the file below in RStudio.

Examine_and_plot_the_bootstrap_distributions_produced_by_h2boot.Rmd

8. In class discussion we will focus on population comparison of the G-matrices (see Figures 1 and 2 in Phillips & Arnold 1999).

For that discussion we will use the final section of the h2boot output (which shows estimates of matrices under different models of population similarity), but we also need output from a second program, cpcrand.exe.  To get out put from that program go back to the PCP website, download cpcrand.exe and place it in the same folder as the data file All_females_2pops.  Run cpcrand.exe (in the same way that you ran h2boot).  When the command screen comes up, answer the queries as follows:

  1. Input file name: All_females_2pops.txt
  2. Trait names included in file: yes
  3. Output file name: cpc.out
  4. Number of randomization runs: 1000
  5. Random number seed: 1996
  6. Create files for likelihood distributions: yes
  7. Type of analysis: Parent-off regression w/full-sib ANOVA
  8. Only use families with complete data: yes
  9. Bend non-positive definite matrices: yes
  10. Automatically order eigenvectors in PCP analysis: yes

This program will conduct statistical tests for various models of similarity between the two G-matrices (identity, proportionality, common principal components, etc).  Stand by with your output file (cpc.out) for discussion in class.  We will compare the cpc.out results for comparison of G-matrices with Table 3 and Figure 3 in Phillips & Arnold 1999.

Your output file should look like this cpc.out

References