Esempio n. 1
0
 def get_matching_pairs():
     """Get pairs of peaks that match within the given tolerance."""
     zero_pairs = collect_peak_pairs(spec1, spec2, tolerance, shift=0.0)
     if modified_cosine:
         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, tolerance, shift=mass_shift)
         unsorted_matching_pairs = zero_pairs + nonzero_pairs
     else:
         unsorted_matching_pairs = zero_pairs
     return sorted(unsorted_matching_pairs, key=lambda x: x[2], reverse=True)
Esempio n. 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_collect_peak_pairs_compiled(shift, expected_pairs, expected_matches):
    """Test finding expected peak matches for given tolerance."""
    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 = numpy.array(collect_peak_pairs(spec1, spec2, tolerance=0.2, shift=shift))
    assert matching_pairs.shape == expected_matches, "Expected different number of matching peaks"
    assert numpy.allclose(matching_pairs, numpy.array(expected_pairs), atol=1e-8), "Expected different values."
def test_collect_peak_pairs_no_matches(numba_compiled):
    """Test function for no matching peaks."""
    shift = -20.0
    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
    if numba_compiled:
        matching_pairs = collect_peak_pairs(spec1, spec2, tolerance=0.2, shift=shift)
    else:
        matching_pairs = collect_peak_pairs.py_func(spec1, spec2, tolerance=0.2, shift=shift)
    assert matching_pairs is None, "Expected pairs to be None."
Esempio n. 5
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,
         mz_power=self.mz_power,
         intensity_power=self.intensity_power)
     if matching_pairs is None:
         return None
     matching_pairs = matching_pairs[
         numpy.argsort(matching_pairs[:, 2])[::-1], :]
     return matching_pairs
def test_collect_peak_pairs_compiled(shift, expected_pairs):
    """Test finding expected peak matches for given tolerance."""
    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,
                                        shift=shift)
    assert len(
        matching_pairs) == 2, "Expected different number of matching peaks"
    assert matching_pairs == [pytest.approx(x, 1e-9) for x in expected_pairs
                              ], "Expected different pairs."