<commit_before>/*
 * Copyright 2006-2021 The MZmine Development Team
 *
 * This file is part of MZmine.
 *
 * MZmine is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * MZmine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with MZmine; if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

package io.github.mzmine.modules.dataprocessing.align_join;

import io.github.mzmine.datamodel.features.FeatureListRow;

/**
 * This class represents a score between feature list row and aligned feature list row
 */
public class RowVsRowScore implements Comparable<RowVsRowScore> {

  double score;
  private FeatureListRow peakListRow, alignedRow;

  public RowVsRowScore(FeatureListRow peakListRow, FeatureListRow alignedRow, double mzMaxDiff,
      double mzWeight, double rtMaxDiff, double rtWeight) {

    this.peakListRow = peakListRow;
    this.alignedRow = alignedRow;

    // Calculate differences between m/z and RT values
    double mzDiff = Math.abs(peakListRow.getAverageMZ() - alignedRow.getAverageMZ());

    double rtDiff = Math.abs(peakListRow.getAverageRT() - alignedRow.getAverageRT());

    score = ((1 - mzDiff / mzMaxDiff) * mzWeight) + ((1 - rtDiff / rtMaxDiff) * rtWeight);

  }

  public RowVsRowScore(FeatureListRow peakListRow, FeatureListRow alignedRow, double mzMaxDiff,
      double mzWeight, double rtMaxDiff, double rtWeight, double mobilityMaxDiff,
      double mobilityWeight) {

    this.peakListRow = peakListRow;
    this.alignedRow = alignedRow;

    // Calculate differences between m/z and RT values
    double mzDiff = Math.abs(peakListRow.getAverageMZ() - alignedRow.getAverageMZ());

    double rtDiff = Math.abs(peakListRow.getAverageRT() - alignedRow.getAverageRT());

    Float row1Mobility = peakListRow.getAverageMobility();
    Float row2Mobility = alignedRow.getAverageMobility();
    if (row1Mobility != null && row2Mobility != null) {
      float mobilityDiff = Math.abs(row1Mobility - row2Mobility);
      score = ((1 - mzDiff / mzMaxDiff) * mzWeight) + ((1 - rtDiff / rtMaxDiff) * rtWeight) + (
          (1 - mobilityDiff / mobilityMaxDiff) * mobilityWeight);
    } else {
      score = ((1 - mzDiff / mzMaxDiff) * mzWeight) + ((1 - rtDiff / rtMaxDiff) * rtWeight);
    }
  }

  /**
   * This method returns the feature list row which is being aligned
   */
  public FeatureListRow getRowToAdd() {
    return peakListRow;
  }

  /**
   * This method returns the row of aligned feature list
   */
  public FeatureListRow getAlignedBaseRow() {
    return alignedRow;
  }

  /**
   * This method returns score between the these two peaks (the lower score, the better match)
   */
  public double getScore() {
    return score;
  }

  /**
   * @see Comparable#compareTo(Object)
   */
  public int compareTo(RowVsRowScore object) {

    // We must never return 0, because the TreeSet in JoinAlignerTask would
    // treat such elements as equal
    if (score < object.getScore()) {
      return 1;
    } else {
      return -1;
    }

  }

}<commit_msg>Fix general contract of comparable for RowVRowScore in alignment<commit_after>/*
 * Copyright 2006-2022 The MZmine Development Team
 *
 * This file is part of MZmine.
 *
 * MZmine is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * MZmine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with MZmine; if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

package io.github.mzmine.modules.dataprocessing.align_join;

import io.github.mzmine.datamodel.features.FeatureListRow;

/**
 * This class represents a score between feature list row and aligned feature list row
 */
public class RowVsRowScore implements Comparable<RowVsRowScore> {

  double score;
  private final FeatureListRow peakListRow;
  private final FeatureListRow alignedRow;

  public RowVsRowScore(FeatureListRow peakListRow, FeatureListRow alignedRow, double mzMaxDiff,
      double mzWeight, double rtMaxDiff, double rtWeight) {

    this.peakListRow = peakListRow;
    this.alignedRow = alignedRow;

    // Calculate differences between m/z and RT values
    double mzDiff = Math.abs(peakListRow.getAverageMZ() - alignedRow.getAverageMZ());

    double rtDiff = Math.abs(peakListRow.getAverageRT() - alignedRow.getAverageRT());

    score = ((1 - mzDiff / mzMaxDiff) * mzWeight) + ((1 - rtDiff / rtMaxDiff) * rtWeight);

  }

  public RowVsRowScore(FeatureListRow peakListRow, FeatureListRow alignedRow, double mzMaxDiff,
      double mzWeight, double rtMaxDiff, double rtWeight, double mobilityMaxDiff,
      double mobilityWeight) {

    this.peakListRow = peakListRow;
    this.alignedRow = alignedRow;

    // Calculate differences between m/z and RT values
    double mzDiff = Math.abs(peakListRow.getAverageMZ() - alignedRow.getAverageMZ());

    double rtDiff = Math.abs(peakListRow.getAverageRT() - alignedRow.getAverageRT());

    Float row1Mobility = peakListRow.getAverageMobility();
    Float row2Mobility = alignedRow.getAverageMobility();
    if (row1Mobility != null && row2Mobility != null) {
      float mobilityDiff = Math.abs(row1Mobility - row2Mobility);
      score = ((1 - mzDiff / mzMaxDiff) * mzWeight) + ((1 - rtDiff / rtMaxDiff) * rtWeight) + (
          (1 - mobilityDiff / mobilityMaxDiff) * mobilityWeight);
    } else {
      score = ((1 - mzDiff / mzMaxDiff) * mzWeight) + ((1 - rtDiff / rtMaxDiff) * rtWeight);
    }
  }

  /**
   * This method returns the feature list row which is being aligned
   */
  public FeatureListRow getRowToAdd() {
    return peakListRow;
  }

  /**
   * This method returns the row of aligned feature list
   */
  public FeatureListRow getAlignedBaseRow() {
    return alignedRow;
  }

  /**
   * This method returns score between the these two peaks (the lower score, the better match)
   */
  public double getScore() {
    return score;
  }

  /**
   * Sorts in descending order
   */
  public int compareTo(RowVsRowScore object) {
    return Double.compare(object.getScore(), score);
  }

}
{'fraction_non_alphanumeric': 0.08765859284890427, 'fraction_numerical': 0.009948096885813149, 'mean_word_length': 3.5369522563767166, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6276081', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2007, 'n_words': 687}