-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNFAT_condrocytes_RNAseq.Rmd
132 lines (102 loc) · 4 KB
/
NFAT_condrocytes_RNAseq.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
---
title: "DE_condrocytes"
author: "mehul_maggie"
date: "25/09/2021"
output: html_document
---
```{r setup, include=FALSE}
# set work directory
library(limma)
library(readxl)
library(dplyr)
library(pheatmap)
library(edgeR)
```
## Preprocess and batch correct
```{r}
#add rawcounts
rawcounts <- read_excel("rawcounts.xlsx") %>% as.data.frame()
counts <- as.data.frame(rawcounts)
rownames(counts) <- counts[,1]
counts <- counts[,-1]
# Normalized counts
dge <- DGEList(counts, remove.zeros = TRUE)
dge <- calcNormFactors(object = dge, method = "TMM")
normCounts <- cpm(dge, normalized.lib.sizes=TRUE)
y <- as.data.frame(normCounts)
#add design matrix
design_cpm <- read_excel("design_cpm.xlsx") %>% as.data.frame()
des <- as.data.frame(design_cpm)
filtergenes <- filterByExpr(normCounts, des, min.count = 0.5, min.total.count = 2, min.prop = 0.7)
x <- as.data.frame(filtergenes)
#write.table(filtergenes, "filter.txt")
genes <- rownames(y)
genes <- as.data.frame(genes)
a <- c(genes,x,y)
a <- as.data.frame(a)
filtered <- subset(a, filtergenes!="FALSE")
filtered_norm <- as.data.frame(filtered)
rownames(filtered_norm) <- filtered_norm[,1]
filtered_norm <- filtered_norm[,-1]
filtered_norm_final <- filtered_norm[2:19]
#write.table(filtered_norm_final, "filter_refined.txt")
#write.table(filtered_norm_final, "filter_refined.csv")
counts_logtrans <- log2(filtered_norm_final + 1)
batch <- c("A","B","C","A","B","C","A","B","C","A","B","C","A","B","C","A","B","C")
batch_correct <- removeBatchEffect(counts_logtrans, batch)
#write.table(batch_correct, "batch_corrected_good_final.csv")
```
## DE
```{r}
data <- as.data.frame(batch_correct)
#rownames(data) <- data[, 1]
data <- data[, 1:18]
meta <- as.data.frame(colnames(data))
meta$stim <- gsub(".*_", "", meta$`colnames(data)`) %>%
factor(., levels = c("unstim", "IL1B", "PMAIono"))
meta$id <- gsub("[0-9].*", "", meta$`colnames(data)`) %>%
factor(., levels = c("Res", "P"))
meta$day <- gsub("P|Res", "", meta$`colnames(data)`) %>%
gsub("_.*", "", .) %>%
as.factor()
rownames(meta) <- meta$`colnames(data)`
meta <- meta[, c("id", "stim", "day")]
# PMA-Ionomycin: Patient vs rescue
test.met <- meta[meta$stim == "PMAIono", ]
test.dat <- data[, rownames(test.met)]
design <- model.matrix(~ id + day, data = test.met)
fit <- lmFit(test.dat, design)
fit <- eBayes(fit)
PMAiono_hits <- topTable(fit, coef = 2, p.value = 0.025, number = 1000) # Patient - Rescue
#topTable(fit, coef = 3, number = 30) # day2
#topTable(fit, coef = 4, number = 30) # day3
# IL1B: Patient vs rescue
test.met <- meta[meta$stim == "IL1B", ]
test.dat <- data[, rownames(test.met)]
design <- model.matrix(~ id + day, data = test.met)
fit <- lmFit(test.dat, design)
fit <- eBayes(fit)
IL1B_hits <-topTable(fit, coef = 2, p.value = 0.025, number = 1000) # Patient - Rescue
#topTable(fit, coef = 3, number = 30) # day2
#topTable(fit, coef = 4, number = 30) # day3
# Unstim: Patient vs rescue
test.met <- meta[meta$stim == "unstim", ]
test.dat <- data[, rownames(test.met)]
design <- model.matrix(~ id + day, data = test.met)
fit <- lmFit(test.dat, design)
fit <- eBayes(fit)
Unstim_hits <- topTable(fit, coef = 2, p.value = 0.025, number = 1000) # Patient - Rescue
#topTable(fit, coef = 3, number = 30) # day2
#topTable(fit, coef = 4, number = 30) # day3
all_genes <- c(rownames(PMAiono_hits), rownames(IL1B_hits), rownames(Unstim_hits)) %>% unique()
#all_genes1 <- c(rownames(PMAiono_hits), rownames(IL1B_hits), rownames(Unstim_hits))
#write.csv(all_genes1, "test.csv")
```
```{r}
meta <- meta[c(1:3, 7:9, 4:6, 10:12, 16:18, 13:15),]
#meta <- meta[c(1:3, 10:12, 7:9, 16:18, 4:6, 13:15), ]
data <- data[, rownames(meta)]
colorPalette <- c("blue", "blue", "white", "red", "red")
colorPalette <- colorRampPalette(colors = colorPalette)(100)
pheatmap(data[all_genes, ], annotation = meta[, -3], scale = "row", cluster_cols = F, fontsize_row = 12, color = colorPalette, border_color = "white")
```