Ejemplo n.º 1
0
  void ProgressLogger::startProgress(SignedSize begin, SignedSize end, const String & label) const
  {
    OPENMS_PRECONDITION(begin <= end, "ProgressLogger::init : invalid range!");
    last_invoke_ = time(NULL);

    switch (type_)
    {
    case CMD:
      begin_ = begin;
      end_ = end;
      if (recursion_depth_)
        cout << '\n';
      cout << string(2 * recursion_depth_, ' ') << "Progress of '" << label << "':" << endl;
      stop_watch_.reset();
      stop_watch_.start();
      break;

    case GUI:
      begin_ = begin;
      end_ = end;
      if (!dlg_)
        dlg_ = new QProgressDialog(label.c_str(), QString(), int(begin), int(end));
      dlg_->setWindowTitle(label.c_str());
      dlg_->setWindowModality(Qt::WindowModal);
      dlg_->show();
      break;

    case NONE:
      break;
    }
    ++recursion_depth_;
    return;
  }
Ejemplo n.º 2
0
  const Residue* ResidueDB::getModifiedResidue(const Residue* residue, const String& modification)
  {
    OPENMS_PRECONDITION(!modification.empty(), "Modification cannot be empty")
    // search if the mod already exists
    String res_name = residue->getName();

    if (residue_names_.find(res_name) == residue_names_.end())
    {
      throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
                                       String("Residue with name " + res_name + " was not registered in residue DB, register first!").c_str());
    }

    // terminal mods. don't apply to residue (side chain), so don't consider them:
    const ResidueModification& mod = ModificationsDB::getInstance()->getModification(modification, residue->getOneLetterCode(), ResidueModification::ANYWHERE);
    String id = mod.getId();
    if (id.empty()) id = mod.getFullId();

    if (residue_mod_names_.has(res_name) && residue_mod_names_[res_name].has(id))
    {
      return residue_mod_names_[res_name][id];
    }

    Residue* res = new Residue(*residue_names_[res_name]);
    res->setModification_(mod);
    //res->setLossFormulas(vector<EmpiricalFormula>());
    //res->setLossNames(vector<String>());

    // now register this modified residue
    addResidue_(res);
    return res;
  }
Ejemplo n.º 3
0
// for SWATH -- get the theoretical b and y series masses for a sequence
void getBYSeries(AASequence& a, //
                 std::vector<double>& bseries, //
                 std::vector<double>& yseries, //
                 UInt charge //
                )
{
    OPENMS_PRECONDITION(charge > 0, "Charge is a positive integer");
    TheoreticalSpectrumGenerator generator;
    Param p;
    p.setValue("add_metainfo", "true",
               "Adds the type of peaks as metainfo to the peaks, like y8+, [M-H2O+2H]++");
    generator.setParameters(p);

    RichPeakSpectrum rich_spec;
    generator.addPeaks(rich_spec, a, Residue::BIon, charge);
    generator.addPeaks(rich_spec, a, Residue::YIon, charge);

    for (RichPeakSpectrum::iterator it = rich_spec.begin();
            it != rich_spec.end(); ++it)
    {
        if (it->getMetaValue("IonName").toString()[0] == 'y')
        {
            yseries.push_back(it->getMZ());
        }
        else if (it->getMetaValue("IonName").toString()[0] == 'b')
        {
            bseries.push_back(it->getMZ());
        }
    }
} // end getBYSeries
Ejemplo n.º 4
0
  void ConsensusIDAlgorithm::apply(vector<PeptideIdentification>& ids,
                                   Size number_of_runs)
  {
    // abort if no IDs present
    if (ids.empty())
    {
      return;
    }

    number_of_runs_ = (number_of_runs != 0) ? number_of_runs : ids.size();

    // prepare data here, so that it doesn't have to happen in each algorithm:
    for (vector<PeptideIdentification>::iterator pep_it = ids.begin(); 
         pep_it != ids.end(); ++pep_it)
    {
      pep_it->sort();
      if ((considered_hits_ > 0) &&
          (pep_it->getHits().size() > considered_hits_))
      {
        pep_it->getHits().resize(considered_hits_);
      }
    }
    // make sure there are no duplicated hits (by sequence):
    IDFilter::removeDuplicatePeptideHits(ids, true);

    SequenceGrouping results;
    apply_(ids, results); // actual (subclass-specific) processing

    String score_type = ids[0].getScoreType();
    bool higher_better = ids[0].isHigherScoreBetter();
    ids.clear();
    ids.resize(1);
    ids[0].setScoreType(score_type);
    ids[0].setHigherScoreBetter(higher_better);
    for (SequenceGrouping::iterator res_it = results.begin(); 
         res_it != results.end(); ++res_it)
    {
      OPENMS_PRECONDITION(!res_it->second.second.empty(),
                          "Consensus score for peptide required");
      PeptideHit hit;

      if (res_it->second.second.size() == 2)
      {
        // filter by "support" value:
        double support = res_it->second.second[1];
        if (support < min_support_) continue;
        hit.setMetaValue("consensus_support", support);
      }
      
      hit.setSequence(res_it->first);
      hit.setCharge(res_it->second.first);
      hit.setScore(res_it->second.second[0]);
      ids[0].insertHit(hit);
#ifdef DEBUG_ID_CONSENSUS
      LOG_DEBUG << " - Output hit: " << hit.getSequence() << " "
                << hit.getScore() << endl;
#endif
    }
    ids[0].assignRanks();
  }
