BIOGRAPHDEMO Tools for rendering interconnected graph 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.

Contents

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 commenting the following lines).

sel = getbyname(tr,'human');
tr = prune(tr,~sel(1:37))
    Phylogenetic tree object with 10 leaves (9 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 the information from the PHYTREE object.

[treePtrs,names,nn,nb,nl] = get(tr,'Pointers','NodeNames',...
                                'NumNodes','NumBranches','NumLeaves');

Build a connection matrix up using the tree information.

cm = zeros(nn);
for k = 1:nb
    cm(treePtrs(k,:),k+nl) = 1;
end

Fill empty names of branches so that they can be used as graph node IDS (BIOGRAPH node IDs must be unique).

for k = nl+1:nn
    names{k} = ['Branch ' num2str(k-nl)];
end

For this type of interconnected data (a phylogenetic tree), it is better to have the root of the tree represented by the first BIOGRAPH node. Therefore you need to flip the connection matrix and the names before constructing the BIOGRAPH object.

cm = cm(end:-1:1,end:-1:1);
names = names(end:-1:1);

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

bg = biograph(cm,names)
get(bg)
Biograph object with 19 nodes and 18 edges.
              ID: ''
           Label: ''
     Description: ''
      LayoutType: 'hierarchical'
        EdgeType: 'curved'
           Scale: 1
     LayoutScale: 1
      ShowArrows: 'on'
    NodeAutoSize: 'on'
    NodeCallback: 'display'
    EdgeCallback: 'display'
           Nodes: [19x1 biograph.node]
           Edges: [18x1 biograph.edge]

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

bg.LayoutType = 'radial';
bg.LayoutScale = 3/4;
get(bg)
              ID: ''
           Label: ''
     Description: ''
      LayoutType: 'radial'
        EdgeType: 'curved'
           Scale: 1
     LayoutScale: 0.7500
      ShowArrows: 'on'
    NodeAutoSize: 'on'
    NodeCallback: 'display'
    EdgeCallback: 'display'
           Nodes: [19x1 biograph.node]
           Edges: [18x1 biograph.edge]

Before rendering the graph, you need to calculate the best location at that every node should be drawn. dolayout is the method that calls the layout engine.

dolayout(bg)

Draw the BIOGRAPH object in a viewer window, then get the object handle so you can change some of the rendering properties.

bgInViewer = view(bg)
Biograph object with 19 nodes and 18 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.

set(bgInViewer.Nodes(1:nb),'Color',[.7 1 .7])

Changing some properties requires you to run the layout engine again. First change the 'Shape' of the branches to circles.

set(bgInViewer.Nodes(1:nb),'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.

bgInViewer.NodeAutoSize = 'off';
set(bgInViewer.Nodes(1:nb),'Size',[20 20])
set(bgInViewer.Nodes(1:nb),'Label','')
dolayout(bgInViewer)