Professor: Zhiwu Zhang

Due on March 30, 2020, Monday, 3:10PM, PST

We will need to install the GWhEAT package since this is a working package in it’s early stages of development it’s only available through Github. To download files off Github first download and load the library of the packaged “devtools” using the code below.

#code to install package from github
#install.packages("devtools")
library(devtools)

Next the code below downloads and installs the package GWhEAT from Github. The bottom two line of code in the chunk below make sure the dependencies GWhEAT relies on are also downloaded and installed.

#install package
install_github("stp4freedom/GWhEAT", force =TRUE)
## 
##   
  
  
   checking for file 'C:\Users\samuel.prather\AppData\Local\Temp\RtmpGIVI6u\remotes3a281d3973b0\stp4freedom-GWhEAT-76305c5/DESCRIPTION' ...
  
v  checking for file 'C:\Users\samuel.prather\AppData\Local\Temp\RtmpGIVI6u\remotes3a281d3973b0\stp4freedom-GWhEAT-76305c5/DESCRIPTION'
## 
  
  
  
-  preparing 'GWhEAT': (585ms)
##    checking DESCRIPTION meta-information ...
  
   checking DESCRIPTION meta-information ... 
  
v  checking DESCRIPTION meta-information
## 
  
  
  
-  checking for LF line-endings in source and make files and shell scripts
## 
  
  
  
-  checking for empty or unneeded directories
## 
  
  
  
-  building 'GWhEAT_0.1.0.tar.gz'
## 
  
   
## 
library(GWhEAT)#package name
#Load dependencies 
if (!require("pacman")) install.packages("pacman")
pacman::p_load(ggplot2,knitr,gridExtra)

The code below downloads and loads into the environment data that can be used for this tutorial.

if (!file.exists("GAPIT_Tutorial_Data.zip"))
{
  download.file("http://zzlab.net/GAPIT/GAPIT_Tutorial_Data.zip", destfile = "GAPIT_Tutorial_Data.zip")
  unzip("GAPIT_Tutorial_Data.zip")
}
download.file("http://zzlab.net/GAPIT/data/CROP545_Covariates.txt", destfile = "CROPS545_Covariates.txt")
download.file("http://zzlab.net/GAPIT/data/CROP545_Phenotype.txt", destfile = "CROPS545_Phenotype.txt")
# Import the GAPIT demo data genotypes
gt_scan <- data.frame(read.table("GAPIT_Tutorial_Data/mdp_numeric.txt", header = T, stringsAsFactors = F, sep = "\t", nrows = 1))
classes <- sapply(gt_scan, class)
genotypes <- data.frame(read.table("GAPIT_Tutorial_Data/mdp_numeric.txt", header = T, row.names = 1, colClasses = classes, stringsAsFactors = F, sep = "\t"))
#import genetic map, phenotypes, and covariates
GM <- read.table("GAPIT_Tutorial_Data/mdp_SNP_information.txt", header = T, stringsAsFactors = F, sep = "\t")
CV <- read.table("CROPS545_Covariates.txt", header = T, stringsAsFactors = F, sep = "\t")
phenotypes <- read.table("CROPS545_Phenotype.txt", header = T, stringsAsFactors = F, sep = "\t")
#Create phenotypes with just n by 1
phenotypes_n_1=phenotypes[,2]

Problem 1 (15 Pts)

The package should contain at least three input: y, X , and C that are R objects of numeric data frame. Their dimensions are n by 1, n by m, and n by t corresponding to phenotype, genotype and covariate data, where n is number of individuals, m is number of markers, and t is number of covariates. The function should return probability values with dimension of 1 by m for the association tests between phenotype and markers. Markers are tested one at a time with covariates in C included as covariates

Please see GWAS_apply.R for the source code to these questions

Our gwas function is called “GWASapply” and the input is “pheno” for the y object, “geno” for the X object, and “Cov” for the C object. They follow the correct dimensions. The function returns various results, but the probability values are contained in the result “P.value.res” and returns an object of 1 by m.

Problem 2 (25 Pts)

