コード例 #1
0
 public String getWeightName(CyEdge edge) {
   return getName(edge.getSource())
       + "("
       + weights.get(edges.indexOf(edge))
       + ")"
       + getName(edge.getTarget());
 }
コード例 #2
0
ファイル: PR.java プロジェクト: nrnb/clusterMaker2
 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);
   }
 }
コード例 #3
0
  /**
   * @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();
  }
コード例 #4
0
  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;
  }
コード例 #5
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;
  }
コード例 #6
0
  /** {@inheritDoc} */
  @Override
  public void mapToTable(Graph graph, Edge edge, Evidence evidence, CyTable table) {
    if (graph == null) throw new NullPointerException("graph cannot be null");
    if (edge == null) throw new NullPointerException("edge cannot be null");
    if (evidence == null) throw new NullPointerException("evidence cannot be null");
    if (table == null) throw new NullPointerException("table cannot be null");
    if (graph.cyNetwork == null)
      throw new IllegalArgumentException("graph's cyNetwork cannot be null");
    if (edge.cyEdge == null) throw new IllegalArgumentException("edge's cyEdge cannot be null");

    CyNetwork cyN = graph.cyNetwork;
    CyEdge cyE = edge.cyEdge;

    CyRow networkRow = cyN.getRow(cyN);
    String networkName = networkRow.get(CyNetwork.NAME, String.class);
    CyRow row = table.getRow(SUIDFactory.getNextSUID());

    row.set(NETWORK_SUID, cyN.getSUID());
    row.set(NETWORK_NAME, networkName);
    row.set(EDGE_SUID, cyE.getSUID());
    row.set(BEL_STATEMENT, evidence.belStatement);
    row.set(SUMMARY_TEXT, evidence.summaryText);

    if (evidence.citation != null) {
      row.set(CITATION_TYPE, evidence.citation.type);
      row.set(CITATION_ID, evidence.citation.id);
      row.set(CITATION_NAME, evidence.citation.name);
    }

    if (evidence.biologicalContext != null) {
      // create any annotation columns that do not already exist
      BiologicalContext bc = evidence.biologicalContext;
      for (String varyingKey : bc.variedAnnotations.keySet()) {
        getOrCreateColumn(varyingKey, String.class, false, table);
      }

      // set annotation values
      row.set(SPECIES, bc.speciesCommonName);
      Map<String, Object> varying = bc.variedAnnotations;
      for (Entry<String, Object> entry : varying.entrySet()) {
        row.set(entry.getKey(), getOrEmptyString(entry.getKey(), varying));
      }
    }
  }
コード例 #7
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);
            }
          }
        }
      }
コード例 #8
0
  /** {@inheritDoc} */
  @Override
  public Evidence[] mapFromTable(CyEdge edge, CyTable table) {
    if (edge == null) throw new NullPointerException("edge cannot be null");
    if (table == null) throw new NullPointerException("table cannot be null");

    Set<String> nonAnnotationColumns =
        new HashSet<String>(
            asList(
                CyNetwork.SUID,
                NETWORK_SUID,
                NETWORK_NAME,
                EDGE_SUID,
                BEL_STATEMENT,
                SUMMARY_TEXT,
                CITATION_ID,
                CITATION_NAME,
                CITATION_TYPE,
                SPECIES));

    Collection<CyRow> evidenceRows = table.getMatchingRows(EDGE_SUID, edge.getSUID());
    List<Evidence> evidences = new ArrayList<Evidence>(evidenceRows.size());
    if (!evidenceRows.isEmpty()) {
      for (CyRow evRow : evidenceRows) {
        Evidence e = new Evidence();
        e.belStatement = evRow.get(BEL_STATEMENT, String.class);
        e.summaryText = evRow.get(SUMMARY_TEXT, String.class);
        e.citation = new Citation();
        e.citation.id = evRow.get(CITATION_ID, String.class);
        e.citation.name = evRow.get(CITATION_NAME, String.class);
        e.citation.type = evRow.get(CITATION_TYPE, String.class);
        e.biologicalContext = new BiologicalContext();
        e.biologicalContext.speciesCommonName = evRow.get(SPECIES, String.class);
        e.biologicalContext.variedAnnotations = new HashMap<String, Object>();
        for (Entry<String, Object> columnValue : evRow.getAllValues().entrySet()) {
          if (nonAnnotationColumns.contains(columnValue.getKey())) continue;
          e.biologicalContext.variedAnnotations.put(columnValue.getKey(), columnValue.getValue());
        }
        evidences.add(e);
      }
    }

    return evidences.toArray(new Evidence[evidences.size()]);
  }
  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);
  }
コード例 #10
0
  @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();
  }