示例#1
0
  private Collection getNeighbors(CyNode node) {
    Set result = new HashSet();
    Collection edges = network.getAdjacentEdgeList(node, org.cytoscape.model.CyEdge.Type.ANY);
    if (edges == null || edges.size() == 0) return result;
    Long targetID = node.getSUID();
    for (Iterator iterator = edges.iterator(); iterator.hasNext(); ) {
      CyEdge curEdge = (CyEdge) iterator.next();
      if (curEdge.getSource().getSUID() != targetID) result.add(curEdge.getSource());
      else if (curEdge.getTarget().getSUID() != targetID) result.add(curEdge.getTarget());
    }

    return result;
  }
 public String getWeightName(CyEdge edge) {
   return getName(edge.getSource())
       + "("
       + weights.get(edges.indexOf(edge))
       + ")"
       + getName(edge.getTarget());
 }
示例#3
0
 private void addEdges() {
   for (CyEdge edge : edgeList) {
     PRNode sourceNode = idToNode.get(edge.getSource().getSUID());
     PRNode targetNode = idToNode.get(edge.getTarget().getSUID());
     PREdge prEdge = new PREdge(edge);
     insertEdgeScore(prEdge, edgeTable, edgeAttributes);
     graph.addEdge(prEdge, new Pair<>(sourceNode, targetNode), EdgeType.DIRECTED);
   }
 }
  /**
   * @param args the function arguments which must be either one object of type Double or Long
   * @return the result of the function evaluation which is the natural logarithm of the first
   *     argument
   */
  public Object evaluateFunction(final Object[] args) {
    final Long edgeID = FunctionUtil.getArgAsLong(args[0]);

    final CyNetwork currentNetwork = applicationManager.getCurrentNetwork();
    if (currentNetwork == null) return (Long) (-1L);

    final CyEdge edge = currentNetwork.getEdge(edgeID);
    if (edge == null)
      throw new IllegalArgumentException("\"" + edgeID + "\" is not a valid edge identifier.");

    return edge.getSource().getSUID();
  }
