/**
   * Return the query specified in the request, shorn of all duplicate classes in the view. Note, it
   * is the users responsibility to ensure that there are only SequenceFeatures in the view.
   *
   * @return A query.
   */
  protected PathQuery getQuery() {
    String xml = getRequiredParameter(XML_PARAM);
    PathQueryBuilder builder = getQueryBuilder(xml);
    PathQuery pq = builder.getQuery();

    List<String> newView = new ArrayList<String>();
    Set<ClassDescriptor> seenTypes = new HashSet<ClassDescriptor>();

    for (String viewPath : pq.getView()) {
      Path p;
      try {
        p = new Path(pq.getModel(), viewPath);
      } catch (PathException e) {
        throw new BadRequestException("Query is invalid", e);
      }
      ClassDescriptor cd = p.getLastClassDescriptor();
      if (!seenTypes.contains(cd)) {
        newView.add(viewPath);
      }
      seenTypes.add(cd);
    }
    if (!newView.equals(pq.getView())) {
      pq.clearView();
      pq.addViews(newView);
    }

    return pq;
  }
 /* (non-Javadoc)
  * @see junit.framework.TestCase#setUp()
  */
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   expectedGoodQuery = new PathQuery(model);
   expectedGoodQuery.addViews("Employee.age", "Employee.name");
   expectedGoodQuery.addConstraint(Constraints.eq("Employee.name", "Tim Canterbury"));
 }
Beispiel #3
0
  // create a query with MainHelper.makeQuery() that contains both QueryClasses and QueryFields
  public void testGetPathToIndex() throws Exception {
    PathQuery pathQuery = new PathQuery(model);
    pathQuery.addViews("Department.name", "Department.manager.name", "Department.employees.name");
    QueryClass dept1 = new QueryClass(Department.class);
    QueryField depName = new QueryField(dept1, "name");

    QueryClass man1 = new QueryClass(Manager.class);
    QueryField manName = new QueryField(man1, "name");

    QueryClass emp1 = new QueryClass(Employee.class);
    QueryField empName = new QueryField(emp1, "name");

    Map<String, QuerySelectable> pathToQueryNode = new HashMap();
    pathToQueryNode.put("Department", dept1);
    pathToQueryNode.put("Department.name", depName);
    pathToQueryNode.put("Department.manager", man1);
    pathToQueryNode.put("Department.manager.name", manName);
    pathToQueryNode.put("Department.employees", emp1);
    pathToQueryNode.put("Department.employees.name", empName);

    Query query = MainHelper.makeQuery(pathQuery, new HashMap(), pathToQueryNode, null, null);
    WebResults webResults =
        new WebResults(im, pathQuery, osd.execute(query), pathToQueryNode, new HashMap());
    LinkedHashMap<String, Integer> actual = webResults.pathToIndex;
    LinkedHashMap<String, Integer> expected = new LinkedHashMap<String, Integer>();
    expected.put("Department.employees.name", 2);
    expected.put("Department.name", 0);
    expected.put("Department.manager.name", 1);
    expected.put("Department.employees", 2);
    expected.put("Department.manager", 1);
    expected.put("Department", 0);
    assertEquals(expected, actual);
  }
