Exemplo n.º 1
0
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    // The protein we're viewing
    int proteinID;

    // User making this request
    User user = UserUtils.getUser(request);
    if (user == null) {
      ActionErrors errors = new ActionErrors();
      errors.add("username", new ActionMessage("error.login.notloggedin"));
      saveErrors(request, errors);
      return mapping.findForward("authenticate");
    }

    NRProtein protein = null;
    try {
      String strID = request.getParameter("id");

      if (strID == null || strID.equals("")) {
        ActionErrors errors = new ActionErrors();
        errors.add("protein", new ActionMessage("error.protein.invalidid"));
        saveErrors(request, errors);
        return mapping.findForward("Failure");
      }

      proteinID = Integer.parseInt(strID);

      // Load our protein
      NRProteinFactory nrpf = NRProteinFactory.getInstance();
      protein = (NRProtein) (nrpf.getProtein(proteinID));

      // Abundance information. Only for yeast
      // Ghaemmaghami, et al., Nature 425, 737-741 (2003)
      if (protein.getSpecies().getId() == TaxonomyUtils.SACCHAROMYCES_CEREVISIAE) {
        List<YeastOrfAbundance> abundances =
            ProteinAbundanceDao.getInstance().getAbundance(protein.getId());
        if (abundances == null || abundances.size() == 0)
          request.setAttribute("proteinAbundance", "NOT AVAILABLE");
        else {
          if (abundances.size() == 1) {
            request.setAttribute("proteinAbundance", abundances.get(0).getAbundanceString());
          } else {
            String aString = "";
            for (YeastOrfAbundance a : abundances) {
              aString += ", " + a.getAbundanceAndOrfNameString();
            }
            aString = aString.substring(1);
            request.setAttribute("proteinAbundance", aString);
          }
        }
      }

    } catch (NumberFormatException nfe) {
      ActionErrors errors = new ActionErrors();
      errors.add("protein", new ActionMessage("error.project.invalidid"));
      saveErrors(request, errors);
      return mapping.findForward("Failure");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("username", new ActionMessage("error.project.projectnotfound"));
      saveErrors(request, errors);
      return mapping.findForward("Failure");
    }

    Map goterms = protein.getGOAll();

    if (((Collection) goterms.get("P")).size() > 0)
      request.setAttribute("processes", goterms.get("P"));

    if (((Collection) goterms.get("C")).size() > 0)
      request.setAttribute("components", goterms.get("C"));

    if (((Collection) goterms.get("F")).size() > 0)
      request.setAttribute("functions", goterms.get("F"));

    // clean up
    goterms = null;

    YatesRunSearcher yrs = new YatesRunSearcher();
    yrs.setProtein(protein);
    Collection runs = yrs.search();

    // Make sure only runs belonging to projects this user has access to are listed.
    if (runs != null && runs.size() > 0) {
      Iterator iter = runs.iterator();
      while (iter.hasNext()) {
        YatesRun yr = (YatesRun) (iter.next());
        if (!yr.getProject().checkReadAccess(user.getResearcher())) iter.remove();
      }

      request.setAttribute("yatesdata", runs);
    }

    // Get the protein inference runs where this protein was listed
    // This is a bit convoluted
    // First get all the users' projects (projects the user has read access to)
    ProjectsSearcher projSearcher = new ProjectsSearcher();
    projSearcher.setResearcher(user.getResearcher());
    List<Project> projects = projSearcher.search();
    //		List<Project> projects = user.getProjects();

    List<Integer> pinferIds = new ArrayList<Integer>();
    for (Project project : projects) {
      List<Integer> experimentIds =
          ProjectExperimentDAO.instance().getExperimentIdsForProject(project.getID());

      for (int experimentId : experimentIds) {
        List<ProteinferJob> piJobs =
            ProteinInferJobSearcher.getInstance().getProteinferJobsForMsExperiment(experimentId);
        for (ProteinferJob job : piJobs) {
          pinferIds.add(job.getPinferId());
        }
      }
    }
    // We now have the protein inference runs for this user.
    // Find out which one of then has the protein of interest.
    List<ProteinferRun> piRuns = new ArrayList<ProteinferRun>(pinferIds.size());
    ProteinferRunDAO piRunDao = ProteinferDAOFactory.instance().getProteinferRunDao();
    ProteinferProteinDAO protDao = ProteinferDAOFactory.instance().getProteinferProteinDao();
    ArrayList<Integer> nrseqIds = new ArrayList<Integer>(1);
    nrseqIds.add(proteinID);
    for (int pinferId : pinferIds) {
      if (protDao.getProteinIdsForNrseqIds(pinferId, nrseqIds).size() > 0) {
        ProteinferRun piRun = piRunDao.loadProteinferRun(pinferId);
        piRuns.add(piRun);
      }
    }
    request.setAttribute("piRuns", piRuns);

    // Set this project in the request, as a bean to be displayed on the view
    request.setAttribute("protein", protein);
    return mapping.findForward("Success");
  }
