Investigation of important elements in biological networks

How to

Other

Using the library

This section explains how to use CentiLib as a library to compute centralities or graph properties. If you want to integrate the GUI as a fixed part into your own tool, please read the section about writing a new plugin. You can use the same interface to easily integrate the GUI into your own tool.

Prerequisites

CentiLib accesses a graph with the Interface Graph. Therefore one has to implement this Interface to wrap his own graph structure and make it usable for CentiLib.

Computing Centralities

To compute centrality values for unweighted graphs, one only has to use the class CentralityHandler. With the functions isPossible(..), getScorer(..) and getGraphCentralityValue(..) it is possible to compute all centralities for a given graph (see the API-Docs for details about the methods and parameters):


Collection<VertexScorer<V,Double> > scorers = new HashSet<VertexScorer<V,Double> >();
for(String cent : CentralityHandler.getCentlist())
  if(CentralityHandler.isPossible(graph,cent)){
    VertexScorer scorer = CentralityHandler.getScorer(graph,cent,null,true)
    if(scorer != null)
      scorers.add();
  };

If there are any errors, they will be available as a string by calling CentralityHandler.getErrorMessage(). After calling this method the errors will be deleted within CentralityHandler.

Centrality Parameters

Some centralities need parameters like the alpha value for the Katz Status Index. The method CentralityHandler.getParameter(..) returns an instance that implements the Interface CentralityParameter if the given centrality needs one, null otherwise. You have to set the value for the parameter via the method setValue(value). The methods getMinValue() and getMaxValue() specify the range of possible values.

Efficiency Tasks

Besides this, there are two options that can be used to make the computations more efficient. First, the cache function can be activated via the method CentralityHandler.useCache(true). If the cache is activated, all centralities and graph properties will be computed only once. This is done by using HashMaps, which map the graphs to the appropriate values.
To use the cache properly it is required to always give the same object to CentiLib. That is, if you generate a new wrapper object each time you call one of CentiLibs functions, the cache will only grow and computed values won't be used again. So be sure to reuse the wrapper objects.
Furthermore, if a graph changes (i.e. a node was removed), it has to be removed from the cache by calling CentralityHandler.removeFromCache(graph). This is necessary because CentiLib isn't able to recognize the changes that were made to a graph and already computed values get unreliable.

The second option, to make the computations more efficient, is the usage of the algorithm for shortest-path based centralities introduced by Ulrik Brandes (see Ulrik Brandes. A faster algorithm for betweenness centrality. Journal of Mathematical Sociology, 25:163-177, 2001.). His algorithm was modified to not only compute the betweenness centrality but all shortest-path based centralities. The algorithm is based on partial dependencies that are computed after every single-source shortest-path run. By default, the shortest-path-based centralities use this algorithm, but every single centrality starts the computation of the shortest paths again.
By using the function CentralityHandler.useBrandes(true) the shortest paths will be computed only once, instead of doing it for every shortest-path-based centrality. After activating this feature, the computation of the shortest-path-based centralities has to be explicitly started:


Collection<VertexScorer<V,Double> > scorers = new HashSet<VertexScorer<V,Double> >();
CentralityHandler.useBrandes(true); scorers.add(CentralityHandler.getScorer(graph,CentralityHandler.SPBetweenness,null,true));
scorers.add(CentralityHandler.getScorer(graph,CentralityHandler.Stress,null,true));
CentralityHandler.startBrandes()

Weighted Centralities

To compute centralities for weighted graphs, the edge weights have to be stored in the cache. So the cache has to be activated before setting the edge weights:


Map edgeWeights = getEdgeWeightsFromSomeWhere(); CentralityHandler.useCache(true);
GraphCachingUtils.setEdgeWeights(graph,edgeWeights);

After saving the edge weights in the cache the following computations will make use of them. To get unweighted values again, simply remove the edge weights from the cache via GraphCachingUtils.removeEdgeWeights(graph).

Graph Properties

Have a look at the API-Docs for GraphCachingUtils to find out which properties can be computed by CentiLib and how to do so.