package org.gvt.action;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.gvt.ChisioMain;
import org.gvt.model.NodeModel;
import org.gvt.model.biopaxl2.Actor;
import org.gvt.model.biopaxl2.BioPAXGraph;
import org.gvt.model.biopaxl2.Compartment;
import org.gvt.model.biopaxl2.ComplexMember;
/**
*
* @author Ozgun Babur
*
* Copyright: Bilkent Center for Bioinformatics, 2007 - present
*/
public class DebugButtonAction extends Action
{
ChisioMain main;
/**
* Constructor
*/
public DebugButtonAction(ChisioMain main)
{
super("Debug button");
this.setToolTipText(
"Debug Button - You can run any\n" +
"code after pressing this button.\n" +
"Insert your code in the class\n" +
"DebugButtonAction");
setImageDescriptor(ImageDescriptor.createFromFile(ChisioMain.class, "icon/bug.png"));
this.main = main;
}
public void run()
{
calculateAverageNodeDegree();
}
private void calculateAverageNodeDegree()
{
BioPAXGraph graph = main.getRootGraph();
int totalDegree = 0;
int nodeCounted = 0;
for (Object o : graph.getNodes())
{
NodeModel node = (NodeModel) o;
if (node instanceof ComplexMember ||
node instanceof Compartment ||
(node instanceof Actor && ((Actor) node).isUbique()))
{
continue;
}
int degree = node.getSourceConnections().size() + node.getTargetConnections().size();
if (degree > 15)
{
System.out.println("degree = " + degree + " node = " + node.getText() + " type = " +
node.getClass().getName().substring(
node.getClass().getName().lastIndexOf(".") + 1));
}
totalDegree += degree;
nodeCounted++;
}
System.out.println("\nnodeCounted = " + nodeCounted);
System.out.println("totalDegree = " + totalDegree);
System.out.println("average degree = " + totalDegree / (double) nodeCounted);
}
}