Post

ISpectrum<T>

The contract for a mass spectrum as a series of data points of type T.


Remarks

The contract for a mass spectrum as a series of data points of type T, which is SpecDataPoint or SpecDataPointEx. Implemented by TSpectrum<T>, and through it by Spectrum and SpectrumEx.

Implements

IDisposable


Properties

IdentifierTypeDescription
CountintThe number of data points.
DataPointsT[]The data points.

Methods

MethodReturnsDescription
Deserialize(byte[] data)voidLoads the spectrum from a Serialize payload.
GetMz(double mz, double ppm = 0)intFinds the data point at an m/z, or the nearest one within a tolerance in parts per million.
Resize(int sz)voidReplaces the data points with a new, empty array of the given size. Existing points are discarded.
Serialize()byte[]Serializes the spectrum to a byte array, suitable as a pipe message payload. Read back by Deserialize.

Example

1
2
3
4
5
6
7
8
using Nova.Data;

// Nearest point within 10 ppm of the target, or -1.
int index = spectrum.GetMz(445.1200, 10);
if (index >= 0)
{
  Console.WriteLine(spectrum.DataPoints[index].Intensity);
}

Code written against the interface handles both spectrum types.

1
2
3
4
5
6
7
8
9
static double TotalIntensity<T>(ISpectrum<T> spectrum) where T : struct, ISpecDataPoint
{
  double total = 0;
  for (int i = 0; i < spectrum.Count; i++)
  {
    total += spectrum.DataPoints[i].Intensity;
  }
  return total;
}
This post is licensed under CC BY 4.0 by the author.

Trending Tags