-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Final CLOVERT bug fixes + hairball figure
(Recompiled with Rory's last additions)
- Loading branch information
Colin J. Carlson
committed
May 16, 2021
1 parent
c12365a
commit ca6d37f
Showing
11 changed files
with
389 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,69 @@ | ||
|
||
library(magrittr) | ||
library(tidyverse) | ||
library(vroom) | ||
|
||
library(igraph) | ||
library(ggraph) | ||
library(graphlayouts) | ||
library(oaqc) | ||
|
||
vir <- vroom("Virion/Virion.csv.gz") | ||
|
||
clo <- read_csv("~/Github/clover/clover/Clover_v1.0_NBCIreconciled_20201218.csv") | ||
vir %<>% | ||
filter(HostNCBIResolved == TRUE, | ||
VirusNCBIResolved == TRUE) %>% | ||
select(Host,Virus,Database) %>% | ||
na.omit() %>% | ||
unique() | ||
|
||
vir %>% | ||
filter(Database=="HP3") %>% | ||
select(Host, Virus) %>% | ||
unique() -> hp3 | ||
|
||
hp3 <- read_csv("~/Github/clover/data/source_databases/HP3_associations.csv") | ||
vir %>% | ||
select(Host, Virus) %>% | ||
unique() -> vir | ||
|
||
vir %>% select(Host,Virus) %>% na.omit() %>% unique() -> vir | ||
hp3$Source = 'HP3' | ||
vir$Source = 'VIRION' | ||
|
||
clo %>% select(Host, Virus) %>% | ||
mutate(Host = str_c(Host, '_clo'), | ||
Virus = str_c(Virus, '_clo')) -> clo | ||
hp3 %<>% mutate(Virus = str_c(Virus,"_hp3"), | ||
Host = str_c(Host, "_hp3")) | ||
|
||
hp3 %>% select(hHostNameFinal, vVirusNameCorrected) %>% | ||
rename(Virus = 'vVirusNameCorrected', | ||
Host = 'hHostNameFinal') %>% | ||
mutate(Host = str_c(Host, '_hp3'), | ||
Virus = str_c(Virus, '_hp3')) -> hp3 | ||
vir %>% bind_rows(hp3) -> vir | ||
vir %<>% na.omit() | ||
|
||
vir %>% bind_rows(clo) %>% bind_rows(hp3) -> vir | ||
net <- graph.data.frame(as.data.frame(vir), directed = FALSE) | ||
|
||
vir %>% unique -> clo | ||
sub_gs <- components(net) | ||
small_sub <- which(sub_gs$csize < 20) | ||
(rm_nodes <- which(sub_gs$membership %in% small_sub)) | ||
net <- delete_vertices(net, rm_nodes) | ||
|
||
net <- graph.data.frame(as.data.frame(clo), directed = FALSE) | ||
|
||
net <- set_vertex_attr(net, 'Type', index = V(net), | ||
ifelse(V(net)$name %in% clo$Host, "Host", "Virus")) | ||
ifelse(V(net)$name %in% vir$Host, "Host", "Virus")) | ||
|
||
net <- decompose.graph(net, min.vertices = 500) | ||
net <- union(net[[1]], net[[2]], net[[3]], byname = TRUE) | ||
V(net)$Type <- ifelse(is.na(V(net)$Type_1), | ||
ifelse(is.na(V(net)$Type_2), V(net)$Type_3, V(net)$Type_2), | ||
V(net)$Type_1) | ||
net <- set_vertex_attr(net, 'Source', index = V(net), | ||
ifelse(str_detect(V(net)$name, "_hp3"), "HP3", "VIRION")) | ||
|
||
got_palette <- c("#325E9A", "#DD5D5D", "#325E9A", "#DD5D5D") | ||
|
||
ggraph(net, layout = "stress") + # layout = "centrality", cent = graph.strength(net)) + | ||
geom_edge_link0(edge_colour = "grey50", alpha = 0.3) + | ||
geom_node_point(aes(fill = Type), colour = "grey50", shape = 21, size = 1, stroke = 0.25) + | ||
ggraph(net, layout = "kk") + | ||
geom_edge_link(edge_colour = "grey80", alpha = 0.2) + | ||
geom_node_point(aes(fill = Type), colour = "grey50", shape = 21, size = 1.1, stroke = 0.8, alpha = 0.5) + | ||
scale_fill_manual(values = got_palette) + | ||
theme_graph() + | ||
theme(legend.position = "none") # , | ||
# panel.background = element_rect(fill = "#ADEADD")) | ||
|
||
theme_bw() + | ||
facet_nodes( ~ Source, scales = "free", shrink = TRUE) + | ||
theme(legend.position = "none", | ||
strip.text = element_text(size = 20), | ||
axis.title.x=element_blank(), | ||
axis.text.x=element_blank(), | ||
axis.ticks.x=element_blank(), | ||
axis.title.y=element_blank(), | ||
axis.text.y=element_blank(), | ||
axis.ticks.y=element_blank(), | ||
panel.background = element_rect(fill = "#ADEADD"), | ||
plot.background = element_rect(fill = "#ADEADD")) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.