Example #1
1
    public void endDocument() throws SAXException {
      // time to actually set up the edges
      IntIterator rows = m_edges.rows();
      while (rows.hasNext()) {
        int r = rows.nextInt();

        String src = m_edges.getString(r, SRCID);
        if (!m_nodeMap.containsKey(src)) {
          throw new SAXException(
              "Tried to create edge with source node id=" + src + " which does not exist.");
        }
        int s = ((Integer) m_nodeMap.get(src)).intValue();
        m_edges.setInt(r, SRC, s);

        String trg = m_edges.getString(r, TRGID);
        if (!m_nodeMap.containsKey(trg)) {
          throw new SAXException(
              "Tried to create edge with target node id=" + trg + " which does not exist.");
        }
        int t = ((Integer) m_nodeMap.get(trg)).intValue();
        m_edges.setInt(r, TRG, t);
      }
      m_edges.removeColumn(SRCID);
      m_edges.removeColumn(TRGID);

      // now create the graph
      m_graph = new Graph(m_nodes, m_edges, m_directed);
      if (m_graphid != null) m_graph.putClientProperty(ID, m_graphid);
    }
  /**
   * GML File constructor. STILL IN DEVELOPMENT: If the file has .xml extension, it considers that
   * it is a Syntren file, and converts it before building
   *
   * @param inputPath File path with TRN information
   */
  public NetworkData(String inputPath) {
    String ext = SyntrenFilter.getExtension(inputPath);
    if (ext.equals("xml")) {
      TRNParser.syntren2GML(inputPath, "es/usal/bicoverlapper/data/TRN.xml");
      f = new File("es/usal/bicoverlapper/data/TRN.xml");
    } else if (ext.equals("txt")) {
      TRNParser.tab2GML(inputPath, "es/usal/bicoverlapper/data/TRN.xml");
      f = new File("es/usal/bicoverlapper/data/TRN.xml");
    } else f = new File(inputPath);

    gr = new GraphMLReader();
    try {
      g = gr.readGraph(f); // takes some time for 2600 nodes, not too much
    } catch (DataIOException dioe) {
      System.out.println("Error reading " + f + ": " + dioe.getMessage());
      System.exit(1);
    }
    nNodes = g.getNodeCount();
    nEdges = g.getEdgeCount();

    g.addColumn("id", int.class);

    // Motifs (pruebas)
    // countFFLs(); //TODO: Improve the search with long number of nodes, for 2600 is terribly slow
  }
  /** @see prefuse.action.Action#run(double) */
  public void run(double frac) {

    Graph g = (Graph) m_vis.getGroup(m_group);
    initSchema(g.getNodes());

    m_origin = getLayoutAnchor();
    NodeItem n = getLayoutRoot();
    Params np = (Params) n.get(PARAMS);

    // calc relative widths and maximum tree depth
    // performs one pass over the tree
    m_maxDepth = 0;
    calcAngularWidth(n, 0);

    if (m_autoScale) setScale(getLayoutBounds());
    if (!m_setTheta) calcAngularBounds(n);

    // perform the layout
    if (m_maxDepth > 0) layout(n, m_radiusInc, m_theta1, m_theta2);

    // update properties of the root node
    setX(n, null, m_origin.getX());
    setY(n, null, m_origin.getY());
    np.angle = m_theta2 - m_theta1;
  }
