openreadout_bruker_tims/
lib.rs1#![forbid(unsafe_code)]
56#![warn(missing_docs)]
57
58mod assurance;
59#[doc(hidden)]
60pub mod baf;
61#[doc(hidden)]
62pub mod calibration;
63#[doc(hidden)]
64pub mod dataset;
65#[doc(hidden)]
66pub mod frame;
67#[doc(hidden)]
68pub mod sqlite;
69
70use std::path::Path;
71
72use openreadout_core::Result;
73use openreadout_core::model::{DetectConfidence, FormatDescriptor};
74use openreadout_core::reader::{Dataset, Detection, FormatReader};
75use openreadout_core::source::Input;
76
77#[doc(hidden)]
78pub use calibration::{MobilityModel, MzCalibrationRow, MzModel, TimsCalibrationRow};
79#[doc(hidden)]
80pub use dataset::{
81 Conversions, FrameRecord, MaldiSpot, PrecursorRecord, Selection, TimsDataset, TimsKind,
82 dataset_dir, kind_of,
83};
84#[doc(hidden)]
85pub use frame::{
86 FrameError, TimsFrame, decode_tdf_frame, decode_tdf_frame_lzf, decode_tsf_profile,
87 decode_tsf_spectrum, group_and_sum, read_blob,
88};
89#[doc(hidden)]
90pub use sqlite::{SqlTable, SqlValue, SqliteDb, SqliteError};
91
92pub use baf::BrukerBafReader;
93
94pub const FORMAT_ID: &str = "bruker-tdf";
96
97#[derive(Debug, Default, Clone, Copy)]
99pub struct BrukerTimsReader;
100
101impl FormatReader for BrukerTimsReader {
102 fn assurance(&self) -> Option<&'static openreadout_core::assurance::AssuranceProfile> {
103 Some(&assurance::BRUKER_TDF)
104 }
105
106 fn descriptor(&self) -> FormatDescriptor {
107 FormatDescriptor {
108 id: FORMAT_ID.into(),
109 name: "Bruker timsTOF (TDF/TSF .d)".into(),
110 vendor: "Bruker".into(),
111 extensions: vec!["d".into(), "tdf".into(), "tsf".into()],
112 family: "mass-spectrometry".into(),
113 can_read: true,
114 can_write: false,
115 confidence: assurance::BRUKER_TDF.confidence,
116 known_gaps: vec![
117 "m/z and 1/K0 apply the file's MzCalibration (types 1, 2) and TimsCalibration (type 2) models, validated to <= 0.065 ppm and 5e-13 V*s/cm2 against vendor-library conversions of five files; other model types fall back to the acquisition-range approximation (tens of ppm off) and say so in notes and check".into(),
118 "prm-PASEF frames (MsMsType 10) are summed whole, not split per target window (no public prm-PASEF file to validate against)".into(),
119 "Spectra are raw sums of TOF bins over scans (no smoothing or centroiding); per-scan mobility arrays are not returned by `spectrum` (library: TimsDataset::read_frame)".into(),
120 "TimsCompressionType 1 frames hold more scans than Frames.NumScans; all are read (NumPeaks and SummedIntensities count them; the reference conversion lists only the first NumScans)".into(),
121 ],
122 }
123 }
124
125 fn sniff(&self, head: &[u8], path: &Path) -> Option<Detection> {
126 self.sniff_input(head, &Input::local(path))
127 }
128
129 fn sniff_input(&self, head: &[u8], input: &Input) -> Option<Detection> {
131 let fs = input.fs();
132 let dir = dataset::dataset_dir_in(fs, input.path())?;
133 let kind = dataset::kind_of_in(fs, &dir)?;
134 let named_d = dir.extension().is_some_and(|e| e.eq_ignore_ascii_case("d"));
135 let _ = head;
137 Some(Detection {
138 format_id: FORMAT_ID,
139 confidence: DetectConfidence::Definite,
140 note: (!named_d).then(|| {
141 format!(
142 "directory holds analysis.{} but is not named *.d",
143 if kind == TimsKind::Tdf { "tdf" } else { "tsf" }
144 )
145 }),
146 })
147 }
148
149 fn open(&self, path: &Path) -> Result<Box<dyn Dataset>> {
150 Ok(Box::new(TimsDataset::open(path)?))
151 }
152
153 fn open_input(&self, input: &Input) -> Result<Box<dyn Dataset>> {
154 Ok(Box::new(TimsDataset::open_input(input)?))
155 }
156
157 fn reads_any_source(&self) -> bool {
158 true
159 }
160}