From 18cc2b96897a1ab1635c47e2b902233e54c36a34 Mon Sep 17 00:00:00 2001 From: Artem Tarasov Date: Mon, 21 Aug 2017 10:59:29 +0200 Subject: [PATCH] use same default isotopePattern params as in v0.3 removed legacy_interface.py (no longer used by sm-engine) --- cpyMSpec/legacy_interface.py | 36 ------------------------------------ cpyMSpec/spectrum.py | 14 ++++++++++++-- cpyMSpec/utils.py | 2 +- ims-cpp | 2 +- 4 files changed, 14 insertions(+), 40 deletions(-) delete mode 100644 cpyMSpec/legacy_interface.py diff --git a/cpyMSpec/legacy_interface.py b/cpyMSpec/legacy_interface.py deleted file mode 100644 index 4e5abea..0000000 --- a/cpyMSpec/legacy_interface.py +++ /dev/null @@ -1,36 +0,0 @@ -from cpyMSpec import isotopePattern, InstrumentModel, ProfileSpectrum - -# layer of compatibility with the original pyMSpec.pyisocalc module - -from pyMSpec.pyisocalc import pyisocalc -from pyMSpec.mass_spectrum import MassSpectrum - -import numpy as np - -def complete_isodist(sf, sigma=0.001, cutoff_perc=0.1, charge=None, pts_per_mz=10000, **kwargs): - if charge is None: - charge = sf.charge() - - 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), 0.9999) - p.addCharge(charge) - - mz = min(p.masses) / abs_charge - resolution = mz / fwhm - - mzs = np.arange(min(p.masses) / abs_charge - 1, - max(p.masses) / abs_charge + 1, 1.0/pts_per_mz) - instr = InstrumentModel('tof', resolution) - intensities = np.asarray(p.envelope(instr)(mzs * abs_charge)) - intensities *= 100.0 / intensities.max() - - ms = MassSpectrum() - ms.add_spectrum(mzs, intensities) - - p = ProfileSpectrum(mzs, intensities).centroids(5) - p.removeIntensitiesBelow(cutoff) - p.sortByMass() - ms.add_centroids(p.masses, np.array(p.intensities) * 100) - return ms diff --git a/cpyMSpec/spectrum.py b/cpyMSpec/spectrum.py index 2743f43..af6a519 100644 --- a/cpyMSpec/spectrum.py +++ b/cpyMSpec/spectrum.py @@ -298,14 +298,24 @@ def trimmed(self, n_peaks): def removeIntensitiesBelow(self, min_intensity): ims.spectrum_trim_intensity(self.ptr, min_intensity) -def isotopePattern(sum_formula, desired_prob=0.99999): +def isotopePattern(sum_formula, threshold=1e-4, rel_threshold=True, 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: minimum peak abundance; if nonzero, desired_prob parameter is ignored + :type threshold: float + :param rel_threshold: if True, threshold is relative to the highest peak, otherwise it is a probability + :type rel_threshold: bool :param desired_prob: total probability covered by the result :type desired_prob: float """ - s = ims.spectrum_new_from_sf(sum_formula.encode('ascii'), desired_prob) + assert threshold >= 0 and threshold < 1 + assert desired_prob > 0 and desired_prob <= 1 + + if threshold > 0: + s = ims.spectrum_new_from_sf_thr(sum_formula.encode('ascii'), threshold, rel_threshold) + else: + 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 821ef48..297d8b5 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.4.0" +VERSION = "0.4.1" diff --git a/ims-cpp b/ims-cpp index 840dc49..0aec99f 160000 --- a/ims-cpp +++ b/ims-cpp @@ -1 +1 @@ -Subproject commit 840dc490c3d551c8ad580f21479398d43b222f53 +Subproject commit 0aec99f937ce0519aee3d86ae9dfc97f918d8c33