Manhattan plot of GWAS results_codes
Manhattan plot of GWAS results_codes
View(per)
str(per)
as.data.frame(per)
install.packages("qqman")
library(qqman)
library(lattice)
qqunif.plot<-function(pvalues,
should.thin=T, thin.obs.places=2, thin.exp.places=2,
xlab=expression(paste("Expected (",-log[10], " p-value)")),
ylab=expression(paste("Observed (",-log[10], " p-value)")),
draw.conf=TRUE, conf.points=1000, conf.col="lightgray", conf.alpha=.05,
already.transformed=FALSE, pch=20, aspect="iso",
prepanel=prepanel.qqunif,
par.settings=list(superpose.symbol=list(pch=pch)), ...) {
#error checking
if (length(pvalues)==0) stop("pvalue vector is empty, can't draw plot")
if(!(class(pvalues)=="numeric" ||
(class(pvalues)=="list" && all(sapply(pvalues,
class)=="numeric"))))
stop("pvalue vector is not numeric, can't draw plot")
if (any(is.na(unlist(pvalues)))) stop("pvalue vector contains NA
values, can't draw plot")
if (already.transformed==FALSE) {
if (any(unlist(pvalues)==0)) stop("pvalue vector contains
zeros, can't draw plot")
} else {
if (any(unlist(pvalues)<0)) stop("-log10 pvalue vector contains
negative values, can't draw plot")
}
grp<-NULL
n<-1
exp.x<-c()
if(is.list(pvalues)) {
nn<-sapply(pvalues, length)
rs<-cumsum(nn)
re<-rs-nn+1
n<-min(nn)
if (!is.null(names(pvalues))) {
grp=factor(rep(names(pvalues), nn),
levels=names(pvalues))
names(pvalues)<-NULL
} else {
grp=factor(rep(1:length(pvalues), nn))
}
pvo<-pvalues
pvalues<-numeric(sum(nn))
exp.x<-numeric(sum(nn))
for(i in 1:length(pvo)) {
if (!already.transformed) {
pvalues[rs[i]:re[i]] <- -log10(pvo[[i]])
exp.x[rs[i]:re[i]] <- -log10((rank(pvo[[i]],
ties.method="first")-.5)/nn[i])
} else {
pvalues[rs[i]:re[i]] <- pvo[[i]]
exp.x[rs[i]:re[i]] <- -log10((nn[i]+1-
rank(pvo[[i]], ties.method="first")-.5)/(nn[i]+1))
}
}
} else {
n <- length(pvalues)+1
if (!already.transformed) {
exp.x <- -log10((rank(pvalues,
ties.method="first")-.5)/n)
pvalues <- -log10(pvalues)
} else {
exp.x <- -log10((n-rank(pvalues,
ties.method="first")-.5)/n)
}
}
prepanel.qqunif= function(x,y,...) {
A = list()
A$xlim = range(x, y)*1.02
A$xlim[1]=0
A$ylim = A$xlim
return(A)
}
qqunif.plot(per$P)
> library(readxl)
> perl <- read_excel("perl.xlsx")
> View(perl)
> library(readxl)
> perl1 <- read_excel("perl1.xlsx")
> View(perl1)
> b = merge(perl1, perl, by = "SNP")
> head(b)
SNP CHR.x BP A1 TEST NMISS BETA STAT P
1 NC_037545.1:100014751[M96] 1 100014751 1 ADD 95 0.20710 1.3240 0.1887
2 NC_037545.1:100014751[M96] 1 100014751 1 COV1 95 -0.16930 -1.0830 0.2817
3 NC_037545.1:100014857[M96] 1 100014857 1 ADD 95 -0.10730 -0.8586 0.3928
4 NC_037545.1:100014857[M96] 1 100014857 1 COV1 95 -0.07356 -0.5885 0.5576
5 NC_037545.1:100105376[M96] 1 100105376 1 ADD 96 -0.01618 -0.1290 0.8976
6 NC_037545.1:100105376[M96] 1 100105376 1 COV1 96 -0.02800 -0.2232 0.8238
CHR.y UNADJ GC BONF HOLM SIDAK_SS SIDAK_SD FDR_BH FDR_BY
1 1 0.1887 0.1956 1 1 1 1 0.9837 1
2 1 0.1887 0.1956 1 1 1 1 0.9837 1
3 1 0.3928 0.4002 1 1 1 1 0.9862 1
4 1 0.3928 0.4002 1 1 1 1 0.9862 1
5 1 0.8976 0.8992 1 1 1 1 0.9978 1
6 1 0.8976 0.8992 1 1 1 1 0.9978 1
> manhattan(b, chr = "CHR.x", bp = "BP", p = "GC", snp = "SNP",
+ col = c("chartreuse", "blue4"), chrlabs = NULL,
+ suggestiveline = -log10(2.59e-06), genomewideline = -log10(1.29e-06),
+ highlight = NULL, logp = TRUE, ylim = c(0, 16))
>
> qqunif.plot(b$GC)