Changes

AdvGeneMap2018Commands

343 bytes removed, 15:54, 23 January 2018
/* GenABEL */
===GenABELFunctional Annotation===
 
===GenABEL===
# Load files
library(GenABEL)
convert.snp.tped(tped = = "gwa_gabel_qtl.tped", tfam = = "gwa_gabel_qtl.tfam", out = = "gwa_gabel_qtl.raw", strand = = "u") g.dat <- load.gwaa.data(phen = = "gwa_gabel_qtl.praw", gen = = "gwa_gabel_qtl.raw", force = = T)
slotNames(g.dat)
slotNames(g.dat@gtdata)
# Trait
summary(g.dat@phdata$disease)
hist(g.dat@phdata$disease, main=="Quantitative Phenotype data summary", xlab = = "Systolic pressure measure", freq = = F,breaks==20, col=="gray")
rug(g.dat@phdata$disease)
###
###
# GLM test
test.snp <- scan.glm('disease ~ CRSNP', family = = gaussian(), data = = g.dat)
names(test.snp)
alpha <- 5e-8
test.snp$P1df[test.snp$P1df < alpha]
# Score test
test.qt &lt;- qtscore(disease, data &#61; = g.dat, trait &#61; = "gaussian")
slotNames(test.qt)
names(test.qt@results)
obs &lt;- sort(results(test.qt)$P1df)
ept &lt;- c(1:length(obs)) / (length(obs) + 1)
plot(-log10(ept), -log10(obs), main &#61; = "GWAS QQ plot, qtl", xlab&#61;="Expected -log10(pvalue)", ylab&#61;="Observed -log10(pvalue)") abline(0, 1, col &#61; = "red") abline(h &#61; = 8, lty &#61; = 2)
# Manhattan plot
plot(test.qt, col &#61; = "black")
# Adding confounders
test.qt.sex &lt;- qtscore(disease ~ sex, data &#61; = g.dat, trait &#61; = "gaussian")
rownames(results(test.qt.sex))[results(test.qt)$P1df < alpha]
summary(lm(disease ~ sex, data &#61; = g.dat))
###
# MDS
###
gkin &lt;- ibs(g.dat, weight &#61; = "freq")
gkin[1:10,1:10]
cps.full &lt;- cmdscale(as.dist(.5 - gkin), eig &#61; = T, k &#61; = 10)
names(cps.full)
cps &lt;- cps.full$points
plot(cps[,1], cps[,2], pch &#61; = g.dat@phdata$popn) legend(-0.16, 0.06, c("TSI","MEX", "CEU"), pch &#61; = c(1,2,3))
###
# Corrected test
gpc.dat &lt;- g.dat
gpc.dat@phdata&lt;-cbind(g.dat@phdata, cps)
test.pc.a &lt;- scan.glm('disease ~ CRSNP + C1 + C2 + C3 + C4 + C5', family&#61;=gaussian(), data &#61; = gpc.dat)
test.pc.a$snpnames[test.pc.a$P1df < alpha]
test.pc.a$P1df[test.pc.a$P1df < alpha]
test.pc.b &lt;- qtscore(disease ~ C1 + C2 + C3 + C4 + C5, data &#61; = gpc.dat, trait &#61; = "gaussian")
test.pc.b@lambda
# scree plot
plot(cps.full$eig[1:10]/sum(cps.full$eig), axes &#61; = F, type &#61; = "b", xlab &#61; = "Components", ylim &#61; = c(0,0.05), ylab &#61; = "Proportion of Variations", main &#61; = "MDS analysis scree plot")
axis(1, 1:10)
axis(2)
# cumulative plot
plot(cumsum(cps.full$eig[1:10])/sum(cps.full$eig), axes &#61; = F, type &#61; = "b", ylim &#61; = c(0,0.2), xlab &#61; = "Components", ylab &#61; = "Proportion of Variations", main &#61; = "MDS analysis cumulative plot")
axis(1, 1:10)
axis(2)
# Check for inflation of statistic
obs &lt;- sort(results(test.qt)$chi2.1df)
ept &lt;- sort(qchisq(1:length(obs) / (length(obs) + 1), df &#61; = 1)) plot(ept, obs, main &#61; = "Genomic control (slope is the inflation factor)", xlab&#61;="Expected chisq, 1df", ylab&#61;="Observed chisq, 1df") abline(0, 1, col &#61; = "red") abline(0, test.qt@lambda[1], lty &#61; = 2)
# Definition of GIF
# Conventional definition
obs &lt;- sort(results(test.qt)$Pc1df)
ept &lt;- c(1:length(obs)) / (length(obs) + 1)
plot(-log10(ept), -log10(obs), main &#61; = "GWAS QQ plot adj. via Genomic Control", xlab&#61;="Expected -log10(pvalue)", ylab&#61;="Observed -log10(pvalue)") abline(0, 1, col &#61; = "red") abline(h &#61; = 8, lty &#61; = 2)
# EIGENSTRAT
adj.gkin &#61; = gkin diag(adj.gkin) &#61; = hom(g.dat)$Var # naxes &#61; = 3 is default value test.eg &lt;- egscore(disease, data &#61; = g.dat, kin &#61; = adj.gkin, naxes &#61; = 2)
descriptives.scan(test.eg)
snp.eg &lt;- row.names(results(test.eg))[results(test.eg)$P1df < alpha]
# Change #PCs
for (k in 1:10){
test.tmp &lt;- egscore(disease, data &#61; = g.dat, kin &#61; = adj.gkin, naxes &#61; = k)
print(test.tmp@lambda$estimate)
}
obs &lt;- sort(results(test.eg)$Pc1df)
ept &lt;- c(1:length(obs)) / (length(obs) + 1)
qqplot(-log10(ept), -log10(obs), main &#61; = "GWAS QQ plot adj. w/ EIGENSTRAT", xlab&#61;="Expected -log10(pvalue)", ylab&#61;="Observed -log10(pvalue)") abline(0, 1, col &#61; = "red") abline(h &#61; = 8, lty &#61; = 2)
# Manhattan plot comparison
plot(test.qt, col &#61; = "black") add.plot(test.eg, col &#61; = "gray", pch &#61; = 3) legend("topright", c("Original plot","After correction w/ EIGENSTRAT"), pch &#61; = c(1,3))
###
# Basic test, binary trait
###
# load files to GenABEL
convert.snp.tped(tped &#61; = "gwa_gabel.tped", tfam &#61; = "gwa_gabel.tfam", out &#61; = "gwa_gabel.raw", strand &#61; = "u") b.dat &lt;- load.gwaa.data(phen &#61; = "gwa_gabel.praw", gen &#61; = "gwa_gabel.raw", force &#61; = T)
slotNames(b.dat)
slotNames(b.dat@gtdata)
b.dat@gtdata@nids
# number of cases and controls
case.size &lt;- length(which(b.dat@phdata$disease &#61;&#61; == 1)) control.size &lt;- length(which(b.dat@phdata$disease &#61;&#61; == 0))
case.size
control.size
snpsb.total &lt;- b.dat@gtdata@nsnps
# GLM test
testb.snp &lt;- scan.glm('disease ~ CRSNP', family &#61; = binomial(), data &#61; = b.dat)
names(testb.snp)
alpha &lt;- 5e-8
testb.snp$P1df[testb.snp$P1df < alpha]
# Score test
testb.qt &lt;- qtscore(disease, data &#61; = b.dat, trait &#61; = "binomial")
slotNames(testb.qt)
descriptives.scan(testb.qt)
Bureaucrat, administrator
1,252
edits