11 releases
0.4.3 | Oct 18, 2024 |
---|---|
0.4.2 | Mar 6, 2024 |
0.3.0 | Dec 1, 2023 |
0.2.0 | Aug 31, 2023 |
0.1.4 | Aug 28, 2023 |
#1149 in Parser implementations
171 downloads per month
3.5MB
537 lines
rust_abf
Rust ABF Reader
This is a Rust project that provides a fast and memory-efficient way to read ABF (Axon Binary Format) files commonly used in electrophysiology.
Features
- Fast Reading: Utilizes optimized algorithms for quick ABF file parsing.
- Low Memory Footprint: Minimizes memory usage while processing large ABF files.
- Minimal Dependencies: Strives to keep dependencies lightweight.
- Easy to Use: Provides a simple API for reading ABF files.
Usage
-
Install Rust and Cargo if you haven't already.
-
Add this library to your
Cargo.toml
or usingcargo add rust_abf
-
In your Rust code:
use std::path::Path; use rust_abf::Abf; fn main() { let abf = Abf::from_file(Path::new("tests/test_abf/14o08011_ic_pair.abf")).unwrap(); match abf { Ok(abf) => { let channels_count = abf.get_channels_count(); let sweeps_count = abf.get_sweeps_count(); println!("There are {:?} channels and {:?} sweeps", channels_count, sweeps_count); (0..channels_count).for_each(|ch| { (0..sweeps_count).for_each(|s|{ let data = abf.get_sweep_in_channel( s, ch).unwrap(); println!("First 10 elements from ch {:?} and sweep {:?}: {:?}", ch, s, &data[0..10]); }); }); }, _ => println!("File not found"), } }
If you prefer to work on channels, you can have direct access to them by using the following code:
...
let ch0 = abf.get_channel(0).unwrap();
println!("Channel 0 has the following unit of measurement {:?} and the following label {:?}", ch0.get_uom(), ch0.get_label());
for s in 0..abf.get_sweeps_count() {
let data = ch0.get_sweep(s).unwrap();
println!("Sweep {:?} has {:?} points", s, data.len());
}
...
You might also prefer a more functional approach like the following:
...
abf.get_channels()
.for_each(|channel| {
channel.get_sweeps()
// take only the Some values
.flatten()
.for_each(|sweep| println!("First 10 elements {:?}, the unit of measurement is {:?}", &sweep[0..10], channel.get_uom()))
});
...
Contributing
Contributions are welcome! If you encounter issues or have suggestions, please open an issue or submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.