Ejemplo n.º 5
0
    int lowess(const std::vector<double>& x, const std::vector<double>& y,
               double f, int nsteps,
               double delta, std::vector<double>& result)
    {
      OPENMS_PRECONDITION(delta >= 0.0, "lowess: parameter delta must be zero or larger")
      OPENMS_PRECONDITION(f > 0.0, "lowess: parameter f must be larger than 0")
      OPENMS_PRECONDITION(f <= 1.0, "lowess: parameter f must be smaller or equal to 1")
      OPENMS_PRECONDITION(nsteps >= 0, "lowess: parameter nstesp must be zero or larger")
      OPENMS_PRECONDITION(x.size() == y.size(), "Vectors x and y must have the same length")
      OPENMS_PRECONDITION(x.size() >= 2, "Need at least two points for smoothing")
      OPENMS_PRECONDITION(std::adjacent_find(x.begin(), x.end(), std::greater<double>()) == x.end(),
                          "The vector x needs to be sorted")

      size_t n = x.size();

      // result as well as working vectors need to have the correct size
      result.clear();
      result.resize(n);
      std::vector<double> resid_weights(n);
      std::vector<double> weights(n);

      c_lowess::TemplatedLowess<std::vector<double>, double> clowess;

      int retval = clowess.lowess(x, y, f, nsteps, delta, result,
                                  resid_weights, weights);

      return retval;
    }
Ejemplo n.º 6
0
  double AScore::computeCumulativeScore_(Size N, Size n, double p) const
  {
    OPENMS_PRECONDITION(n <= N, "The number of matched ions (n) can be at most as large as the number of trials (N).");
    OPENMS_PRECONDITION(p >= 0 && p <= 1.0, "p must be a probability [0,1].");

    // return bad p value if none has been matched (see Beausoleil et al.)
    if (n == 0) return 1.0;

    double score = 0.0;
    // score = sum_{k=n..N}(\choose{N}{k}p^k(1-p)^{N-k})
    for (Size k = n; k <= N; ++k)
    {
      double coeff = boost::math::binomial_coefficient<double>((unsigned int)N, (unsigned int)k);
      double pow1 = pow((double)p, (int)k);
      double pow2 = pow(double(1 - p), double(N - k));
      
      score += coeff * pow1 * pow2;
    }

    return score;
  }
Ejemplo n.º 7
0
 double AScore::peptideScore_(const std::vector<double> & scores) const
 {
   OPENMS_PRECONDITION(scores.size() == 10, "Scores vector must contain a score for every peak level."); 
   return (scores[0] * 0.5
           + scores[1] * 0.75
           + scores[2]
           + scores[3]
           + scores[4]
           + scores[5]
           + scores[6] * 0.75
           + scores[7] * 0.5
           + scores[8] * 0.25
           + scores[9] * 0.25)
          / 10.0;
 }
