Skip to content

Commit

Permalink
updated ims-cpp to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Tarasov committed Aug 18, 2017
1 parent 3ac0e91 commit ed386f7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cpyMSpec/legacy_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions cpyMSpec/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion cpyMSpec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion ims-cpp
15 changes: 8 additions & 7 deletions test/test_centroiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand Down

0 comments on commit ed386f7

Please sign in to comment.