knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  error   = FALSE,
  cache.path = file.path(R.cache::getCachePath(),
                         "chariotViz",
                         "vignettes"),
  cache = TRUE
)

Last Update On: r as.character(Sys.time())

library(chariotViz)
version_key <- 
  get_version_key()
rmd_print_version(version_key, 
                  "HemOnc")
library(chariotViz)

ChariotViz visualizes all valid Concepts at the Concept Class level by either properties represented by the CONCEPT_RELATIONSHIP table or by traversing direct relationships via the CONCEPT_ANCESTOR table.

OMOP Relationships are fetched from the CONCEPT_RELATIONSHIP table with corresponding annotations from the CONCEPT table.

omop_relationships <- 
  fetch_omop_relationships(version_key = get_version_key())
omop_relationships

This dataframe is then converted to a subset of 2 dataframes of nodes and edges.

omop_nodes_and_edges <- 
  create_nodes_and_edges(omop_relationships = omop_relationships)

omop_nodes_and_edges

Prior to visualization, a tooltip and attributes are added.

omop_nodes_and_edges <- 
  omop_nodes_and_edges %>% 
  add_tooltip() %>%
  map_node_attributes() %>% 
  map_edge_attributes()
omop_nodes_and_edges

The graph is constructed.

omop_graph <- 
  construct_graph(omop_nodes_and_edges)
omop_graph

The above is a graph of the entire OMOP Vocabularies in its present state.

chariotViz(omop_graph = omop_graph)

Due to the large number of nodes, the graph is not rendered, but can be forced to do so by setting force to TRUE.

Specific sets of vocabularies can be isolated by filtering the omop.relationships class object prior to conversion to nodes and edges.

Here, we are filtering for relationships within the HemOnc vocabulary only.

hemonc_relationships <- 
  omop_relationships %>% 
  filter_omop_relationships(
    vocabulary_id_1 == "HemOnc",
    vocabulary_id_2 == "HemOnc"
  )

The HemOnc graph is constructed after it is filtered for.

hemonc_graph <- 
  create_nodes_and_edges(hemonc_relationships) %>% 
  add_tooltip() %>% 
  map_node_attributes() %>% 
  map_edge_attributes() %>% 
  construct_graph()

With a smaller node count, chariotViz will automatically render the graph.

chariotViz(hemonc_graph)

The fillcolor of the nodes can be remapped.

hemonc_graph2 <- 
  hemonc_graph %>% 
  remap_fillcolor_by_concept_class()

chariotViz(hemonc_graph2)

Relationships

The relationships can also be filtered based on 3 classes of relationships: Taxonomy, Mapping, or Lateral. These classes are not defined by OHDSI and are specific to the chariot and chariotViz packages.

Taxonomy

Taxonomy relationships are relationships that represent a hierarchy (Is a and Subsumes).

hemonc_taxonomy_relationships <- 
  hemonc_relationships %>% 
  filter_for_taxonomy_relationships() 

hemonc_taxonomy_graph <- 
  create_nodes_and_edges(hemonc_taxonomy_relationships) %>% 
  add_tooltip() %>% 
  map_node_attributes() %>% 
  map_edge_attributes() %>% 
  construct_graph() %>% 
  remap_fillcolor_by_concept_class()

chariotViz(hemonc_taxonomy_graph,
           height = 500,
           width = 500)

Mapping

Mapping relationships are relationships that represent a mapping from a source to target, as in the case of an ETLing into the OMOP CDM. Since we filtered for concepts within HemOnc, the filter returns zero relationships since the basis of these relationships is mapping between different vocabularies.

hemonc_mapping_relationships <- 
  hemonc_relationships %>% 
  filter_for_mapping_relationships() 

hemonc_mapping_relationships

To view HemOnc's mapping relationships, we can re-filter the original object for HemOnc on side 1 only.

all_hemonc_relationships <- 
  omop_relationships %>% 
  filter_omop_relationships(
    vocabulary_id_1 == "HemOnc")

hemonc_mapping_relationships <- 
  all_hemonc_relationships %>% 
  filter_for_mapping_relationships() 

hemonc_mapping_relationships

We can now see how HemOnc maps to other OMOP vocabularies.