Beispiel #4
0
  // Test with a PathQuery and some dummy results, call method with a made up row,
  // create expected ResultElements.  Doesn't need too much testing as Path.resolve() is tested.
  public void testTranslateRow() throws Exception {
    PathQuery pq = new PathQuery(model);
    pq.addViews("Department.name", "Department.company.name", "Department.manager.name");
    Map<String, QuerySelectable> pathToQueryNode = new HashMap();
    Query query = MainHelper.makeQuery(pq, new HashMap(), pathToQueryNode, null, null);
    Results results = osd.execute(query);
    WebResults webResults = new WebResults(im, pq, results, pathToQueryNode, classKeys);
    List row1 = webResults.getResultElements(0);

    Department dept1 = new Department();
    dept1.setId(new Integer(4));
    dept1.setName("Department1");
    ResultElement res1 = new ResultElement(dept1, new Path(model, "Department.name"), false);

    Company c1 =
        (Company) DynamicUtil.instantiateObject("org.intermine.model.testmodel.Company", null);
    c1.setId(new Integer(1));
    c1.setName("Company1");
    ResultElement res2 = new ResultElement(c1, new Path(model, "Department.company.name"), false);

    Manager m1 = new Manager();
    m1.setId(new Integer(1));
    m1.setSeniority(new Integer(100));
    m1.setName("Manager1");
    ResultElement res3 = new ResultElement(m1, new Path(model, "Department.manager.name"), false);

    ResultsRow expected = new ResultsRow();
    expected.add(new MultiRowFirstValue(res1, 1));
    expected.add(new MultiRowFirstValue(res2, 1));
    expected.add(new MultiRowFirstValue(res3, 1));
    assertEquals(new MultiRow(Collections.singletonList(expected)), row1);
  }
 /**
  * Create a PathQuery to get the contents of an InterMineBag
  *
  * @param imBag the bag
  * @param webConfig the WebConfig
  * @param model the Model
  * @return a PathQuery
  */
 public static PathQuery makePathQueryForBag(
     InterMineBag imBag, WebConfig webConfig, Model model) {
   PathQuery query = new PathQuery(model);
   query.addViews(getDefaultViewForClass(imBag.getType(), model, webConfig));
   query.addConstraint(Constraints.in(imBag.getType(), imBag.getName()));
   return query;
 }
Beispiel #6
0
 @Override
 public Iterator<Item> iterator() {
   PathQuery pq = new PathQuery(services.getModel());
   pq.addViews(PQUtil.getStar(services.getModel(), getType()));
   pq.addConstraint(Constraints.in(type, name));
   Iterator<Map<String, Object>> it = services.getQueryService().getRowMapIterator(pq);
   return new ItemIterator(it);
 }
 @Before
 public void setup() {
   query = new PathQuery(flymine.getFactory().getModel());
   query.addViews("Gene.symbol", "Gene.length");
   query.addConstraint(Constraints.eq("Gene.symbol", "c*"));
   query.addConstraint(Constraints.isNotNull("Gene.length"));
   expectedSize = flymine.getCount(query);
 }
 /**
  * Return an API query fetching all Comments for Genes, ordered by type
  *
  * @author radek
  * @param proteinID
  * @param query
  * @return
  */
 private PathQuery proteinCommentsQuery(String proteinID, PathQuery query) {
   query.addViews(
       "Protein.comments.description", "Protein.comments.type", "Protein.primaryIdentifier");
   query.addOrderBy("Protein.comments.type", OrderDirection.ASC);
   query.addConstraint(Constraints.eq("Protein.id", proteinID));
   query.addConstraint(
       Constraints.oneOfValues("Protein.comments.type", Arrays.asList(allowedCommentTypes)));
   return query;
 }
