| Bioinformatics Toolbox | ![]() |
Align peaks in mass spectrum to reference peaks
YOut = msalign(MZ, Y, R, 'PropertyName', PropertyValue...)
msalign(..., 'Weights', WeightsValue)
msalign(..., 'Range', RangeValue)
msalign(..., 'WidthOfPulses', WidthOfPulsesValue)
msalign(..., 'WindowSizeRatio', WindowSizeRatioValue)
msalign(..., 'Iterations', IterationsValue)
msalign(..., 'GridSteps', GridStepsValue)
msalign(..., 'SearchSpace', SearchSpaceValue)
[YOut, ROut] = msalign(..., 'Group', GroupValue),
msalign(..., 'ShowPlot', ShowPlotValue)
MZ | Mass/charge vector with the range of ions in the spectra. |
Y | Ion intensity vector with the same length as the mass/charge vector (MZ). Y can also be a matrix with several spectra that share the same mass/charge (MZ) range. |
| R | Reference mass vector with a list of known masses in the sample spectrum. |
YOut = msalign(MZ, Y, R, 'PropertyName', PropertyValue...)aligns a raw mass spectrum (Y) by scaling and shifting the mass/charge scale (MZ) so that the cross-correlation between the spectrum (Y) and a synthetic spectrum is maximum. A synthetic spectrum is built with Gaussian pulses centered at the masses specified by the reference mass vector (R). Once the new mass/charge scale is determined, a new spectrum (YOut) is calculated by piecewise cubic interpolating and shifting the new spectrum from the original mass/charge vector (MZ). This method preserves the shape of the peaks.
msalign uses an iterative grid search until it finds the best scale and shift factors for every spectrum.
Note The algorithm works best with three to five marker masses that you know will appear in the spectrum. If you use a single marker mass (a single internal standard), there is a possibility of picking a peak between the marker and sample peak for that marker as msalign scales and shifts the MZ vector. If you only require to shift the MZ vector, you may prefer to useYOut = interp1(MZ, MZ-(MarkerMass-PeakPosition, Y). |
msalign(..., 'Weights', WeightsValue)specifies the relative weights for every mass in the reference mass vector (R). The size of the weight vector (WeightsValue) must be the same as the reference mass vector (R). The default value is ones(size(R)) with a range of 0 to1, but you can use any range. If you have a small number of reference masses, you might want to change the weights.
msalign(..., 'Range', RangeValue)specifies the lower and upper bound for the allowable range in m/z units to shift any of the mass peaks. The default value is [-100 100]. Use these values to tune the robustness of the algorithm. Ideally, you should only try to correct small shifts by keeping the bounds small.
Note You can try to correct larger shifts by increasing the bounds, but you might also pick the wrong peaks to be aligned. |
msalign(..., 'WidthOfPulses', WidthOfPulsesValue) specifies the width (WidthOfPulsesValue) in m/z units for all the Gaussian pulses used to build the correlating synthetic spectrum. WidthOfPulsesValue is at the point where the Gaussian pulse reaches 60.65% of its maximum. The default value is 10. WidthOfPulsesValue may also be a function handle. The function is evaluated at the respective m/z values and returns a variable width for the pulses. Its evaluation should give reasonable values between 0 and max(abs(Range)); otherwise, the function errors out.
Note Tuning the spread of the Gaussian pulses controls a tradeoff between robustness (wider pulses) and precision (narrower pulses), but the spread is unrelated to the shape of the observed peaks in the spectrum. |
msalign(..., 'WindowSizeRatio', WindowSizeRatioValue) specifies a scaling value that determines the size of the window around every alignment peak. The synthetic spectrum is correlated to the sample spectrum only within these regions, which saves computation time. Size of the window is given by Width * WindowSizeRatio in m/z units. The default value is 2.5, which means at the limits of the window, the Gaussian pulses have a value of 4.39% of their maximum.
msalign(..., 'Iterations', IterationsValue) specifies the number of refining iterations. At every iteration the search grid is scaled down to improve the estimates. The default value is 5.
msalign(..., 'GridSteps', GridStepsValue) specifies the number of steps for the search grid. For example, at every iteration the search area is divided by GridStepValue^2. The default value is 20.
msalign(..., 'SearchSpace', SearchSpaceValue) specifies the type of search space. Enter either 'regular'( evenly spaced lattice) or 'latin' (random latin hypercube with Grid^2 samples). The default value is 'regular'.
[YOut, ROut] = msalign(..., 'Group', GroupValue), when GroupValue is true and Y contains more than one spectrum, updates the original peak locations so that the actual movement of the peaks is minimized. ROut contains the reference masses with the updated ion peak locations. Use this property when you are uncertain about the values for the reference masses. The default value is false.
msalign(..., 'ShowPlot', ShowPlotValue) plots the original and the aligned spectrum over the reference masses (R). When msalign is called without output arguments, the spectra are plotted unless ShowPlotValue is false. When ShowPlotValues is true, only the first spectrum in Y is plotted. The default value is false.
Load sample data, reference masses, and parameter data for synthetic peak width.
load sample_lo_res R = [3991.4 4598 7964 9160]; W = [60 100 60 100];
Display a color image of the mass spectra before alignment.
msheatmap(MZ_lo_res,Y_lo_res,'markers',R,'limit',[3000 10000])
title('before alignment')

Align spectra with reference masses and display a color image of mass spectra after alignment.
YA = msalign(MZ_lo_res,Y_lo_res,R,'weights',W);
msheatmap(MZ_lo_res,YA,'markers',R,'limit',[3000 10000])
title('after alignment')

Align a spectrum with a single reference peak. Load sample data and view the first sample spectrum.
load sample_lo_res MZ = MZ_lo_res Y = Y_lo_res(:,1) msviewer(MZ, Y)

Select a reference peak by zooming and right-clicking a peak.

Shift a spectrum by the difference between the known reference mass (RP) and the experimental mass (SP).
RP = 4000; SP = 4050.33; YOut = interp1(MZ, MZ-(RP-SP, Y);
The plot below shows the original spectrum on top and the shifted spectrum on the bottom.

Bioinformatic Toolbox functions msbackadj, msheatmap, mslowess, msnorm, msresample, mssgolay, msviewer
| mapcaplot | msbackadj | ![]() |
© 1994-2005 The MathWorks, Inc.