-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStep08_DiffMarkers.R
More file actions
141 lines (128 loc) · 7.19 KB
/
Step08_DiffMarkers.R
File metadata and controls
141 lines (128 loc) · 7.19 KB
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
##############################################################################################################################
# Expression data in rat, mouse and human muscle, L6, C2C12 and human myotubes ========
##############################################################################################################################
library(here)
library(ggplot2)
library(ggrepel)
library(ggfortify)
library(gplots)
library(stringr)
library(grid)
library(gridExtra)
#cbPalette <- c("#E69F00", "#0072B2", "#CC79A7", "#009E73", "#D3C839", "#BC5300", "#84C4E8", "#000000") #color palette for colorblind people
cbPalette <- c("#56B4E9", "#D3C839", "#CC79A7", "#0072B2", "#E69F00", "#D55E00") #color palette for colorblind people
# light blue yellow pink dark blue orange red
cbShapes <- c( 21 , 21 , 24 , 24 , 22 , 22 , 23 , 23 )
cbLines <- c( 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' )
#load data and define samples
res <- readRDS(here("Data_Processed", "GENENAME_norm.Rds"))
res <- cbind(res[grep('HumanCell', colnames(res))],
res[grep('MouseC2C12', colnames(res))],
res[grep('RatL6', colnames(res))],
res[grep('HumanTissue', colnames(res))],
res[grep('MouseTissue', colnames(res))],
res[grep('RatTissue', colnames(res))])
Sample <- c(rep("Human Myotube", length(grep('HumanCell', colnames(res)))),
rep("Mouse C2C12", length(grep('MouseC2C12', colnames(res)))),
rep("Rat L6", length(grep('RatL6', colnames(res)))),
rep("Human Tissue", length(grep('HumanTissue', colnames(res)))), #list of sample types
rep("Mouse Tissue", length(grep('MouseTissue', colnames(res)))),
rep("Rat Tissue", length(grep('RatTissue', colnames(res)))))
#======================================================================================================
# Function to make boxplots
#======================================================================================================
PlotFunction <- function(genename) {
data <- data.frame() #create an empty dataframe to collect data
for( i in 1:length(genename)) {
y <- as.numeric(res[genename[i],]) #collect data for gene name i
datay <- cbind.data.frame(Sample, y, rep(genename[i])) #create table with x="sample type", y="data", "gene name"
colnames(datay) <- c("x","y","Gene") #rename column names to make it possible to rbind later
data <- rbind.data.frame(data, datay) #bind the new gene data at the bottom of the previous one
}
data$x <- factor(data$x, levels=c("Human Myotube", "Mouse C2C12", "Rat L6",
"Human Tissue", "Mouse Tissue", "Rat Tissue")) #for a box plot, x should be a factor
ggplot(data, aes(x=x, y=y, fill=x)) +
geom_boxplot() +
labs(x="",
y=paste(genename, "expression, log2")) +
theme_bw() +
theme(plot.title = element_text(face="bold", color="black", size=7, angle=0),
axis.text.x = element_text(color="black", size=6, angle=45, hjust=1),
axis.text.y = element_text(color="black", size=6, angle=0),
axis.title = element_text(face="bold", color="black", size=7, angle=0),
legend.text = element_text(face="bold", color="black", size=6, angle=0),
legend.position="none", legend.title = element_blank()) +
scale_fill_manual(values=cbPalette) +
scale_color_manual(values=cbPalette)
}
#======================================================================================================
# Gene markers of differentiation
#======================================================================================================
library(grid)
library(gridExtra)
png(filename=here("Figures", "Markers_Differentiation.png"), #print graph
units="cm", width=18, height=12,
pointsize=12, res=300)
matrix <- rbind(c(1,2,3,4), c(5,6,7,8))
grid.arrange(PlotFunction('DES'),
PlotFunction('MYOG'),
PlotFunction('DMD'),
PlotFunction('CKM'),
PlotFunction('MYOD1'),
PlotFunction('MSTN'),
PlotFunction('MYF5'),
PlotFunction('PAX3'),
layout_matrix=matrix)
dev.off()
#======================================================================================================
# Normalize by tissue from each Species
#======================================================================================================
library(matrixStats)
median_human <- rowMedians(as.matrix(res[grep('HumanTissue', colnames(res))]), na.rm=T)
median_mouse <- rowMedians(as.matrix(res[grep('MouseTissue', colnames(res))]), na.rm=T)
median_rat <- rowMedians(as.matrix(res[grep('RatTissue', colnames(res))]), na.rm=T)
res_norm <- cbind(res[grep('HumanCell', colnames(res))] - median_human,
res[grep('MouseC2C12', colnames(res))] - median_mouse,
res[grep('RatL6', colnames(res))] - median_rat)
Sample <- c(rep("HSMC", length(grep('HumanCell', colnames(res)))),
rep("C2C12", length(grep('MouseC2C12', colnames(res)))),
rep("L6", length(grep('RatL6', colnames(res)))))
PlotFunction <- function(genename) {
data <- data.frame() #create an empty dataframe to collect data
for( i in 1:length(genename)) {
y <- as.numeric(res_norm[genename[i],]) #collect data for gene name i
datay <- cbind.data.frame(Sample, y, rep(genename[i])) #create table with x="sample type", y="data", "gene name"
colnames(datay) <- c("x","y","Gene") #rename column names to make it possible to rbind later
data <- rbind.data.frame(data, datay) #bind the new gene data at the bottom of the previous one
}
data$x <- factor(data$x, levels=c("HSMC", "C2C12", "L6")) #for a box plot, x should be a factor
ggplot(data, aes(x=x, y=y, fill=x)) +
geom_boxplot() +
labs(x="",
y=paste(genename)) +
theme_bw() +
theme(plot.title = element_text(face="bold", color="black", size=7, angle=0),
axis.text.x = element_text(color="black", size=6, angle=45, hjust=1),
axis.text.y = element_text(color="black", size=6, angle=0),
axis.title = element_text(face="bold", color="black", size=7, angle=0),
legend.text = element_text(face="bold", color="black", size=6, angle=0),
legend.position="none", legend.title = element_blank()) +
scale_fill_manual(values=cbPalette) +
scale_color_manual(values=cbPalette)
}
library(grid)
library(gridExtra)
png(filename=here("Figures", "Markers_Differentiation_norm.png"), #print graph
units="cm", width=18, height=12,
pointsize=12, res=300)
matrix <- rbind(c(1,2,3,4), c(5,6,7,8))
grid.arrange(PlotFunction('DES'),
PlotFunction('MYOG'),
PlotFunction('DMD'),
PlotFunction('CKM'),
PlotFunction('MYOD1'),
PlotFunction('MSTN'),
PlotFunction('MYF5'),
PlotFunction('PAX3'),
layout_matrix=matrix)
dev.off()