Post

FileReader.ReadSpectrum

Reads a spectrum, opening the file first if it is not the current one.


Remarks

With a scan number, that scan is read, or an empty spectrum if it does not pass the filter. With -1, the next spectrum that passes the filter is read, and an empty spectrum, with ScanNumber 0, marks the end of the file.


Syntax

SyntaxDescription
ReadSpectrum(string fileName = “”, int scanNumber = -1, bool centroid = true)Reads a spectrum, opening the file first if it is not the current one.

Parameters

NameTypeDescription
fileNamestringThe file to read from, or empty for the current file.
scanNumberintThe scan number, or -1 for the next spectrum.
centroidboolThe preferred peak type. Not guaranteed; check the Spectrum.Centroid property.

Returns

TypeDescription
SpectrumThe spectrum, or an empty one if it could not be read.

Exceptions

ExceptionCondition
SpectrumFileOpenExceptionA new file could not be opened.

Example

1
2
3
4
5
6
7
8
9
10
11
12
using Nova.Data;
using Nova.Io.Read;

FileReader reader = new FileReader(MSFilter.MS1);

// The first call names the file; later calls keep reading it.
Spectrum spectrum = reader.ReadSpectrum("DDA.raw");
while (spectrum.ScanNumber > 0)
{
  Console.WriteLine(spectrum.ScanNumber + ": " + spectrum.Count + " peaks");
  spectrum = reader.ReadSpectrum();
}
This post is licensed under CC BY 4.0 by the author.

Trending Tags