knitr::opts_chunk$set(echo = TRUE, out.width = "100%")
library(dplyr)
library(tidyverse)
library(phewasHelper)
library(associationsubgraphs)

association_pairs <- virus_net %>% 
  arrange(desc(strength))

Finding all subgraphs

First we will run subgraph finding algorithm across the associations

subgraphs <- association_pairs %>% head(10000) %>% calculate_subgraph_structure()

subgraphs %>% 
  select(-subgraphs) %>% 
  head() %>% 
  knitr::kable()

Visualizing subgraphs search

Next we can investigate the subgraph structure over search

min_rel <- subgraphs %>%
  filter(rel_max_size == min(rel_max_size)) %>%
  tail(1)

max_num_subgraphs <- subgraphs %>%
  filter(n_subgraphs == max(n_subgraphs)) %>%
  tail(1)

max_num_triples <- subgraphs %>%
  filter(n_triples == max(n_triples)) %>%
  tail(1)

subgraphs %>%
  # filter(rel_max_size < 0.5) %>%
  select(
    strength,
    n_subgraphs,
    max_size,
    rel_max_size,
    avg_density,
    n_triples,
    step
  ) %>% 
  pivot_longer(-step) %>%
  ggplot(aes(x = step, y = value)) +
  geom_step() +
  geom_vline(xintercept = min_rel$step, color = 'orangered') +
  geom_vline(xintercept = max_num_subgraphs$step, color = 'forestgreen') +
  geom_vline(xintercept = max_num_triples$step, color = 'steelblue') +
  facet_grid(rows = vars(name), scales = "free_y")
node_info <- virus_host_viruses %>% 
  rename(id = virus_id) %>% 
  mutate(color = ifelse(type == "RNA", "orangered", "steelblue"))

visualize_subgraph_structure(
  association_pairs,
  node_info = node_info,
  subgraph_results = subgraphs,
  trim_subgraph_results = TRUE
)

"Pinning" a node

If you have a particular interest in a node in your network you can "pin" that node in the visualization so the intitial start point of the visualization is when that node is first added to the visible subgraphs. For instance, say you are a researcher interested in Dengue, simply supply the id of "Dengue virus" to the visualize_subgraph_structure() function and you will be automatically taken to where Dengue first gets grouped into a subgraph.

visualize_subgraph_structure(
  association_pairs,
  node_info = node_info,
  subgraph_results = subgraphs,
  trim_subgraph_results = TRUE,
  pinned_node = "Dengue virus"
)


nstrayer/entropynet documentation built on Oct. 12, 2020, 2:20 a.m.