diff --git a/cpyMSpec/legacy_interface.py b/cpyMSpec/legacy_interface.py index e416477..4e5abea 100644 --- a/cpyMSpec/legacy_interface.py +++ b/cpyMSpec/legacy_interface.py @@ -14,7 +14,7 @@ def complete_isodist(sf, sigma=0.001, cutoff_perc=0.1, charge=None, pts_per_mz=1 cutoff = cutoff_perc / 100.0 fwhm = sigma * 2.3548200450309493 # the exact ratio is 2 \sqrt{2 \log 2} abs_charge = max(1, abs(charge)) - p = isotopePattern(str(sf), cutoff / 10.0) + p = isotopePattern(str(sf), 0.9999) p.addCharge(charge) mz = min(p.masses) / abs_charge diff --git a/cpyMSpec/spectrum.py b/cpyMSpec/spectrum.py index ef99237..2743f43 100644 --- a/cpyMSpec/spectrum.py +++ b/cpyMSpec/spectrum.py @@ -298,16 +298,14 @@ def trimmed(self, n_peaks): def removeIntensitiesBelow(self, min_intensity): ims.spectrum_trim_intensity(self.ptr, min_intensity) -def isotopePattern(sum_formula, threshold=1e-4, fft_threshold=1e-8): +def isotopePattern(sum_formula, desired_prob=0.99999): """ Calculates isotopic peaks for a sum formula. :param sum_formula: text representation of an atomic composition :type sum_formula: str - :param threshold: minimal abundance to keep in the final results - :param fft_threshold: minimal abundance to keep in intermediate - results (for each of the distinct atomic species) + :param desired_prob: total probability covered by the result + :type desired_prob: float """ - s = ims.spectrum_new_from_sf(sum_formula.encode('ascii'), - threshold, fft_threshold) + s = ims.spectrum_new_from_sf(sum_formula.encode('ascii'), desired_prob) return _new_spectrum(TheoreticalSpectrum, s) diff --git a/cpyMSpec/utils.py b/cpyMSpec/utils.py index 2ccc799..821ef48 100644 --- a/cpyMSpec/utils.py +++ b/cpyMSpec/utils.py @@ -17,4 +17,4 @@ def init_ffi(): def load_shared_lib(ffi): return ffi.dlopen(full_filename(shared_lib("ms_cffi"))) -VERSION = "0.3.5" +VERSION = "0.4.0" diff --git a/ims-cpp b/ims-cpp index 3615e6e..840dc49 160000 --- a/ims-cpp +++ b/ims-cpp @@ -1 +1 @@ -Subproject commit 3615e6ed6b4d5ea0bf825787b5b57ab6b052b5e7 +Subproject commit 840dc490c3d551c8ad580f21479398d43b222f53 diff --git a/test/test_centroiding.py b/test/test_centroiding.py index 206c304..616388b 100644 --- a/test/test_centroiding.py +++ b/test/test_centroiding.py @@ -2,22 +2,23 @@ import pytest -def assert_patterns_almost_equal(p1, p2): +def assert_patterns_almost_equal(p1, p2, instr): peaks1 = list(zip(p1.masses, p1.intensities)) peaks2 = list(zip(p2.masses, p2.intensities)) - assert_peaks_almost_equal(peaks1[:5], peaks2[:5]) + assert_peaks_almost_equal(peaks1[:5], peaks2[:5], instr) -def assert_peaks_almost_equal(peaks1, peaks2): +def assert_peaks_almost_equal(peaks1, peaks2, instr): for (m1, a1), (m2, a2) in zip(peaks1, peaks2): - assert abs(m1 - m2) < 1e-4 - assert abs(a1 - a2) < 1e-3 + ppm = m1 / instr.resolvingPowerAt(m1) + assert abs((m1 - m2) / m1) < 0.1 * ppm + assert abs((a1 - a2) / a2) < 1e-3 formulas = ["C5H8O13Cl", "C3H5O7", "Fe2Cl3K5H7", "C44H28O32K", "C18Cl5Na3H22"] @pytest.mark.parametrize("f", formulas) @pytest.mark.parametrize("resolution", [10000, 30000, 50000, 80000, 100000]) def test_centroiding(f, resolution): - p = isotopePattern(f, threshold=1e-7) + p = isotopePattern(f, 0.9999999) instr = InstrumentModel('tof', resolution) p1 = p.centroids(instr, points_per_fwhm=500) min_mz = min(p1.masses) @@ -26,7 +27,7 @@ def test_centroiding(f, resolution): n_pts = int((max_mz + 2 - min_mz) / step) mzs = [min_mz - 1 + step * i for i in range(n_pts)] p2 = ProfileSpectrum(mzs, p.envelope(instr)(mzs)).centroids(window_size=15) - assert_patterns_almost_equal(p1, p2) + assert_patterns_almost_equal(p1, p2, instr) @pytest.mark.parametrize("f", formulas) @pytest.mark.parametrize("threshold", [1e-7, 1e-5, 1e-3])