Example #4
0
  /*
   * Test method for 'prefuse.Visualization.getSourceData(String)'
   */
  @Test
  public void testGetSourceData() {
    Assert.assertEquals(m_t, m_vis.getSourceData("t"));
    Assert.assertEquals(m_t, m_vt0.getSourceData());

    Assert.assertEquals(m_g, m_vis.getSourceData("g"));
    Assert.assertEquals(m_g.getNodeTable(), m_vis.getSourceData("g.nodes"));
    Assert.assertEquals(m_g.getEdgeTable(), m_vis.getSourceData("g.edges"));
    Assert.assertEquals(m_g.getNodeTable(), m_vn0.getSourceData());
  }
  public GraphVisualisation(rndalg.Graph graphToShow, Vector<Vertex> cut) {
    super();

    Graph displayed = new Graph(false);
    displayed.addColumn("id", String.class);
    displayed.addColumn("isCut", Boolean.class);

    this.makeGraph(displayed, graphToShow, cut);
    this.addGraph("graph", displayed);

    LabelRenderer r = new LabelRenderer("id");
    r.setRoundedCorner(10, 10);
    r.setHorizontalPadding(5);
    r.setVerticalPadding(2);
    this.setRendererFactory(new DefaultRendererFactory(r));

    ActionList layoutActions = new ActionList(Activity.INFINITY);
    ForceDirectedLayout layout = new ForceDirectedLayout("graph");
    layoutActions.add(layout);
    layoutActions.add(new RepaintAction());

    // black text
    ColorAction textCA =
        new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.rgb(0, 0, 0));
    // black edges
    // ColorAction edgeCA = new ColorAction("graph.edges", VisualItem.STROKECOLOR,
    // ColorLib.rgb(0,0,0));
    // edges
    ColorAction edgeCA =
        new ColorAction(
            "graph.edges",
            ExpressionParser.predicate("isCut = false"),
            VisualItem.STROKECOLOR,
            ColorLib.rgb(0, 0, 0));
    ColorAction edgeCutCA =
        new ColorAction(
            "graph.edges",
            ExpressionParser.predicate("isCut = true"),
            VisualItem.STROKECOLOR,
            ColorLib.rgb(255, 0, 0));

    // concatenate the color actions
    ActionList colorActions = new ActionList();
    colorActions.add(textCA);
    colorActions.add(edgeCA);
    colorActions.add(edgeCutCA);

    this.putAction("draw", colorActions);
    this.putAction("layout", layoutActions);
    this.runAfter("draw", "layout");

    this.run("draw");
  }
  public JPanel demo(String datafile, final String label) {
    Graph g = new Graph();
    g.addNodeRow();

    try {
      g = new GraphMLReader().readGraph(datafile);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
    return demo(g, label);
  }
    public void run(double frac) {
      TupleSet focus = m_vis.getGroup(Visualization.FOCUS_ITEMS);
      if (focus == null || focus.getTupleCount() == 0) return;

      Graph g = (Graph) m_vis.getGroup(m_group);
      Node f = null;
      @SuppressWarnings("unchecked")
      Iterator<Node> tuples = focus.tuples();
      while (tuples.hasNext() && !g.containsTuple(f = tuples.next())) {
        f = null;
      }
      if (f == null) return;
      g.getSpanningTree(f);
    }
  private void makeGraph(Graph displayed, rndalg.Graph graphToShow, Vector<Vertex> cut) {
    HashMap<rndalg.Graph.Vertex, Node> nodeMap = new HashMap<rndalg.Graph.Vertex, Node>();

    for (rndalg.Graph.Vertex v : graphToShow.vertices) {
      Node n = displayed.addNode();
      n.set("id", v.id + "");

      nodeMap.put(v, n);
    }

    for (rndalg.Graph.Edge e : graphToShow.getEdges()) {
      Edge edge = displayed.addEdge(nodeMap.get(e.a), nodeMap.get(e.b));
      edge.set("isCut", isFromCut(e, cut));
    }
  }
Example #9
0
  private static void runUDFS(final Graph g, Integer n, LinkedHashSet pre) {
    Queue q = new LinkedList();

    Node nd;
    Integer nodeRow;
    Integer nodeNumber;
    Edge edg;
    Node nd2;
    q.add(new Integer(n.intValue()));
    while (!q.isEmpty()) {
      nodeRow = new Integer(((Integer) q.poll()).intValue());
      if (!pre.contains(nodeRow)) {
        nd = g.getNode(nodeRow.intValue());
        pre.add(nodeRow);

        for (Iterator it = nd.edges(); it.hasNext(); ) {
          edg = (Edge) it.next();
          nd2 = edg.getTargetNode();
          nodeNumber = new Integer(nd2.getRow());
          if (!pre.contains(nodeNumber)) q.add(nodeNumber);
          nd2 = edg.getSourceNode();
          nodeNumber = new Integer(nd2.getRow());
          if (!pre.contains(nodeNumber)) q.add(nodeNumber);
        }
      }
    }
    nodeRow = null;
    nodeNumber = null;
    q = null;
    edg = null;
    nd2 = null;
  }
 public void addDependency(Dependency dependency) {
   Node componentNode = addNode(dependency.getComponentType());
   Node dependencyNode = addNode(dependency.getDependencyType());
   if (dependencyNode != null) {
     graph.addEdge(componentNode, dependencyNode);
   }
 }
Example #11
0
 private Node addNode(String label, int size, int index) {
   Node node = graph.addNode();
   node.setString(LABEL, label);
   node.setInt(Index, index);
   node.setInt(SIZE, size);
   return node;
 }
Example #12
0
  /**
   * sets invisible nodes with visible edges connected to them visible these nodes exist because the
   * setNodesAndEdgesVisible(...) method does not follow data flow ("DF") edges
   *
   * @param graph
   */
  private void setIsolatedNodesVisible(Graph graph) {

    Iterator graphNodes = graph.nodes();
    TableNodeItem node;

    while (graphNodes.hasNext()) {
      node = (TableNodeItem) graphNodes.next();

      if (!node.isVisible()) {
        Iterator incidentEdges = node.edges();
        int visibleEdges = 0;

        while (incidentEdges.hasNext()) {
          TableEdgeItem edge = (TableEdgeItem) incidentEdges.next();
          if (edge.isVisible()) {
            visibleEdges++;
          }
        }
        if (visibleEdges != 0) {
          node.setVisible(true);
          Iterator edges = node.edges();
          while (edges.hasNext()) {
            TableEdgeItem edgeItem = (TableEdgeItem) (edges.next());
            if (!edgeItem.getSourceItem().getString(TYPE).equals(STEP)
                && !edgeItem.getTargetItem().getString(TYPE).equals(STEP)) {
              edgeItem.setVisible(true);
            }
          }
        }
      }
    }
  }
 private Node addNode(Class type) {
   if (type != null && !nodes.containsKey(type)) {
     Node node = graph.addNode();
     node.set("type", type);
     nodes.put(type, node);
   }
   return (Node) nodes.get(type);
 }
Example #14
0
  public static Graph reverseGraph(final Graph g) {
    Graph g2 = g;
    for (Iterator it = g.edges(); it.hasNext(); ) {

      Edge e = (Edge) it.next();

      int edgeRow = e.getRow();
      e = g2.getEdge(edgeRow);
      int newTarget = e.getSourceNode().getRow();
      int newSource = e.getTargetNode().getRow();

      e.set(0, new Integer(newSource));
      e.set(1, new Integer(newTarget));
    }

    return g2;
  }
Example #15
0
 public static LinkedHashSet directedDepthFirstSearch(
     final Graph g, Integer n, boolean getPreOrder, boolean isReverse) {
   LinkedHashSet nodeSet = new LinkedHashSet();
   Graph g2 = g;
   if (isReverse) {
     if (isReverse) {
       g2 = reverseGraph(g);
     }
   }
   if (n == null) {
     for (Iterator it = g2.nodes(); it.hasNext(); ) {
       Integer nodeNumber = new Integer(((Node) it.next()).getRow());
       runDDFS(g2, nodeNumber, nodeSet, getPreOrder);
     }
   } else {
     runDDFS(g2, n, nodeSet, getPreOrder);
   }
   return nodeSet;
 }
 /**
  * Returns the number of Fast Forward Loops (FFL) network motifs found at our TRN In matrix form,
  * an FFL has this appearance 1|2|3 ------- 1|0|1|1 2|0|0|1 3|0|0|0
  */
 private void countFFLs() {
   ffls = new LinkedList<int[]>();
   for (int i = 0; i < nNodes; i++)
     for (int j = 0; j < nNodes; j++) {
       if (g.getEdge(i, j) >= 0)
         for (int k = j + 1; k < nNodes; k++) {
           if (g.getEdge(i, k) >= 0) {
             if (k != i && i != j && k != j) // Son tres nodos distintos (motif de 3)
             {
               if (g.getEdge(j, k) >= 0) {
                 ffls.add(new int[] {i, j, k});
               }
               if (g.getEdge(k, j) >= 0) {
                 ffls.add(new int[] {i, k, j});
               }
             }
           }
         } // recorremos k
     } // recorremos j
 }
Example #17
0
 private Table populateTable(Table t, Graph g) {
   for (final Iterator it = g.nodes(); it.hasNext(); ) {
     final Node n = (Node) it.next();
     t.addRow();
     for (int i = 0; i < n.getColumnCount(); i++) {
       t.set(t.getRowCount() - 1, i, n.get(i));
     }
     t.set(t.getRowCount() - 1, UNIQUE_INDEX_COLUMN_NAME, new Integer(t.getRowCount()));
   }
   return t;
 }
Example #18
0
  public SelfLoopsParallelEdges(final Graph g) {
    HashSet selfLoops = new HashSet();
    HashSet parallelEdges = new HashSet();
    HashMap edges = new HashMap();
    boolean directed = g.isDirected();
    Edge edg;

    for (Iterator it = g.edges(); it.hasNext(); ) {
      edg = (Edge) it.next();

      this.addEdge(edg, directed, selfLoops, parallelEdges, edges);
    }

    selfLoopInfo = this.calculateSelfLoops(selfLoops);
    parallelEdgeInfo = this.calculateParallelEdges(parallelEdges, edges);

    selfLoops = null;
    edges = null;
    parallelEdges = null;
    edg = null;
  }
  /**
   * Syntren File constructor. Builds a GML file from a Syntren file, saving it to disk and building
   * the TRNData
   *
   * @param inputPath Syntren input file path
   * @param outputPath GML output file path
   */
  public NetworkData(String inputPath, String outputPath) {
    TRNParser.syntren2GML(inputPath, outputPath);
    // System.out.println("Termina el conversor");

    f = new File(outputPath);
    gr = new GraphMLReader();
    try {
      g = gr.readGraph(f);
    } catch (DataIOException dioe) {
      System.out.println("Error reading " + f + ": " + dioe.getMessage());
      System.exit(1);
    }
    //	System.out.println("Hemos terminado de crear el grafo sin problemas");
    System.out.println("Network with " + g.getNodeCount() + " nodes");
    System.out.println("Network with " + g.getEdgeCount() + " edges");
    nNodes = g.getNodeCount();
    nEdges = g.getEdgeCount();

    // countFFLs();
    System.out.println("Number of FFLs found: " + ffls.size());
  }
Example #20
0
  private Graph makeMergeGraph(Table nodeTable, StringBuffer noteLog) {
    Graph mergeGraph = makeEmptyMergeGraph(nodeTable);
    // for each group of nodes with a common attribute prefix...
    ListMap groupedNodes =
        sortNodesByAttributePrefix(nodeTable, this.compareAttributeName, this.numPrefixLetters);
    for (Iterator groupIt = groupedNodes.values().iterator(); groupIt.hasNext(); ) {
      List nodeGroup = (List) groupIt.next();
      // for each pair of nodes in the group...
      for (int i = 0; i < nodeGroup.size(); i++) {
        Integer firstNodeIndex = (Integer) nodeGroup.get(i);
        for (int j = i; j < nodeGroup.size(); j++) {
          Integer secondNodeIndex = (Integer) nodeGroup.get(j);
          // test how similar the two nodes are
          float similarity =
              compareNodesCaseInsensitiveBy(
                  this.compareAttributeName, firstNodeIndex, secondNodeIndex, nodeTable);

          // if their similarity is high enough to merge...
          if (similarity >= this.mergeOnSimilarity) {
            // link the nodes in the merge graph
            mergeGraph.addEdge(firstNodeIndex.intValue(), secondNodeIndex.intValue());
          }
          // else if their similarity is noteworthy...
          else if (similarity >= this.makeNoteOnSimilarity) {
            // record it in the log
            String nodeOneAttribute =
                (String) nodeTable.getString(firstNodeIndex.intValue(), this.compareAttributeName);
            String nodeTwoAttribute =
                (String) nodeTable.getString(secondNodeIndex.intValue(), this.compareAttributeName);
            noteLog.append("" + similarity + " similar:" + "\r\n");
            noteLog.append("  \"" + nodeOneAttribute + "\"" + "\r\n");
            noteLog.append("  \"" + nodeTwoAttribute + "\"" + "\r\n");
          }
        }
      }
    }

    return mergeGraph;
  }
Example #21
0
  public List extractWeakComponentClusters(final Graph grph) {
    List clusters = new ArrayList();

    HashSet seenNodes = new HashSet();
    for (Iterator it = grph.nodes(); it.hasNext(); ) {
      Node n = (Node) it.next();
      Integer i = new Integer(n.getRow());
      if (!seenNodes.contains(i)) {

        LinkedHashSet cluster = GraphSearchAlgorithms.undirectedDepthFirstSearch(grph, i);
        seenNodes.addAll(cluster);
        clusters.add(cluster);
      }
    }
    return clusters;
  }
Example #22
0
  public static LinkedHashSet undirectedDepthFirstSearch(final Graph g, Integer n) {

    LinkedHashSet nodeSet = new LinkedHashSet();
    Integer nodeNumber;
    if (n == null) { // If no node number is presented, search the whole graph.
      for (Iterator it = g.nodes(); it.hasNext(); ) {
        nodeNumber = new Integer(((Node) it.next()).getRow());
        runUDFS(g, nodeNumber, nodeSet);
      }
    } else { // Otherwise, just search the specific node.
      nodeNumber = new Integer(n.intValue());
      runUDFS(g, nodeNumber, nodeSet);
    }

    return nodeSet;
  }
Example #23
0
  /**
   * sets nodes with no visible edges connected to them (isolated nodes) invisible these nodes exist
   * because the setNodesAndEdgesInvisible(...) method does not follow data flow ("DF") edges
   *
   * @param graph
   */
  private void setIsolatedNodesInvisible(Graph graph) {

    Iterator graphNodes = graph.nodes();
    TableNodeItem node;
    boolean rootDrawn = false;
    while (graphNodes.hasNext()) {
      node = (TableNodeItem) graphNodes.next();
      if (node.isVisible() && getOutVDegree(node) == 0 && rootDrawn) {
        node.setVisible(false);
        Iterator incidentEdges = node.edges();
        while (incidentEdges.hasNext()) {
          ((TableEdgeItem) incidentEdges.next()).setVisible(false);
        }
      }
      rootDrawn = true;
    }
  }
  /**
   * Returns the node item which should be used as root of the layout. If the nextRootItem was
   * explicitly set, this item is returned, otherwise this method behaves like the getLayoutRoot()
   * method from the RadialTreeLayout
   */
  public NodeItem getLayoutRoot() {
    if (m_root != null) return m_root;

    TupleSet ts = m_vis.getGroup(m_group);
    if (ts instanceof Graph) {
      if (nextRootItem != null) {
        ((Graph) ts).getSpanningTree(nextRootItem);
        NodeItem ret = nextRootItem;
        nextRootItem = null;
        return ret;
      } else {
        Tree tree = ((Graph) ts).getSpanningTree();
        return (NodeItem) tree.getRoot();
      }
    } else {
      throw new IllegalStateException(
          "This action's data group does" + "not resolve to a Graph instance.");
    }
  }
Example #25
0
  @Before
  public void setUp() {
    m_vis = new Visualization();
    m_t = TableTest.getTestCaseTable();
    m_g = GraphTest.getTestCaseGraph();

    m_t0 = m_t.getTuple(0);
    m_n0 = m_g.getNode(0);

    VisualTable vt = (VisualTable) m_vis.add("t", m_t);
    VisualGraph vg = (VisualGraph) m_vis.add("g", m_g);

    m_vt0 = vt.getItem(0);
    m_vn0 = (NodeItem) vg.getNode(0);

    TupleSet ts = m_vis.getFocusGroup(Visualization.FOCUS_ITEMS);
    ts.addTuple(m_vt0);
    ts.addTuple(m_vn0);
  }
Example #26
0
  private static void runDDFS(final Graph g, Integer n, LinkedHashSet nodeSet, boolean isPreOrder) {
    boolean done = false;

    Node nd;
    Node nd2;
    Integer nodeRow;
    Integer nodeNumber;

    Stack nodeStack = new Stack();

    nodeStack.add(new Integer(n.intValue()));
    while (!nodeStack.isEmpty()) {
      nodeRow = (Integer) nodeStack.peek();
      nd = g.getNode(nodeRow.intValue());
      if (!nodeSet.contains(nodeRow)) {
        if (isPreOrder) nodeSet.add(nodeRow);
        nodeSet.add(nodeRow);
      }
      done = true;
      for (Iterator it = nd.outNeighbors(); it.hasNext(); ) {
        nd2 = ((Node) it.next());
        nodeNumber = new Integer(nd2.getRow());
        if (!nodeSet.contains(nodeNumber)) {
          nodeStack.add(nodeNumber);
          done = false;
          break;
        }
      }
      if (done) {
        if (!isPreOrder) nodeSet.add(nodeRow);
        nodeStack.pop();
      }
    }
    nodeStack = null;
    nd = null;
    nd2 = null;
    nodeRow = null;
    nodeNumber = null;
  }
  private void initDataGroups() {
    // create sample graph
    // 9 nodes broken up into 3 interconnected cliques
    Graph g = new Graph();
    for (int i = 0; i < 3; ++i) {
      Node n1 = g.addNode();
      Node n2 = g.addNode();
      Node n3 = g.addNode();
      g.addEdge(n1, n2);
      g.addEdge(n1, n3);
      g.addEdge(n2, n3);
    }
    g.addEdge(0, 3);
    g.addEdge(3, 6);
    g.addEdge(6, 0);

    // add visual data groups
    VisualGraph vg = m_vis.addGraph(GRAPH, g);
    m_vis.setInteractive(EDGES, null, false);
    m_vis.setValue(NODES, null, VisualItem.SHAPE, new Integer(Constants.SHAPE_ELLIPSE));

    at = m_vis.addAggregates(AGGR);
    at.addColumn(VisualItem.POLYGON, float[].class);
    at.addColumn("id", int.class);

    // add nodes to aggregates
    // create an aggregate for each 3-clique of nodes
    Iterator nodes = vg.nodes();
    for (int i = 0; i < 3; ++i) {
      AggregateItem aitem = (AggregateItem) at.addItem();
      aitem.setInt("id", i);
      for (int j = 0; j < 3; ++j) {
        aitem.addItem((VisualItem) nodes.next());
      }
    }
  }
Example #28
0
 private Table constructAlteredNodeTable(prefuse.data.Graph graph) {
   Table outputTable = new Table();
   outputTable = createTableSchema(graph.getNodeTable().getSchema(), outputTable);
   outputTable = populateTable(outputTable, graph);
   return outputTable;
 }
Example #29
0
 /** @see prefuse.data.Node#getParentEdge() */
 public Edge getParentEdge() {
   return m_graph.getSpanningTree().getParentEdge(this);
 }
Example #30
0
 /** @see prefuse.data.Node#getParent() */
 public Node getParent() {
   return m_graph.getSpanningTree().getParent(this);
 }