def plot_range(fpath, mz0, mz1, ax, col, size=20, in_ppm=False): """Plot peak scatter within mz0 and mz1 """ ts = mx.get_triplets_range(fpath, mz0, mz1) if len(ts) == 0: return h = np.array([t.height for t in ts]) t = np.array([t.index for t in ts]) mz = np.array([t.mz for t in ts]) if in_ppm: x_m = np.mean(mz) x = (mz - x_m) / x_m * 1e6 ax.scatter(x, t, size * h / np.max(h), c=col, alpha=0.5) else: ax.scatter(mz, t, size * h / np.max(h), c=col, alpha=0.5)
fig.savefig(fpath_scatter + '/mz_{}.png'.format(int(mz_i)), dpi=200) ax.cla() # ---------- compute mass dispersions around mean spectrum ---------- from msiwarp.util.warp import dispersion_triplets import pandas as pd dispersion_raw = np.zeros(len(mz_ref)) dispersion_warped = np.zeros(len(mz_ref)) for i, mz_i in enumerate(mz_ref): d = mass_tolerance * mz_i / 1e6 # -+ 350 ppm around reference mass mz0 = mz_i - d mz1 = mz_i + d ts_raw = mx.get_triplets_range(fpath_triplets_raw, mz0, mz1) ts_warped = mx.get_triplets_range(fpath_triplets_warped, mz0, mz1) q = 0.25 # remove background signal if len(ts_raw) > 3: dispersion_raw[i] = dispersion_triplets(ts_raw, q) if len(ts_warped) > 3: dispersion_warped[i] = dispersion_triplets(ts_warped, q) d = { 'mz': mz_ref, 'dispersion raw [ppm]': dispersion_raw, 'dispersion warped [ppm]': dispersion_warped } df = pd.DataFrame(d)