コード例 #1
0
  double BinnedSumAgreeingIntensities::operator()(const BinnedSpectrum & spec1, const BinnedSpectrum & spec2) const
  {
    // avoid crash while comparing
    if (!spec1.checkCompliance(spec2))
    {
      throw IncompatibleBinning(__FILE__, __LINE__, __PRETTY_FUNCTION__, "");
    }

    // shortcut similarity calculation by comparing PrecursorPeaks (PrecursorPeaks more than delta away from each other are supposed to be from another peptide)
    DoubleReal pre_mz1 = 0.0;
    if (!spec1.getPrecursors().empty())
      pre_mz1 = spec1.getPrecursors()[0].getMZ();
    DoubleReal pre_mz2 = 0.0;
    if (!spec1.getPrecursors().empty())
      pre_mz2 = spec2.getPrecursors()[0].getMZ();
    if (fabs(pre_mz1 - pre_mz2) > (double)param_.getValue("precursor_mass_tolerance"))
    {
      return 0;
    }

    double score(0), sharedBins(min(spec1.getBinNumber(), spec2.getBinNumber())), sum1(0), sum2(0), summax(0);

    // all bins at equal position and similar intensities contribute positively to score
    for (Size i = 0; i < sharedBins; ++i)
    {
      sum1 += spec1.getBins()[i];
      sum2 += spec2.getBins()[i];
      summax += max((float)0, ((spec1.getBins()[i] + spec2.getBins()[i]) / 2) - fabs(spec1.getBins()[i] - spec2.getBins()[i]));
    }

    // resulting score normalized to interval [0,1]
    score = summax * (2 / (sum1 + sum2));

    return score;

  }
コード例 #2
0
  double BinnedSharedPeakCount::operator()(const BinnedSpectrum& spec1, const BinnedSpectrum& spec2) const
  {
    if (!spec1.checkCompliance(spec2))
    {
      cout << "incompatible" << endl;
      throw BinnedSpectrumCompareFunctor::IncompatibleBinning(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "");
    }

    // shortcut similarity calculation by comparing PrecursorPeaks (PrecursorPeaks more than delta away from each other are supposed to be from another peptide)
    double pre_mz1 = 0.0;
    if (!spec1.getRawSpectrum().getPrecursors().empty())
    {
      pre_mz1 = spec1.getRawSpectrum().getPrecursors()[0].getMZ();
    }
    double pre_mz2 = 0.0;
    if (!spec2.getRawSpectrum().getPrecursors().empty())
    {
      pre_mz2 = spec2.getRawSpectrum().getPrecursors()[0].getMZ();
    }
    if (fabs(pre_mz1 - pre_mz2) > precursor_mass_tolerance_)
    {
      return 0;
    }

    double score(0), sum(0);
    UInt denominator(max(spec1.getFilledBinNumber(), spec2.getFilledBinNumber())), shared_Bins(min(spec1.getBinNumber(), spec2.getBinNumber()));

    // all bins at equal position that have both intensity > 0 contribute positively to score
    for (Size i = 0; i < shared_Bins; ++i)
    {
      if (spec1.getBins()[i] > 0 && spec2.getBins()[i] > 0)
      {
        sum++;
      }
    }

    // resulting score normalized to interval [0,1]
    score = sum / denominator;

    return score;

  }