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;

  }
Exemple #2
0
  TEST_NOT_EQUAL(bs1,nullPointer)
}
END_SECTION

START_SECTION((BinnedSpectrum(const BinnedSpectrum &source)))
{
  BinnedSpectrum copy(*bs1);
  TEST_EQUAL(copy.getName(), bs1->getName());
  TEST_EQUAL(copy.getBinSize(), bs1->getBinSize());
  TEST_EQUAL((UInt)copy.getPrecursors()[0].getMZ(),(UInt)bs1->getPrecursors()[0].getMZ());
}
END_SECTION

START_SECTION((BinnedSpectrum& operator=(const BinnedSpectrum &source)))
{
  BinnedSpectrum copy(*bs1);
  bs1 = new BinnedSpectrum(1.5,2,s1);
  TEST_EQUAL(copy.getName(), bs1->getName());
  TEST_EQUAL(copy.getBinSize(), bs1->getBinSize());
  TEST_EQUAL((UInt)copy.getPrecursors()[0].getMZ(),(UInt)bs1->getPrecursors()[0].getMZ());
}
END_SECTION

START_SECTION((BinnedSpectrum& operator=(const PeakSpectrum &source)))
{
  bs1 = new BinnedSpectrum();
  *bs1 = s1;
  TEST_EQUAL(bs1->getPrecursors()[0].getMZ(),s1.getPrecursors()[0].getMZ());
  bs1->setBinSize(1.5);
  bs1->setBinSpread(2);
}
 BinnedSpectrum::BinnedSpectrum(const BinnedSpectrum& source) :
   bin_spread_(source.getBinSpread()), bin_size_(source.getBinSize()), bins_(source.getBins()), raw_spec_(source.raw_spec_)
 {
 }
 //yields false if given BinnedSpectrum size or spread differs from this one (comparing those might crash)
 bool BinnedSpectrum::checkCompliance(const BinnedSpectrum& bs) const
 {
   return (this->bin_size_ == bs.getBinSize()) &&
          (this->bin_spread_ == bs.getBinSpread());
 }
  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;

  }