-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataViz_JSRe0167_ProteinDomainVisualizer.Rmd
More file actions
299 lines (250 loc) · 11.7 KB
/
DataViz_JSRe0167_ProteinDomainVisualizer.Rmd
File metadata and controls
299 lines (250 loc) · 11.7 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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
---
title: "JSRe0167_ProteinDomains"
author: "Jacob Roth"
date: "2024-05-06"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
```{r}
library(ggplot2)
library(plyr)
df_protein <- readxl::read_excel("2-data_raw/ProteinDomains.xlsx",
sheet = 1)
# Example dataframe
# df_protein <- data.frame(
# name = c("Protein1", "Protein1", "Protein1", "Protein2"),
# type = c("Domain A", "Domain B", "length", "length"),
# start = c(1, 20, 1, 1),
# end = c(15, 28, 500, 150),
# rank = c(1, 1, 1, 2) # Assume rank indicates the order in which proteins should be displayed
#
# )
df_protein$start <- as.numeric(df_protein$start)
df_protein$end <- as.numeric(df_protein$end)
# Define x-axis limits based on the data range or specific interest
x_min <- round_any(min(df_protein$start) - 10, 50, f = ceiling) # Extend a bit beyond the minimum start value
x_max <- round_any(max(df_protein$end) + 10, 50, f = ceiling) # Extend a bit beyond the maximum end value
```
```{r}
```
```{r}
# Assuming df_protein is already defined and includes "length" rows for each protein
# Plotting the domains
g <- ggplot(df_protein) +
geom_segment(data = df_protein %>% filter(type == "length"), aes(x = start, xend = end, y = name, yend = name), size = 1, color = "black") +
geom_segment(data = df_protein %>% filter(type != "length"), aes(x = start, xend = end, y = name, yend = name, color = type), size = 5) +
scale_color_brewer(palette = "Set1") +
# coord_flip() +
labs(x = "Amino Acid Position", title = "Protein Domains Visualization", color = "Domain Type") +
theme_minimal() +
theme(panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
legend.title = element_text(size = 12),
legend.text = element_text(size = 10),
axis.text.y = element_text(size = 12))
# scale_x_continuous(limits = c(x_min, x_max), breaks = seq(x_min, x_max, by = 20))
# Display the plot
print(g)
```
```{r, eval = F}
# unique(df_protein$type)
colors_JSRe0150 <- c("#636363", #"length"
"#fa9fb5", #"WD-repeat"
# "#404040", #"Replaced with G4S"
# "#80cdc1", #"Tag_GST"
"#018571" #"Tag_MBP"
)
colors_JSRe0167 <- c("length" = "#636363",
# "WD-repeat" = "#fa9fb5",
"Acetylation" = "#d8b365",
"Methylation" = "#404040",
"Ubiquitinylation" = "#c7eae5",
"Phosphorylation" = "#000000",
"Sumoylation" = "#01665e"
)
pie(rep(1,6), col=colors_JSRe0167)
types <- unique(df_protein$type)
color_set = setNames(colors_JSRe0150,
types)
```
```{r E2F1 colors, eval = F}
# unique(df_protein$type)
types_E2F1 <- df_protein %>%
filter(name == "E2F1") %>%
filter(plot == "y") %>%
pull(label3) %>%
unique()%>%
na.omit() # Removes NA values
types_E2F1
colors_E2F1 <- c("length" = "#000000",
# "WD-repeat" = "#fa9fb5",
"Acetylation" = "cyan3",
"Methylation" = "magenta",
"Ubiquitinylation" = "#000000",
"Phosphorylation" = "#000000",
"CyclinA-CDK2 binding" = "lightseagreen",
"Leucine-Zipper" = "#d8b365",
"Dimerization" = "#01665e",
"Transactivation" = "gray75",
"RB1 binding" = "gray65"
)
# pie(rep(1,10), col=colors_E2F1)
# color_E2F1 = setNames(colors_E2F1,
# types_E2F1)
# color_E2F1
```
```{r E2F1}
library(ggrepel)
library(tidyverse)
df_protein <- df_protein %>%
filter(name == "E2F1")
df_protein$label3 <- factor(df_protein$label3,
levels = c("Methylation",
"Acetylation",
"Phosphorylation",
"Ubiquitinylation",
"Leucine-Zipper",
"Dimerization",
"CyclinA-CDK2 binding",
"Transactivation",
"RB1 binding"
))
g <- df_protein %>%
ggplot() +
geom_text_repel(data = df_protein %>% filter(plot == "y"
# & label == "Methylation"
& label_start_top == "y"),
aes(x = start, y = name, label = residue, color = label3),
nudge_x = 0, nudge_y = 0.25,
# direction = "y",
size = 3,
# fill = alpha(c("white"),0.9),
fill = "white",
fontface = 'bold',
max.overlaps = 10, # Control maximum number of overlaps allowed
box.padding = 0.75, # Padding around text box
segment.color = 'grey50', # Line color from label to point
point.padding = 0.3 # Padding between points and text
) +
# geom_text_repel(data = df_protein %>% filter(plot == "y" & label_end_top == "y"), aes(x = end, y = name, label = end),
# nudge_x = 0, nudge_y = 0.3, direction = "y", size = 3) +
geom_text_repel(data = df_protein %>% filter(plot == "y" & label_start_bot == "y"),
aes(x = start, y = name, label = residue, color = label3),
nudge_x = 0, nudge_y = -0.25,
# direction = "y",
size = 3,
fontface = 'bold',
# fill = alpha(c("blue"),0.5),
# alpha = 0.1,
fill = "white", # Set background color of label box
max.overlaps = 10, # Control maximum number of overlaps allowed
box.padding = 0.5, # Padding around text box
segment.color = 'grey50', # Line color from label to point
point.padding = 0.3 # Padding between points and text
) +
geom_segment(data = df_protein %>% filter(plot == "y" & type == "length"), aes(x = start, xend = end, y = name, yend = name), size = 1, color = "black") +
geom_segment(data = df_protein %>% filter(plot == "y" & type == "Domain"),
aes(x = start, xend = end, y = name, yend = name, color = label),
size = 5) +
# geom_text_repel(data = df_protein %>% filter(plot == "y" & label_end_bot == "y"), aes(x = end, y = name, label = end),
# nudge_x = 0, nudge_y = -0.3, direction = "y", size = 3) +
# scale_color_brewer(palette = "Set1") +
scale_color_manual(values = colors_E2F1,
breaks=c("Methylation",
"Acetylation",
"Phosphorylation",
"Ubiquitinylation",
"Leucine-Zipper",
# "Dimerization",
# "CyclinA-CDK2 binding",
# "Transactivation",
"RB1 binding")) +
# geom_label_repel(data = df_protein %>% filter(!is.na(label)), aes(x = (start + end) / 2, y = name, label = label),
# nudge_x = 0, nudge_y = 0.2, size = 4, segment.color = "grey50") +
# coord_flip() +
labs(x = "Amino Acid Position",
y = "",
title = "Visualization of E2F1 PTMs", color = "Modification") +
theme_minimal() +
theme(panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
legend.title = element_text(size = 12),
legend.text = element_text(size = 10),
axis.text.y = element_text(size = 12),
# axis.text.x=element_blank(),
legend.position="bottom"
# ,legend.direction="vertical"
) +
scale_x_continuous(breaks = seq(x_min, x_max, by = 50), labels = seq(x_min, x_max, by = 50)) # Adjusted for y-axis due to coord_flip
# scale_x_continuous(breaks = function(x) ifelse(x == 0, 0, NA), labels = function(x) ifelse(x == 0, "0", ""))
# scale_y_discrete(limits=rev)
# Display the plot
print(g)
ggsave("5-figures/20240905_E2F1-ProteinDomains3.png", plot = g, width = 10, height = 5, dpi = 300)
```
```{r SRSF3 colors, eval = F}
# unique(df_protein$type)
colors_JSRe0150 <- c("#636363", #"length"
"#fa9fb5", #"WD-repeat"
# "#404040", #"Replaced with G4S"
# "#80cdc1", #"Tag_GST"
"#018571" #"Tag_MBP"
)
colors_JSRe0167 <- c("length" = "#636363",
# "WD-repeat" = "#fa9fb5",
"Acetylation" = "#d8b365",
"Methylation" = "#404040",
"Ubiquitinylation" = "#c7eae5",
"Phosphorylation" = "#000000",
"Sumoylation" = "#01665e"
)
pie(rep(1,6), col=colors_JSRe0167)
types <- unique(df_protein$type)
color_set = setNames(colors_JSRe0150,
types)
```
```{r SRSF3, eval = FALSE}
library(ggrepel)
library(tidyverse)
g <- df_protein %>%
ggplot() +
geom_text_repel(data = df_protein %>% filter(plot == "y" & label == "Methylation" & label_start_top == "y"), aes(x = start, y = name, label = start),
nudge_x = 0, nudge_y = 0.15, direction = "y", size = 3) +
# geom_text_repel(data = df_protein %>% filter(plot == "y" & label_end_top == "y"), aes(x = end, y = name, label = end),
# nudge_x = 0, nudge_y = 0.3, direction = "y", size = 3) +
geom_text_repel(data = df_protein %>% filter(plot == "y" & label_start_bot == "y"), aes(x = start, y = name, label = start, color = label),
nudge_x = 0, nudge_y = -0.15, direction = "y", size = 3) +
# geom_text_repel(data = df_protein %>% filter(plot == "y" & label_end_bot == "y"), aes(x = end, y = name, label = end),
# nudge_x = 0, nudge_y = -0.3, direction = "y", size = 3) +
# scale_color_brewer(palette = "Set1") +
scale_color_manual(values = colors_JSRe0167) +
# geom_label_repel(data = df_protein %>% filter(!is.na(label)), aes(x = (start + end) / 2, y = name, label = label),
# nudge_x = 0, nudge_y = 0.2, size = 4, segment.color = "grey50") +
# coord_flip() +
geom_segment(data = df_protein %>% filter(plot == "y" & type == "length"), aes(x = start, xend = end, y = name, yend = name), size = 1, color = "black") +
geom_segment(data = df_protein %>% filter(plot == "y" & type == "Domain"), aes(x = start, xend = end, y = name, yend = name, color = label), size = 5) +
labs(x = "Amino Acid Position",
y = "",
title = "Visualization of SRSF3 PTMs", color = "Modification") +
theme_minimal() +
theme(panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
legend.title = element_text(size = 12),
legend.text = element_text(size = 10),
axis.text.y = element_text(size = 12),
# axis.text.x=element_blank(),
legend.position="bottom"
# ,legend.direction="vertical"
) +
scale_x_continuous(breaks = seq(x_min, x_max, by = 50), labels = seq(x_min, x_max, by = 50)) # Adjusted for y-axis due to coord_flip
# scale_x_continuous(breaks = function(x) ifelse(x == 0, 0, NA), labels = function(x) ifelse(x == 0, "0", ""))
# scale_y_discrete(limits=rev)
# Display the plot
print(g)
ggsave("5-figures/20240506_SRSF3-ProteinDomains-Mods_visualization.png", plot = g, width = 10, height = 5, dpi = 300)
```
```{r}
```