-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_bsp1_and_bsp3.R
253 lines (212 loc) · 11.4 KB
/
process_bsp1_and_bsp3.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
library('SummarizedExperiment')
library('sva')
library('jaffelab')
library('sessioninfo')
## Create directories
dir.create('brainseq_phase1_qsv', showWarnings = FALSE)
dir.create('brainseq_phase1_qsv/pdf', showWarnings = FALSE)
dir.create('brainseq_phase1_qsv/rdas', showWarnings = FALSE)
dir.create('brainseq_phase3_qsv', showWarnings = FALSE)
dir.create('brainseq_phase3_qsv/pdf', showWarnings = FALSE)
dir.create('brainseq_phase3_qsv/rdas', showWarnings = FALSE)
## BSP1
load('/dcl01/lieber/RNAseq/Datasets/BrainSeq_hg38/Phase1/Counts/degradation_rse_BrainSeq_Phase1_hg38.rda', verbose = TRUE)
## Add genotype data
load('/dcl01/lieber/RNAseq/Datasets/BrainSeq_hg38/Phase1/genotype_data/brainseq_phase1_Genotypes_n732.rda', verbose = TRUE)
## Match brains to genotype
m_geno <- match(colData(cov_rse)$BrNum, rownames(mds))
stopifnot(all(!is.na(m_geno)))
colData(cov_rse) <- cbind(colData(cov_rse), mds[m_geno, 1:10])
## Fix mitoRate, rRNA_rate and totalAssignedGene
colData(cov_rse)$mitoRate = sapply(colData(cov_rse)$mitoRate,mean)
colData(cov_rse)$rRNA_rate = sapply(colData(cov_rse)$rRNA_rate,mean)
colData(cov_rse)$totalAssignedGene = sapply(colData(cov_rse)$totalAssignedGene,mean)
## Drop age 17 or less
keepIndex <- which(colData(cov_rse)$Age > 17)
length(keepIndex)
# [1] 614
cov_rse <- cov_rse[, keepIndex]
with(colData(cov_rse), table(Dx))
# Dx
# Bipolar Control MDD Schizo
# 67 221 147 179
## Find qsvs
mod <- model.matrix(
~ Dx + Age + Sex + mitoRate + rRNA_rate + totalAssignedGene + RIN + snpPC1 + snpPC2 +snpPC3 + snpPC4 + snpPC5,
data = colData(cov_rse)
)
## get qSVs for top bonferroni
qsvBonf = prcomp(t(log2(assays(cov_rse)$counts+1)))
##qsva
k = num.sv(log2(assays(cov_rse)$counts+1), mod)
k
# 13
qSVs = qsvBonf$x[,1:k]
getPcaVars(qsvBonf)[1:k]
# [1] 76.300 7.150 3.120 1.680 0.970 0.923 0.667 0.516 0.448 0.425
# [11] 0.394 0.335 0.318
modQsva = cbind(mod, qSVs)
pdf('/dcl01/ajaffe/data/lab/qsva_brain/brainseq_phase1_qsv/pdf/qsvs_var_explained_age17.pdf', useDingbats = FALSE)
plot(getPcaVars(qsvBonf)[1:k], pch=20)
dev.off()
save(qsvBonf, qSVs, mod, modQsva, keepIndex, file = '/dcl01/ajaffe/data/lab/qsva_brain/brainseq_phase1_qsv/rdas/brainseq_phase1_qsvs_age17.Rdata')
## BSP1 later just load this object ^^
## Save subsetted cov_rse with the snpPCs already added
save(cov_rse, file = '/dcl01/ajaffe/data/lab/qsva_brain/brainseq_phase1_qsv/rdas/brainseq_phase1_cov_rse_age17.Rdata')
## BSP2 (qSVs on HIPPO only)
load('/dcl01/ajaffe/data/lab/qsva_brain/brainseq_phase2_qsv/rdas/brainseq_phase2_qsvs_age17_noHGold_HIPPO.Rdata', verbose = TRUE)
dim(qSVs)
# [1] 333 16
head(qSVs)
## If you need HIPPO ages <=17 and the HGold then you need to redo the qSVs without filtering. See:
## https://github.com/LieberInstitute/qsva_brain/blob/master/brainseq_phase2_qsv/make_qSVs.R#L129-L181
## BSP3
load('/dcl01/lieber/RNAseq/Datasets/BrainSeq_hg38/Phase3/count_data/degradation_rse_phase3_caudate.rda', verbose = TRUE)
## Add genotype data
load('/dcl01/lieber/RNAseq/Datasets/BrainSeq_hg38/Phase3/genotype_data/BrainSeq_Phase3_Caudate_RiboZero_MDSonly_n464.rda', verbose = TRUE)
## Use the gene-level metadata information
load('/dcl01/lieber/RNAseq/Datasets/BrainSeq_hg38/Phase3/count_data/caudate_brainseq_phase3_hg38_rseGene_merged_n464.rda', verbose = TRUE)
## Match by sample id
m <- match(colData(cov_rse_caudate)$sample, sapply(colData(rse_gene)$SAMPLE_ID, '[', 1))
## Check that all samples matched
stopifnot(all(!is.na(m)))
## Replace the degradation RSE colData() with the gene-level one
colData(cov_rse_caudate) <- colData(rse_gene)[m, ]
## Match brains to genotype
m_geno <- match(colData(cov_rse_caudate)$RNum, rownames(mds))
stopifnot(all(!is.na(m_geno)))
colData(cov_rse_caudate) <- cbind(colData(cov_rse_caudate), mds[m_geno, 1:10])
## Fix mitoRate, rRNA_rate and totalAssignedGene
colData(cov_rse_caudate)$mitoRate = sapply(colData(cov_rse_caudate)$mitoRate,mean)
colData(cov_rse_caudate)$rRNA_rate = sapply(colData(cov_rse_caudate)$rRNA_rate,mean)
colData(cov_rse_caudate)$totalAssignedGene = sapply(colData(cov_rse_caudate)$totalAssignedGene,mean)
## Drop age 17 or less
ncol(cov_rse_caudate)
# [1] 464
keepIndex <- which(colData(cov_rse_caudate)$Age > 17)
length(keepIndex)
# [1] 438
cov_rse_caudate <- cov_rse_caudate[, keepIndex]
with(colData(cov_rse_caudate), table(Dx))
# Dx
# Bipolar Control Schizo
# 44 240 154
## Find qsvs
mod <- model.matrix(
~ Dx + Age + Sex + mitoRate + rRNA_rate + totalAssignedGene + RIN + snpPC1 + snpPC2 +snpPC3 + snpPC4 + snpPC5,
data = colData(cov_rse_caudate)
)
## get qSVs for top bonferroni
qsvBonf = prcomp(t(log2(assays(cov_rse_caudate)$counts+1)))
##qsva
k = num.sv(log2(assays(cov_rse_caudate)$counts+1), mod)
k
# [1] 17
qSVs = qsvBonf$x[,1:k]
getPcaVars(qsvBonf)[1:k]
# [1] 38.200 6.970 3.340 1.990 1.610 1.490 1.150 1.100 0.877 0.833
# [11] 0.807 0.658 0.569 0.514 0.468 0.451 0.414
modQsva = cbind(mod, qSVs)
pdf('/dcl01/ajaffe/data/lab/qsva_brain/brainseq_phase3_qsv/pdf/qsvs_var_explained_age17.pdf', useDingbats = FALSE)
plot(getPcaVars(qsvBonf)[1:k], pch=20)
dev.off()
save(qsvBonf, qSVs, mod, modQsva, keepIndex, file = '/dcl01/ajaffe/data/lab/qsva_brain/brainseq_phase3_qsv/rdas/brainseq_phase3_qsvs_age17.Rdata')
## BSP3 later just load this object ^^
## Save subsetted cov_rse_caudate with the snpPCs already added
save(cov_rse_caudate, file = '/dcl01/ajaffe/data/lab/qsva_brain/brainseq_phase3_qsv/rdas/brainseq_phase3_cov_rse_caudate_age17.Rdata')
## Reproducibility information
print('Reproducibility information:')
Sys.time()
proc.time()
options(width = 120)
session_info()
# ─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
# setting value
# version R version 3.5.3 Patched (2019-03-11 r76311)
# os Red Hat Enterprise Linux Server release 6.9 (Santiago)
# system x86_64, linux-gnu
# ui X11
# language (EN)
# collate en_US.UTF-8
# ctype en_US.UTF-8
# tz US/Eastern
# date 2019-06-03
#
# ─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
# package * version date lib source
# annotate 1.60.1 2019-03-07 [1] Bioconductor
# AnnotationDbi 1.44.0 2018-10-30 [1] Bioconductor
# assertthat 0.2.1 2019-03-21 [2] CRAN (R 3.5.1)
# Biobase * 2.42.0 2018-10-30 [2] Bioconductor
# BiocGenerics * 0.28.0 2018-10-30 [1] Bioconductor
# BiocParallel * 1.16.6 2019-02-10 [1] Bioconductor
# bit 1.1-14 2018-05-29 [2] CRAN (R 3.5.1)
# bit64 0.9-7 2017-05-08 [2] CRAN (R 3.5.0)
# bitops 1.0-6 2013-08-17 [2] CRAN (R 3.5.0)
# blob 1.1.1 2018-03-25 [2] CRAN (R 3.5.0)
# cli 1.1.0 2019-03-19 [1] CRAN (R 3.5.3)
# colorout * 1.2-0 2018-05-02 [1] Github (jalvesaq/colorout@c42088d)
# colorspace 1.4-1 2019-03-18 [2] CRAN (R 3.5.1)
# crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.0)
# DBI 1.0.0 2018-05-02 [2] CRAN (R 3.5.0)
# DelayedArray * 0.8.0 2018-10-30 [2] Bioconductor
# digest 0.6.18 2018-10-10 [1] CRAN (R 3.5.1)
# dplyr 0.8.0.1 2019-02-15 [1] CRAN (R 3.5.1)
# genefilter * 1.64.0 2018-10-30 [1] Bioconductor
# GenomeInfoDb * 1.18.2 2019-02-12 [1] Bioconductor
# GenomeInfoDbData 1.2.0 2018-11-02 [2] Bioconductor
# GenomicRanges * 1.34.0 2018-10-30 [1] Bioconductor
# ggplot2 3.1.0 2018-10-25 [1] CRAN (R 3.5.1)
# glue 1.3.1 2019-03-12 [1] CRAN (R 3.5.1)
# gtable 0.3.0 2019-03-25 [2] CRAN (R 3.5.1)
# htmltools 0.3.6 2017-04-28 [2] CRAN (R 3.5.0)
# htmlwidgets 1.3 2018-09-30 [1] CRAN (R 3.5.1)
# httpuv 1.5.0 2019-03-15 [2] CRAN (R 3.5.1)
# IRanges * 2.16.0 2018-10-30 [1] Bioconductor
# jaffelab * 0.99.21 2018-05-03 [1] Github (LieberInstitute/jaffelab@7ed0ab7)
# jsonlite 1.6 2018-12-07 [2] CRAN (R 3.5.1)
# later 0.8.0 2019-02-11 [2] CRAN (R 3.5.1)
# lattice 0.20-38 2018-11-04 [3] CRAN (R 3.5.3)
# lazyeval 0.2.2 2019-03-15 [2] CRAN (R 3.5.1)
# limma 3.38.3 2018-12-02 [1] Bioconductor
# magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.0)
# Matrix 1.2-15 2018-11-01 [3] CRAN (R 3.5.3)
# matrixStats * 0.54.0 2018-07-23 [1] CRAN (R 3.5.1)
# memoise 1.1.0 2017-04-21 [2] CRAN (R 3.5.0)
# mgcv * 1.8-27 2019-02-06 [3] CRAN (R 3.5.3)
# munsell 0.5.0 2018-06-12 [2] CRAN (R 3.5.1)
# nlme * 3.1-137 2018-04-07 [3] CRAN (R 3.5.3)
# pillar 1.3.1 2018-12-15 [1] CRAN (R 3.5.1)
# pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.5.1)
# plyr 1.8.4 2016-06-08 [2] CRAN (R 3.5.0)
# png 0.1-7 2013-12-03 [2] CRAN (R 3.5.0)
# promises 1.0.1 2018-04-13 [2] CRAN (R 3.5.0)
# purrr 0.3.2 2019-03-15 [2] CRAN (R 3.5.1)
# R6 2.4.0 2019-02-14 [2] CRAN (R 3.5.1)
# rafalib * 1.0.0 2015-08-09 [1] CRAN (R 3.5.0)
# RColorBrewer 1.1-2 2014-12-07 [2] CRAN (R 3.5.0)
# Rcpp 1.0.1 2019-03-17 [1] CRAN (R 3.5.3)
# RCurl 1.95-4.12 2019-03-04 [2] CRAN (R 3.5.1)
# rlang 0.3.3 2019-03-29 [1] CRAN (R 3.5.3)
# rmote * 0.3.4 2018-05-02 [1] deltarho (R 3.5.0)
# RSQLite 2.1.1 2018-05-06 [2] CRAN (R 3.5.0)
# S4Vectors * 0.20.1 2018-11-09 [1] Bioconductor
# scales 1.0.0 2018-08-09 [2] CRAN (R 3.5.1)
# segmented 0.5-3.0 2017-11-30 [2] CRAN (R 3.5.0)
# servr 0.13 2019-03-04 [1] CRAN (R 3.5.1)
# sessioninfo * 1.1.1 2018-11-05 [1] CRAN (R 3.5.1)
# SummarizedExperiment * 1.12.0 2018-10-30 [1] Bioconductor
# survival 2.43-3 2018-11-26 [3] CRAN (R 3.5.3)
# sva * 3.30.1 2019-01-04 [2] Bioconductor
# tibble 2.1.1 2019-03-16 [1] CRAN (R 3.5.3)
# tidyselect 0.2.5 2018-10-11 [2] CRAN (R 3.5.1)
# withr 2.1.2 2018-03-15 [2] CRAN (R 3.5.0)
# xfun 0.6 2019-04-02 [1] CRAN (R 3.5.3)
# XML 3.98-1.19 2019-03-06 [2] CRAN (R 3.5.1)
# xtable 1.8-3 2018-08-29 [2] CRAN (R 3.5.1)
# XVector 0.22.0 2018-10-30 [1] Bioconductor
# zlibbioc 1.28.0 2018-10-30 [2] Bioconductor
#
# [1] /users/lcollado/R/x86_64-pc-linux-gnu-library/3.5.x
# [2] /jhpce/shared/jhpce/core/conda/miniconda-3/envs/svnR-3.5.x/R/3.5.x/lib64/R/site-library
# [3] /jhpce/shared/jhpce/core/conda/miniconda-3/envs/svnR-3.5.x/R/3.5.x/lib64/R/library