/**
   * 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 java.lang.Runnable#run() */
  public void run() {
    while (true) {
      Entry e = null;
      synchronized (s_queue) {
        if (s_queue.size() > 0) e = (Entry) s_queue.remove(0);
      }

      if (e != null) {
        try {
          if (e.listener != null) e.listener.preQuery(e);
          e.ds.getData(e.table, e.query, e.keyField, e.lock);
          if (e.listener != null) e.listener.postQuery(e);
        } catch (DataIOException dre) {
          s_logger.warning(dre.getMessage() + "\n" + StringLib.getStackTrace(dre));
        }
      } else {
        // nothing to do, chill out until notified
        try {
          synchronized (this) {
            wait();
          }
        } catch (InterruptedException ex) {
        }
      }
    }
  }
  /**
   * 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());
  }
Exemple #4
0
    public Data[] execute() {
      LogService logger = (LogService) context.getService(LogService.class.getName());

      String fileHandler = (String) data[0].getData();
      File inData = new File(fileHandler);

      try {
        if (validateGraphMLHeader(inData)) {
          (new GraphMLReader()).readGraph(new FileInputStream(fileHandler));
          Data[] dm = new Data[] {new BasicData(inData, "file:text/graphml+xml")};
          dm[0].getMetaData().put(DataProperty.LABEL, "Prefuse GraphML file: " + fileHandler);
          dm[0].getMetaData().put(DataProperty.TYPE, DataProperty.NETWORK_TYPE);
          return dm;
        } else return null;
      } catch (DataIOException dioe) {
        logger.log(
            LogService.LOG_ERROR, "Might not be a GraphML file. Got the following exception");
        logger.log(LogService.LOG_ERROR, "DataIOException", dioe);
        dioe.printStackTrace();
        return null;
      } catch (SecurityException exception) {
        logger.log(
            LogService.LOG_ERROR, "Might not be a GraphML file. Got the following exception");
        logger.log(LogService.LOG_ERROR, "SecurityException", exception);
        exception.printStackTrace();
        return null;
      } catch (FileNotFoundException e) {
        logger.log(LogService.LOG_ERROR, "FileNotFoundException", e);
        e.printStackTrace();
        return null;
      } catch (IOException ioe) {
        logger.log(LogService.LOG_ERROR, "IOException", ioe);
        ioe.printStackTrace();
        return null;
      }
    }
Exemple #5
0
  public static void main(String[] argv) {

    // -- 1. load the data ------------------------------------------------

    // load the socialnet.xml file. it is assumed that the file can be
    // found at the root of the java classpath
    Graph graph = null;
    try {
      graph = new GraphMLReader().readGraph(System.in);
    } catch (DataIOException e) {
      e.printStackTrace();
      System.err.println("Error loading graph. Exiting...");
      System.exit(1);
    }

    // -- 2. the visualization --------------------------------------------

    // add the graph to the visualization as the data group "graph"
    // nodes and edges are accessible as "graph.nodes" and "graph.edges"
    Visualization vis = new Visualization();
    vis.add("graph", graph);
    vis.setInteractive("graph.edges", null, false);

    // -- 3. the renderers and renderer factory ---------------------------

    // draw the "name" label for NodeItems
    LabelRenderer r = new LabelRenderer("label");
    r.setRoundedCorner(8, 8); // round the corners

    EdgeRenderer eRender =
        new EdgeRenderer(Constants.EDGE_TYPE_CURVE, Constants.EDGE_ARROW_FORWARD);

    // create a new default renderer factory
    // return our name label renderer as the default for all non-EdgeItems
    // includes straight line edges for EdgeItems by default
    vis.setRendererFactory(new DefaultRendererFactory(r, eRender));

    // -- 4. the processing actions ---------------------------------------

    // create our nominal color palette
    // pink for females, baby blue for males
    int[] palette =
        new int[] {
          ColorLib.rgb(190, 190, 255), ColorLib.rgb(255, 180, 180), ColorLib.rgb(128, 128, 128),
        };
    // map nominal data values to colors using our provided palette
    DataColorAction fill =
        new DataColorAction(
            "graph.nodes", "type", Constants.NOMINAL, VisualItem.FILLCOLOR, palette);

    // use black for node text
    ColorAction text = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.gray(0));
    // use light grey for edges
    ColorAction edges = new ColorAction("graph.edges", VisualItem.STROKECOLOR, ColorLib.gray(200));
    ColorAction arrows = new ColorAction("graph.edges", VisualItem.FILLCOLOR, ColorLib.gray(200));

    // create an action list containing all color assignments
    ActionList color = new ActionList();
    color.add(fill);
    color.add(text);
    color.add(edges);
    color.add(arrows);

    // Add a size action
    DataSizeAction size = new DataSizeAction("graph.nodes", "type", 2, Constants.LINEAR_SCALE);
    vis.putAction("size", size);

    // create an action list with an animated layout
    ActionList layout = new ActionList(Activity.INFINITY);
    layout.add(new ForceDirectedLayout("graph"));
    layout.add(new RepaintAction());

    // add the actions to the visualization
    vis.putAction("color", color);
    vis.putAction("layout", layout);

    // -- 5. the display and interactive controls -------------------------

    Display d = new Display(vis);
    d.setSize(720, 500); // set display size
    // drag individual items around
    d.addControlListener(new DragControl());
    // pan with left-click drag on background
    d.addControlListener(new PanControl());
    // zoom with right-click drag
    d.addControlListener(new ZoomControl());

    // -- 6. launch the visualization -------------------------------------

    // create a new window to hold the visualization
    JFrame frame = new JFrame("IFDS Visualization");
    // ensure application exits when window is closed
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(d);
    frame.pack(); // layout components in window
    frame.setVisible(true); // show the window

    // assign the colors
    vis.run("color");
    // start up the animated layout
    vis.run("layout");
  }