-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08_Infomap_analysis_full_network.R
588 lines (488 loc) · 22.3 KB
/
08_Infomap_analysis_full_network.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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
####################################################################################################################
# Plasmid rumen network analysis
#
# Script 8: Multilayer network analysis on full network using Infomap
#
#
# The following outputs are used for downstream analysis:
# net.2k.edgelist.Rda, plas.2k.list.Rda, layer.id.table.2k.Rda, plas_mods.df.Rda, plas_mods.stats.Rda
#
# The following figures are created:
# Figure 1B, simplified network visualization
#
# Script tested for R version 4.1.1
####################################################################################################################
####################################################################################################################
# SCRIPT SET-UP
####################################################################################################################
# Set working directory to wherever your files are located
# Load necessary packages:
library(tidyverse)
library(infomapecology)
library(igraph)
# Starting files:
# Edgelist with edgeweights created in script 03_Network_setup.R
load("net.dat2k.ew.Rda")
# Metadata file created in script 01_Initial_data_processing.R
load("plasmid.metadat.updated.Rda")
# Plasmids per cow file created in in script 04_Basic_network_statistics.R
load("plas.per.cow.Rda")
####################################################################################################################
####################################################################################################################
# Section 1: SET-UP DATA FOR INFOMAP
####################################################################################################################
# Create the necessary dataframes for infomap
# First, a simplified extended edgelist in the right order:
net.2k.edgelist <- net.dat2k.ew %>%
ungroup() %>%
select(layer_from, node_from, layer_to, node_to, weight)
# Save the data
save(net.2k.edgelist, file="net.2k.edgelist.Rda")
# Make a metadata file, node id table and layer table for the included plasmids
# Start by making a full list of the included plasmids
plas.2k.list <- net.2k.edgelist %>%
ungroup() %>%
select(node_from, node_to) %>%
gather(.) %>%
select(-key) %>%
mutate(node_id = as.integer(value)) %>%
select(-value) %>%
left_join(plasmid.metadat.updated, by = "node_id") %>%
select(node_id, plasmid_length) %>%
distinct()
# Create layer id table
layer.id.table.2k <- net.2k.edgelist %>%
ungroup() %>%
select(layer_from, layer_to) %>%
gather(.) %>%
select(value) %>%
rename(layer_id= value) %>%
distinct() %>%
droplevels()
# Save for downstream analysis:
save(plas.2k.list, file="plas.2k.list.Rda")
save(layer.id.table.2k, file="layer.id.table.2k.Rda")
####################################################################################################################
####################################################################################################################
# Section 2: RUN INFOMAP ON FULL NETWORK
####################################################################################################################
# Making multilayer network with infomapecology package
# Default:
plas.multilay.2k <- create_multilayer_object(extended = net.2k.edgelist,
nodes = plas.2k.list, layers = layer.id.table.2k)
#Run infomap
plas_modules <- run_infomap_multilayer(M=plas.multilay.2k,infomap_executable = "Infomap",
flow_model = 'undirected', silent = T, relax = F,
trials = 100, seed = 123, temporal_network = F, run_standalone = T)
####################################################################################################################
####################################################################################################################
# Section 3: STATISTICAL ANALYSIS ON INFOMAP MODULES
####################################################################################################################
# Turn infomap output into a dataframe and reorganize slightly:
plas_mods.df <- as.data.frame(plas_modules$modules) %>%
select(module, everything())
# Calculate the number of nodes and layers per module:
plas_mods.stats <- plas_mods.df %>%
group_by(module) %>%
summarise(n.state.nodes=n(),
n.phys.nodes = n_distinct(node_id),
n.layers = n_distinct(layer_id),
mod.flow=sum(flow))
# Save data for downstream analysis:
save(plas_mods.df, file="plas_mods.df.Rda")
save(plas_mods.stats, file="plas_mods.stats.Rda")
# Visualize module characteristics with histograms:
# Distribution of state nodes per module
st.nodes.mod <- ggplot(plas_mods.stats, aes(x=n.state.nodes))+
geom_histogram(color="black", fill="white") +
labs(x = "Number of State Nodes", y="Count(Modules)") +
theme(text = element_text(size=14)) +
theme(axis.title.x = element_text(size = 16), axis.title.y = element_text(size = 16))
# Distribution of physical nodes per module
phys.nodes.mod <- ggplot(plas_mods.stats, aes(x=n.phys.nodes))+
geom_histogram(color="black", fill="white") +
scale_x_continuous(breaks = seq(2, 13, 3)) +
labs(x = "Number of Physical Nodes", y="Count (Modules)" ) +
theme(text = element_text(size=16)) +
theme(axis.title.x = element_text(size = 20), axis.title.y = element_text(size = 20))
# Distribution of layers per module
layer.mod <- ggplot(plas_mods.stats, aes(x=n.layers))+
geom_histogram(color="black", fill="white") +
scale_x_continuous(breaks = seq(1, 16, 3)) +
labs(x = "Number of Layers", y="Count (Modules)" ) +
theme(text = element_text(size=14)) +
theme(axis.title.x = element_text(size = 16), axis.title.y = element_text(size = 16))
####################################################################################################################
####################################################################################################################
# Section 4A: DATA FORMATTING FOR NETWORK VISUALIZATIONS - BIG MODULE
####################################################################################################################
# Format data for visualizations:
plas_mods.stats.lab <- plas_mods.stats %>%
mutate(mod.type=ifelse(module == 1, "big", "not big")) # THE LARGEST MODULE IS WITH ID 1
plas_mods2 <- plas_mods.df %>%
left_join(., plas_mods.stats.lab, by="module") %>%
select(layer_id,node_id, mod.type) %>%
filter(mod.type=="big")
plas_mods3 <- net.dat2k.ew %>%
left_join(., plas_mods2, by=c("node_from"="node_id","layer_from"="layer_id")) %>%
rename(mod.from = mod.type) %>%
left_join(., plas_mods2, by=c("node_to"="node_id","layer_to"="layer_id")) %>%
rename(mod.to = mod.type) %>%
mutate(inter.big=ifelse(mod.from=="big" & mod.to=="big", "big.to.big", "not big"))
# Biggest module, intra-module edges
big.to.big <- plas_mods3 %>%
filter(inter.big == "big.to.big")
# Biggest module, inter-module edges
big.to.not.big <- plas_mods3 %>%
filter(mod.from=="big" & is.na(mod.to) | is.na(mod.from) & mod.to=="big")
# Total edges
tot.big.edges <- big.to.big %>%
bind_rows(., big.to.not.big)
# To get a list of all plasmids involved in the biggest module:
big.plas_mods.from <- plas_mods3 %>%
ungroup() %>%
select(layer_from, node_from, mod.from) %>%
filter(mod.from=="big") %>%
dplyr::rename(mod.lab = mod.from,
layer_id = layer_from,
node_id = node_from)
big.plas_mods.to <- plas_mods3 %>%
ungroup() %>%
select(layer_to, node_to,mod.to) %>%
filter(mod.to=="big") %>%
dplyr::rename(mod.lab = mod.to,
layer_id= layer_to,
node_id = node_to)
big.mod.plas.list <- big.plas_mods.from %>%
rbind(., big.plas_mods.to) %>%
select(-layer_id) %>%
distinct()
big.mod.plas.list.layers <- big.plas_mods.from %>%
rbind(., big.plas_mods.to) %>%
distinct()
not.big.plas_mods.from <- plas_mods3 %>%
ungroup() %>%
select(layer_from, mod.from) %>%
filter(is.na(mod.from)) %>%
rename(mod.lab = mod.from,
layer_id = layer_from) %>%
mutate(mod.lab = replace_na(mod.lab, "not big"))
not.big.plas_mods.to <- plas_mods3 %>%
ungroup() %>%
select(layer_to, mod.to) %>%
filter(is.na(mod.to)) %>%
rename(mod.lab = mod.to,
layer_id = layer_to) %>%
mutate(mod.lab = replace_na(mod.lab, "not big")) %>%
rbind(., not.big.plas_mods.from) %>%
distinct()
only.not.big <- not.big.plas_mods.to %>%
filter(!(layer_id %in% big.mod.plas.list.layers$layer_id))
mod.layer.list <- big.mod.plas.list.layers %>%
select(-node_id) %>%
rbind(only.not.big) %>%
mutate(layer_id = as.factor(layer_id))
# Set up data for visualizations:
# Labelling edges as part of the largest module or not:
inter.for.vis2 <- plas_mods3 %>%
filter(edge_type=="Inter") %>%
ungroup() %>%
mutate(l_fr = paste("L",layer_from,sep = "")) %>%
mutate(l_to = paste("L",layer_to, sep = "")) %>%
rowwise() %>%
mutate(uniq_laypair = paste(sort(c(l_fr, l_to)), collapse = "_")) %>%
select(-l_fr, -l_to) %>%
select(uniq_laypair, everything()) %>%
group_by(layer_from, layer_to, uniq_laypair, inter.big) %>%
summarise(weight = n()) %>%
mutate(layer_from = as.numeric(layer_from),
layer_to = as.numeric(layer_to)) %>%
mutate_at(vars(inter.big), ~replace_na(., "not.big")) %>%
group_by(uniq_laypair, inter.big) %>%
slice(1) %>%
distinct() %>%
ungroup %>%
select(layer_from, layer_to, weight, inter.big)
# Node list
inter.list2 <- inter.for.vis2 %>%
ungroup() %>%
select(layer_from, layer_to) %>%
gather() %>%
select(value) %>%
distinct() %>%
rename(layer=value)
# Intra-layer values for visualization:
intra.for.vis2 <- plas_mods3 %>%
filter(edge_type=="Intra") %>%
ungroup() %>%
group_by(layer_from, layer_to) %>%
mutate(intra.edg = n()) %>%
rename(layer=layer_from) %>%
ungroup() %>%
select(layer, intra.edg) %>%
bind_rows(.,inter.list2) %>%
group_by(layer) %>%
arrange(desc(intra.edg)) %>%
slice(1) %>%
distinct() %>%
mutate_at(vars(intra.edg), ~replace_na(., 0)) %>%
mutate(layer = as.factor(layer)) %>%
left_join(., mod.layer.list, by=c("layer"="layer_id")) %>%
left_join(., plas.per.cow, by=c("layer"="layer_id")) %>%
distinct()
####################################################################################################################
####################################################################################################################
# Section 5A: NETWORK VISUALIZATIONS - BIG MODULE
####################################################################################################################
# Visualization of the network with interlayer edges and the largest module highlighted
graph2 <- graph_from_data_frame(inter.for.vis2, directed=F, vertices = intra.for.vis2)
set_edge_attr(graph2, "weight", value= inter.for.vis2$weight)
is.weighted(graph2)
V(graph2)$size <- 12+intra.for.vis2$intra.edg
V(graph2)$color <- intra.for.vis2$mod.lab
E(graph2)$color <- as.factor(inter.for.vis2$inter.big)
V(graph2)$color <- as.factor(intra.for.vis2$mod.lab)
E(graph2)$color <- ifelse(inter.for.vis2$inter.big == "big.to.big", "red", "gray")
V(graph2)$color <- ifelse(intra.for.vis2$mod.lab == "big", "red", "gray")
# Use the same coordinates for the big module and the ABR module (sections 4B and 5B)
Coords <- layout_with_lgl(graph2) %>%
as_tibble %>%
bind_cols(data_frame(names = names(V(graph2))))
# Test plotting
# Node labels are: cow number (number of plasmids)
plot(graph2, edge.width=(E(graph2)$weight*0.1),vertex.label=
paste(V(graph2)$name,' (',intra.for.vis2$tot.plas,')',sep=''),
vertex.label.font=2, vertex.label.cex=0.7,
vertex.label.color = "black", layout=as.matrix(Coords[,1:2]))
# Create Figure 2 Panel B: Full network plot with largest module highlighted:
png(filename = "big.mod.highlight.plot.labs.png",res = 900, width = 10, height = 10, units = "in")
{
plot(graph2, edge.width=(E(graph2)$weight*0.1),vertex.label=
paste(V(graph2)$name,' (',intra.for.vis2$tot.plas,')',sep=''),
vertex.label.font=2, vertex.label.cex=0.7,
vertex.label.color = "black", layout=as.matrix(Coords[,1:2]))
}
dev.off()
# Save as pdf
pdf(file = "big.mod.highlight.plot.pdf", width = 6, height = 6)
{
plot(graph2, edge.width=(E(graph2)$weight*0.1),vertex.label=
paste(V(graph2)$name,' (',intra.for.vis2$tot.plas,')',sep=''),
vertex.label.font=2, vertex.label.cex=0.4,
vertex.label.color = "black", layout=as.matrix(Coords[,1:2]))
}
dev.off()
####################################################################################################################
# The code in sections 4B and 5B is a copy-paste from 4A nd 5A. The only difference is the module ID and the color of the plot
####################################################################################################################
# Section 4B: DATA FORMATTING FOR NETWORK VISUALIZATIONS - ABR MODULE
####################################################################################################################
# Format data for visualizations:
plas_mods.stats.lab <- plas_mods.stats %>%
mutate(mod.type=ifelse(module == 2, "abr", "not abr")) # The ABR module is with ID 2
plas_mods2 <- plas_mods.df %>%
left_join(., plas_mods.stats.lab, by="module") %>%
select(layer_id,node_id, mod.type) %>%
filter(mod.type=="abr")
plas_mods3 <- net.dat2k.ew %>%
left_join(., plas_mods2, by=c("node_from"="node_id","layer_from"="layer_id")) %>%
rename(mod.from = mod.type) %>%
left_join(., plas_mods2, by=c("node_to"="node_id","layer_to"="layer_id")) %>%
rename(mod.to = mod.type) %>%
mutate(inter.abr=ifelse(mod.from=="abr" & mod.to=="abr", "abr.to.abr", "not abr"))
# Biggest module, intra-module edges
abr.to.abr <- plas_mods3 %>%
filter(inter.abr == "abr.to.abr")
# Biggest module, inter-module edges
abr.to.not.abr <- plas_mods3 %>%
filter(mod.from=="abr" & is.na(mod.to) | is.na(mod.from) & mod.to=="abr")
# Total edges
tot.abr.edges <- abr.to.abr %>%
bind_rows(., abr.to.not.abr)
# To get a list of all plasmids involved in the biggest module:
abr.plas_mods.from <- plas_mods3 %>%
ungroup() %>%
select(layer_from, node_from, mod.from) %>%
filter(mod.from=="abr") %>%
dplyr::rename(mod.lab = mod.from,
layer_id = layer_from,
node_id = node_from)
abr.plas_mods.to <- plas_mods3 %>%
ungroup() %>%
select(layer_to, node_to,mod.to) %>%
filter(mod.to=="abr") %>%
dplyr::rename(mod.lab = mod.to,
layer_id= layer_to,
node_id = node_to)
abr.mod.plas.list <- abr.plas_mods.from %>%
rbind(., abr.plas_mods.to) %>%
select(-layer_id) %>%
distinct()
abr.mod.plas.list.layers <- abr.plas_mods.from %>%
rbind(., abr.plas_mods.to) %>%
distinct()
not.abr.plas_mods.from <- plas_mods3 %>%
ungroup() %>%
select(layer_from, mod.from) %>%
filter(is.na(mod.from)) %>%
rename(mod.lab = mod.from,
layer_id = layer_from) %>%
mutate(mod.lab = replace_na(mod.lab, "not abr"))
not.abr.plas_mods.to <- plas_mods3 %>%
ungroup() %>%
select(layer_to, mod.to) %>%
filter(is.na(mod.to)) %>%
rename(mod.lab = mod.to,
layer_id = layer_to) %>%
mutate(mod.lab = replace_na(mod.lab, "not abr")) %>%
rbind(., not.abr.plas_mods.from) %>%
distinct()
only.not.abr <- not.abr.plas_mods.to %>%
filter(!(layer_id %in% abr.mod.plas.list.layers$layer_id))
mod.layer.list <- abr.mod.plas.list.layers %>%
select(-node_id) %>%
rbind(only.not.abr) %>%
mutate(layer_id = as.factor(layer_id))
# Set up data for visualizations:
# Labelling edges as part of the largest module or not:
inter.for.vis2 <- plas_mods3 %>%
filter(edge_type=="Inter") %>%
ungroup() %>%
mutate(l_fr = paste("L",layer_from,sep = "")) %>%
mutate(l_to = paste("L",layer_to, sep = "")) %>%
rowwise() %>%
mutate(uniq_laypair = paste(sort(c(l_fr, l_to)), collapse = "_")) %>%
select(-l_fr, -l_to) %>%
select(uniq_laypair, everything()) %>%
group_by(layer_from, layer_to, uniq_laypair, inter.abr) %>%
summarise(weight = n()) %>%
mutate(layer_from = as.numeric(layer_from),
layer_to = as.numeric(layer_to)) %>%
mutate_at(vars(inter.abr), ~replace_na(., "not.abr")) %>%
group_by(uniq_laypair, inter.abr) %>%
slice(1) %>%
distinct() %>%
ungroup %>%
select(layer_from, layer_to, weight, inter.abr)
# Node list
inter.list2 <- inter.for.vis2 %>%
ungroup() %>%
select(layer_from, layer_to) %>%
gather() %>%
select(value) %>%
distinct() %>%
rename(layer=value)
# Intra-layer values for visualization:
intra.for.vis2 <- plas_mods3 %>%
filter(edge_type=="Intra") %>%
ungroup() %>%
group_by(layer_from, layer_to) %>%
mutate(intra.edg = n()) %>%
rename(layer=layer_from) %>%
ungroup() %>%
select(layer, intra.edg) %>%
bind_rows(.,inter.list2) %>%
group_by(layer) %>%
arrange(desc(intra.edg)) %>%
slice(1) %>%
distinct() %>%
mutate_at(vars(intra.edg), ~replace_na(., 0)) %>%
mutate(layer = as.factor(layer)) %>%
left_join(., mod.layer.list, by=c("layer"="layer_id")) %>%
left_join(., plas.per.cow, by=c("layer"="layer_id")) %>%
distinct()
####################################################################################################################
####################################################################################################################
# Section 5B: NETWORK VISUALIZATIONS - ABR MODULE
####################################################################################################################
# Visualization of the network with interlayer edges and the largest module highlighted
graph2_abr <- graph_from_data_frame(inter.for.vis2, directed=F, vertices = intra.for.vis2)
set_edge_attr(graph2_abr, "weight", value= inter.for.vis2$weight)
is.weighted(graph2_abr)
V(graph2_abr)$size <- 12+intra.for.vis2$intra.edg
V(graph2_abr)$color <- intra.for.vis2$mod.lab
E(graph2_abr)$color <- as.factor(inter.for.vis2$inter.abr)
V(graph2_abr)$color <- as.factor(intra.for.vis2$mod.lab)
E(graph2_abr)$color <- ifelse(inter.for.vis2$inter.abr == "abr.to.abr", "purple", "gray")
V(graph2_abr)$color <- ifelse(intra.for.vis2$mod.lab == "abr", "purple", "gray")
# Test plotting
# Use the same Coords as in the figure for the large module
plot(graph2_abr, edge.width=(E(graph2_abr)$weight*0.1),vertex.label=
paste(V(graph2_abr)$name,' (',intra.for.vis2$tot.plas,')',sep=''),
vertex.label.font=2, vertex.label.cex=0.4,
vertex.label.color = "black", layout=as.matrix(Coords[,1:2]))
# Create Figure 2 Panel B: Full network plot with largest module highlighted:
png(filename = "abr.mod.highlight.plot.labs.png",res = 900, width = 10, height = 10, units = "in")
{
plot(graph2_abr, edge.width=(E(graph2_abr)$weight*0.1),vertex.label=
paste(V(graph2_abr)$name,' (',intra.for.vis2$tot.plas,')',sep=''),
vertex.label.font=2, vertex.label.cex=0.7,
vertex.label.color = "black", layout=as.matrix(Coords[,1:2]))}
dev.off()
# Save as pdf
pdf(file = "abr.mod.highlight.plot.pdf", width = 6, height = 6)
{
plot(graph2_abr, edge.width=(E(graph2_abr)$weight*0.1),vertex.label=
paste(V(graph2_abr)$name,' (',intra.for.vis2$tot.plas,')',sep=''),
vertex.label.font=2, vertex.label.cex=0.4,
vertex.label.color = "black", layout=as.matrix(Coords[,1:2]))}
dev.off()
####################################################################################################################
####################################################################################################################
# Section 6: NETWORK VISUALIZATIONS - OVERLAPPING ABR AND LARGEST MODULES
####################################################################################################################
# Need to recalcualte the edges because now we do not highlight specific edges. The weight is the number of interlayer edges connected to the cow
inter.for.vis2 <- plas_mods3 %>%
filter(edge_type=="Inter") %>%
ungroup() %>%
mutate(l_fr = paste("L",layer_from,sep = "")) %>%
mutate(l_to = paste("L",layer_to, sep = "")) %>%
rowwise() %>%
mutate(uniq_laypair = paste(sort(c(l_fr, l_to)), collapse = "_")) %>%
select(-l_fr, -l_to) %>%
select(uniq_laypair, everything()) %>%
group_by(layer_from, layer_to, uniq_laypair) %>%
summarise(weight = n()) %>%
mutate(layer_from = as.numeric(layer_from),
layer_to = as.numeric(layer_to))
# Create the graph
graph_overlap <- graph_from_data_frame(inter.for.vis2, directed=F, vertices = intra.for.vis2)
set_edge_attr(graph_overlap, "weight", value= inter.for.vis2$weight)
is.weighted(graph_overlap)
V(graph_overlap)$size <- 12+intra.for.vis2$intra.edg
E(graph_overlap)$color <- "gray"
# Find the overlapping layers and plot them
# Color map for the module categories
colmap_V <-
tibble(big=V(graph2)$mod.lab, abr=V(graph2_abr)$mod.lab) %>%
mutate(col=case_when(big == 'big' & abr == 'not abr' ~ 'red',
big == 'big' & abr == 'abr' ~ 'orange',
big == 'not big' & abr == 'not abr' ~ 'gray',
big == 'not big' & abr == 'abr' ~ '#FC97FF'))
V(graph_overlap)$color <- colmap_V$col
# # Layers that have both modules
# layers_overlap <- V(graph2)$mod.lab=='big' & V(graph2_abr)$mod.lab=='abr'
# which(layers_overlap==T)
V(graph_overlap)$rel_strength <- round(100*strength(graph_overlap)/sum(strength(graph_overlap)),1)
pdf(file = "overlap.mod.highlight.plot.pdf", width = 6, height = 6)
plot(graph_overlap, edge.width=(E(graph_overlap)$weight*0.1),
vertex.label=paste(V(graph2_abr)$name,' (',V(graph_overlap)$rel_strength,')',sep=''),
vertex.label.font=2, vertex.label.cex=0.35,
vertex.label.color = "black", layout=as.matrix(Coords[,1:2]))
dev.off()
####################################################################################################################
# Section 6: LARGEST MODULE CHARACTERISTICS
####################################################################################################################
# Compare flow of the largest module vs rest of modules in the observed network with a Z-score
z.sc.flow.big <- (max(plas_mods.stats$mod.flow) - mean(plas_mods.stats$mod.flow)) / sd(plas_mods.stats$mod.flow)
# P value
2*pnorm(q=z.sc.flow.big, lower.tail=FALSE)
# Inter- and intra-module edges
big.mod2 <- plas_mods3 %>%
filter(inter.big == "big.to.big") %>%
ungroup()
big.mod.intra <- big.mod2 %>%
count(edge_type=="Intra")
big.mod.inter <- big.mod2 %>%
count(edge_type=="Inter")
####################################################################################################################