forked from elijahedmondson/NASA-GRSD-HS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2. Genome Reconstruction.R
235 lines (177 loc) · 8.07 KB
/
2. Genome Reconstruction.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
library(DOQTL)
#Loading in data
load(url("ftp://ftp.jax.org/MUGA/MM_snps.Rdata"))
extract.raw.data(in.path = "/Volumes/External Terabyte/QTL/Founders", prefix = "",
out.path = "/Volumes/External Terabyte/QTL/extract.raw.data/Founders",
array = "megamuga")
extract.raw.data(in.path = c("/Users/elijahedmondson/Desktop/R/QTL/FINAL GENOTYPE DATA/1 - 96",
"/Users/elijahedmondson/Desktop/R/QTL/FINAL GENOTYPE DATA/2 - 23 (last plate)",
"/Users/elijahedmondson/Desktop/R/QTL/FINAL GENOTYPE DATA/2 - 481",
"/Users/elijahedmondson/Desktop/R/QTL/FINAL GENOTYPE DATA/3 - 18 (last plate)",
"/Users/elijahedmondson/Desktop/R/QTL/FINAL GENOTYPE DATA/4 - 600",
"/Users/elijahedmondson/Desktop/R/QTL/FINAL GENOTYPE DATA/5 - 12 (last plate 600)",
"/Users/elijahedmondson/Desktop/R/QTL/FINAL GENOTYPE DATA/6 - 648"),
prefix = c("", "", "", "", "", "", ""),
out.path = "/Users/elijahedmondson/Desktop/R/QTL/extract.raw.data/GRSD",
array = "megamuga")
#FIRST STEP
setwd("/Users/elijahedmondson/Desktop/R/QTL/WD")
getwd()
list.files("/Users/elijahedmondson/Desktop/R/QTL/WD")
# Read in founders.
fg = read.delim("/Users/elijahedmondson/Desktop/R/QTL/extract.raw.data/Founders/geno.txt")
fg[fg == TRUE] = "T"
fx = read.delim("/Users/elijahedmondson/Desktop/R/QTL/extract.raw.data/Founders/x.txt")
fy = read.delim("/Users/elijahedmondson/Desktop/R/QTL/extract.raw.data/Founders/y.txt")
# Load in data.
g = read.delim("/Users/elijahedmondson/Desktop/R/QTL/extract.raw.data/GRSD/geno.txt")
g[g == TRUE] = "T"
x = read.delim("/Users/elijahedmondson/Desktop/R/QTL/extract.raw.data/GRSD/x.txt")
y = read.delim("/Users/elijahedmondson/Desktop/R/QTL/extract.raw.data/GRSD/y.txt")
setwd("/Users/elijahedmondson/Desktop/R/QTL/WD/")
getwd()
save(x, y, g, fx, fy, fg, file = "GRSD1878data.Rdata")
load(file = "GRSD1878data.Rdata")
load(url("ftp://ftp.jax.org/MUGA/MM_snps.Rdata"))
# Combine founders and samples.
x = rbind(fx, x)
y = rbind(fy, y)
g = rbind(fg, g)
# Remove outlier samples.
rmx = rowMeans(x, na.rm = T)
rmy = rowMeans(y, na.rm = T)
plot(rmx, rmy)
remove = which(rmx > 0.6)
View(remove)
list(remove)
[[1]]
97 237 1392 650 1614 1653 1697 1657 1671 1633 1707 1790 1636
1639 1641 1686 1319 1429 1432 1414 1417 1419 1446
627 783 903 1138 1245 1258 1259 1264 1282 1287 1289 1291 1293
1299 1305 1306 1662 1794 1802 1825 1841 1849 1850
x = x[-remove,]
y = y[-remove,]
g = g[-remove,]
sex = sex.predict(x, y, MM_snps, plot=T)
list(sex)
View(sex)
# All of the HS sample IDs are numbers.
fndr.idx = which(is.na(as.numeric(rownames(x))))
samp.idx = which(!is.na(as.numeric(rownames(x))))
fsex = sex[fndr.idx]
sex = sex[samp.idx]
fx = x[fndr.idx,]
fy = y[fndr.idx,]
fg = g[fndr.idx,]
x = x[samp.idx,]
y = y[samp.idx,]
g = g[samp.idx,]
# A: A/J
# B: AKR/J
# C: BALB/cJ
# D: C3H/HeJ
# E: C57BL/6J
# F: CBA/J
# G: DBA/2J
# H: LP/J
#This needs to be specific for the data set and in order
code = c("HH", "EE", "AA", "BB", "CC", "FF", "DD", "GG")
names(code) = rownames(fx)
gen = rep(70, nrow(x))
names(gen) = rownames(x)
states = DOQTL:::create.genotype.states(LETTERS[1:8])
data = list(geno = as.matrix(g), sex = sex, gen = gen)
founders = list(geno = fg, sex = fsex, code = code, states = states)
# We only have male founders.
# For the allele call method, we're going to fake out the HMM by duplicating
# the males and calling them females.
founders$geno = as.matrix(rbind(founders$geno, founders$geno))
founders$sex = c(founders$sex, rep("F", length(founders$sex)))
names(founders$sex) = rownames(founders$geno)
founders$code = c(founders$code, founders$code)
names(founders$code) = rownames(founders$geno)
#
attr(founders, "method") = "allele"
founders = add.missing.F1s(founders, MM_snps[,1:4])
getwd()
ls()
setwd("/Users/elijahedmondson/Desktop/R/QTL/WD")
getwd()
list.files("/Users/elijahedmondson/Desktop/R/QTL/WD")
calc.genoprob(data = data, chr = c(1:19, "X"), output.dir = "/Users/elijahedmondson/Desktop/R/QTL/HMM",
plot = T, array = "megamuga", sampletype = "HS", method = "allele", founders = founders)
plot.genoprobs(x = prsmth, snps = MM_snps, main = "1696")
recomb = summarize.genotype.transitions(path = "/Users/elijahedmondson/Desktop/R/QTL/HMM", snps = MM_snps)
head(recomb[[1]])
View(recomb)
mean(sapply(recomb, nrow))
#SECOND STEP
library(DOQTL)
setwd("/Users/elijahedmondson/Desktop/R/QTL/WD")
getwd()
list.files("/Users/elijahedmondson/Desktop/R/QTL/WD")
load(file = "/Users/elijahedmondson/Desktop/R/QTL/HMM/founder.probs.Rdata")
load(url("ftp://ftp.jax.org/MUGA/MM_snps.Rdata"))
#EFE add "bychr = TRUE"
K = kinship.probs(model.probs, bychr = TRUE, snps = MM_snps)
#can you plot?
pheno = data.frame(row.names = Sarcomatoid$row.names, sex = as.numeric(Sarcomatoid$Sex == "M"),
sarcomatoid = as.numeric(Sarcomatoid$sarcomatoid))
pheno = data.frame(row.names = GRSD.phenotype$row.names, sex = as.numeric(GRSD.phenotype$Sex == "M"),
Age = as.numeric(GRSD.phenotype$days),
Weight = GRSD.phenotype$weight,
BCS = GRSD.phenotype$BCS,
Albino = as.numeric(GRSD.phenotype$albino),
Amyloidosis = as.numeric(GRSD.phenotype$amyloidosis),
Lymphoma = as.numeric(GRSD.phenotype$lymphoma),
Harderian = as.numeric(GRSD.phenotype$harderian.gland),
Histiocytic.sarcoma = as.numeric(GRSD.phenotype$histiocytic.sarcoma),
AML = as.numeric(GRSD.phenotype$myeloid.leukemia),
LSA.AML = as.numeric(GRSD.phenotype$lymphoma.or.leukemia),
Lymphoid.leukemia = as.numeric(GRSD.phenotype$lymphoid.leukemia),
Pituitary.adenoma = as.numeric(GRSD.phenotype$pituitary.adenoma),
HCC = as.numeric(GRSD.phenotype$HCC),
Pulmonary.adenocarcinoma = as.numeric(GRSD.phenotype$pulmonary.adenocarcinoma),
Mammary.adenocarcinoma = as.numeric(GRSD.phenotype$mammary.adenocarcinoma),
GCT = as.numeric(GRSD.phenotype$GCT),
OSA = as.numeric(GRSD.phenotype$OSA),
Sarcoma = as.numeric(GRSD.phenotype$sarcoma),
HSA = as.numeric(GRSD.phenotype$HSA),
Metastasis = as.numeric(GRSD.phenotype$metastasis),
Solid.tumors = as.numeric(GRSD.phenotype$Solid.tumors))
covar = data.frame(sex = as.numeric(Sarcomatoid$Sex == "M"))
rownames(covar) = rownames(pheno)
qtl = scanone(pheno = pheno, pheno.col = "sarcomatoid", probs = model.probs, K = K,
addcovar = covar, snps = MM_snps)
save(qtl, file = "")
plot(qtl, main = "EMT")
perms = scanone.perm(pheno = pheno, pheno.col = "sarcomatoid", probs = model.probs, addcovar = covar,
snps = MM_snps, path = "/Users/elijahedmondson/Desktop/R/QTL/perms",
nperm = 1000)
save(perms, file = "Sarcomatoid.Rdata")
#scanone.perm(n=10) takes about 1 hour
thr1 = quantile(perms, probs = 0.90)
thr2 = quantile(perms, probs = 0.95)
thr3 = quantile(perms, probs = 0.99)
plot(AM.qtl, sig.thr = c(thr1, thr2, thr3), main = "Epithelial to Mesenchymal Transition")
setwd("/Users/elijahedmondson/Desktop/R/QTL/WD")
getwd()
save(perms, file = "SarcomatoidPerms.Rdata")
save(qtl, file = "SarcomatoidQTL.Rdata")
list.files("/Users/elijahedmondson/Desktop/R/QTL/WD")
interval = bayesint(AM.qtl, chr = 14)
interval
mgi = get.mgi.features(chr = interval[1,2], start = interval[1,3], end = interval[3,3],
type = "gene", source = "MGI")
nrow(mgi)
head(mgi)
ma = assoc.map(pheno = pheno, pheno.col = "albino", probs = model.probs, K = K, addcovar = covar,
snps = MM_snps, chr = 7, start = 87, end = 88)
coefplot(qtl, chr = 1)
tmp = assoc.plot(ma, thr = 7)
unique(tmp$sdps)
load(file = "/Users/elijahedmondson/Desktop/R/QTL/WD/GRSD.K.model.probs.RData")
load(file = "")
load(file = "")
load(file = "")
library(DOQTL)