forked from hbctraining/Training-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRscript.R
61 lines (49 loc) · 1.84 KB
/
Rscript.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
# Set-up libraries and data
## Load libraries
library(tidyverse)
library(pheatmap)
## Load data
load("data/Rmarkdown_data.Rdata")
# Top 20 significant genes
## Get names of top 20 genes
top20_sigOE_genes <- res_tableOE_tb %>%
arrange(padj) %>% #Arrange rows by padj values
pull(gene) %>% #Extract character vector of ordered genes
head(n=20)
## normalized counts for top 20 significant genes
top20_sigOE_norm <- normalized_counts %>%
filter(gene %in% top20_sigOE_genes)
## Gathering the columns to have normalized counts to a single column
gathered_top20_sigOE <- top20_sigOE_norm %>%
gather(colnames(top20_sigOE_norm)[2:9], key = "samplename", value = "normalized_counts")
gathered_top20_sigOE <- inner_join(mov10_meta, gathered_top20_sigOE)
## plot using ggplot2
ggplot(gathered_top20_sigOE) +
geom_point(aes(x = gene, y = normalized_counts, color = sampletype)) +
scale_y_log10() +
xlab("Genes") +
ylab("log10 Normalized Counts") +
ggtitle("Top 20 Significant DE Genes") +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme(plot.title = element_text(hjust = 0.5))
# Create a heatmap of the differentially expressed genes
## Extract normalized expression for significant genes from the OE and control samples (2:4 and 7:9)
res_tableOE_tb_sig <- res_tableOE_tb %>%
filter(padj < 0.05)
## Return the normalized counts for the significant DE genes
norm_OEsig <- normalized_counts %>%
filter(gene %in% res_tableOE_tb_sig$gene)
meta <- mov10_meta %>%
column_to_rownames("samplename") %>%
data.frame()
## Run pheatmap using the metadata data frame for the annotation
pheatmap(norm_OEsig[2:9],
cluster_rows = T,
show_rownames = F,
annotation = meta,
border_color = NA,
fontsize = 10,
scale = "row",
fontsize_row = 10,
height = 20)