Esempio n. 1
0
 def _make_mx_nodes(self, X):
     # MSIWarp discards peaks outside the node_mzs range, so add a safety margin at either end
     # in case some other spectra in the dataset have a wider m/z range than the sample spectra.
     # Also, round to the nearest 10 or 1 Da for consistency and interpretability, and only pick
     # unique values in case n_segments is too high or the mass range is too small
     min_mz = np.floor(X.mz.min() / 10 - 1) * 10
     max_mz = np.ceil(X.mz.max() / 10 + 1) * 10
     node_mzs = np.unique(np.round(np.linspace(min_mz, max_mz, self.n_segments + 1)))
     node_slacks = peak_width(node_mzs, self.analyzer, self.align_sigma_1) / 2
     return mx.initialize_nodes(node_mzs, node_slacks, self.n_steps)
Esempio n. 2
0
    format(i_r, sigma_1 * 1e6, 2 * epsilon * sigma_1 * 1e6))

# ---------- find peak dense regions across data set spectra ----------
xi = np.linspace(mz_begin, mz_end, 4000)
(yi, xp, yp) = peak_density_mz(spectra, xi, bandwidth=bandwidth, stride=5)

# we're using the same warping nodes for all spectra here
node_mzs = (xp[:-1] + xp[1:]) / 2
node_mzs = np.array([mz_begin, *node_mzs, mz_end])

# setup warping parameters
n_steps = 50  # the slack of a warping node is +- (n_steps * s * sigma @ the node's m/z)
slack = 2.0 * epsilon * sigma_1

node_slacks = np.array([slack * mz for mz in node_mzs])
nodes = mx.initialize_nodes(node_mzs, node_slacks, n_steps)

# ---------- warp spectra ----------
s_r = get_mx_spectrum(fpath_sbd, meta, i_r, sigma_1, instrument_type)

print("warping spectra...")

import time
t0 = time.time()
optimal_moves = mx.find_optimal_spectra_warpings(spectra, s_r, nodes, epsilon)
t1 = time.time()
print("found optimal warpings in {:0.2f}s".format(t1 - t0))

t2 = time.time()
warped_spectra = [
    mx.warp_peaks(s_i, nodes, o_i)