Ejemplo n.º 8
0
  float MRMDecoy::AASequenceIdentity(const String& sequence, const String& decoy)
  {
    OPENMS_PRECONDITION(sequence.size() == decoy.size(), "Cannot compare two sequences of unequal length");

    std::vector<char> sequence_v(sequence.begin(), sequence.end());
    std::vector<char> decoy_v(decoy.begin(), decoy.end());
    int running = 0;
    for (Size i = 0; i < sequence_v.size(); i++)
    {
      if (sequence_v[i] == decoy_v[i])
      {
        running += 1;
      }
    }
    double identity = (double) running / sequence_v.size();
    return identity;
  }
Ejemplo n.º 9
0
  std::vector<std::size_t> SpectrumAccessOpenMS::getSpectraByRT(double RT, double deltaRT) const
  {
    OPENMS_PRECONDITION(deltaRT >= 0, "Delta RT needs to be a positive number");

    // we first perform a search for the spectrum that is past the
    // beginning of the RT domain. Then we add this spectrum and try to add
    // further spectra as long as they are below RT + deltaRT.
    MSExperimentType::Iterator spectrum = ms_experiment_->RTBegin(RT - deltaRT);
    std::vector<std::size_t> result;
    result.push_back(std::distance(ms_experiment_->begin(), spectrum));
    spectrum++;
    while (spectrum->getRT() <= RT + deltaRT && spectrum != ms_experiment_->end())
    {
      result.push_back(spectrum - ms_experiment_->begin());
      spectrum++;
    }
    return result;
  }
Ejemplo n.º 10
0
  void OpenSwathScoring::calculateDIAScores(OpenSwath::IMRMFeature* imrmfeature, const std::vector<TransitionType> & transitions,
      OpenSwath::SpectrumAccessPtr swath_map, OpenSwath::SpectrumAccessPtr ms1_map, OpenMS::DIAScoring & diascoring,
      const PeptideType& pep, OpenSwath_Scores & scores)
  {
    OPENMS_PRECONDITION(transitions.size() > 0, "There needs to be at least one transition.");

    std::vector<double> normalized_library_intensity;
    getNormalized_library_intensities_(transitions, normalized_library_intensity);

    // parameters
    int by_charge_state = 1; // for which charge states should we check b/y series
    double precursor_mz = transitions[0].precursor_mz;

    // find spectrum that is closest to the apex of the peak using binary search
    OpenSwath::SpectrumPtr spectrum_ = getAddedSpectra_(swath_map, imrmfeature->getRT(), add_up_spectra_);
    OpenSwath::SpectrumPtr* spectrum = &spectrum_;

    // Isotope correlation / overlap score: Is this peak part of an
    // isotopic pattern or is it the monoisotopic peak in an isotopic
    // pattern?
    diascoring.dia_isotope_scores(transitions, (*spectrum), imrmfeature, scores.isotope_correlation, scores.isotope_overlap);
    // Mass deviation score
    diascoring.dia_massdiff_score(transitions, (*spectrum), normalized_library_intensity,
        scores.massdev_score, scores.weighted_massdev_score);

    // Presence of b/y series score
    OpenMS::AASequence aas;
    OpenSwathDataAccessHelper::convertPeptideToAASequence(pep, aas);
    diascoring.dia_by_ion_score((*spectrum), aas, by_charge_state, scores.bseries_score, scores.yseries_score);

    // FEATURE we should not punish so much when one transition is missing!
    scores.massdev_score = scores.massdev_score / transitions.size();

    // DIA dotproduct and manhattan score
    diascoring.score_with_isotopes((*spectrum), transitions, scores.dotprod_score_dia, scores.manhatt_score_dia);

    // MS1 ppm score : check that the map is not NULL and contains spectra
    if (ms1_map && ms1_map->getNrSpectra() > 0) 
    {
      OpenSwath::SpectrumPtr ms1_spectrum = getAddedSpectra_(ms1_map, imrmfeature->getRT(), add_up_spectra_);
      diascoring.dia_ms1_massdiff_score(precursor_mz, ms1_spectrum, scores.ms1_ppm_score);
      diascoring.dia_ms1_isotope_scores(precursor_mz, ms1_spectrum, pep.getChargeState(), scores.ms1_isotope_correlation, scores.ms1_isotope_overlap);
    }
  }