The package should perform PCA and incorporate PCs as cofactors for GWAS. Your package should also automatically exclude the PCs that are in linear dependent to the covariates provided by users.

Please see GWAS_apply.R for the source code to these questions

In our package we use the “prcomp” function to perform PCA on the X “geno” object and use a “fix_Dep” function to test for dependency and then excludethe PCs that are in linear dependence.

Problem 3 (20 Pts)

Develop a user manual and tutorials. Name your package and create a logo.

Please see User_Manual_Tutorial.Rmd and User_Manual_Tutorial.html for the user manual and tutorials.

Also included is a Reference_Manual.pdf for all our functions in the package which include “fix_Dep”, “manhattan_plot”, “qq_plot”, “power.fdr”, and our main functions “GWASapply”, and “GWASapply_rapid”.

Problem 4 (15 Pts)

Perform GWAS on the data provided or your own data which must contain cofactors.

Methods:

Our GWASapply function accepts the tutorial data phenotypes, genotypes, CV, and Genetic Map. It displays the PCA variance table and plots and scatterplots along with a QQ-plot and manhattan plot. The messages displayed give information on certain aspects of our GWAS results. The results returned returned are the probability values, cutoff used, order of snps and a table with the significant SNP information.

Results and Interpretation:

For the demo data, our function shows that since there was no cutoff specified, it defaults to a Bonferroni correction that results in a cutoff for significant values of “1.62e-05” with four significant SNPs. The results are shown below in the plots and the information is displayed in table 1. The MAF for each associated SNP ranged from 0.10 to 0.35. If these associated SNP’s MAF were very low like below 0.05 it would be cause of concern, however with the lowest MAF at 0.10 we can have confidence in these SNP associations.

Perform GWAS and display results

## [1] "GWASapply Starting"
## [1] "Principal Components have been calculated Successfully"
## 
## 
##                             PC1    PC2    PC3    PC4    PC5    PC6    PC7    PC8    PC9   PC10
## -----------------------  ------  -----  -----  -----  -----  -----  -----  -----  -----  -----
## Standard deviation        10.28   7.76   6.27   5.73   5.65   5.26   5.11   4.87   4.80   4.43
## Proportion of Variance     0.06   0.03   0.02   0.02   0.02   0.02   0.01   0.01   0.01   0.01
## Cumulative Proportion      0.06   0.09   0.12   0.13   0.15   0.17   0.18   0.19   0.21   0.22

## [1] "Principal Components plots have been printed Successfully"
## [1] "The final cuttoff for a significant p-value is 1.61655350792111e-05"
## [1] "4 Significant SNPs were found"

## [1] "Manhattan Plot Printed without QTN"

## [1] "QQ-Plot Printed"
## [1] "GWASapply results have printed"
## [1] "GWASapply ran successfully and took 2.59 seconds"

GWAS Threshold

## [1] 1.616554e-05

Significant SNPs and Minor Allele Frequency

Table 1. Significant SNP Results.

SNP ID SNP Position P-value MAF
PZA03058.21 2717 0e+00 0.1032028
PZA03058.17 2715 0e+00 0.1120996
PZA02699.1 1013 0e+00 0.3451957
PZA00615.3 937 1e-07 0.1103203

Problem 5 (25 Pts)

Demonstrate that your method is superior to the competing method (GWASbyCor) through simulation.

Methods:

In order to accurately compare our GWAS function and “GWASbyCor”, we will simulate data and use 10 QTNs in order to calculate false positives and true positives. We will use Manhattan plots and QQ plots to compare our results with the QTNs, false positives, and true positives denoted on the Manhattan plot. Using the replicate function, We replicated the GWAS functions, and then calculated how many false positives and true positives were calculated. We then took the averages and standard deviations of all the replicates. Then we use a t-test for both results in order to use statisitcal inferences and show a significant difference between the two methods. We also plotted ROC curves for Power vs FDR and Power vs Type 1 error.

Results and Interpretation:

