Exemple #1
0
 FeatureHandle::FeatureHandle(UInt64 map_index, const BaseFeature& feature) :
   Peak2D(feature),
   UniqueIdInterface(feature),
   map_index_(map_index),
   charge_(feature.getCharge()),
   width_(feature.getWidth())
 {
 }
  pair<bool, DoubleReal> FeatureDistance::operator()(const BaseFeature & left,
                                                     const BaseFeature & right)
  {
    if (!ignore_charge_)
    {
      Int charge_left = left.getCharge(), charge_right = right.getCharge();
      if (charge_left != charge_right)
      {
        if ((charge_left != 0) && (charge_right != 0))
        {
          return make_pair(false, infinity);
        }
      }
    }

    bool valid = true;

    // check m/z difference constraint:
    DoubleReal left_mz = left.getMZ(), right_mz = right.getMZ();
    DoubleReal dist_mz = fabs(left_mz - right_mz);
    DoubleReal max_diff_mz = params_mz_.max_difference;
    if (params_mz_.max_diff_ppm) // compute absolute difference (in Da/Th)
    {
      max_diff_mz *= left_mz * 1e-6;
      // overwrite this parameter - it will be recomputed each time anyway:
      params_mz_.norm_factor = 1 / max_diff_mz;
    }

    if (dist_mz > max_diff_mz)
    {
      if (force_constraints_)
      {
        return make_pair(false, infinity);
      }
      valid = false;
    }

    // check RT difference constraint:
    DoubleReal dist_rt = fabs(left.getRT() - right.getRT());
    if (dist_rt > params_rt_.max_difference)
    {
      if (force_constraints_)
      {
        return make_pair(false, infinity);
      }
      valid = false;
    }

    dist_rt = distance_(dist_rt, params_rt_);
    dist_mz = distance_(dist_mz, params_mz_);

    DoubleReal dist_intensity = 0.0;
    if (params_intensity_.relevant)     // not by default, so worth checking
    {
      dist_intensity = fabs(left.getIntensity() - right.getIntensity());
      dist_intensity = distance_(dist_intensity, params_intensity_);
    }

    DoubleReal dist = dist_rt + dist_mz + dist_intensity;
    dist *= total_weight_reciprocal_;

    return make_pair(valid, dist);
  }