-
Notifications
You must be signed in to change notification settings - Fork 9
/
code8.r
53 lines (37 loc) · 1.66 KB
/
code8.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# ---- code8 ----
# Association analysis of imputed SNPs
source("globals.R")
# load derived data from previous snippets
load(working.data.fname(7))
library(snpStats)
library(plyr)
source("map2gene.R")
# ---- code8-a ----
# Carry out association testing for imputed SNPs using snp.rhs.tests()
rownames(phenoSub) <- phenoSub$id
imp <- snp.rhs.tests(phenotype ~ sex + age + pc1 + pc2 + pc3 + pc4 + pc5 + pc6 + pc7 + pc8 + pc9 + pc10,
family = "Gaussian", data = phenoSub, snp.data = target, rules = rules)
# Obtain p values for imputed SNPs by calling methods on the returned GlmTests object.
results <- data.frame(SNP = imp@snp.names, p.value = p.value(imp), stringsAsFactors = FALSE)
results <- results[!is.na(results$p.value),]
#Write a file containing the results
write.csv(results, impute.out.fname, row.names=FALSE)
# Merge imputation testing results with support to obtain coordinates
imputeOut<-merge(results, support[, c("SNP", "position")])
imputeOut$chr <- 16
imputeOut$type <- "imputed"
# Find the -log_10 of the p-values
imputeOut$Neg_logP <- -log10(imputeOut$p.value)
# Order by p-value
imputeOut <- arrange(imputeOut, p.value)
print(head(imputeOut))
# ---- code8-b ----
# Read in file containing protein coding genes coords
genes <- read.csv(protein.coding.coords.fname, stringsAsFactors = FALSE)
# Subset for CETP SNPs
impCETP <- map2gene("CETP", coords = genes, SNPs = imputeOut)
# Filter only the imputed CETP SNP genotypes
impCETPgeno <- imputed[, impCETP$SNP ]
# ---- code8-end ----
save(genotype, genoBim, clinical, pcs, imputed, target, rules,
phenoSub, support, genes, impCETP, impCETPgeno, imputeOut, file = working.data.fname(8))