Visually Representing Interconnected Data

This example shows how to use the BIOGRAPH object to visually represent interconnected data.

The need for representing interconnected data appears in several bioinformatics applications. For example, protein-protein interactions, network inference, reaction pathways, cluster data, Bayesian networks, and phylogenetic trees can be represented with interconnected graphs. The BIOGRAPH object allows you to create a comprehensive and graphical layout of this type of data. In this example you learn how to populate a BIOGRAPH object, render it, and then modify its properties in order to customize its display.

Representing a Phylogenetic Tree as a Graph

Read a phylogenetic tree into a PHYTREE object.

tr = phytreeread('pf00002.tree');

Reduce the tree to only the human proteins (to make the example smaller, you can also use the full tree by omitting the following lines).

sel = getbyname(tr,'human');
tr = prune(tr,~sel(1:33))

Phylogenetic tree object with 11 leaves (10 branches)

The plot method for a PHYTREE object can create a basic layout of the phylogenetic tree; however, the graph elements are static.

plot(tr)

The PHYTREE object information can be put into a BIOGRAPH object, so you can create a dynamic layout. First, pull some information from the PHYTREE object. Use get to obtain the PHYTREE object properties and the getmatrix method to obtain the connection matrix.

A connection matrix of a low degree graph is best represented by a sparse matrix. The average degree of a phylogenetic tree is approximately equal to two. You can use the function spy to visualize the sparsity pattern, every mark represents an edge in the graph.

figure
spy(cm)
colormap(flipud(bone))
title('Top-down direct edges')

A different approach to visualize this information is to look at pairwise distances between all the nodes (branches and leaves) in the tree. Use the pdist method for PHYTREE objects to find the pairwise distances.

Phylogenetic tree datasets provide the root of the tree as the last element in the set. When building a BIOGRAPH connection matrix, it helps to reverse the order of both the data and names, so that the graph is built from the root out. This will create a more logical and visually appealing presentation.

cm = flipud(fliplr(cm));
names = flipud(names);

Call the BIOGRAPH object constructor with the connection matrix and the node IDs. To explore its properties you can use the get function.

Once a BIOGRAPH object has been created with the essential information (the connection matrix and node IDs), you can modify its properties. For example, change the layout type to 'radial', which is best for phylogenetic data and the scale.

Although nodes and edges have been created, the BIOGRAPH object does not have the coordinates in which the graph elements should be drawn such that its rendering results into a pretty and uncluttered display. Before rendering a BIOGRAPH object, you need to calculate an appropriate location for every node. dolayout is the method that calls the layout engine.

Some properties of the BIOGRAPH object interact with the layout engine, among them 'LayoutType' which selects the layout algorithm.

dolayout(bg)

Draw the BIOGRAPH object in a viewer window. The view method creates a Graphical User Interface (GUI) with the interconnected graph returning a handle to a deep copy of the BIOGRAPH object which is contained by the figure. With this object handle you can later change some of the rendering properties.

bgInViewer = view(bg)

Biograph object with 21 nodes and 20 edges.

Changing the BIOGRAPH Object Properties

You might want to change the color of all the nodes that represent branches. Knowing that the first 'nb' nodes are branches, you can use the vectorized form of set to change the 'Color' property of these nodes.

Changing some geometrical properties requires you to call the dolayout method again to update the graph to the desired specifications.

% First change the 'Shape' of the branches to circles.
set(branchHandlers,'Shape','circle')

Notice that the new shape is an ellipse and the edges do not connect nicely to the limits of new shapes.

Now, run the layout engine over the BIOGRAPH object contained by the viewer to correct the shapes and the edges.

dolayout(bgInViewer)

The extent (size) of the nodes is estimated automatically using the node 'FontSize' and 'Label' properties. You can force the nodes to have any size by turning off the BIOGRAPH 'NodeAutoSize' property and then refreshing the layout.

To remove the labels from the branch node, we need to manually copy the text strings from the 'ID' property to the 'Label' property. dolayout automatically sets the 'ShowTextInNodes' property to 'ID' if all nodes have their 'Label' property empty. By default when a new biograph object is created the 'Label' properties are empty.

Drawing Customized Nodes

You can draw your own customized nodes in the layout; for example, pie charts or histograms may be embedded into the nodes. In this example you will use the function customnodedraw (an example in the biodemos directory) to display the atomic composition of each protein as a pie chart. Use this function as a template to create your own customized nodes.

Get the sequences of the current human proteins you are working with and put the sequences into the "UserData" property of their respective nodes. Also store the vector with the respective atomic composition.