Exemplo n.º 1
0
  @SuppressWarnings("unchecked")
  @Override
  public void display(HttpServletRequest request, ReportObject reportObject) {

    // get the gene/protein in question from the request
    InterMineObject object = reportObject.getObject();
    // wrapper for the result so we can say what type it is
    HashMap<String, Object> result = new HashMap();

    // API connection
    HttpSession session = request.getSession();
    final InterMineAPI im = SessionMethods.getInterMineAPI(session);
    Model model = im.getModel();
    PathQuery query = new PathQuery(model);

    // dealing with genes...
    if (object instanceof Gene) {
      // cast me Gene
      Gene gene = (Gene) object;
      String geneID = String.valueOf(gene.getId());
      query = geneCommentsQuery(geneID, query);

      Profile profile = SessionMethods.getProfile(session);
      PathQueryExecutor executor = im.getPathQueryExecutor(profile);
      ExportResultsIterator values;
      try {
        values = executor.execute(query);
      } catch (ObjectStoreException e) {
        throw new RuntimeException(e);
      }

      result.put("gene", geneComments2(values));

      // result.put("gene", geneComments(gene));
    } else if (object instanceof Protein) {
      // cast me Protein
      Protein protein = (Protein) object;
      String proteinID = String.valueOf(protein.getId());
      query = proteinCommentsQuery(proteinID, query);

      Profile profile = SessionMethods.getProfile(session);
      PathQueryExecutor executor = im.getPathQueryExecutor(profile);
      ExportResultsIterator values;
      try {
        values = executor.execute(query);
      } catch (ObjectStoreException e) {
        throw new RuntimeException(e);
      }

      result.put("protein", proteinComments2(values));

      // result.put("protein", proteinComments(protein));
    } else {
      // big fat fail
    }

    request.setAttribute("response", result);
  }
  public void testCreateSpanningLocations() throws Exception {
    Exon exon1 = (Exon) DynamicUtil.createObject(Collections.singleton(Exon.class));
    exon1.setId(new Integer(107));
    Exon exon2 = (Exon) DynamicUtil.createObject(Collections.singleton(Exon.class));
    exon2.setId(new Integer(108));
    Exon exon3 = (Exon) DynamicUtil.createObject(Collections.singleton(Exon.class));
    exon3.setId(new Integer(109));

    Location exon1OnChr = createLocation(getChromosome(), exon1, "1", 51, 100, Location.class);
    exon1OnChr.setId(new Integer(1010));
    Location exon2OnChr = createLocation(getChromosome(), exon2, "1", 201, 250, Location.class);
    exon2OnChr.setId(new Integer(1011));
    Location exon3OnChr = createLocation(getChromosome(), exon3, "1", 201, 400, Location.class);
    exon3OnChr.setId(new Integer(1012));

    Transcript trans1 =
        (Transcript) DynamicUtil.createObject(Collections.singleton(Transcript.class));
    trans1.setId(new Integer(201));

    Transcript trans2 =
        (Transcript) DynamicUtil.createObject(Collections.singleton(Transcript.class));
    trans2.setId(new Integer(202));

    Location trans2OnChr = createLocation(getChromosome(), trans2, "1", 61, 300, Location.class);

    Gene gene = (Gene) DynamicUtil.createObject(Collections.singleton(Gene.class));
    gene.setId(new Integer(301));

    exon1.setTranscripts(new HashSet<Transcript>(Arrays.asList(new Transcript[] {trans1})));
    exon2.setTranscripts(new HashSet<Transcript>(Arrays.asList(new Transcript[] {trans1})));

    // the location of exon3 should be ignored by createSpanningLocations() because trans2
    // already has a location
    exon3.setTranscripts(new HashSet<Transcript>(Arrays.asList(new Transcript[] {trans2})));

    trans1.setGene(gene);
    trans2.setGene(gene);

    Set<InterMineObject> toStore =
        new HashSet<InterMineObject>(
            Arrays.asList(
                new InterMineObject[] {
                  getChromosome(),
                  gene,
                  trans1,
                  trans2,
                  exon1,
                  exon2,
                  exon3,
                  exon1OnChr,
                  exon2OnChr,
                  trans2OnChr
                }));

    for (InterMineObject imo : toStore) {
      osw.store(imo);
    }

    CalculateLocations cl = new CalculateLocations(osw);
    cl.createSpanningLocations("Transcript", "Exon", "exons");
    cl.createSpanningLocations("Gene", "Transcript", "transcripts");

    ObjectStore os = osw.getObjectStore();
    Transcript resTrans1 = (Transcript) os.getObjectById(new Integer(201));

    Assert.assertEquals(1, resTrans1.getLocations().size());
    Location resTrans1Location = (Location) resTrans1.getLocations().iterator().next();
    Assert.assertEquals(51, resTrans1Location.getStart().intValue());
    Assert.assertEquals(250, resTrans1Location.getEnd().intValue());

    Transcript resTrans2 = (Transcript) os.getObjectById(new Integer(202));

    Assert.assertEquals(1, resTrans2.getLocations().size());
    Location resTrans2Location = (Location) resTrans2.getLocations().iterator().next();
    Assert.assertEquals(61, resTrans2Location.getStart().intValue());
    Assert.assertEquals(300, resTrans2Location.getEnd().intValue());

    Gene resGene = (Gene) os.getObjectById(new Integer(301));
    Assert.assertEquals(1, resGene.getLocations().size());
    Location resGeneLocation = (Location) resGene.getLocations().iterator().next();
    Assert.assertEquals(51, resGeneLocation.getStart().intValue());
    Assert.assertEquals(300, resGeneLocation.getEnd().intValue());
  }
  @Override
  public void display(HttpServletRequest request, ReportObject reportObject) {

    // get the gene/protein in question from the request
    InterMineObject object = reportObject.getObject();

    // API connection
    HttpSession session = request.getSession();
    final InterMineAPI im = SessionMethods.getInterMineAPI(session);
    Model model = im.getModel();
    PathQuery query = new PathQuery(model);

    // cast me Gene
    Gene gene = (Gene) object;
    Object genePrimaryIDObj = gene.getPrimaryIdentifier();
    if (genePrimaryIDObj != null) {
      // fetch the expression
      String genePrimaryID = String.valueOf(genePrimaryIDObj);
      query = geneExpressionAtlasQuery(genePrimaryID, query);

      // execute the query
      Profile profile = SessionMethods.getProfile(session);
      PathQueryExecutor executor = im.getPathQueryExecutor(profile);
      ExportResultsIterator values = executor.execute(query);

      // convert to a map
      GeneExpressionAtlasDiseasesExpressions geae =
          new GeneExpressionAtlasDiseasesExpressions(values);

      // attach to results
      request.setAttribute("expressions", geae);
      request.setAttribute("url", "http://www.ebi.ac.uk/gxa/experiment/E-MTAB-62/" + genePrimaryID);
      request.setAttribute("defaultPValue", "1e-4");
      request.setAttribute("defaultTValue", "4");

      // get the corresponding collection
      for (FieldDescriptor fd : reportObject.getClassDescriptor().getAllFieldDescriptors()) {
        if ("atlasExpression".equals(fd.getName()) && fd.isCollection()) {
          // fetch the collection
          Collection<?> collection = null;
          try {
            collection = (Collection<?>) reportObject.getObject().getFieldValue("atlasExpression");
          } catch (IllegalAccessException e) {
            e.printStackTrace();
          }

          List<Class<?>> lc =
              PathQueryResultHelper.queryForTypesInCollection(
                  reportObject.getObject(), "atlasExpression", im.getObjectStore());

          // create an InlineResultsTable
          InlineResultsTable t =
              new InlineResultsTable(
                  collection,
                  fd.getClassDescriptor().getModel(),
                  SessionMethods.getWebConfig(request),
                  im.getClassKeys(),
                  collection.size(),
                  false,
                  lc);

          request.setAttribute("collection", t);
          break;
        }
      }
    }
  }