示例#1
0
 def get_matching_pairs():
     """Find all pairs of peaks that match within the given tolerance."""
     zero_pairs = collect_peak_pairs(spec1, spec2, self.tolerance, shift=0.0)
     message = "Precursor_mz missing. Apply 'add_precursor_mz' filter first."
     assert spectrum1.get("precursor_mz") and spectrum2.get("precursor_mz"), message
     mass_shift = spectrum1.get("precursor_mz") - spectrum2.get("precursor_mz")
     nonzero_pairs = collect_peak_pairs(spec1, spec2, self.tolerance, shift=mass_shift)
     unsorted_matching_pairs = zero_pairs + nonzero_pairs
     return sorted(unsorted_matching_pairs, key=lambda x: x[2], reverse=True)
示例#2
0
 def get_matching_pairs():
     """Get pairs of peaks that match within the given tolerance."""
     matching_pairs = collect_peak_pairs(spec1,
                                         spec2,
                                         self.tolerance,
                                         shift=0.0)
     return sorted(matching_pairs, key=lambda x: x[2], reverse=True)
def test_cosine_hungarian_tolerance_01():
    """Test finding expected peak matches within tolerance=0.2."""
    spec1 = numpy.array([[100, 200, 300, 500],
                         [0.1, 0.1, 1.0, 1.0]], dtype="float").T

    spec2 = numpy.array([[105, 205.1, 300, 500.1],
                         [0.1, 0.1, 1.0, 1.0]], dtype="float").T

    matching_pairs = collect_peak_pairs(spec1, spec2, tolerance=0.2)
    assert len(matching_pairs) == 2, "Expected different number of matching peaks"
    assert matching_pairs == [(2, 2, 1.0), (3, 3, 1.0)], "Expected different matchin pairs."
def test_cosine_hungarian_tolerance_01_shift_min5():
    """Test finding expected peak matches when given a mass_shift of -5.0."""
    spec1 = numpy.array([[100, 200, 300, 500],
                         [1.0, 1.0, 0.1, 0.1]], dtype="float").T

    spec2 = numpy.array([[105, 205.1, 300, 500.1],
                         [1.0, 1.0, 0.1, 0.1]], dtype="float").T

    matching_pairs = collect_peak_pairs(spec1, spec2, tolerance=0.2, shift=-5.0)
    assert len(matching_pairs) == 2, "Expected different number of matching peaks"
    assert matching_pairs == [(0, 0, 1.0), (1, 1, 1.0)], "Expected different matchin pairs."