The VisuNet tutorial


Input formats {#InputFormats}

VisuNet works with any rule-based classifier in supported data frame formats.

'Line by line' format {#LbL}

Input data should be in a data frame format that contains the following columns:

library(VisuNet)
library(knitr)
library("kableExtra")
library(autoimage)
kable(autcon_ruleset[1:5,], format="html",  caption = "The sample 'line by line' data frame") %>%
  kable_styling(bootstrap_options = "striped", full_width = F, position = "left")

You can use the 'line by line' format with the option: type = "L"

rules <- autcon_ruleset
vis_out <- visunet(rules, type = "L")


R.ROSETTA data frame {#RDF}

The rules data frame that is the output of R.ROSETTA can be directly imported in VisuNet. See ?rosetta from the R.ROSETTA package for details.

The R.ROSETTA output format can be used with the option: type = "RDF".

#the rule-based model construction using R.ROSETTA
resultsRos <- rosetta(autcon)
vis_out <- visunet(resultsRos$main, type = "RDF")

Run VisuNet {#runVisunet}

VisuNet is an R package implemented as Shiny Gadgets.

require(VisuNet)

#Sample rule set for a classifier of  young males with autism and control
#'Line by line' data type
autcon_ruleset

#Run VisuNet
#Remember to click DONE once you finish working on VisuNet
vis_out <- visunet(autcon_ruleset, type = "L")

The available visunet parameters are:

Please note that the node scaling is perfomed per decision. See ?visNodes for the node scaling details.


CustObjectNodes and CustObjectEdges parameters are optional and can be used when rule network customization is needed.

See Node customization for details.

See Edge customization for details.


The interface

The VisuNet interface

VisuNet displays the rule network construct for the 10% of rules with the highest connection score. When only one decision variable is visible in the top 10% of rules, we extend the threshold to obtain rules for all decisions. The initial values of accuracy and support are defined for this set of rules.

The rule networks filtration panel:


VisuNet output

The VisuNet output is a collection of lists corresponding to decision variables and an additional list for the combined decision "all". The lists contain information required to reproduce the rule network, i.e. data frames for nodes, edges and RulesSetPerNode - a list that shows rules for each node. Data frames for nodes and edges incorporate essential variables from the visNetwork package and variables that describe the quality of each node/edge obtained from the rules.

Structure of the data frame for nodes:

Structure of the data frame for edges:


Rule network customization {#RNCust}

Rule networks are constructed using the visNetwork package that enables adding and modifying node- and edge- properties. We can add other variables that are implemented in visNetwork. See ?visNodes and ?visEdges for a full list of available options.

Node customization {#CustNodes}

Example

We identified 11 genes previously reported in databases of autism associations: SFARI, AutDB and ASD. In this example we would like to mark those genes as stars.

#genes reported in databases of autism associations
aut_genes <- c("TSPOAP1", "COX2","NCS1","RHPN1","FLRT2",
              "BAHD1","NCKAP5L","PPOX", "NGR2",
              "ATXN8OS","DEPDC1")

#create a new variable that contains node information for the "all" decision
nodes_RNO <- vis_out$all$nodes

#create a new vector of variables: shape. "dot" is the default shape of nodes
nodes_RNO$shape <- rep("dot", length(nodes_RNO$label))

#mark selected genes as stars using the label attribute 
nodes_RNO$shape[which(as.character(nodes_RNO$label) %in% aut_genes)] <- "star"

#create the node object list
nodesL <- list(nodes = nodes_RNO,CustCol =  c("shape"))

#rerun VisuNet with the new shape for nodes
vis_out2 <- visunet(autcon_ruleset, type = "L", CustObjectNodes = nodesL)

To rerun VisuNet with the customized object for nodes, you need to provide the original rule set and a list CustObjectNodes that contains the customized VisuNet object for nodes. CustObjectNodes includes the customized object for nodes: nodes and a vector of column names that were changed/added to the object: CustCol.

vis_out <- readRDS("data/visunet_out_nodes.RDS")
visNetwork(nodes = vis_out$nodes, edges = vis_out$edges, width = "100%")%>% 
  visLayout(randomSeed = 123) %>%
  visInteraction(hover = TRUE, navigationButtons = TRUE) %>%
  visOptions(selectedBy = list(variable = "group" , multiple = TRUE, main = "Select by decision", style = 'width: 200px; height: 30px;
                                                                padding-left: 80px;
                               font-size: 15px;
                               color: black;
                               border:none;
                               outline:none;'))


Edge customization {#CustEdges}

Example

Let’s assume that COX2 controls MAP7 and we would like to show the directionality of this edge in the rule network:

#mark the interaction between COX2 and MAP7 genes
edges_RNO <- vis_out$all$edges

#create a new vector of variables: arrows. "enabled" is the default variable for edges
edges_RNO$arrows <- rep("enabled", length(edges_RNO$label2))

#add direction to the selected edge using the label2 attribute 
edges_RNO$arrows[which(edges_RNO$label2 == "COX2=3-MAP7=2")] <- "to"

#create the edge object list
edgesL <- list(edges = edges_RNO,CustCol =   c("arrows"))

#rerun VisuNet with a new variable for edges
vis_out3 <- visunet(autcon_ruleset, type = "L", CustObjectNodes = nodesL, CustObjectEdges = edgesL)

We can rerun VisuNet using customized objects for edges by providing the original rule set and a list CustObjectEdges that contains the customized VisuNet object for edges. CustObjectEdges includes the customized object for edges: edges and a vector of column names that were changed/added to the object: CustCol.

We can rerun VisuNet using both customized objects: CustObjectEdges and CustObjectNodes.

vis_out <- readRDS("data/visunet_out_edges.RDS")
visNetwork(nodes = vis_out$nodes, edges = vis_out$edges, width = '100%')%>% 
  visLayout(randomSeed = 123) %>%
  visInteraction(hover = TRUE, navigationButtons = TRUE) %>%
  visOptions(selectedBy = list(variable = "group", multiple = TRUE, main = "Select by decision", style = 'width:   200px; height: 30px;
                                padding-left: 80px;
                               font-size: 15px;
                               color: black;
                               border:none;
                               outline:none;'))

Network for alternative rule-based classifier {#Arules}

VisuNet can be used with any rule-based model as long as the input data is created in the VisuNet format. To show the universality of VisuNet we created an association rule-based model for the case-control study of autism based on an arulesCBA package.

Example

library("arulesCBA")


#create a training set by randomly selecting 48 objects from each decsion class
autcon_training <- autcon %>% 
  group_by(decision) %>% 
  sample_n(48, set.seed=1, replace =  FALSE) %>%  
  as.data.frame()

#create a test set
id_training <- rbind(autcon_training, autcon) %>% duplicated()
id_test <- which(id_training[97:length(id_training)] == FALSE) 
autcon_test <- autcon[id_test,] 

# run the CBA classifier
classifier <-  CBA(decision ~ ., data = autcon_training) 

#obtain rules from the model
rules <- DATAFRAME(rules(classifier), setStart = '',setEnd = '')

#format a left-hand side of rules
ruleslhs <- rules$LHS

#change discretization levels from intervals to 1,2,3
ruleslhs2 <- gsub( " *\\[-Inf.*?\\) *", "1", ruleslhs)
ruleslhs2 <- gsub( " *\\[.*?\\) *", "2", ruleslhs2)
ruleslhs2 <- gsub( " *\\[.*?\\Inf] *", "3", ruleslhs2)


#select required columns from the rules 
rules2 <- rules %>%  dplyr::select(LHS:confidence)  

#replace the original left-hand side of rules with the modified version
rules2$LHS <- ruleslhs2

#rename columns name to fullfil the VisuNet input format
colnames(rules2) <- c('features', 'decision', 'supportRHS', 'accuracyRHS')

# format support to obtain intiger numbers
rules2$supportRHS <- (rules2$supportRHS * 96) %>%  round()

#run VisuNet
vis <- visunet(rules2, type = 'L')
vis_out <- readRDS("data/arules_vis.RDS")

visNetwork(nodes = vis_out$all$nodes, edges = vis_out$all$edges, width = '100%')%>% 
  visLayout(randomSeed = 123) %>%
  visInteraction(hover = TRUE, navigationButtons = TRUE) %>%
  visOptions(selectedBy = list(variable = "group", multiple = TRUE, main = "Select by decision", style = 'width:   200px; height: 30px;
                                padding-left: 80px;
                               font-size: 15px;
                               color: black;
                               border:none;
                               outline:none;'))


komorowskilab/VisuNet documentation built on Feb. 18, 2022, 8:16 p.m.