10 个不稳定版本 (3 个破坏性更新)
0.4.2 | 2024年3月6日 |
---|---|
0.4.1 | 2024年3月6日 |
0.3.0 | 2023年12月1日 |
0.2.0 | 2023年8月31日 |
0.1.4 | 2023年8月28日 |
#712 in 解析器实现
3.5MB
510 行
rust_abf
Rust ABF 读取器
这是一个 Rust 项目,提供了一种快速且内存高效的读取 ABF(Axon 二进制格式)文件的方法,这种格式在电生理学中常用。
功能
- 快速读取:利用优化算法快速解析 ABF 文件。
- 低内存占用:在处理大型 ABF 文件时最小化内存使用。
- 最小依赖:努力保持依赖项轻量。
- 易于使用:提供简单的 API 读取 ABF 文件。
使用方法
-
如果您还没有安装 Rust 和 Cargo,请先安装它们。
-
将此库添加到您的
Cargo.toml
或使用cargo add rust_abf
-
在您的 Rust 代码中
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"), } }
如果您更喜欢在通道上工作,您可以使用以下代码直接访问它们
...
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());
}
...
您也可能更喜欢以下更函数式的方法
...
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()))
});
...
贡献
欢迎贡献!如果您遇到问题或有建议,请打开一个问题或提交一个 pull request。
许可证
本项目采用 MIT 许可证。有关详细信息,请参阅 LICENSE 文件。