In comparing the Manhattan plots and qq plots. The red lines display the locations for each QTN simulated. The blue lines show false positives, and the black lines show true positives. If there are red lines, in the results they are technically false negatives since the black lines would cover them if present.Since there was no cutoff specified, it defaults to a Bonferroni correction. We can easily see the large amounts of false positives in the GWASbyCor Manhattan plot, with only one appearing in the GWASapply Manhattan plot. The qqplots also show the GWASapply function results with less deviation from the expected except for the significant SNPS. Both ROC curves both look similar between the two functions. For the replicated results, we see that GWASbyCor results in a very large number of false positives with an averge of 31 and a large standard deviation of 48, whereas, our GWASapply function only results in an average of 4 false positives and a standard deviation of around 6. However, both functions result in a similar average for true positives. The t-tests show a significant difference for false positives but not true positives. The results show the GWASapply function results in a much lower rate of false positives.

Simulated Data

## [1] "GWASapply Starting"
## [1] "Principal Components have been calculated Successfully"
## [1] "The final cuttoff for a significant p-value is 1.61655350792111e-05"
## [1] "4 Significant SNPs were found"
## [1] "QTN's detected with 3 True Positives and 1 False Positives."
## [1] "GWASapply results have printed"
## [1] "GWASapply ran successfully and took 1.67 seconds"

Manhattan Plots

QQ Plots

ROC Curve Power vs FDR

ROC Curve Power vs Type 1

Mean Power, FDR, and True and False Positives

GWASbyCor

Power FDR False Positive True Positives
Averages 0.7891163 0.9878771 42.46667 3.700000
Standard Deviations 0.0754973 0.0018384 58.02302 1.316998

GWASapply

Power FDR False Positive True Positives
Averages 0.8248303 0.9868498 3.066667 3.533333
Standard Deviations 0.0000000 0.0000000 2.490442 1.074255

Statistical Inference

Power

## 
##  Paired t-test
## 
## data:  gcrep[1, ] and garep[1, ]
## t = -2.591, df = 29, p-value = 0.01482
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.063905148 -0.007522808
## sample estimates:
## mean of the differences 
##             -0.03571398

FDR

## 
##  Paired t-test
## 
## data:  gcrep[2, ] and garep[2, ]
## t = 3.0606, df = 29, p-value = 0.004725
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.0003407912 0.0017137492
## sample estimates:
## mean of the differences 
##              0.00102727

False Positives

## 
##  Paired t-test
## 
## data:  gcrep[3, ] and garep[3, ]
## t = 3.7822, df = 29, p-value = 0.0007202
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  18.0946 60.7054
## sample estimates:
## mean of the differences 
##                    39.4

True Positives

## 
##  Paired t-test
## 
## data:  gcrep[4, ] and garep[4, ]
## t = 0.57868, df = 29, p-value = 0.5673
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.4223815  0.7557148
## sample estimates:
## mean of the differences 
##               0.1666667

Problem 6 (25 Pts)

Demonstrate that your package is better than BLINK C version (http://zzlab.net/blink) on either statistical power or speed.

Methods:

In order to accurately compare our GWAS function and Blink, we will simulate data and use 10 QTNs in order to calculate power, FDR, false positives and true positives, and most importantly compare the speed of our functions. We will use Manhattan plots and QQ plots to compare our results with the QTNs, false positives, and true positives denoted on the Manhattan plot. Using the replicate function, We replicated the GWAS functions, and then calculated how many false positives and true positives were calculated. We then took the averages and standard deviations of all the replicates. Then we use a t-test for both results in order to use statisitcal inferences and show a significant difference between the two methods.We did the same thing for Power and FDR. We then tested the replicated functions on two more datasets.

Results and Interpretation:

In comparing the Manhattan plots and qq plots. The red lines display the locations for each QTN simulated. The blue lines show false positives, and the black lines show true positives. If there are red lines, in the results they are technically false negatives since the black lines would cover them if present.Since there was no cutoff specified, it defaults to a Bonferroni correction. Both functions display very few if any false positives, with BLINK producing more TRUE positives. This is confirmed by the replicates and averages for the two functions. The one thing that GWASapply has on BLINK is speed. The average speed is lower and is also significant in the t-test. This proved true for all three datasets.

Second Dataset

Third Dataset