Package org.gvt.action

Source Code of org.gvt.action.DebugButtonAction

package org.gvt.action;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
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;
import org.patika.mada.graph.Node;
import org.patika.mada.graph.GraphObject;
import org.patika.mada.algorithm.BFS;
import org.biopax.paxtools.model.level2.physicalEntity;

import java.util.*;

/**
*
* @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()
  {
    debug();
  }

  public void debug()
  {
  }

  public void testAlgo()
  {
    ScrollingGraphicalViewer viewer = main.getViewer();
    Iterator selectedObjects = ((IStructuredSelection) viewer.getSelection()).iterator();

    Set<Node> selectedNodes = new HashSet<Node>();
    while (selectedObjects.hasNext())
    {
      Object model = ((EditPart)selectedObjects.next()).getModel();

      if (model instanceof Node)
      {
        Node node = (Node) model;

        if (node instanceof ComplexMember)
        {
          node = node.getParents().iterator().next();
        }

        selectedNodes.add(node);
      }
    }

    BFS bfs = new BFS(selectedNodes, null, false, 1);

    Map<GraphObject, Integer> map = bfs.run();

    for (GraphObject go : map.keySet())
    {
      go.setHighlight(true);
    }
  }

  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);
  }
}
TOP

Related Classes of org.gvt.action.DebugButtonAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.