Ejemplo n.º 11
0
// for SWATH -- get the theoretical b and y series masses for a sequence
void getTheorMasses(AASequence& a, std::vector<double>& masses,
                    UInt charge)
{
    OPENMS_PRECONDITION(charge > 0, "Charge is a positive integer");
    TheoreticalSpectrumGenerator generator;
    Param p;
    p.setValue("add_metainfo", "true",
               "Adds the type of peaks as metainfo to the peaks, like y8+, [M-H2O+2H]++");
    generator.setParameters(p);
    RichPeakSpectrum rich_spec;
    generator.addPeaks(rich_spec, a, Residue::BIon, charge);
    generator.addPeaks(rich_spec, a, Residue::YIon, charge);
    generator.addPrecursorPeaks(rich_spec, a, charge);
    for (RichPeakSpectrum::iterator it = rich_spec.begin();
            it != rich_spec.end(); ++it)
    {
        masses.push_back(it->getMZ());
    }
} // end getBYSeries
  std::vector<std::size_t> SpectrumAccessOpenMSInMemory::getSpectraByRT(double RT, double deltaRT) const
  {
    OPENMS_PRECONDITION(deltaRT >= 0, "Delta RT needs to be a positive number");

    // we first perform a search for the spectrum that is past the
    // beginning of the RT domain. Then we add this spectrum and try to add
    // further spectra as long as they are below RT + deltaRT.
    std::vector<std::size_t> result;
    OpenSwath::SpectrumMeta s;
    s.RT = RT - deltaRT;
    std::vector< OpenSwath::SpectrumMeta >::const_iterator spectrum = std::upper_bound(
        spectra_meta_.begin(), spectra_meta_.end(), s, OpenSwath::SpectrumMeta::RTLess());

    result.push_back(std::distance(spectra_meta_.begin(), spectrum));
    ++spectrum;
    while (spectrum->RT < RT + deltaRT && spectrum != spectra_meta_.end())
    {
      result.push_back(std::distance(spectra_meta_.begin(), spectrum));
      ++spectrum;
    }
    return result;
  }
