-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04circosPlot.R
141 lines (109 loc) · 3.34 KB
/
04circosPlot.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
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
rm(list = ls())
#Did you change it to your base location?
baseDir="~/LeadNPC/"
setwd(baseDir)
source(file = "bin/00base.R")
# CIRCOS PLOT - TI-1 ------------------------------------------------------
library(circlize)
library(dplyr)
figures = "figures"
load("./Data/allTranscriptogramers80")
load("./Data/assocNoDup.RData")
load("./Data/clusters12.RData")
# Calculate gaps
temp1 <- clusters12[, -4]
temp1$na <- is.na(temp1$Clust1)
tmp <- 30
na <- c()
for (i in 1:nrow(temp1)) {
if(temp1$na[i]) {
na[i] <- tmp
}
else {
na[i] <- temp1$Clust1[i]
tmp <- tmp + 1
}
}
temp1$clusters2 <- na
# Get association data
time1 <- transc[[1]]
association <- transc[[1]]@association
idx <- !duplicated(t(apply(association, 1, sort)))
assocNoDup <- association[idx,]
# Merge and organize dataframes
df1 <- merge(temp1, assocNoDup, by.x = "Protein", by.y = "p1")
colnames(df1)[1] <- "p1"
df2 <- unique(merge(temp1, df1, by.x = "Protein", by.y = "p2"))
df3 <- as.data.frame(table(df2$clusters2.x, df2$clusters2.y), stringsAsFactors = F)
# Calculate clusters size
size2 <- temp1 %>%
group_by(clusters2) %>%
summarise(size = n())
# Merge and prepare plot data
c_filter3 <- merge(df3, size2, by.x = "Var1", by.y = "clusters2")
c_filter4 <- c_filter3 %>%
group_by(Var1) %>%
mutate(k = Freq / size) %>%
dplyr::select(Var1, Var2, k)
c_filter5 <- c_filter4 %>%
ungroup() %>%
mutate(Var1 = as.numeric(Var1), Var2 = as.numeric(Var2)) %>%
filter(Var1 < 30 & Var2 < 30) %>%
arrange(Var1)
col_grid <- c("#ff2222ff", "#009900ff", "#ffff00ff", "#ff9e30ff", "#1818fcff", "#b2a77fff",
"#000055ff", "#00aaaaff", "#00ffffff", "#8000aaff", "#fd11c2ff")
# Plot
circos.clear()
pdf(width = 11,height = 11,file = paste0("./",figures,"/circ1.pdf"))
chordDiagram(c_filter5, grid.col = col_grid)
dev.off()
# CIRCOS PLOT - TI-2 ------------------------------------------------------
library(circlize)
library(dplyr)
# Calculate gaps
temp1 <- clusters12[, -3]
temp1$na <- is.na(temp1$Clust2)
tmp <- 30
na <- c()
for (i in 1:nrow(temp1)) {
if(temp1$na[i]) {
na[i] <- tmp
}
else {
na[i] <- temp1$Clust2[i]
tmp <- tmp + 1
}
}
temp1$clusters2 <- na
# Get association data
time1 <- transc[[2]]
association <- transc[[2]]@association
idx <- !duplicated(t(apply(association, 1, sort)))
assocNoDup <- association[idx,]
# Merge dataframes
df1 <- merge(temp1, assocNoDup, by.x = "Protein", by.y = "p1")
colnames(df1)[1] <- "p1"
df2 <- unique(merge(temp1, df1, by.x = "Protein", by.y = "p2"))
df3 <- as.data.frame(table(df2$clusters2.x, df2$clusters2.y), stringsAsFactors = F)
# Calculate clusters size
size2 <- temp1 %>%
group_by(clusters2) %>%
summarise(size = n())
# Merge and prepare plot data
c_filter3 <- merge(df3, size2, by.x = "Var1", by.y = "clusters2")
c_filter4 <- c_filter3 %>%
group_by(Var1) %>%
mutate(k = Freq / size) %>%
dplyr::select(Var1, Var2, k)
c_filter5 <- c_filter4 %>%
ungroup() %>%
mutate(Var1 = as.numeric(Var1), Var2 = as.numeric(Var2)) %>%
filter(Var1 < 30 & Var2 < 30) %>%
arrange(Var1)
col_grid <- c("#ff2222ff", "#ff9e30ff", "#01ff40ff", "#0000ffff", "#ada27aff", "#000055ff",
"#00aaaaff", "#8000aaff", "#ff05c0ff", "#6666ffff", "#3333aaff")
# Plot
circos.clear()
pdf(width = 11,height = 11,file = paste0("./",figures,"/circ2.pdf"))
chordDiagram(c_filter5, grid.col = col_grid)
dev.off()