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\lance.merrick\AppData\Local\Temp\RtmpYBmcmt\remotes493caf9180a\stp4freedom-GWhEAT-3a3cac7/DESCRIPTION' ...
v checking for file 'C:\Users\lance.merrick\AppData\Local\Temp\RtmpYBmcmt\remotes493caf9180a\stp4freedom-GWhEAT-3a3cac7/DESCRIPTION'
##
- preparing 'GWhEAT': (334ms)
## 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"))
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")
phenotypes_n_1=phenotypes[,2]
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.
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.
Develop a user manual and tutorials. Name your package and create a logo.
###Please see User_Manual.Rmd and User_Manual.html forthe 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”.
Perform GWAS on the data provided or your own data which must contain cofactors.
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.
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 SNP is relative low ranging from 0.10 to 0.35.
p4=GWASapply(phenotypes_n_1,genotypes,CV,GM,PCA.M = 3,plots=TRUE,messages=TRUE,trait="Problem 4")
## [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.88 seconds"
p4$cutoff.final.res
## [1] 1.616554e-05
kable(p4$sig.table)
| 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 |
Demonstrate that your method is superior to the competing method (GWASbyCor) through simulation.
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. Since
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. 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.
source("http://www.zzlab.net/StaGen/2020/R/G2P.R")
source("http://www.zzlab.net/StaGen/2020/R/GWASbyCor.R")
NQTN = 10 #specify number of QTN
h2 = 0.75 #heritability
alpha = 0.6 #alpha value
distribution = "normal" #specify distribution
set.seed(1)
#plotting
#phenotype simulation
mySim=G2P(genotypes, h2, alpha, NQTN, distribution)
p=GWASbyCor(X=genotypes,y=mySim$y)#GWAS by using the correlation methods
p=t(matrix(p))
pres=power.fdr(p, QTN.position=mySim$QTN.position,cutoff=NULL)
p5=GWASapply(mySim$y,genotypes,CV,GM,PCA.M = 3,QTN.position=mySim$QTN.position,message=TRUE)
## [1] "GWASapply Starting"
## [1] "Principal Components have been calculated Successfully"
## [1] "The final cuttoff for a significant p-value is 1.61655350792111e-05"
## [1] "6 Significant SNPs were found"
## [1] "QTN's detected with 3 True Positives and 3 False Positives."
## [1] "GWASapply results have printed"
## [1] "GWASapply ran successfully and took 1.67 seconds"
gcm=manhattan_plot(GM,p,cutoff=NULL,mySim$QTN.position,FP=pres$FP.fdr.power,TP=pres$TP.fdr.power, trait = "GWASbyCor",messages=FALSE)
gtm=manhattan_plot(GM,p5$P.value.res,cutoff=NULL,mySim$QTN.position,FP=p5$False.Positive,TP=p5$True.Positive, trait = "GWASapply",messages=FALSE)
grid.arrange(gcm, gtm, nrow = 2, ncol = 1, top = "Manhattan Plots")
gcq=qq_plot(GM,p,mySim$QTN.position, trait = "GWASbyCor")
gtq=qq_plot(GM,p5$P.value.res,mySim$QTN.position, trait = "GWASapply")
grid.arrange(gcq,gtq, nrow = 2, ncol = 1, top = "QQ-Plots")
gcrep=replicate (30,{
mySim=G2P(genotypes, h2, alpha, NQTN, distribution) #phenotype simulation
p= GWASbyCor(X=genotypes,y=mySim$y)#GWAS by using the correlation methods
p=data.frame(p)
pres=power.fdr(p, QTN.position=mySim$QTN.position,cutoff=NULL)
FalP=length(pres$FP.fdr.power)
TruP=length(pres$TP.fdr.power)
num_output=c()
num_output=c(FalP,TruP)
})
means=rowMeans(gcrep)
stdevs=apply(gcrep,1,sd)
out4 <- rbind(means,stdevs)
out4 <- as.data.frame(out4)
colnames(out4) <- c("False Positive","True Positives")
rownames(out4)<-c("Averages","Standard Deviations")
kable(out4)
| False Positive | True Positives | |
|---|---|---|
| Averages | 31.33333 | 3.600000 |
| Standard Deviations | 47.99952 | 1.220514 |
| #### GWASapply |
garep=replicate(30,{
mySim=G2P(genotypes, h2, alpha, NQTN, distribution)
p5_rep=GWASapply(mySim$y,genotypes,CV,GM,PCA.M = 3,QTN.position=mySim$QTN.position)
FalP=length(p5_rep$False.Positive)
TruP=length(p5_rep$True.Positive)
num_output=c()
num_output=c(FalP,TruP)
})
means=rowMeans(garep)
stdevs=apply(garep,1,sd)
out5 <- rbind(means,stdevs)
out5 <- as.data.frame(out5)
colnames(out5) <- c("False Positive","True Positives")
rownames(out5) <-c("Averages","Standard Deviations")
kable(out5)
| False Positive | True Positives | |
|---|---|---|
| Averages | 2.933333 | 3.233333 |
| Standard Deviations | 2.638355 | 1.072648 |
t.test(gcrep[1,],garep[1,], paired = T, na.rm=T)
##
## Paired t-test
##
## data: gcrep[1, ] and garep[1, ]
## t = 3.28, df = 29, p-value = 0.002703
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 10.69116 46.10884
## sample estimates:
## mean of the differences
## 28.4
t.test(gcrep[2,],garep[2,], paired = T, na.rm=T)
##
## Paired t-test
##
## data: gcrep[2, ] and garep[2, ]
## t = 1.2838, df = 29, p-value = 0.2094
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.2174635 0.9507969
## sample estimates:
## mean of the differences
## 0.3666667
Demonstrate that your package is better than BLINK C version (http://zzlab.net/blink) on either statistical power or speed.
garapid=replicate(30,{
loop_start <- proc.time()
p6_rep=GWASapply_rapid(phenotypes_n_1,genotypes,CV,GM,PCA.M = 3)
loop_end <- proc.time()
loop_elapsed <- loop_end[3] - loop_start[3]
timet=c(loop_elapsed[[1]])
})
mean(garapid)
## [1] 1.264