hemonc_mapping_graph <- 
  create_nodes_and_edges(hemonc_mapping_relationships) %>% 
  add_tooltip() %>% 
  map_node_attributes() %>% 
  map_edge_attributes() %>% 
  construct_graph() 

chariotViz(hemonc_mapping_graph)

Lateral

Lateral relationships are relationships that are all other relationships. Returning to the relationships within HemOnc, the lateral relationships are filtered for.

hemonc_lateral_relationships <- 
  hemonc_relationships %>% 
  filter_for_lateral_relationships()

hemonc_lateral_graph <- 
  create_nodes_and_edges(hemonc_lateral_relationships) %>% 
  add_tooltip() %>% 
  map_node_attributes() %>% 
  map_edge_attributes() %>% 
  construct_graph() 

chariotViz(hemonc_lateral_graph)

With the relationships within and outside of HemOnc, the all_hemonc_relationships returns the following graph.

hemonc_lateral_relationships <- 
  all_hemonc_relationships %>% 
  filter_for_lateral_relationships()

hemonc_lateral_graph <- 
  create_nodes_and_edges(hemonc_lateral_relationships) %>% 
  add_tooltip() %>% 
  map_node_attributes() %>% 
  map_edge_attributes() %>% 
  construct_graph() 

chariotViz(hemonc_lateral_graph)

Foreign

To retrieve any relationships outside of HemOnc instead, the original omop_relationships object must be filtered once more, but this time with exclusion of HemOnc in the filter.

foreign_hemonc_relationships <- 
  omop_relationships %>% 
  filter_omop_relationships(
    vocabulary_id_1 == "HemOnc",
    vocabulary_id_2 != "HemOnc") %>% 
  filter_for_lateral_relationships() 

foreign_hemonc_lateral_graph <- 
  create_nodes_and_edges(foreign_hemonc_relationships) %>% 
  add_tooltip() %>% 
  map_node_attributes() %>% 
  map_edge_attributes() %>% 
  construct_graph()

chariotViz(foreign_hemonc_lateral_graph)

Filtering for Taxonomy relationships allows visualization of how ancestry of a vocabulary relates to other vocabularies. Here, it is evident that only HemOnc's Component Class is a parent to RxNorm and RxNorm Extension Concept Classes.

foreign_hemonc_relationships <- 
  omop_relationships %>% 
  filter_omop_relationships(
    vocabulary_id_1 == "HemOnc",
    vocabulary_id_2 != "HemOnc") %>% 
  filter_for_taxonomy_relationships() 

foreign_hemonc_taxonomy_graph <- 
  create_nodes_and_edges(foreign_hemonc_relationships) %>% 
  add_tooltip() %>% 
  map_node_attributes() %>% 
  map_edge_attributes() %>% 
  construct_graph()

chariotViz(foreign_hemonc_taxonomy_graph)

To view all possible foreign relationships, the filter can be lifted.

foreign_hemonc_relationships <- 
  omop_relationships %>% 
  filter_omop_relationships(
    vocabulary_id_1 == "HemOnc",
    vocabulary_id_2 != "HemOnc") #%>% 
#  filter_for_lateral_relationships() 

foreign_hemonc_graph <- 
  create_nodes_and_edges(foreign_hemonc_relationships) %>% 
  add_tooltip() %>% 
  map_node_attributes() %>% 
  map_edge_attributes() %>% 
  construct_graph()

chariotViz(foreign_hemonc_graph)

Visualizing Concepts

Samples of concepts along with a tooltip containing the concept's attribute values can be appended to the graph with the append_concept_examples function.

foreign_hemonc_graph %>% 
  append_concept_examples(sample_size = 3) %>% 
  chariotViz(force = TRUE,
             width = 1500)

The count of the samples can be adjusted.

foreign_hemonc_graph %>% 
  append_concept_examples(sample_size = 5) %>% 
  chariotViz(force = TRUE,
             width = 1500)
foreign_hemonc_graph %>% 
  append_concept_examples(sample_size = 10) %>% 
  chariotViz(force = TRUE,
             height = 2000)


meerapatelmd/chariotViz documentation built on Dec. 21, 2021, 4:53 p.m.