Skip to main content

Reader

The entry point is RawFileReader. Opening a file parses the file header, audit tags, sample information, run header, scan event tree, scan index, error log, and generic data section. Scan peak data is read on demand from a separate std::fs::File handle.

use opentfraw::RawFileReader;

let raw = RawFileReader::open_path("sample.raw")?;

After open_path returns, the following fields are populated:

FieldTypeDescription
num_scansu32Scan count from the run header
device_familyDeviceFamilyHeuristic instrument classification
scan_formatScanDataFormatWhich decoder will be used for peaks
instrument_modelStringReported instrument model from RawFileInfo
scan_eventsVec<ScanEvent>Per-scan event metadata (filter, polarity, ...)

Peaks are read with read_scan_peaks:

let mut file = std::fs::File::open("sample.raw")?;
let peaks = raw.read_scan_peaks(&mut file, 1)?;
for (mz, intensity) in peaks.mz.iter().zip(peaks.intensity.iter()) {
println!("{mz:.4}\t{intensity:.0}");
}

read_scan_peaks dispatches on scan_format to one of the three decoders described in Scan data.

Error handling

Public functions return opentfraw::Result<T>. The error type is opentfraw::Error, which wraps the failure category (Io, Parse, UnsupportedVersion, BadMagic, ...) and a message.