1#![forbid(unsafe_code)]
54#![warn(missing_docs)]
55
56mod assurance;
57#[doc(hidden)]
58pub mod atf;
59#[doc(hidden)]
60pub mod command;
61#[doc(hidden)]
62pub mod dataset;
63#[doc(hidden)]
64pub mod file;
65
66use std::path::Path;
67
68use openreadout_core::Result;
69use openreadout_core::model::{DetectConfidence, FormatDescriptor};
70use openreadout_core::reader::{Dataset, Detection, FormatReader, has_extension};
71use openreadout_core::source::Input;
72
73pub use atf::{ATF_FORMAT_ID, AtfReader};
74#[doc(hidden)]
75pub use atf::{
76 AtfColumn, AtfDataset, MAX_ATF_LEN, MAX_COLUMNS, MAX_HEADER_RECORDS, looks_like_atf,
77};
78#[doc(hidden)]
79pub use command::{CommandPlan, command_plan, command_sweep};
80#[doc(hidden)]
81pub use dataset::{AbfDataset, MAX_READ_SAMPLES, command_trace_info, trace_info};
82#[doc(hidden)]
83pub use file::{
84 ABF1_BASIC_LEN, ABF1_EXTENDED_LEN, AbfFile, AcquisitionMode, BLOCK_LEN, DigitalEpoch, Epoch,
85 EpochKind, Generation, InputChannel, MAX_RECORDS, MAX_STRINGS_LEN, OutputChannel,
86 SECTION_ENTRY_LEN, SECTION_MAP_OFFSET, SECTION_NAMES, SampleFormat, SectionEntry, Sweep, Tag,
87 Telegraph, channel_scaling, guid_text, iso_datetime, parse_string_table, usable_factor,
88};
89
90pub const FORMAT_ID: &str = "abf";
92
93#[derive(Debug, Default, Clone, Copy)]
95pub struct AbfReader;
96
97impl FormatReader for AbfReader {
98 fn assurance(&self) -> Option<&'static openreadout_core::assurance::AssuranceProfile> {
99 Some(&assurance::ABF)
100 }
101
102 fn descriptor(&self) -> FormatDescriptor {
103 FormatDescriptor {
104 id: FORMAT_ID.into(),
105 name: "Axon Binary Format (ABF)".into(),
106 vendor: "Molecular Devices (Axon Instruments) pCLAMP".into(),
107 extensions: vec!["abf".into()],
108 family: "electrophysiology".into(),
109 can_read: true,
110 can_write: false,
111 confidence: assurance::ABF.confidence,
112 known_gaps: vec![
113 "Command (DAC) waveforms are synthesized (trace 1) for episodic files with step, ramp and pulse-train epochs only; stimulus files, user lists, alternating outputs, conditioning trains, triangle/cosine/biphasic epochs, ABF 1 files before 1.6 and ABF 1 files with epoch tables on both DACs keep the epoch table only".into(),
114 "User lists, statistics, math, scope and voice-tag sections are listed but not decoded".into(),
115 "Pre-1.6 ABF 1 files: telegraph, protocol path and 20-entry epoch tables are not in the header and are not reported".into(),
116 "Old pCLAMP/Axotape files without an `ABF ` signature (CLPX, FTCX) are not read".into(),
117 ],
118 }
119 }
120
121 fn sniff(&self, head: &[u8], path: &Path) -> Option<Detection> {
122 match head.get(..4) {
123 Some(b"ABF2") => Some(Detection {
124 format_id: FORMAT_ID,
125 confidence: DetectConfidence::Definite,
126 note: None,
127 }),
128 Some(b"ABF ") => Some(Detection {
129 format_id: FORMAT_ID,
130 confidence: DetectConfidence::Definite,
131 note: None,
132 }),
133 _ if has_extension(path, &["abf"]) && head.len() < 4 => Some(Detection {
135 format_id: FORMAT_ID,
136 confidence: DetectConfidence::ExtensionOnly,
137 note: Some("ABF extension but no `ABF ` or `ABF2` signature at byte 0".into()),
138 }),
139 _ => None,
140 }
141 }
142
143 fn open(&self, path: &Path) -> Result<Box<dyn Dataset>> {
144 Ok(Box::new(AbfDataset::open(path)?))
145 }
146
147 fn open_input(&self, input: &Input) -> Result<Box<dyn Dataset>> {
148 Ok(Box::new(AbfDataset::open_input(input)?))
149 }
150
151 fn reads_any_source(&self) -> bool {
152 true
153 }
154}