コード例 #1
1
ファイル: GraphMLReader.java プロジェクト: iadgov/GRASSMARLIN
    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);
    }
コード例 #2
0
  // this mutates nodeTable
  private Table makeMergeTable(Table nodeTable, Graph mergeGraph, StringBuffer mergeLog) {
    // get all the clusters in our merge graph (where each cluster is a group of nodes to be merged)
    List clusters = extractWeakComponentClusters(mergeGraph);
    // for each cluster...
    for (Iterator clusterIt = clusters.iterator(); clusterIt.hasNext(); ) {
      LinkedHashSet cluster = (LinkedHashSet) clusterIt.next();
      // mark that we will merge every node into a single node
      // (this step could be made smarter, but is ok for now. Will need user intervention in some
      // cases)
      Integer[] eachNodeInCluster = (Integer[]) cluster.toArray(new Integer[cluster.size()]);
      Integer firstNode = null;

      if (eachNodeInCluster.length <= 1) continue;
      for (int ii = 0; ii < eachNodeInCluster.length; ii++) {
        Integer node = eachNodeInCluster[ii];
        if (firstNode == null) {
          // (we arbitrarily choose the first node as the node to merge other nodes into)
          firstNode = node;
          String nodeOneAttribute =
              (String) nodeTable.getString(firstNode.intValue(), this.compareAttributeName);
          mergeLog.append("for \"" + nodeOneAttribute + "\"..." + "\r\n");

        } else {
          Integer nodeBeyondFirst = node;
          // (we merge nodes beyond the first into the first node)

          // (last value is off by one, because unique indices are 1-based instead of 0-based, but
          // otherwise correlate with row number.
          nodeTable.setInt(
              nodeBeyondFirst.intValue(), UNIQUE_INDEX_COLUMN_NAME, firstNode.intValue() + 1);
          String iAmNotThePrimaryNodeInCluster = "";
          nodeTable.setString(
              nodeBeyondFirst.intValue(),
              COMBINE_VALUES_COLUMN_NAME,
              iAmNotThePrimaryNodeInCluster);
          String nodeOneAttribute =
              (String) nodeTable.getString(nodeBeyondFirst.intValue(), this.compareAttributeName);
          mergeLog.append("  merging in \"" + nodeOneAttribute + "\"" + "\r\n");
        }
      }
    }

    return nodeTable;
  }
コード例 #3
0
  public Graph toGraph() {
    Table edgeTable = new Table();
    Table nodeTable = new Table();
    HashMap<String, Integer> unique = new HashMap<String, Integer>();

    edgeTable.addColumn("Node1", int.class);
    edgeTable.addColumn("Node2", int.class);
    nodeTable.addColumn("key", int.class);
    nodeTable.addColumn("name", String.class);
    nodeTable.addColumn("type", String.class);
    nodeTable.addColumn("indeterminate", int.class);

    int idx = 0;
    for (Protein prot : minProteins.values()) {
      int row = nodeTable.addRow();
      unique.put(prot.getName(), idx);
      nodeTable.setInt(row, "key", idx++);
      nodeTable.setString(row, "name", prot.getName());
      nodeTable.setString(row, "type", "protein");
      nodeTable.setInt(row, "indeterminate", 0);
    }

    for (Peptide pep : minPeptides.values()) {
      int row = nodeTable.addRow();
      unique.put(pep.getSequence(), idx);
      nodeTable.setInt(row, "key", idx++);
      nodeTable.setString(row, "name", pep.getSequence());
      nodeTable.setString(row, "type", "peptide");
      if (pep.getIndeterminateType() == PeptideIndeterminacyType.NONE) {
        nodeTable.setInt(row, "indeterminate", 0);
      } else {
        nodeTable.setInt(row, "indeterminate", 1);
      }
    }

    for (Protein prot : minProteins.values()) {
      int id1 = unique.get(prot.getName());
      for (String pep : prot.getPeptides()) {
        int id2 = unique.get(pep);
        int row = edgeTable.addRow();
        edgeTable.setInt(row, "Node1", id1);
        edgeTable.setInt(row, "Node2", id2);
      }
    }
    Graph g = new Graph(nodeTable, edgeTable, false, "key", "Node1", "Node2");
    // System.err.println(g.getEdgeCount());
    return g;
  }