Exemplo n.º 2
0
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    log.info("Got request for GO Slim analysis for ProtenProphet protein inference");

    // form for filtering and display options
    ProteinProphetFilterForm filterForm = (ProteinProphetFilterForm) form;

    // get the protein inference id
    int pinferId = filterForm.getPinferId();

    long s = System.currentTimeMillis();

    // Get the peptide definition; We don't get peptide definition from ProteinProphet params so
    // just
    // use a dummy one.
    PeptideDefinition peptideDef = new PeptideDefinition();
    peptideDef.setUseCharge(true);
    peptideDef.setUseMods(true);

    // filtering criteria from the request
    ProteinProphetFilterCriteria filterCriteria_request = filterForm.getFilterCriteria(peptideDef);

    // protein Ids
    List<Integer> proteinIds = null;

    ProteinInferSessionManager sessionManager = ProteinInferSessionManager.getInstance();

    // Check if we already have information in the session
    ProteinProphetFilterCriteria filterCriteria_session =
        sessionManager.getFilterCriteriaForProteinProphet(request, pinferId);
    proteinIds = sessionManager.getStoredProteinIds(request, pinferId);

    // If we don't have a filtering criteria in the session return an error
    if (filterCriteria_session == null || proteinIds == null) {

      log.info("NO information in session for: " + pinferId);
      // redirect to the /viewProteinInferenceResult action if this different from the
      // protein inference ID stored in the session
      log.error("Stale ProteinProphet ID: " + pinferId);
      response.setContentType("text/html");
      response.getWriter().write("STALE_ID");
      return null;
    } else {

      log.info("Found information in session for: " + pinferId);
      System.out.println("stored protein ids: " + proteinIds.size());

      // we will use the sorting column and sorting order from the filter criteria in the session.
      filterCriteria_request.setSortBy(filterCriteria_session.getSortBy());
      filterCriteria_request.setSortOrder(filterCriteria_session.getSortOrder());

      boolean match = matchFilterCriteria(filterCriteria_session, filterCriteria_request);

      // if the filtering criteria has changed we need to filter the results again
      if (!match) {

        log.info("Filtering criteria has changed");

        proteinIds = ProteinProphetResultsLoader.getProteinIds(pinferId, filterCriteria_request);
      }
    }

    long e = System.currentTimeMillis();
    log.info(
        "Got filtered nrseq protein ids for GO Slim analysis in: "
            + TimeUtils.timeElapsedMinutes(s, e)
            + " minutes");

    request.setAttribute("pinferId", pinferId);
    request.setAttribute("goAspect", filterForm.getGoAspect());
    request.setAttribute("goSlimTermId", filterForm.getGoSlimTermId());

    if (filterForm.isGetGoSlimTree()) {

      // We have the protein inference protein IDs; Get the corresponding nrseq protein IDs
      List<Integer> nrseqIds = new ArrayList<Integer>(proteinIds.size());
      ProteinferDAOFactory factory = ProteinferDAOFactory.instance();
      ProteinferProteinDAO protDao = factory.getProteinferProteinDao();
      for (int proteinId : proteinIds) {
        ProteinferProtein protein = protDao.loadProtein(proteinId);
        nrseqIds.add(protein.getNrseqProteinId());
      }
      request.setAttribute("nrseqProteinIds", nrseqIds);

      return mapping.findForward("GoTree");
    } else {

      // We have the protein inference protein IDs; Get the corresponding nrseq protein IDs and
      // protein group IDs
      List<GOAnalysisProtein> goAnalysisProteins =
          new ArrayList<GOAnalysisProtein>(proteinIds.size());
      ProteinferDAOFactory factory = ProteinferDAOFactory.instance();
      ProteinProphetProteinDAO protDao = factory.getProteinProphetProteinDao();
      for (int proteinId : proteinIds) {
        ProteinProphetProtein protein = protDao.loadProtein(proteinId);
        goAnalysisProteins.add(
            new GOAnalysisProtein(protein.getNrseqProteinId(), protein.getGroupId()));
      }

      request.setAttribute("goSlimProteins", goAnalysisProteins);
      request.setAttribute(
          "doGroupAnalysis", true); // default is to get GO information at the group level
      return mapping.findForward("Success");
    }
  }