public PeptideTerminalAAResult calculateForRunSearchAnalysisIds(
      int analysisId, List<Integer> runSearchAnalysisIds) {

    long s = System.currentTimeMillis();

    PeptideTerminalAAResult result = new PeptideTerminalAAResult();
    result.setAnalysisId(analysisId);
    result.setScoreCutoff(this.scoreCutoff);
    result.setScoreType("PERC_PSM_QVAL");
    result.setEnzyme(this.enzyme);

    for (Integer rsaId : runSearchAnalysisIds) {

      PeptideTerminalAAResult rsaResult = calculateForRunSearchAnalysis(analysisId, rsaId);
      result.combineWith(rsaResult);
    }

    long e = System.currentTimeMillis();

    log.info("Total time to get results " + TimeUtils.timeElapsedSeconds(s, e) + " seconds");
    log.info("Total filtered results: " + result.getTotalResultCount());

    result.setEnzyme(enzyme);
    return result;
  }
Esempio 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");
    }
  }
  public PeptideTerminalAAResult calculateForRunSearchAnalysis(
      int analysisId, int runSearchAnalysisId) {

    if (lookAtUniqPeptides) {
      if (this.peptides == null) {
        peptides = new HashSet<String>();
      }
    }

    PercolatorResultDAO percDao = DAOFactory.instance().getPercolatorResultDAO();

    PercolatorResultFilterCriteria filterCriteria = new PercolatorResultFilterCriteria();
    filterCriteria.setMaxQValue(scoreCutoff);

    long s = System.currentTimeMillis();

    PeptideTerminalAAResultBuilder builder = new PeptideTerminalAAResultBuilder(analysisId, enzyme);
    builder.setScoreCutoff(this.scoreCutoff);
    builder.setScoreType("PERC_PSM_QVAL");

    int totalResults = 0;

    List<Integer> percResultIds =
        percDao.loadIdsForRunSearchAnalysis(runSearchAnalysisId, filterCriteria, null);

    log.info(
        "Found "
            + percResultIds.size()
            + " Percolator results at qvalue <= "
            + scoreCutoff
            + " for runSearchAnalysisID "
            + runSearchAnalysisId);

    for (Integer percResultId : percResultIds) {

      PercolatorResult pres = percDao.loadForPercolatorResultId(percResultId);
      MsSearchResultPeptide peptide = pres.getResultPeptide();
      String seq = peptide.getPeptideSequence();

      if (this.lookAtUniqPeptides) {
        String fullseq = peptide.getPreResidue() + "." + seq + "." + peptide.getPostResidue();
        if (peptides.contains(fullseq)) continue;
        else peptides.add(fullseq);
      }

      totalResults++;

      char ntermMinusOne = peptide.getPreResidue(); // nterm - 1 residue
      builder.addNtermMinusOneCount(ntermMinusOne);

      char nterm = seq.charAt(0); // nterm residue
      builder.addNtermCount(nterm);

      char cterm = seq.charAt(seq.length() - 1); // cterm residue
      builder.addCtermCount(cterm);

      char ctermPlusOne = peptide.getPostResidue(); // cterm + 1 residue
      builder.addCtermPlusOneCount(ctermPlusOne);

      int numEnzTerm = 0;
      if (this.rule != null)
        numEnzTerm = rule.getNumEnzymaticTermini(seq, ntermMinusOne, ctermPlusOne);
      builder.addEnzymaticTerminiCount(numEnzTerm);
    }

    long e = System.currentTimeMillis();

    log.info(
        "Time to get results for runSearchAnalysisId "
            + runSearchAnalysisId
            + " "
            + TimeUtils.timeElapsedSeconds(s, e)
            + " seconds");
    log.info("# filtered results: " + totalResults);

    builder.setTotalResultCount(totalResults);

    return builder.getResult();
  }