eXamine Automation Tutorial

This case study demonstrates how to use the REST API of eXamine to study a small, annotated graph in Cytoscape. The graph we study is Zachary's karate club.


In [ ]:
# HTTP Client for Python
import requests

# Cytoscape port number
PORT_NUMBER = 1234

BASE_URL = "https://raw.githubusercontent.com/ls-cwi/eXamine/master/data/"

# The Base path for the CyRest API
BASE = 'http://localhost:' + str(PORT_NUMBER) + '/v1/'

#Helper command to call a command via HTTP POST
def executeRestCommand(namespace="", command="", args={}):
    postString = BASE + "commands/" + namespace + "/" + command
    res = requests.post(postString,json=args)
    return res

Importing network and node-specific annotation

We start by importing the graph directly from the eXamine repository on github.


In [ ]:
# First we import our demo network
executeRestCommand("network", "import url", {"indexColumnSourceInteraction":"1",
                                             "indexColumnTargetInteraction":"2",
                                             "url": BASE_URL + "edges_karate.gml"})

We then import node-specific annotation directly from the eXamine repository on github. The imported file contains set membership information for each node. Note that it is important to ensure that set-membership information is imported as List of String, as indicated by sl. Additionaly, note that the default list separator is a pipe character.


In [ ]:
# Next we import node annotations
executeRestCommand("table", "import url",
                   {"firstRowAsColumnNames":"true",
                    "keyColumnIndex" : "1",
                    "startLoadRow" : "1",
                    "dataTypeList":"s,sl",
                    "url": BASE_URL + "nodes_karate.txt"})

In [ ]:
executeRestCommand("network", "select", {"nodeList" : "all"})

In [ ]:
executeRestCommand("examine", "generate groups",
                   {"selectedGroupColumns" : "Community"})

Set-based visualization using eXamine

We now describe how to visualize the current selection. First, we set the visualization options.


In [ ]:
# Adjust the visualization settings
executeRestCommand("examine", "update settings",
                   {"labelColumn" : "label",
                    "URL" : "label",
                    "showScore" : "false",
                    "selectedGroupColumns" : "Community"})

We then select six groups.


In [ ]:
# Select groups for demarcation in the visualization
executeRestCommand("examine", "select groups",
                   {"selectedGroups":"A,B,C,D,E,F"})

There are two options: either we launch the interactive eXamine visualization, or we directly generate an SVG.


In [ ]:
# Launch the interactive eXamine visualization
executeRestCommand("examine", "interact", {})

The command below launches the eXamine window. If this window is blank, simply resize the window to force a redraw of the scene.


In [ ]:
# Export a graphic instead of interacting with it
# use absolute path; writes in Cytoscape directory if not changed 
executeRestCommand("examine", "export", {"path": "test.svg"})