Exemplo n.º 1
0
  /** Add any nodes that are above the neighbor threshold to our cluster */
  public NodeCluster doFilter(List<CyNode> nodeList, Map<NodeCluster, List<CyNode>> addedNodeMap) {
    Set<CyNode> clusterNodes = new HashSet<CyNode>(nodeList);
    List<CyNode> newNodeList = new ArrayList<CyNode>();
    newNodeList.addAll(nodeList);
    List<CyNode> nodesToAdd = new ArrayList<CyNode>();
    for (CyNode node : nodeList) {
      for (CyNode neighbor : network.getNeighborList(node, CyEdge.Type.ANY)) {
        if (clusterNodes.contains(neighbor)) continue;
        double adjacency = getAdjacency(neighbor, clusterNodes);
        if (adjacency > context.threshold) {
          // Add this node to our list
          nodesToAdd.add(neighbor);
        }
      }
    }

    newNodeList.addAll(nodesToAdd);

    if (newNodeList.size() > 1) {
      NodeCluster newNodeCluster = new NodeCluster(newNodeList);
      if (nodesToAdd.size() > 0) addedNodeMap.put(newNodeCluster, nodesToAdd);
      return newNodeCluster;
    }
    return null;
  }
  /** Will fail if it doesn't find the specified interaction. */
  protected void findInteraction(
      CyNetwork net, String source, String target, String interaction, int count) {
    for (CyNode n : net.getNodeList()) {
      String sname = net.getRow(n).get(CyNetwork.NAME, String.class);
      assertNotNull("Source name is NULL", sname);

      if (source.equals(sname)) {
        List<CyNode> neigh = net.getNeighborList(n, CyEdge.Type.ANY);
        assertEquals("wrong number of neighbors", count, neigh.size());

        for (CyNode nn : neigh) {
          String tname = net.getRow(nn).get(CyNetwork.NAME, String.class);
          assertNotNull("Target name is NULL", tname);

          if (tname.equals(target)) {
            List<CyEdge> con = net.getConnectingEdgeList(n, nn, CyEdge.Type.ANY);
            assertTrue("Connecting edge list is empty", con.size() > 0);

            for (CyEdge e : con) {
              String inter = net.getRow(e).get(CyEdge.INTERACTION, String.class);
              assertNotNull("Edge interaction is NULL", inter);

              if (inter.equals(interaction)) {
                return;
              }
            }
          }
        }
      }
    }
    fail("couldn't find interaction: " + source + " " + interaction + " " + target);
  }