Skip to main content

openreadout_chrom/
lib.rs

1//! Readers for chromatography data.
2//!
3//! - Agilent ChemStation `.D` directories and their `.ch`/`.uv`/`.ms` files (`chemstation`):
4//!   `docs/formats/chemstation.md`.
5//! - Agilent OpenLab CDS injections (`.dx` containers with their `.rx` result packages,
6//!   `openlab-cds`): `docs/formats/openlab-cds.md`.
7//! - AIA/ANDI netCDF (`.cdf`), chromatography and mass-spectrometry templates (`andi-chrom`):
8//!   `docs/formats/andi-chrom.md`; includes a netCDF-3 classic reader.
9//! - Shimadzu LabSolutions `.lcd`/`.gcd` (`shimadzu`): `docs/formats/shimadzu.md`; includes a
10//!   compound-file (OLE2) reader.
11//! - Thermo Scientific Chromeleon 7 archives (`.cmbx`, `chromeleon`): `docs/formats/chromeleon.md`.
12//! - Waters Empower ASCII raw-data exports (`.arw`, `empower-arw`): `docs/formats/empower-arw.md`.
13//!
14//! Provenance of every layout: `docs/provenance/<format>.md`.
15//!
16//! # Example
17//!
18//! Every reader implements [`openreadout_core::FormatReader`]: `descriptor`
19//! says what it reads, `sniff` recognises a file from its first bytes, and `open` returns a
20//! [`openreadout_core::Dataset`] with a header-only `info()` summary and lazy data
21//! access.
22//!
23//! ```
24//! use openreadout_core::FormatReader;
25//! use openreadout_chrom::ChemStationReader;
26//!
27//! let format = ChemStationReader.descriptor();
28//! assert_eq!(format.id, openreadout_chrom::CHEMSTATION_ID);
29//! println!("{} ({}): .{}", format.name, format.family, format.extensions.join(", ."));
30//! ```
31//!
32//! Reading a file:
33//!
34//! ```no_run
35//! use std::path::Path;
36//!
37//! use openreadout_core::FormatReader;
38//! use openreadout_chrom::ChemStationReader;
39//!
40//! let mut dataset = ChemStationReader.open(Path::new("sample.D"))?;
41//! let info = dataset.info()?; // headers only
42//! let trace = &info.traces[0];
43//! println!("{} sweep(s) at {} Hz, {} channel(s)", trace.sweep_count, trace.sample_rate_hz, trace.channels.len());
44//! // The first 1000 samples of sweep 0, every channel, scaled to physical units.
45//! let samples = dataset.read_trace(0, 0, 0, 1000)?;
46//! for (channel, values) in trace.channels.iter().zip(&samples.channels) {
47//!     println!("{} ({}): {:?}", channel.name, channel.unit.as_deref().unwrap_or("?"), values.first());
48//! }
49//! # Ok::<(), openreadout_core::Error>(())
50//! ```
51//!
52//! Applications that accept any instrument file usually register every reader in an
53//! [`openreadout_core::Registry`] and let it detect the format; that is what the
54//! `openreadout` command-line tool does.
55//!
56//! # API stability
57//!
58//! The supported API is what this page documents. The parser modules are public only so that
59//! tests and fuzz targets can reach them: they are hidden from this documentation and may change
60//! in any release.
61#![forbid(unsafe_code)]
62#![warn(missing_docs)]
63
64#[doc(hidden)]
65pub mod andi_dataset;
66mod assurance;
67mod binary;
68#[doc(hidden)]
69pub mod chemstation_dataset;
70#[doc(hidden)]
71pub mod chemstation_decode;
72#[doc(hidden)]
73pub mod chemstation_header;
74mod chemstation_method;
75#[doc(hidden)]
76pub mod chemstation_report;
77#[doc(hidden)]
78pub mod chromeleon;
79#[doc(hidden)]
80pub mod chromeleon_dataset;
81#[doc(hidden)]
82pub mod chromeleon_results;
83#[doc(hidden)]
84pub mod empower_arw;
85#[doc(hidden)]
86pub mod netcdf;
87#[doc(hidden)]
88pub mod openlab_dataset;
89#[doc(hidden)]
90pub mod openlab_xml;
91#[doc(hidden)]
92pub mod shimadzu_channels;
93#[doc(hidden)]
94pub mod shimadzu_dataset;
95#[doc(hidden)]
96pub mod shimadzu_gcms;
97#[doc(hidden)]
98pub mod shimadzu_peaks;
99#[doc(hidden)]
100pub mod shimadzu_signal;
101#[doc(hidden)]
102pub mod shimadzu_tlm;
103
104use std::path::Path;
105
106use openreadout_core::Result;
107use openreadout_core::model::{DetectConfidence, FormatDescriptor};
108use openreadout_core::reader::{Dataset, Detection, FormatReader, has_extension};
109use openreadout_core::source::Input;
110use openreadout_core::zip;
111
112#[doc(hidden)]
113pub use andi_dataset::{AndiDataset, AndiTemplate, andi_template, andi_timestamp};
114#[doc(hidden)]
115pub use chemstation_dataset::{ChemStationDataset, DirFile, SignalFile, is_chemstation_dir};
116#[doc(hidden)]
117pub use chemstation_decode::{
118    BodyEnd, DecodedSignal, MS_RECORD_HEADER, MS_RECORD_TRAILER, ScanRecord, UV_RECORD_HEADER,
119    decode_delta_records, decode_float64, decode_second_difference, ms_intensity, ms_pairs,
120    ms_record, uv_record, uv_values,
121};
122#[doc(hidden)]
123pub use chemstation_header::{
124    BodyEncoding, DECODED_VERSIONS, SignalHeader, SignalKind, looks_like_chemstation, parse_date,
125    version_of,
126};
127#[doc(hidden)]
128pub use chromeleon_dataset::ChromeleonDataset;
129#[doc(hidden)]
130pub use netcdf::{
131    AttrValue, Attribute, Dimension, HeaderError, NcType, NetCdf, Variable, read_header,
132};
133#[doc(hidden)]
134pub use openlab_dataset::{OpenLabDataset, SignalMapping, decode_pairs};
135#[doc(hidden)]
136pub use openreadout_core::cfb::{CFB_MAGIC, Cfb, CfbEntry};
137#[doc(hidden)]
138pub use shimadzu_dataset::{
139    ShimadzuChannel, ShimadzuDataset, ShimadzuSignal, ShimadzuSignalKind, property_fields,
140    text_runs,
141};
142
143/// Format id of the Agilent ChemStation reader.
144pub const CHEMSTATION_ID: &str = "chemstation";
145
146pub(crate) fn has_ext(path: &Path, exts: &[&str]) -> bool {
147    has_extension(path, exts)
148}
149
150/// Agilent ChemStation `.D` directories and `.ch`/`.uv`/`.ms` signal files.
151#[derive(Debug, Default, Clone, Copy)]
152pub struct ChemStationReader;
153
154impl FormatReader for ChemStationReader {
155    fn assurance(&self) -> Option<&'static openreadout_core::assurance::AssuranceProfile> {
156        Some(&assurance::CHEMSTATION)
157    }
158
159    fn descriptor(&self) -> FormatDescriptor {
160        FormatDescriptor {
161            id: CHEMSTATION_ID.into(),
162            name: "Agilent ChemStation data directory (.D: .ch, .uv, .ms)".into(),
163            vendor: "Agilent".into(),
164            extensions: vec!["d".into(), "ch".into(), "uv".into(), "ms".into()],
165            family: "chromatography".into(),
166            can_read: true,
167            can_write: false,
168            confidence: assurance::CHEMSTATION.confidence,
169            known_gaps: vec![
170                "Signal-file versions other than 2 (.ms), 30, 81, 130, 131 (.uv), 179 and 181 are listed but not decoded".into(),
171                "Signal files are read whole; .ch files above 512 MiB are refused (exit 6)".into(),
172                ".reg register files, RUN.LOG and method (.M) files are listed with sizes, not decoded".into(),
173                "Vendor peak reports are tables[0] vendor_peaks: Result.xml (limits, baselines, named compounds and amounts), else Report.TXT (the printed report), and RESULTS.CSV (MSD ChemStation TIC integration); check finds every reported peak on our decoded signal, Result.xml areas recomputed between the vendor's limits (median ratio 0.9999 on 66 peaks) (2 + 4 GC runs, 144 peaks; 12 MSD runs, 46 peaks). Binary reports (REPORT.REG, .rpt) and calibration curves/levels are not read".into(),
174                "MS scans are reported as stored (thresholded m/z–intensity pairs at 0.05 m/z resolution), MS level 1, polarity unknown".into(),
175                "Agilent MassHunter (.d with AcqData/) and OpenLab CDS (.dx) are different formats: agilent-masshunter and openlab-cds read them".into(),
176                ".ch headers hold no point count: a version 81/179/181 body cut exactly at a value boundary cannot be told from a complete one (check reports the interval the header time range implies)".into(),
177            ],
178        }
179    }
180
181    fn sniff(&self, head: &[u8], path: &Path) -> Option<Detection> {
182        self.sniff_input(head, &Input::local(path))
183    }
184
185    /// A `.D` directory is recognised by its signal files, read through the namespace.
186    fn sniff_input(&self, head: &[u8], input: &Input) -> Option<Detection> {
187        let path = input.path();
188        if input.is_dir() {
189            return chemstation_dataset::is_chemstation_dir_in(input.fs(), path).then_some(
190                Detection {
191                    format_id: CHEMSTATION_ID,
192                    confidence: DetectConfidence::Definite,
193                    note: None,
194                },
195            );
196        }
197        if let Some(v) = looks_like_chemstation(head) {
198            let known = DECODED_VERSIONS.contains(&v.as_str());
199            return Some(Detection {
200                format_id: CHEMSTATION_ID,
201                confidence: DetectConfidence::Definite,
202                note: (!known)
203                    .then(|| format!("ChemStation file version {v} is listed but not decoded")),
204            });
205        }
206        if has_extension(path, &["ch", "uv"]) {
207            return Some(Detection {
208                format_id: CHEMSTATION_ID,
209                confidence: DetectConfidence::ExtensionOnly,
210                note: Some("ChemStation extension but no version string at byte 0".into()),
211            });
212        }
213        None
214    }
215
216    fn open(&self, path: &Path) -> Result<Box<dyn Dataset>> {
217        Ok(Box::new(ChemStationDataset::open(path)?))
218    }
219
220    fn open_input(&self, input: &Input) -> Result<Box<dyn Dataset>> {
221        Ok(Box::new(ChemStationDataset::open_input(input)?))
222    }
223
224    fn reads_any_source(&self) -> bool {
225        true
226    }
227}
228
229/// Format id of the Agilent OpenLab CDS reader.
230pub const OPENLAB_ID: &str = "openlab-cds";
231
232/// The first member name of a zip head, lower case.
233fn first_member(head: &[u8]) -> Option<String> {
234    Some(zip::first_member_name(head)?.to_ascii_lowercase())
235}
236
237/// Does `head` start like an OpenLab CDS container: a zip whose first member is the manifest,
238/// the results document or a GUID-named signal part? (A first `[Content_Types].xml` or
239/// `_rels/.rels` is any Open Packaging Conventions file, such as `.xlsx`: it counts only with a
240/// `.dx`/`.rx` extension, in [`OpenLabReader`]'s sniff.)
241pub fn looks_like_openlab(head: &[u8]) -> bool {
242    let Some(lower) = first_member(head) else {
243        return false;
244    };
245    if matches!(lower.as_str(), "injection.acmd" | "base/injectionacaml") {
246        return true;
247    }
248    // `<guid>.CH` / `<guid>.IT` / `<guid>.UV`
249    let (stem, ext) = lower.rsplit_once('.').unwrap_or((&lower, ""));
250    stem.len() == 36
251        && stem.chars().all(|c| c.is_ascii_hexdigit() || c == '-')
252        && stem.matches('-').count() == 4
253        && matches!(ext, "ch" | "it" | "uv" | "uvd")
254}
255
256/// Agilent OpenLab CDS injections: `.dx` containers (with the `.rx` result package of the same
257/// name and the result set's `.acaml` sequence file when present) and `.rx` packages.
258#[derive(Debug, Default, Clone, Copy)]
259pub struct OpenLabReader;
260
261impl FormatReader for OpenLabReader {
262    fn assurance(&self) -> Option<&'static openreadout_core::assurance::AssuranceProfile> {
263        Some(&assurance::OPENLAB_CDS)
264    }
265
266    fn descriptor(&self) -> FormatDescriptor {
267        FormatDescriptor {
268            id: OPENLAB_ID.into(),
269            name: "Agilent OpenLab CDS injection (.dx, with its .rx results)".into(),
270            vendor: "Agilent".into(),
271            extensions: vec!["dx".into(), "rx".into()],
272            family: "chromatography".into(),
273            can_read: true,
274            can_write: false,
275            confidence: assurance::OPENLAB_CDS.confidence,
276            known_gaps: vec![
277                "Detector signals (.CH, Signal179), instrument curves (.IT: pressure, flow, solvent ratios, temperatures) and DAD spectra parts (.UV, Spectra131: one trace, one channel per wavelength; bit-identical to rainbow-api, unit checked against the DAD's own channels) are traces; spectra directories (.UVD) and parts of other content types are listed, not decoded".into(),
278                "Vendor peaks (.rx) are a table with the vendor's retention times, areas, heights, area %, limits and baseline codes; compound amounts, calibration and custom fields (e.g. GPC results) are not read, and every corpus file has unnamed compounds".into(),
279                "Without the result set's .acaml sequence file, vendor peaks are matched to a signal by their baseline values (the vendor's baseline at a BB peak limit is the signal sample there); tables[0].extra.signal_mapping says how".into(),
280                "A result-set folder (.rslt) is not one data set: open its .dx files (openreadout batch 'set.rslt/*.dx')".into(),
281                "Validated on GC-FID (54 injections, OpenLab CDS 2.6 and a YADG GC injection), one LC-DAD/FLD result set whose detector signals were cut to 4 values by its publisher and two LC-DAD injections with spectra; no LC-MS .dx in the corpus".into(),
282            ],
283        }
284    }
285
286    fn sniff(&self, head: &[u8], path: &Path) -> Option<Detection> {
287        self.sniff_input(head, &Input::local(path))
288    }
289
290    fn sniff_input(&self, head: &[u8], input: &Input) -> Option<Detection> {
291        let path = input.path();
292        if input.is_dir() {
293            // A result-set folder is claimed only by its extension, so that opening it gives
294            // the hint to open its injections while recursive walks still enter it and take
295            // each `.dx` as its own data set.
296            let dx = openlab_dataset::injections_in(input.fs(), path);
297            return (has_extension(path, &["rslt"]) && !dx.is_empty()).then_some(Detection {
298                format_id: OPENLAB_ID,
299                confidence: DetectConfidence::ExtensionOnly,
300                note: Some("an OpenLab CDS result-set folder: open one of its .dx files".into()),
301            });
302        }
303        if !zip::is_zip(head) {
304            return None;
305        }
306        let ours = has_extension(path, &["dx", "rx"]);
307        let packaging = first_member(head)
308            .is_some_and(|n| matches!(n.as_str(), "[content_types].xml" | "_rels/.rels"));
309        if looks_like_openlab(head) || (ours && packaging) {
310            return Some(Detection {
311                format_id: OPENLAB_ID,
312                confidence: if ours {
313                    DetectConfidence::Definite
314                } else {
315                    DetectConfidence::Likely
316                },
317                note: None,
318            });
319        }
320        ours.then(|| Detection {
321            format_id: OPENLAB_ID,
322            confidence: DetectConfidence::ExtensionOnly,
323            note: Some(
324                "a zip archive with an OpenLab CDS extension but an unexpected first member".into(),
325            ),
326        })
327    }
328
329    fn open(&self, path: &Path) -> Result<Box<dyn Dataset>> {
330        Ok(Box::new(OpenLabDataset::open(path)?))
331    }
332
333    fn open_input(&self, input: &Input) -> Result<Box<dyn Dataset>> {
334        Ok(Box::new(OpenLabDataset::open_input(input)?))
335    }
336
337    fn reads_any_source(&self) -> bool {
338        true
339    }
340}
341
342/// Format id of the Shimadzu LabSolutions reader.
343pub const SHIMADZU_ID: &str = "shimadzu";
344
345/// Shimadzu LabSolutions `.lcd` (LC) and `.gcd` (GC) data files.
346#[derive(Debug, Default, Clone, Copy)]
347pub struct ShimadzuReader;
348
349impl FormatReader for ShimadzuReader {
350    fn assurance(&self) -> Option<&'static openreadout_core::assurance::AssuranceProfile> {
351        Some(&assurance::SHIMADZU)
352    }
353
354    fn descriptor(&self) -> FormatDescriptor {
355        FormatDescriptor {
356            id: SHIMADZU_ID.into(),
357            name: "Shimadzu LabSolutions data file (.lcd, .gcd, .qgd)".into(),
358            vendor: "Shimadzu".into(),
359            extensions: vec!["lcd".into(), "gcd".into(), "qgd".into()],
360            family: "chromatography".into(),
361            can_read: true,
362            can_write: false,
363            confidence: assurance::SHIMADZU.confidence,
364            known_gaps: vec![
365                "Read: chromatograms (older layout in mV; newer layout and .gcd in the unit of their Chromatogram Status record, e.g. µV), status traces (pump pressures, oven/cooler temperatures in the record's unit), the PDA field (stored µAU, shown in mAU) and LabSolutions' own peak tables (tables[0] vendor_peaks). Validated point for point against LabSolutions ASCII exports of an older-layout (LCsolution 1.25) and a newer-layout (5.109) file (25,038 trace points, 8 peaks in every column), bit-exact against chromConverter on 2 files, and against the vendor's own peak areas on 4 files (LC-UV, PDA, GC)".into(),
366                "Newer-layout LC chromatograms (LSS Raw Data/Chromatogram ChN) are named by their 2D Data Item title (DT 52 or 48) and scaled by their status record; the unit rule is the one validated on older-layout exports, a 5.109 export and a GC file's vendor peak areas, but no export exists of a file-version-5.01 (DT 48) chromatogram".into(),
367                "PDA channel chromatograms (a wavelength and bandwidth) are not extracted: their vendor peak tables are read and labelled with the channel's wavelength (channel 0 has none recorded); newer-layout peak records are read in their first 64 bytes only (no k', plates, tailing, resolution)".into(),
368                "Older-layout status traces are named by module model and quantity (LC-20AD pressure 1): the file stores no names; LabSolutions' export names (Pump A Pressure, Oven Temp.) are its own".into(),
369                "LC-MS (TLM Raw Data): MRM and SIM records are spectra (run 0), equal to msconvert's on 610 spectra of 3 CC0 files and to the vendor's own mzXML on a two-polarity LCMS-8060 run (polarity, time, points and each point's precursor, MRM events with several precursors included); full-scan and product-ion-scan spectra are refused (exit 6: the vendor's reader returns other values), their retention time, TIC and precursor listed. MS quantitative results, compound and calibration tables and method streams are listed, not decoded".into(),
370                "LCMS-9030 Q-TOF data (QTFL RawData) are not read: the stored m/z are flight times whose calibration is not decoded; info names the storage and its scan count, and the file is partially validated".into(),
371                "GCMSsolution .qgd GC-MS (GCMS Raw Data): scans are spectra, intensities minus the record's stored offset, equal to the vendor's ANDI and mzXML exports on 22,561 scans of 3 files (GCMS-QP2010 Ultra, GCMS-TQ8040); MRM records are listed and refused (exit 6). Polarity is not stated".into(),
372            ],
373        }
374    }
375
376    fn sniff(&self, head: &[u8], path: &Path) -> Option<Detection> {
377        if !has_extension(path, &["lcd", "gcd", "qgd"]) {
378            return None;
379        }
380        // A file long enough to show the compound-file signature that does not is another kind
381        // of file (exit 3), not a damaged one.
382        if head.len() >= CFB_MAGIC.len() && !head.starts_with(&CFB_MAGIC) {
383            return None;
384        }
385        Some(Detection {
386            format_id: SHIMADZU_ID,
387            confidence: if head.starts_with(&CFB_MAGIC) {
388                DetectConfidence::Definite
389            } else {
390                DetectConfidence::ExtensionOnly
391            },
392            note: (!head.starts_with(&CFB_MAGIC))
393                .then(|| "LabSolutions extension but no compound-file signature".into()),
394        })
395    }
396
397    fn open(&self, path: &Path) -> Result<Box<dyn Dataset>> {
398        Ok(Box::new(ShimadzuDataset::open(path)?))
399    }
400
401    fn open_input(&self, input: &Input) -> Result<Box<dyn Dataset>> {
402        Ok(Box::new(ShimadzuDataset::open_input(input)?))
403    }
404
405    fn reads_any_source(&self) -> bool {
406        true
407    }
408}
409
410/// Format id of the AIA/ANDI netCDF reader.
411pub const ANDI_ID: &str = "andi-chrom";
412
413/// Does `head` look like an ANDI netCDF file (netCDF magic plus a template attribute or
414/// variable name in the header bytes)?
415pub fn looks_like_andi(head: &[u8]) -> bool {
416    if head.len() < 4 || &head[..3] != b"CDF" || !matches!(head[3], 1 | 2) {
417        return false;
418    }
419    let has = |needle: &[u8]| head.windows(needle.len()).any(|w| w == needle);
420    has(b"aia_template_revision")
421        || has(b"ms_template_revision")
422        || has(b"ordinate_values")
423        || has(b"mass_values")
424}
425
426/// AIA/ANDI netCDF chromatography and mass-spectrometry files.
427#[derive(Debug, Default, Clone, Copy)]
428pub struct AndiReader;
429
430impl FormatReader for AndiReader {
431    fn assurance(&self) -> Option<&'static openreadout_core::assurance::AssuranceProfile> {
432        Some(&assurance::ANDI_CHROM)
433    }
434
435    fn descriptor(&self) -> FormatDescriptor {
436        FormatDescriptor {
437            id: ANDI_ID.into(),
438            name: "AIA/ANDI netCDF (chromatography and mass spectrometry)".into(),
439            vendor: "ASTM E1947 / E2077 open standard (exported by most chromatography data systems)".into(),
440            extensions: vec!["cdf".into(), "nc".into()],
441            family: "chromatography".into(),
442            can_read: true,
443            can_write: false,
444            confidence: assurance::ANDI_CHROM.confidence,
445            known_gaps: vec![
446                "netCDF CDF-5 (64-bit data) files are recognised but not read (ANDI files are CDF-1)".into(),
447                "Non-uniform chromatography sampling (raw_data_retention) is reported, but traces assume the regular actual_sampling_interval grid".into(),
448                "ANDI/MS: MS level is reported as 1 (the template has no MS level); library/SIM extensions (group variables) are listed, not mapped".into(),
449                "ANDI/MS: the total-ion chromatogram is a trace only when scan times are evenly spaced (within 1 %)".into(),
450            ],
451        }
452    }
453
454    fn sniff(&self, head: &[u8], path: &Path) -> Option<Detection> {
455        if looks_like_andi(head) {
456            return Some(Detection {
457                format_id: ANDI_ID,
458                confidence: DetectConfidence::Definite,
459                note: None,
460            });
461        }
462        if head.len() >= 4 && &head[..3] == b"CDF" && has_extension(path, &["cdf"]) {
463            return Some(Detection {
464                format_id: ANDI_ID,
465                confidence: DetectConfidence::Likely,
466                note: Some("netCDF file with a .cdf extension but no ANDI template marker in its first bytes".into()),
467            });
468        }
469        None
470    }
471
472    fn open(&self, path: &Path) -> Result<Box<dyn Dataset>> {
473        Ok(Box::new(AndiDataset::open(path)?))
474    }
475
476    fn open_input(&self, input: &Input) -> Result<Box<dyn Dataset>> {
477        Ok(Box::new(AndiDataset::open_input(input)?))
478    }
479
480    fn reads_any_source(&self) -> bool {
481        true
482    }
483}
484
485/// Format id of the Chromeleon archive reader.
486pub const CHROMELEON_ID: &str = "chromeleon";
487
488/// Thermo Scientific Chromeleon 7 archives (`.cmbx`): a sequence's injections and their 2D
489/// signals.
490#[derive(Debug, Default, Clone, Copy)]
491pub struct ChromeleonReader;
492
493impl FormatReader for ChromeleonReader {
494    fn assurance(&self) -> Option<&'static openreadout_core::assurance::AssuranceProfile> {
495        Some(&assurance::CHROMELEON)
496    }
497
498    fn descriptor(&self) -> FormatDescriptor {
499        FormatDescriptor {
500            id: CHROMELEON_ID.into(),
501            name: "Thermo Scientific Chromeleon 7 archive (.cmbx)".into(),
502            vendor: "Thermo Fisher Scientific".into(),
503            extensions: vec!["cmbx".into()],
504            family: "chromatography".into(),
505            can_read: true,
506            can_write: false,
507            confidence: assurance::CHROMELEON.confidence,
508            known_gaps: vec![
509                "Read: every archived 2D signal (detector channels, PDA-extracted channels, MS extracted-ion chromatograms, pump pressure and flow; encodings PtsLDiff, PtsLL2Df, PtsDDCmp) and every 3D field (PDA spectra: one trace, one channel per wavelength) of every injection, and the calibration standards a processing method holds, as traces with their unit, device and recorded range from the sequence file. Validated point for point against Chromeleon's own ASCII exports (6 HPAEC-PAD injections, 55,446 points, Chromeleon 7.3.1) and a Chromeleon 7.2.10 PDF report (57 GC-FID injections); every signal and 3D field of 10 archives equals the sequence file's recorded point count, times, minimum and maximum; Chromeleon's extracted channels equal our 3D fields bit for bit".into(),
510                "Chromeleon's own integration results, as it last saved them, are tables[0] vendor_peaks (retention time, limits, baseline, area, height, component, 50/10/5 % points; widths, asymmetry, tailing, plates and resolution computed from those points): equal to the PDF report's printed values, and every one of 5,360 stored peaks of 9 archives reproduced by our integration on our decoded signal within 1e-6. Injection details (position, volume, inject time, type, status, level, methods) are tables[1] injections and traces[].extra, equal to the vendor's exports and report. Amounts are not stored with the peaks and are not computed; injections Chromeleon saved no results for have none".into(),
511                "Audit trails, instrument methods (the script: stages, times, property settings such as gradients and oven programs) and processing-method settings are decompressed (LZMA2) and offered as attachments and in dump; report definitions, layouts and custom raw items are listed only".into(),
512                "Mass-spectrometry data (MSRawItem) is an embedded Thermo .raw file: listed with a hint to extract it and open it as thermo-raw; MS channels Chromeleon derives on demand have no stored points and are not traces. Unknown section tags, block layouts or result values never seen are refused (exit 6)".into(),
513                "Chromeleon 6 backups (.cmb) are a different format and are not read".into(),
514            ],
515        }
516    }
517
518    fn sniff(&self, head: &[u8], path: &Path) -> Option<Detection> {
519        if !zip::is_zip(head) {
520            return None;
521        }
522        let ours = has_extension(path, &["cmbx"]);
523        let seq = first_member(head).is_some_and(|n| chromeleon::first_member_is_sequence(&n));
524        if !(seq || ours) {
525            return None;
526        }
527        Some(Detection {
528            format_id: CHROMELEON_ID,
529            confidence: match (seq, ours) {
530                (true, true) => DetectConfidence::Definite,
531                (true, false) => DetectConfidence::Likely,
532                _ => DetectConfidence::ExtensionOnly,
533            },
534            note: (!seq).then(|| {
535                "a zip archive with the .cmbx extension but no sequence file as its first member"
536                    .into()
537            }),
538        })
539    }
540
541    fn open(&self, path: &Path) -> Result<Box<dyn Dataset>> {
542        Ok(Box::new(ChromeleonDataset::open(path)?))
543    }
544
545    fn open_input(&self, input: &Input) -> Result<Box<dyn Dataset>> {
546        Ok(Box::new(ChromeleonDataset::open_input(input)?))
547    }
548
549    fn reads_any_source(&self) -> bool {
550        true
551    }
552}
553
554/// Format id of the Waters Empower ASCII export reader.
555pub const EMPOWER_ARW_ID: &str = "empower-arw";
556
557/// Waters Empower ASCII raw-data exports (`.arw`): one chromatogram with the header fields the
558/// export method chose.
559#[derive(Debug, Default, Clone, Copy)]
560pub struct EmpowerArwReader;
561
562impl FormatReader for EmpowerArwReader {
563    fn assurance(&self) -> Option<&'static openreadout_core::assurance::AssuranceProfile> {
564        Some(&assurance::EMPOWER_ARW)
565    }
566
567    fn descriptor(&self) -> FormatDescriptor {
568        FormatDescriptor {
569            id: EMPOWER_ARW_ID.into(),
570            name: "Waters Empower ASCII raw-data export (.arw)".into(),
571            vendor: "Waters".into(),
572            extensions: vec!["arw".into()],
573            family: "chromatography".into(),
574            can_read: true,
575            can_write: false,
576            confidence: assurance::EMPOWER_ARW.confidence,
577            known_gaps: vec![
578                "Read: 2D exports (a row of quoted field names, a row of their values, then time/value rows) as one trace with every exported field; equal to Appia's reading of the same files. Empower keeps its native raw data in its database: exports (this ASCII export and AIA/netCDF, read by andi-chrom) are how data leaves it".into(),
579                "Multi-column (3D PDA) exports are refused (exit 6): no public example with a licence; export PDA data as AIA/netCDF or as single-wavelength channels".into(),
580                "The export does not state the value's unit, and times are assumed to be minutes (Empower's export unit)".into(),
581            ],
582        }
583    }
584
585    fn sniff(&self, head: &[u8], path: &Path) -> Option<Detection> {
586        let text = empower_arw::looks_like_arw(head);
587        let ext = has_extension(path, &["arw"]);
588        if !text && ext && empower_arw::looks_like_arw_field_lines(head) {
589            // one field per line, the first value a number: named `.arw`
590            return Some(Detection {
591                format_id: EMPOWER_ARW_ID,
592                confidence: DetectConfidence::Likely,
593                note: Some("a header of one quoted field name and its value per line".into()),
594            });
595        }
596        if !text {
597            // an export without its header rows: rows of two numbers, named `.arw`
598            return (ext && empower_arw::looks_like_headerless_arw(head)).then_some(Detection {
599                format_id: EMPOWER_ARW_ID,
600                confidence: DetectConfidence::Likely,
601                note: Some(
602                    "rows of two numbers and no header: an Empower export whose method selected no fields"
603                        .into(),
604                ),
605            });
606        }
607        Some(Detection {
608            format_id: EMPOWER_ARW_ID,
609            confidence: if ext {
610                DetectConfidence::Definite
611            } else {
612                DetectConfidence::Likely
613            },
614            note: None,
615        })
616    }
617
618    fn open(&self, path: &Path) -> Result<Box<dyn Dataset>> {
619        Ok(Box::new(empower_arw::EmpowerArwDataset::open(path)?))
620    }
621
622    fn open_input(&self, input: &Input) -> Result<Box<dyn Dataset>> {
623        Ok(Box::new(empower_arw::EmpowerArwDataset::open_input(input)?))
624    }
625
626    fn reads_any_source(&self) -> bool {
627        true
628    }
629}