-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay1.Rmd
275 lines (181 loc) · 6.29 KB
/
Day1.Rmd
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
---
title: "UT_Hackathon Start"
author: "D. Ford Hannum Jr."
date: "4/14/2021"
output:
html_document:
toc: true
toc_depth: 3
number_sections: false
theme: united
highlight: tango
---
```{r setup, include=TRUE, message=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE)
library(data.table)
library(ggplot2)
```
# Introduction
Welcome to the First Annual ABCB/CDRL Bioinformatics Hackathon.
We are at the first stage: Dataset Reveal.
The dataset that we are using this year is a personal favorite dataset of mine. This dataset is a transcriptomic dataset of post-mortem brain samples. There are three brain regions (Nucleus Accumbens, Dorolateral Prefrontal Cortex and Anterior Cingulate Gyrus) across four disease states Major Depressive Disorder, Bipolar Affective Disorder, Schizophrenia and Controls). There is demographic data available and the data itself comes from Pritzker Brain Bank. The dataset is GSE80655 (https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE80655).
The dataset is available at this history on the galaxy server: https://usegalaxy.org/u/asimami/h/abcbcdrl-hackathon-2021
There are two pre-loaded files.
1. GSE80655-Count-Data.csv
This file has the gene counts. This was mapped against GRCh38 using the latest ENSEMBL file.
2. GSE80655-Sample-Metadata.csv
This file has all the available and relevant metadata, including things like RNA Integrity Number, Post-Mortem Interval, Race and ethnicity and sequencing data
```{r}
getwd()
data <- read.csv('/Users/dfhannum/Desktop/UT_Hackathon/data/Galaxy1-[GSE80655-Count-Data.csv].csv')
dim(data)
md <- read.csv('/Users/dfhannum/Desktop/UT_Hackathon/data/Galaxy2-[GSE80655-Sample-Metadata.csv].csv')
dim(md)
```
First thing is the columns in data and the rows in md have different sizes.
```{r}
summary(colnames(data) %in% md$Sample.ID)
summary(md$Sample.ID %in% colnames(data))
multi.samples <- md$Sample.ID[duplicated(md$Sample.ID)]
# head(md[md$Sample.ID %in% multi.samples,])
```
It looks like in the meta data file there are repeated samples that have two different runs. The only things that change between the rows is: Run, Bases, and Bytes. For the most part this shouldn't be an issue because we weren't
thinking of using these as covariates. So removing the duplicated rows.
```{r}
md <- md[!duplicated(md$Sample.ID),]
summary(md$Sample.ID %in% colnames(data))
summary(colnames(data) %in% md$Sample.ID)
dim(md)
dim(data)
```
No the data has a 1-1 orientation.
# Looking at Sample Read Depth
```{r}
head(data[1:5,1:5])
rownames(data) <- data[,1]
data <- data[,-1]
head(data[1:5,1:5])
```
```{r}
summary(colnames(data) == md$Sample.ID)
md$sample.depth <- colSums(data)
summary(md$sample.depth)
ggplot(md, aes(x = Bytes, y = sample.depth)) + geom_point()
ggplot(md, aes(x = sample.depth, color = clinical_diagnosis)) + geom_density()
```
# Normalizing to TPM
```{r}
data.raw <- data
data.tpm <- data
for (i in 1:dim(data.tpm)[2]){
# print(colnames(data.tpm)[i])
data.tpm[,i] <- data.tpm[,i] * 1000000 / md$sample.depth[i]
}
data.tpm[1:5,1:5]
```
# Highly Variable Genes
```{r}
RowVar <- function(x, ...) {
rowSums((x - rowMeans(x, ...))^2, ...)/(dim(x)[2] - 1)
}
gene.variances <- RowVar(data.tpm)
top2k.genes <- names(gene.variances[order(gene.variances, decreasing = T)][1:2000])
```
# PCA of TPM
Checking to see if our different clinical things can be distinguished in PCA
## All Genes
```{r}
pc <- prcomp(data.tpm)
pc.vars <- pc$rotation
md$pc1.all <- pc.vars[,1]
md$pc2.all <- pc.vars[,2]
ggplot(md, aes( x= pc1.all, y = pc2.all, color = clinical_diagnosis,
shape = brain_region)) +
geom_point() +
theme_bw()
```
## Top 2K Genes
```{r}
pc <- prcomp(data.tpm[top2k.genes,])
pc.vars <- pc$rotation
md$pc1.hv <- pc.vars[,1]
md$pc2.hv <- pc.vars[,2]
ggplot(md, aes( x= pc1.hv, y = pc2.hv, color = clinical_diagnosis,
shape = brain_region)) +
geom_point() +
theme_bw()
class(pc.vars)
pc.vars <- as.data.frame(pc.vars)
pc.vars$diag <- md$clinical_diagnosis
```
# PCA of Raw
Checking to see if our different clinical things can be distinguished in PCA
## All Genes
```{r}
pc <- prcomp(data.raw)
pc.vars <- pc$rotation
md$pc1.all <- pc.vars[,1]
md$pc2.all <- pc.vars[,2]
ggplot(md, aes( x= pc1.all, y = pc2.all, color = clinical_diagnosis,
shape = brain_region)) +
geom_point() +
theme_bw()
```
## Top 2K Genes
```{r}
pc <- prcomp(data.raw[top2k.genes,])
dim(pc$rotation)
pcs <- pc$rotation[,1:20]
pc.vars <- pc$rotation
md$pc1.hv <- pc.vars[,1]
md$pc2.hv <- pc.vars[,2]
ggplot(md, aes( x= pc1.hv, y = pc2.hv, color = clinical_diagnosis)) +
geom_point() +
theme_bw()
ggplot(md, aes( x= pc1.hv, y = pc2.hv, color = clinical_diagnosis)) +
geom_point(aes(shape = brain_region)) +
theme_bw()
```
```{r}
# head(md)
```
PCs aren't really picking anything out
# UMAP
## TPM HV Genes
```{r}
# install.packages('umap')
library(umap)
data.tpm.hv.umap <- umap(t(data.tpm[top2k.genes,]))
md$umap.tpm.hv.1 <- data.tpm.hv.umap$layout[,1]
md$umap.tpm.hv.2 <- data.tpm.hv.umap$layout[,2]
ggplot(md, aes(x = umap.tpm.hv.1, y = umap.tpm.hv.2,
color = clinical_diagnosis, shape = brain_region)) +
geom_point() + theme_bw()
colnames(md)
v.o.i <- c(4,10,11,13, 14, 19, 21) # variables of interest
for (i in v.o.i){
i <- colnames(md)[i]
print(ggplot(md, aes_string(x = 'umap.tpm.hv.1', y = 'umap.tpm.hv.2',
color = i)) +
geom_point() + theme_bw() + ggtitle(i))
}
```
## TPM All Genes
```{r}
# install.packages('umap')
# library(umap)
data.tpm.hv.umap <- umap(t(data.tpm))
md$umap.tpm.hv.1 <- data.tpm.hv.umap$layout[,1]
md$umap.tpm.hv.2 <- data.tpm.hv.umap$layout[,2]
ggplot(md, aes(x = umap.tpm.hv.1, y = umap.tpm.hv.2,
color = clinical_diagnosis, shape = brain_region)) +
geom_point() + theme_bw()
# colnames(md)
v.o.i <- c(4,10,11,13, 14, 19, 21) # variables of interest
for (i in v.o.i){
i <- colnames(md)[i]
print(ggplot(md, aes_string(x = 'umap.tpm.hv.1', y = 'umap.tpm.hv.2',
color = i)) +
geom_point() + theme_bw() + ggtitle(i))
}
```