Ejemplo n.º 13
0
    void LinearRegression::computeGoodness_(const std::vector<Wm5::Vector2d>& points, double confidence_interval_P)
    {
      OPENMS_PRECONDITION(static_cast<unsigned>(points.size()) > 2, 
          "Cannot compute goodness of fit for regression with less than 3 data points");
      // specifically, boost throws an exception for a t-distribution with zero df

      unsigned N = static_cast<unsigned>(points.size());
      std::vector<double> X; X.reserve(N);
      std::vector<double> Y; Y.reserve(N);
      for (unsigned i = 0; i < N; ++i)
      {
        X.push_back(points[i].X());
        Y.push_back(points[i].Y());
      }

      // Mean of abscissa and ordinate values
      double x_mean = Math::mean(X.begin(), X.end());
      double y_mean = Math::mean(Y.begin(), Y.end());

      // Variance and Covariances
      double var_X = Math::variance(X.begin(), X.end(), x_mean);
      double var_Y = Math::variance(Y.begin(), Y.end(), y_mean);
      double cov_XY = Math::covariance(X.begin(), X.end(), Y.begin(), Y.end());

      // S_xx
      double s_XX = var_X * (N-1);
      /*for (unsigned i = 0; i < N; ++i)
      {
        double d = (X[i] - x_mean);
        s_XX += d * d;
      }*/

      // Compute the squared Pearson coefficient
      r_squared_ = (cov_XY * cov_XY) / (var_X * var_Y);

      // The standard deviation of the residuals
      double sum = 0;
      for (unsigned i = 0; i < N; ++i)
      {
        double x_i = fabs(Y[i] - (intercept_ + slope_ * X[i]));
        sum += x_i;
      }
      mean_residuals_       = sum / N;
      stand_dev_residuals_ = sqrt((chi_squared_ - (sum * sum) / N) / (N - 1));

      // The Standard error of the slope
      stand_error_slope_ = stand_dev_residuals_ / sqrt(s_XX);

      // and the intersection of Y_hat with the x-axis
      x_intercept_ = -(intercept_ / slope_);

      double P = 1 - (1 - confidence_interval_P) / 2;
      boost::math::students_t tdist(N - 2);
      t_star_ = boost::math::quantile(tdist, P);

      //Compute the asymmetric 95% confidence interval of around the X-intercept
      double g = (t_star_ / (slope_ / stand_error_slope_));
      g *= g;
      double left = (x_intercept_ - x_mean) * g;
      double bottom = 1 - g;
      double d = (x_intercept_ - x_mean);
      double right = t_star_ * (stand_dev_residuals_ / slope_) * sqrt((d * d) / s_XX + (bottom / N));

      // Confidence interval lower_ <= X_intercept <= upper_
      lower_ = x_intercept_ + (left + right) / bottom;
      upper_ = x_intercept_ + (left - right) / bottom;

      if (lower_ > upper_)
      {
        std::swap(lower_, upper_);
      }

      double tmp = 0;
      for (unsigned i = 0; i < N; ++i)
      {
        tmp += (X[i] - x_mean) * (X[i] - x_mean);
      }

      //            cout << "100.0 / abs( x_intercept_ ) " << (100.0 / fabs( x_intercept_ )) << endl;
      //            cout << "tmp : " << tmp << endl;
      //            cout << "slope_ " << slope_ << endl;
      //            cout << "y_mean " << y_mean << endl;
      //            cout << "N " << N << endl;
      //            cout << "stand_dev_residuals_ " << stand_dev_residuals_ << endl;
      //            cout << " (1.0/ (double) N)  " <<  (1.0/ (double) N)  << endl;
      //            cout << "sx hat " << (stand_dev_residuals_ / slope_) * sqrt(  (1.0/ (double) N) * (y_mean / (slope_ * slope_ * tmp ) ) ) << endl;

      // compute relative standard deviation (non-standard formula, taken from Mayr et al. (2006) )
      rsd_ = (100.0 / fabs(x_intercept_)) * (stand_dev_residuals_ / slope_) * sqrt((1.0 / (double) N) * (y_mean / (slope_ * slope_ * tmp)));

      if (rsd_ < 0.0)
      {
        std::cout << "rsd < 0.0 " << std::endl;
        std::cout <<   "Intercept                                " << intercept_
                  << "\nSlope                                    " << slope_
                  << "\nSquared pearson coefficient              " << r_squared_
                  << "\nValue of the t-distribution              " << t_star_
                  << "\nStandard deviation of the residuals      " << stand_dev_residuals_
                  << "\nStandard error of the slope              " << stand_error_slope_
                  << "\nThe X intercept                          " << x_intercept_
                  << "\nThe lower border of confidence interval  " << lower_
                  << "\nThe higher border of confidence interval " << upper_
                  << "\nChi squared value                        " << chi_squared_
                  << "\nx mean                                   " << x_mean
                  << "\nstand_error_slope/slope_                 " << (stand_dev_residuals_ / slope_)
                  << "\nCoefficient of Variation                 " << (stand_dev_residuals_ / slope_) / x_mean * 100  << std::endl
                  << "========================================="
                  << std::endl;
      }
    }
Ejemplo n.º 14
0
 void Feature::setQuality(Size index, Feature::QualityType q)
 {
   OPENMS_PRECONDITION(index < 2, "Feature<2>::setQuality(Size): index overflow!");
   qualities_[index] = q;
 }
Ejemplo n.º 15
0
 Feature::QualityType Feature::getQuality(Size index) const
 {
   OPENMS_PRECONDITION(index < 2, "Feature<2>::getQuality(Size): index overflow!");
   return qualities_[index];
 }