Skip to main content

Quickstart

Rust​

Open a file and read its peaks:

use std::{fs::File, io::BufReader};
use opentfraw::RawFileReader;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let raw = RawFileReader::open_path("sample.raw")?;
println!("{} -- {} scans", raw.device_family.display_name(), raw.num_scans);

// Buffer the scan reads: an unbuffered File is about 11x slower.
let mut file = BufReader::new(File::open("sample.raw")?);
let info = &raw.run_header.sample_info;
for scan_num in info.first_scan_number..=info.last_scan_number {
let peaks = raw.read_scan_peaks(&mut file, scan_num)?;
println!("scan {scan_num}: {} peaks", peaks.len());
}
Ok(())
}

The repo ships two examples:

cargo run --release --example dump -- path/to/file.raw [--max-scans N]
cargo run --release --example to_mzml -- path/to/file.raw output.mzML

dump walks every section of the file and prints a summary; to_mzml writes a minimal mzML.

Python​

import opentfraw

raw = opentfraw.RawFile("run.raw")
print(raw.num_scans, raw.instrument_model)

mz, intensity = raw.peaks(3) # float64 / float32 numpy arrays
scan = raw.scan(3) # dict: ms_level, RT, charge, filter, ...
print(scan["filter_string"])

raw.to_mzml("run.mzML")

Next​