Ejemplo n.º 1
0
  /**
   * Query all edges of worm regulatory network.
   *
   * @param model the Model
   * @param executor to run the query
   * @return interactionEdgeSet
   */
  private static void queryWormRegulatoryEdges(Model model, PathQueryExecutor executor) {

    interactionEdgeSetWorm = new LinkedHashSet<CytoscapeNetworkEdgeData>();

    PathQuery query = new PathQuery(model);
    query.addViews(
        "Regulation.type", // interaction type, e.g. TF-TF
        "Regulation.source.primaryIdentifier",
        "Regulation.source.symbol",
        "Regulation.source.id",
        "Regulation.target.primaryIdentifier",
        "Regulation.target.symbol",
        "Regulation.target.id");

    query.addConstraint(Constraints.eq("Regulation.source.organism.shortName", "C. elegans"));

    ExportResultsIterator result;
    try {
      result = executor.execute(query);
    } catch (ObjectStoreException e) {
      throw new RuntimeException("Error retrieving results.", e);
    }

    while (result.hasNext()) {
      List<ResultElement> row = result.next();

      String interactionType = (String) row.get(0).getField();
      String sourcePId = (String) row.get(1).getField();
      String sourceSymbol = (String) row.get(2).getField();
      Integer sourceId = (Integer) row.get(3).getField();
      String targetPId = (String) row.get(4).getField();
      String targetSymbol = (String) row.get(5).getField();
      Integer targetId = (Integer) row.get(6).getField();

      // TODO Hack for a database issue
      //            if ("blmp-1".equals(targetSymbol)) {
      //                targetId = 1644007904;
      //            }
      //
      //            if ("unc-130".equals(targetSymbol)) {
      //                targetId = 1644015202;
      //            }
      //
      //            if ("mab-5".equals(targetSymbol)) {
      //                targetId = 1644006300;
      //            }
      //
      //            if ("mdl-1".equals(targetSymbol)) {
      //                targetId = 1644006399;
      //            }
      //
      //            if ("elt-3".equals(targetSymbol)) {
      //                targetId = 1644003204;
      //            }
      //
      //            if ("lin-11".equals(targetSymbol)) {
      //                targetId = 1644006039;
      //            }
      //
      //            if ("skn-1".equals(targetSymbol)) {
      //                targetId = 1644009973;
      //            }
      //
      //            if ("egl-27".equals(targetSymbol)) {
      //                targetId = 1644003074;
      //            }

      CytoscapeNetworkEdgeData aEdge = new RegulatoryNetworkEdgeData();

      aEdge.setSourceId(String.valueOf(sourceId));

      if (sourceSymbol == null || sourceSymbol.length() < 1) {
        aEdge.setSourceLabel(sourcePId);
      } else {
        aEdge.setSourceLabel(sourceSymbol);
      }

      aEdge.setTargetId(String.valueOf(targetId));

      if (targetSymbol == null || targetSymbol.length() < 1) {
        aEdge.setTargetLabel(targetPId);
      } else {
        aEdge.setTargetLabel(targetSymbol);
      }

      aEdge.setInteractionType(interactionType);

      interactionEdgeSetWorm.add(aEdge);
    }
  }
Ejemplo n.º 2
0
  /**
   * Query all edges of fly regulatory network.
   *
   * @param model the Model
   * @param executor to run the query
   * @return interactionEdgeSet
   */
  private static void queryFlyRegulatoryEdges(Model model, PathQueryExecutor executor) {

    interactionEdgeSetFly = new LinkedHashSet<CytoscapeNetworkEdgeData>();

    // TODO fly doesn't use IM Object id
    PathQuery query = new PathQuery(model);
    query.addViews(
        "Regulation.type", // interaction type, e.g. TF-TF
        "Regulation.source.primaryIdentifier",
        "Regulation.source.symbol",
        "Regulation.target.primaryIdentifier",
        "Regulation.target.symbol");

    query.addConstraint(Constraints.eq("Regulation.source.primaryIdentifier", "FBgn*"), "A");
    query.addConstraint(Constraints.eq("Regulation.target.primaryIdentifier", "FBgn*"), "B");

    query.setConstraintLogic("A and B");

    ExportResultsIterator result;
    try {
      result = executor.execute(query);
    } catch (ObjectStoreException e) {
      throw new RuntimeException("Error retrieving results.", e);
    }

    while (result.hasNext()) {
      List<ResultElement> row = result.next();

      String interactionType = (String) row.get(0).getField();
      String sourceNodePId = (String) row.get(1).getField();
      String sourceNodeSymbol = (String) row.get(2).getField();
      String targetNodePId = (String) row.get(3).getField();
      String targetNodeSymbol = (String) row.get(4).getField();

      CytoscapeNetworkEdgeData aEdge = new CytoscapeNetworkEdgeData();

      // Handle bidirectional edges
      if (interactionEdgeSetFly.isEmpty()) {
        aEdge.setSourceId(sourceNodePId);

        if (sourceNodeSymbol == null || sourceNodeSymbol.length() < 1) {
          aEdge.setSourceLabel(sourceNodePId);
        } else {
          aEdge.setSourceLabel(sourceNodeSymbol);
        }

        aEdge.setTargetId(targetNodePId);

        if (targetNodeSymbol == null || targetNodeSymbol.length() < 1) {
          aEdge.setTargetLabel(targetNodePId);
        } else {
          aEdge.setTargetLabel(targetNodeSymbol);
        }

        aEdge.setInteractionType(interactionType);
        aEdge.setDirection("one");

        interactionEdgeSetFly.add(aEdge);
      } else {
        aEdge.setSourceId(sourceNodePId);

        if (sourceNodeSymbol == null || sourceNodeSymbol.length() < 1) {
          aEdge.setSourceLabel(sourceNodePId);
        } else {
          aEdge.setSourceLabel(sourceNodeSymbol);
        }

        aEdge.setTargetId(targetNodePId);

        if (targetNodeSymbol == null || targetNodeSymbol.length() < 1) {
          aEdge.setTargetLabel(targetNodePId);
        } else {
          aEdge.setTargetLabel(targetNodeSymbol);
        }

        // miRNA-TF and TF-miRNA are the same interaction type
        if ("TF-miRNA".equals(interactionType) || "miRNA-TF".equals(interactionType)) {
          String uniType = "miRNA-TF";
          aEdge.setInteractionType(uniType);
        } else {
          aEdge.setInteractionType(interactionType);
        }

        String interactingString = aEdge.generateInteractionString();
        String interactingStringRev = aEdge.generateReverseInteractionString();

        // Get a list of interactionString from interactionSet
        LinkedHashSet<String> intcStrSet = new LinkedHashSet<String>();
        for (CytoscapeNetworkEdgeData edgedata : interactionEdgeSetFly) {
          intcStrSet.add(edgedata.generateInteractionString());
        }
        // A none dulipcated edge
        if (!(intcStrSet.contains(interactingString)
            || intcStrSet.contains(interactingStringRev))) {
          aEdge.setDirection("one");
          interactionEdgeSetFly.add(aEdge);
        } else { // duplicated edge
          // Pull out the CytoscapeNetworkEdgeData which contains the current
          // interactionString
          for (CytoscapeNetworkEdgeData edgedata : interactionEdgeSetFly) {
            if (edgedata.generateInteractionString().equals(interactingString)
                || edgedata.generateInteractionString().equals(interactingStringRev)) {
              edgedata.setDirection("both");
              aEdge.setInteractionType(interactionType);
            }
          }
        }
      }
    }
  }