Beispiel #9
0
 /**
  * Add items to this list by using a query.
  *
  * @param items The items to add to the list.
  */
 private void appendItems(Iterable<Item> items) {
   PathQuery pq = new PathQuery(services.getModel());
   pq.addViews(getType() + ".id");
   Set<String> values = new HashSet<String>();
   for (Item i : items) {
     values.add(Integer.toString(i.getId()));
   }
   pq.addConstraint(Constraints.oneOfValues(getType() + ".id", values));
   update(services.getListService().append(this, pq));
 }
  /**
   * Query all nodes of worm regulatory network.
   *
   * @param model the Model
   * @param executor to run the query
   * @return interactionNodeSet
   */
  private static void queryWormRegulatoryNodes(Model model, PathQueryExecutor executor) {

    interactionNodeSetWorm = new LinkedHashSet<CytoscapeNetworkNodeData>();

    PathQuery query = new PathQuery(model);
    query.addViews(
        "NetworkProperty.node.primaryIdentifier",
        "NetworkProperty.node.symbol",
        "NetworkProperty.node.id",
        "NetworkProperty.type",
        "NetworkProperty.value");

    query.addConstraint(Constraints.eq("NetworkProperty.node.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 featurePId = (String) row.get(0).getField();
      String featureSymbol = (String) row.get(1).getField();
      Integer id = (Integer) row.get(2).getField();
      String key = (String) row.get(3).getField();
      String value = (String) row.get(4).getField();

      CytoscapeNetworkNodeData aNode = new CytoscapeNetworkNodeData();
      aNode.setInterMineId(id);
      aNode.setSourceId(String.valueOf(id)); // Use IM Id instead of PId

      if (featureSymbol == null || featureSymbol.length() < 1) {
        aNode.setSourceLabel(featurePId);
      } else {
        aNode.setSourceLabel(featureSymbol);
      }

      if (interactionNodeSetWorm.contains(aNode)) {
        for (CytoscapeNetworkNodeData n : interactionNodeSetWorm) {
          if (n.getInterMineId() == id) {
            n.getExtraInfo().put(key, value);
          }
        }
      } else {
        Map<String, String> extraInfo = new HashMap<String, String>();
        extraInfo.put(key, value);
        aNode.setExtraInfo(extraInfo);
      }

      interactionNodeSetWorm.add(aNode);
    }
  }
Beispiel #11
0
  @Override
  protected void execute() throws Exception {

    Profile profile = getPermission().getProfile();
    PathQueryExecutor executor = this.im.getPathQueryExecutor(profile);
    // For FASTA/BED/GFF only set Gene.id in the view in im-tables system
    PathQuery pathQuery = getQuery();
    checkPathQuery(pathQuery);

    // Bring back original views for extra fields to be included in data export
    // NB: Functional but bad practice?
    // view in http request will look like: view=Gene.name&view=Gene.length...
    // Support the standard mechanism for accepting multiple parameter values
    List<String> views = getPathQueryViews(request.getParameterValues(VIEW_PARAM));
    if (views != null) {
      try {
        pathQuery.addViews(views);
      } catch (IllegalArgumentException e) {
        throw new BadRequestException("Bad value for view parameter", e);
      }
      // Remove duplicates in views
      ArrayList<String> al = new ArrayList<String>();
      al.clear();
      al.addAll(new LinkedHashSet<String>(pathQuery.getView()));
      pathQuery.clearView();
      pathQuery.addViews(al);
    }

    Exporter exporter = getExporter(pathQuery);

    ExportResultsIterator iter = null;
    try {
      iter = executor.execute(pathQuery, 0, WebServiceRequestParser.DEFAULT_LIMIT);
      iter.goFaster();
      exporter.export(iter);
    } finally {
      if (iter != null) {
        iter.releaseGoFaster();
      }
    }
  }
  @Test
  public void test() throws Exception {
    Model m = osw.getModel();

    Long start = System.currentTimeMillis();

    PathQuery pq = new PathQuery(m);

    pq.addViews("Types.name", "Types.intType", "Types.doubleType");
    pq.addConstraint(Constraints.eq("Types.name", "histo*"));

    Query q = MainHelper.makeSummaryQuery(pq, "Types.intType", new HashMap(), new HashMap(), null);

    Results res = osw.execute(q, 100000, true, false, false);

    Long sum = 0L;
    Map<Integer, Long> actual = new TreeMap<Integer, Long>();

    for (Object o : res) {
      // System.out.println("ROW:" + o);
      List row = (List) o;
      Integer bucket = (Integer) row.get(5);
      Integer min = (Integer) row.get(0);
      Integer max = (Integer) row.get(1);
      Integer buckets = (Integer) row.get(4);
      Integer width = (max - min) / (buckets - 1);
      Integer group = min + ((bucket - 1) * width);
      Long count = ((BigDecimal) row.get(6)).longValue();
      actual.put(group, count);
      sum += count;
    }
    Long postExecution = System.currentTimeMillis();
    showHistogram("Actual", actual);
    System.out.printf(
        "MIN:        %d\nMAX:        %d\nAVG:        %.03f\nSTD-DEV:    %.03f\n",
        ((List) res.get(0)).subList(0, 4).toArray());
    System.out.println("TOTAL THINGS: " + sum);
    System.out.printf(
        "Query composition and execution took %.4f seconds",
        Double.valueOf(postExecution - start) / 1000);

    res = osw.execute(getCheckQuery());
    Long countFromOSQ = null;
    for (Object o : res) {
      List row = (List) o;
      countFromOSQ = (Long) row.get(0);
    }
    // int scale = generator.nextInt(MAX_SCALE - MIN_SCALE) + MIN_SCALE;

    assertEquals("Sum of buckets and total count agrees", sum, countFromOSQ);
    assertEquals("Sum of buckets agrees with what we inserted", made, sum.intValue());
  }
Beispiel #13
0
  public void test() throws Exception {
    IqlQuery fq =
        new IqlQuery(
            "SELECT DISTINCT a1_, a3_, a4_ FROM org.intermine.model.testmodel.Department AS a1_,"
                + " org.intermine.model.testmodel.CEO AS a2_, org.intermine.model.testmodel.Company "
                + "AS a3_, org.intermine.model.testmodel.Manager AS a4_ "
                + "WHERE (a1_.manager CONTAINS a2_ AND a2_.company CONTAINS a3_ "
                + "AND a1_.employees CONTAINS a4_)",
            "org.intermine.model.testmodel");
    Query query = fq.toQuery();
    Results results = osd.execute(query);

    PathQuery pathQuery = new PathQuery(model);
    pathQuery.addViews(
        "Department.name",
        "Department.manager.company.name",
        "Department.manager.company.vatNumber",
        "Department.employees.seniority");
    pathQuery.addConstraint(new PathConstraintSubclass("Department.manager", "CEO"));
    pathQuery.addConstraint(new PathConstraintSubclass("Department.employees", "Manager"));
    Map<String, QuerySelectable> pathToQueryNode = new HashMap<String, QuerySelectable>();
    QueryClass deptQC = (QueryClass) query.getSelect().get(0);
    pathToQueryNode.put("Department", deptQC);
    QueryField deptNameQF = new QueryField(deptQC, "name");
    pathToQueryNode.put("Department.name", deptNameQF);

    QueryClass compQC = (QueryClass) query.getSelect().get(1);
    pathToQueryNode.put("Department.manager.company", compQC);
    QueryField compNameQF = new QueryField(compQC, "name");
    pathToQueryNode.put("Department.manager.company.name", compNameQF);
    QueryField compVatNumQF = new QueryField(compQC, "vatNumber");
    pathToQueryNode.put("Department.manager.company.vatNumber", compVatNumQF);

    QueryClass manQC = (QueryClass) query.getSelect().get(2);
    pathToQueryNode.put("Department.employees", manQC);
    QueryField manSeniority = new QueryField(manQC, "seniority");
    pathToQueryNode.put("Department.employees.seniority", manSeniority);
    WebResults webResults = new WebResults(im, pathQuery, results, pathToQueryNode, null);

    assertEquals("Department1", webResults.get(0).get(0).get(0).getValue().getField());
    assertEquals("Company1", webResults.get(0).get(0).get(1).getValue().getField());
    assertEquals(new Integer(101), webResults.get(0).get(0).get(2).getValue().getField());
    assertEquals("Department2", webResults.get(1).get(0).get(0).getValue().getField());
    assertEquals("Company2", webResults.get(1).get(0).get(1).getValue().getField());
    assertEquals(new Integer(102), webResults.get(1).get(0).get(2).getValue().getField());
    assertEquals("Department3", webResults.get(2).get(0).get(0).getValue().getField());
    assertEquals("Company3", webResults.get(2).get(0).get(1).getValue().getField());
    assertEquals(new Integer(103), webResults.get(2).get(0).get(2).getValue().getField());
  }
  /**
   * Return an API query fetching all tissue expressions
   *
   * @author radek
   * @param genePrimaryID
   * @param query
   * @return
   */
  private PathQuery geneExpressionAtlasQuery(String genePrimaryID, PathQuery query) {
    query.addViews(
        "Gene.atlasExpression.condition",
        "Gene.atlasExpression.expression",
        "Gene.atlasExpression.pValue",
        "Gene.atlasExpression.tStatistic",
        "Gene.atlasExpression.type",
        "Gene.primaryIdentifier");
    query.addConstraint(Constraints.eq("Gene.primaryIdentifier", genePrimaryID));
    query.addConstraint(Constraints.eq("Gene.atlasExpression.type", "disease_state"));
    query.addConstraint(Constraints.notLike("Gene.atlasExpression.condition", "(empty)"));
    query.addOrderBy("Gene.atlasExpression.condition", OrderDirection.ASC);

    return query;
  }
Beispiel #15
0
 // create a PathQuery, create expected column objects and compare.  Include:
 //   - some paths with descriptions
 //   - select fields that are/aren't class keys
 public void testSetColumns() throws Exception {
   PathQuery pq = new PathQuery(model);
   pq.addViews("Company.name", "Company.vatNumber", "Company.CEO.name");
   pq.setDescription("Company", "description 1");
   Map<String, QuerySelectable> pathToQueryNode = new HashMap();
   Query query = MainHelper.makeQuery(pq, new HashMap(), pathToQueryNode, null, null);
   Results results = osd.execute(query);
   WebResults webResults = new WebResults(im, pq, results, pathToQueryNode, classKeys);
   List<Column> expectedColumns = new ArrayList<Column>();
   Column col1 = new Column("description 1 > name", 0, Company.class);
   Column col2 = new Column("description 1 > vatNumber", 1, Company.class);
   Column col3 = new Column("description 1 > CEO > name", 2, CEO.class);
   expectedColumns.add(col1);
   expectedColumns.add(col2);
   expectedColumns.add(col3);
   assertEquals(expectedColumns.get(0), webResults.getColumns().get(0));
   assertEquals(expectedColumns.get(1), webResults.getColumns().get(1));
   assertEquals(expectedColumns.get(2), webResults.getColumns().get(2));
 }
  /**
   * Query all nodes of fly regulatory network.
   *
   * @param model the Model
   * @param executor to run the query
   * @return interactionNodeSet
   */
  private static void queryFlyRegulatoryNodes(Model model, PathQueryExecutor executor) {

    interactionNodeSetFly = new LinkedHashSet<CytoscapeNetworkNodeData>();

    PathQuery query = new PathQuery(model);
    query.addViews(
        "NetworkProperty.node.primaryIdentifier",
        "NetworkProperty.node.symbol",
        "NetworkProperty.node.id",
        "NetworkProperty.value");

    query.addConstraint(Constraints.eq("NetworkProperty.node.primaryIdentifier", "FBgn*"));

    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 featurePId = (String) row.get(0).getField();
      String featureSymbol = (String) row.get(1).getField();
      Integer featureIMId = (Integer) row.get(2).getField();
      String position = (String) row.get(3).getField();

      CytoscapeNetworkNodeData aNode = new CytoscapeNetworkNodeData();
      aNode.setInterMineId(featureIMId);
      aNode.setSourceId(featurePId);

      if (featureSymbol == null || featureSymbol.length() < 1) {
        aNode.setSourceLabel(featurePId);
      } else {
        aNode.setSourceLabel(featureSymbol);
      }

      aNode.setPosition(position);

      interactionNodeSetFly.add(aNode);
    }
  }