示例#5
0
      public void paintview(ArrayList<HashSet<String>> t, Color c, boolean flag) {

        for (CyEdge e : network.getEdgeList()) {
          HashSet<String> th = new HashSet<String>();
          th.add(network.getRow(e.getSource()).get("name", String.class));
          th.add(network.getRow(e.getTarget()).get("name", String.class));

          if (t.contains(th)) {

            networkView.getEdgeView(e).setLockedValue(BasicVisualLexicon.EDGE_PAINT, c);
            if (flag) {
              networkView
                  .getNodeView(e.getSource())
                  .setVisualProperty(BasicVisualLexicon.NODE_FILL_COLOR, c);
              networkView
                  .getNodeView(e.getTarget())
                  .setVisualProperty(BasicVisualLexicon.NODE_FILL_COLOR, c);
            }
          }
        }
      }
  public BellmanFordStatsImpl findPath(
      CyNetwork network, CyNode source, boolean directed, WeightFunction function) {

    Map<CyNode, MetaNode> nodeToMetaNodeMap = new IdentityHashMap<CyNode, MetaNode>();

    boolean negativeCycle = true;

    for (CyNode node : network.getNodeList()) {

      MetaNode metaNode = new MetaNode(node, Double.POSITIVE_INFINITY, null);
      nodeToMetaNodeMap.put(node, metaNode);
    }

    nodeToMetaNodeMap.get(source).setDistance(0.0);

    for (int i = 0; i < network.getNodeCount() - 1; i++) {

      for (CyEdge edge : network.getEdgeList()) {

        MetaNode sourceMetaNode = nodeToMetaNodeMap.get(edge.getSource());
        MetaNode targetMetaNode = nodeToMetaNodeMap.get(edge.getTarget());

        if (targetMetaNode.getDistance()
            > sourceMetaNode.getDistance() + function.getWeight(edge)) {
          targetMetaNode.setDistance(sourceMetaNode.getDistance() + function.getWeight(edge));
          targetMetaNode.setPredecessor(sourceMetaNode.getNode());
        }
      }
    }

    for (CyEdge edge : network.getEdgeList()) {

      MetaNode sourceMetaNode = nodeToMetaNodeMap.get(edge.getSource());
      MetaNode targetMetaNode = nodeToMetaNodeMap.get(edge.getTarget());
      if (targetMetaNode.getDistance() > sourceMetaNode.getDistance() + function.getWeight(edge))
        negativeCycle = false;
    }

    return new BellmanFordStatsImpl(source, nodeToMetaNodeMap, negativeCycle);
  }
  private double getAdjacency(CyNode neighbor, Set<CyNode> clusterNodes) {
    List<CyEdge> edgeList = network.getAdjacentEdgeList(neighbor, CyEdge.Type.ANY);
    int totalEdges = edgeList.size();
    if (totalEdges == 0) return 0;

    int adjacentEdges = 0;
    for (CyEdge edge : edgeList) {
      if (clusterNodes.contains(edge.getSource()) || clusterNodes.contains(edge.getTarget())) {
        adjacentEdges += 1;
      }
    }
    return (double) adjacentEdges / (double) totalEdges;
  }
  @Override
  public void serialize(CyNetworkView networkView, JsonGenerator jgen, SerializerProvider provider)
      throws IOException, JsonProcessingException {
    jgen.useDefaultPrettyPrinter();

    jgen.writeStartObject();
    jgen.writeStringField(
        CytoscapeJsNetworkModule.FORMAT_VERSION_TAG, CytoscapeJsNetworkModule.FORMAT_VERSION);
    jgen.writeStringField(CytoscapeJsNetworkModule.GENERATED_BY_TAG, "cytoscape-" + version);
    jgen.writeStringField(
        CytoscapeJsNetworkModule.TARGET_CYJS_VERSION_TAG,
        CytoscapeJsNetworkModule.CYTOSCAPEJS_VERSION);

    final CyNetwork network = networkView.getModel();

    // Serialize network data table
    jgen.writeObjectFieldStart(DATA.getTag());
    jgen.writeObject(network.getRow(network));
    jgen.writeEndObject();

    jgen.writeObjectFieldStart(ELEMENTS.getTag());

    // Write array
    final List<CyNode> nodes = network.getNodeList();
    final List<CyEdge> edges = network.getEdgeList();

    jgen.writeArrayFieldStart(NODES.getTag());
    for (final CyNode node : nodes) {
      jgen.writeStartObject();

      // Data field
      jgen.writeObjectFieldStart(DATA.getTag());
      jgen.writeStringField(ID.getTag(), node.getSUID().toString());
      // Write CyRow in "data" field
      jgen.writeObject(network.getRow(node));
      jgen.writeEndObject();

      // Position and other visual props
      jgen.writeObject(networkView.getNodeView(node));

      // Special case for cytoscape.js format:
      // - Selected
      jgen.writeBooleanField(
          CyNetwork.SELECTED, network.getRow(node).get(CyNetwork.SELECTED, Boolean.class));

      jgen.writeEndObject();
    }
    jgen.writeEndArray();

    jgen.writeArrayFieldStart(EDGES.getTag());
    for (final CyEdge edge : edges) {
      jgen.writeStartObject();

      jgen.writeObjectFieldStart(DATA.getTag());
      jgen.writeStringField(ID.getTag(), edge.getSUID().toString());
      jgen.writeStringField(SOURCE.getTag(), edge.getSource().getSUID().toString());
      jgen.writeStringField(TARGET.getTag(), edge.getTarget().getSUID().toString());

      // Write CyRow in "data" field
      jgen.writeObject(network.getRow(edge));

      jgen.writeEndObject();

      // Special case for cytoscape.js format:
      // - Selected
      jgen.writeBooleanField(
          CyNetwork.SELECTED, network.getRow(edge).get(CyNetwork.SELECTED, Boolean.class));

      jgen.writeEndObject();
    }
    jgen.writeEndArray();

    jgen.writeEndObject();
  }