TSpectrum<T>.GetMz
Finds the data point at an m/z, or the nearest one within a tolerance.
Remarks
Uses a binary search, so DataPoints must be sorted by ascending m/z, the order the point types’ CompareTo defines. If both neighbors of a miss are within tolerance, the lower-m/z one is returned.
Inherited by Spectrum and SpectrumEx.
Syntax
| Syntax | Description |
|---|---|
| GetMz(double mz, double ppm = 0) | Finds the data point at an m/z, or the nearest one within a tolerance. |
Parameters
| Name | Type | Description |
|---|---|---|
| mz | double | The m/z to look for. |
| ppm | double | Tolerance in parts per million; 0 means an exact match only. |
Returns
| Type | Description |
|---|---|
| int | The index into DataPoints, or -1 if the spectrum is empty or no point is within tolerance. |
Example
1
2
3
4
5
6
7
8
9
10
using Nova.Data;
Spectrum spectrum = new Spectrum(3);
spectrum.DataPoints[0] = new SpecDataPoint(445.1200, 10523.0);
spectrum.DataPoints[1] = new SpecDataPoint(522.7700, 850.0);
spectrum.DataPoints[2] = new SpecDataPoint(600.3000, 2000.0);
int exact = spectrum.GetMz(522.7700); // 1
int near = spectrum.GetMz(522.7720, 10); // 1: 3.8 ppm away
int miss = spectrum.GetMz(522.7800, 10); // -1: 19 ppm away
This post is licensed under CC BY 4.0 by the author.