コード例 #1
0
bool IDEvaluationBase::getPoints(std::vector<PeptideIdentification>& peptides /* cannot be const, to avoid copy */,
                                 const std::vector<double>& q_value_thresholds, MSSpectrum<>& points)
{
    points.clear(true);

    FalseDiscoveryRate fdr;
    fdr.setParameters(param_.copy("fdr:", true));
    try
    {
        fdr.apply(peptides); // computes a q-value (if its params are correct)
    }
    catch (Exception::MissingInformation)
    {
        LOG_FATAL_ERROR << "Tool failed due to missing information (see above)." << std::endl;
        return false;
    }

    // get list of q-values and sort them
    std::vector<double> q_values;
    q_values.reserve(peptides.size());
    for (vector<PeptideIdentification>::iterator it = peptides.begin(); it != peptides.end(); ++it)
    {
        it->assignRanks();
        if (it->getHits().size() > 0)
            q_values.push_back(it->getHits()[0].getScore());
    }
    std::sort(q_values.begin(), q_values.end());


    for (Size i = 0; i < q_value_thresholds.size(); ++i)
    {
        // get position in sorted q-values where cutoff is reached
        std::vector<double>::iterator pos = std::upper_bound(q_values.begin(), q_values.end(), q_value_thresholds[i]);
        Peak1D p;
        p.setMZ(q_value_thresholds[i] * 100);
        p.setIntensity(std::distance(q_values.begin(), pos));
        points.push_back(p);
    }

    return true;
}
コード例 #2
0
  ExitCodes main_(int, const char**)
  {
    //-------------------------------------------------------------
    // parameter handling
    //-------------------------------------------------------------

    Param alg_param = getParam_().copy("algorithm:", true);
    FalseDiscoveryRate fdr;

    if (!alg_param.empty())
    {
      fdr.setParameters(alg_param);
      writeDebug_("Parameters passed to FalseDiscoveryRate", alg_param, 3);
    }

    // input/output files
    // either "in_target" and "in_decoy" must be given, or just "in" (which contains results of a search against a concatenated target-decoy sequence db):
    String in_target = getStringOption_("in_target"),
      in_decoy = getStringOption_("in_decoy"), in = getStringOption_("in");
    bool combined = false;
    if (!in_target.empty() && !in_decoy.empty())
    {
      if (!in.empty())
      {
        writeLog_("Error, either 'in_target' and 'in_decoy' must be given or 'in', but not both");
        return ILLEGAL_PARAMETERS;
      }
    }
    else
    {
      if (!in.empty())
      {
        combined = true;
      }
      else
      {
        writeLog_("Error, at least 'in_target' and 'in_decoy' or 'in' must be given");
        return ILLEGAL_PARAMETERS;
      }
    }
    String out = getStringOption_("out");
    bool proteins_only = getFlag_("proteins_only");
    bool peptides_only = getFlag_("peptides_only");

    //-------------------------------------------------------------
    // loading input
    //-------------------------------------------------------------

    if (combined) // "in" was given
    {
      vector<PeptideIdentification> pep_ids;
      vector<ProteinIdentification> prot_ids;

      IdXMLFile().load(in, prot_ids, pep_ids);

      try
      {
        if (!proteins_only)
        {
          fdr.apply(pep_ids);
        }
        if (!peptides_only)
        {
          fdr.apply(prot_ids);
        }
      }
      catch (Exception::MissingInformation)
      {
        LOG_FATAL_ERROR << "FalseDiscoveryRate failed due to missing information (see above).\n";
        return INCOMPATIBLE_INPUT_DATA;
      }

      for (vector<ProteinIdentification>::iterator it = prot_ids.begin(); it != prot_ids.end(); ++it)
      {
        it->assignRanks();
      }
      for (vector<PeptideIdentification>::iterator it = pep_ids.begin(); it != pep_ids.end(); ++it)
      {
        it->assignRanks();
      }

      IdXMLFile().store(out, prot_ids, pep_ids);
    }
    else // "in_target" and "in_decoy" given
    {
      vector<PeptideIdentification> pep_target, pep_decoy;
      vector<ProteinIdentification> prot_target, prot_decoy;

      IdXMLFile().load(in_target, prot_target, pep_target);
      IdXMLFile().load(in_decoy, prot_decoy, pep_decoy);

      //-------------------------------------------------------------
      // calculations
      //-------------------------------------------------------------

      writeDebug_("Starting calculations with " + String(pep_target.size()) + " target and " + String(pep_decoy.size()) + " decoy peptide IDs", 1);

      if (!proteins_only)
      {
        fdr.apply(pep_target, pep_decoy);
      }
      if (!peptides_only)
      {
        fdr.apply(prot_target, prot_decoy);
      }

      // TODO @all shouldn't ranks be assigned here as well?

      //-------------------------------------------------------------
      // writing output
      //-------------------------------------------------------------
      IdXMLFile().store(out, prot_target, pep_target);
    }

    return EXECUTION_OK;
  }
コード例 #3
0
  ExitCodes main_(int, const char**) override
  {
    //-------------------------------------------------------------
    // parameter handling
    //-------------------------------------------------------------

    Param alg_param = getParam_().copy("algorithm:", true);
    FalseDiscoveryRate fdr;

    if (!alg_param.empty())
    {
      fdr.setParameters(alg_param);
      writeDebug_("Parameters passed to FalseDiscoveryRate", alg_param, 3);
    }

    // input/output files
    String in = getStringOption_("in");
    String out = getStringOption_("out");
    const double protein_fdr = getDoubleOption_("FDR:protein");
    const double psm_fdr = getDoubleOption_("FDR:PSM");

    //-------------------------------------------------------------
    // loading input
    //-------------------------------------------------------------

    vector<PeptideIdentification> pep_ids;
    vector<ProteinIdentification> prot_ids;

    IdXMLFile().load(in, prot_ids, pep_ids);

    try
    {
      if (getStringOption_("protein") == "true")
      {
        fdr.apply(prot_ids);

        if (protein_fdr < 1)
        {
          LOG_INFO << "FDR control: Filtering proteins..." << endl;
          IDFilter::filterHitsByScore(prot_ids, protein_fdr);
        }
      }

      if (getStringOption_("PSM") == "true")
      {
        fdr.apply(pep_ids);

        if (psm_fdr < 1)
        {      
          LOG_INFO << "FDR control: Filtering PSMs..." << endl;
          IDFilter::filterHitsByScore(pep_ids, psm_fdr);
        }
      }
    }
    catch (Exception::MissingInformation)
    {
      LOG_FATAL_ERROR << "FalseDiscoveryRate failed due to missing information (see above).\n";
      return INCOMPATIBLE_INPUT_DATA;
    }

    for (vector<ProteinIdentification>::iterator it = prot_ids.begin(); it != prot_ids.end(); ++it)
    {
      it->assignRanks();
    }
    for (vector<PeptideIdentification>::iterator it = pep_ids.begin(); it != pep_ids.end(); ++it)
    {
      it->assignRanks();
    }

    IdXMLFile().store(out, prot_ids, pep_ids);
    return EXECUTION_OK;
  }