Beispiel #17
0
 /**
  * Convenience method for finding members of a collection matching certain properties.
  *
  * <p>This search is implemented with a query that performs case-insensitive matching on values.
  * Null constraints will be honoured, but other lookups will be converted to strings. Wild-cards
  * are permitted wherever they are permitted in path-queries. <br>
  * Using a query to back the search means that finding matching members is efficient even over
  * large lists - you will not need to pull in and iterate over thousands of rows of data to find
  * items if you have specific conditions. <br>
  * These conditions must all match for the result to be included. For more specific and flexible
  * searching strategies, please see the {@link PathQuery} API.
  *
  * @param conditions The properties these elements should have.
  * @return A list of matching items.
  */
 public List<Item> find(Map<String, Object> conditions) {
   List<Item> ret = new ArrayList<Item>();
   PathQuery q = new PathQuery(services.getModel());
   q.addViews(PQUtil.getStar(services.getModel(), type));
   q.addConstraint(Constraints.in(type, name));
   for (Entry<String, Object> condition : conditions.entrySet()) {
     String path = type + "." + condition.getKey();
     if (condition.getValue() == null) {
       q.addConstraint(Constraints.isNull(path));
     } else {
       q.addConstraint(Constraints.eq(path, condition.getValue().toString()));
     }
   }
   List<Map<String, Object>> results = services.getQueryService().getRowsAsMaps(q);
   for (Map<String, Object> result : results) {
     ret.add(new Item(services, type, result));
   }
   return ret;
 }
  /**
   * 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);
            }
          }
        }
      }
    }
  }
  /**
   * 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);
    }
  }
  @SuppressWarnings({"rawtypes", "unchecked"})
  @Override
  protected void setUp() throws Exception {

    testProps = new Properties();
    testProps.load(getClass().getResourceAsStream("JSONRowFormatterTest.properties"));

    os = new ObjectStoreDummyImpl();

    sw = new StringWriter();
    pw = new PrintWriter(sw);

    attributes = new HashMap<String, Object>();
    attributes.put(JSONResultFormatter.KEY_ROOT_CLASS, "Gene");
    attributes.put(JSONResultFormatter.KEY_VIEWS, Arrays.asList("foo", "bar", "baz"));
    attributes.put(JSONResultFormatter.KEY_MODEL_NAME, model.getName());
    attributes.put(JSONRowFormatter.KEY_TITLE, "Test Results");
    attributes.put(JSONRowFormatter.KEY_EXPORT_CSV_URL, "some.csv.url");
    attributes.put(JSONRowFormatter.KEY_EXPORT_TSV_URL, "some.tsv.url");
    attributes.put(JSONRowFormatter.KEY_PREVIOUS_PAGE, "url.to.previous");
    attributes.put(JSONRowFormatter.KEY_NEXT_PAGE, "url.to.next");
    attributes.put("SOME_NULL_KEY", null);

    tim = new Employee();
    tim.setId(new Integer(5));
    tim.setName("Tim Canterbury");
    tim.setAge(30);

    gareth = new Employee();
    gareth.setId(new Integer(6));
    gareth.setName("Gareth Keenan");
    gareth.setAge(32);

    dawn = new Employee();
    dawn.setId(new Integer(7));
    dawn.setName("Dawn Tinsley");
    dawn.setAge(26);

    keith = new Employee();
    keith.setId(new Integer(8));
    keith.setName("Keith Bishop");
    keith.setAge(41);

    lee = new Employee();
    lee.setId(new Integer(9));
    lee.setName("Lee");
    lee.setAge(28);

    os.setResultsSize(5);

    ResultsRow row1 = new ResultsRow();
    row1.add(tim);
    ResultsRow row2 = new ResultsRow();
    row2.add(gareth);
    ResultsRow row3 = new ResultsRow();
    row3.add(dawn);
    ResultsRow row4 = new ResultsRow();
    row4.add(keith);
    ResultsRow row5 = new ResultsRow();
    row5.add(lee);

    os.addRow(row1);
    os.addRow(row2);
    os.addRow(row3);
    os.addRow(row4);
    os.addRow(row5);

    PathQuery pq = new PathQuery(model);
    pq.addViews("Employee.name", "Employee.age");

    iterator = getIterator(pq);
    processor = new JSONRowResultProcessor(dummyAPI);
  }