diff --git a/Cargo.toml b/Cargo.toml index 184d9c0..eb6c9c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,9 @@ optional = true [dev-dependencies] rayon = "1" +downloader = "0.2" +regex = "1" +reqwest = { version = "0.13", features = ["blocking"] } [build-dependencies] j4rs = "0.24" diff --git a/src/bioformats.rs b/src/bioformats.rs index ffc00e0..9ae2121 100644 --- a/src/bioformats.rs +++ b/src/bioformats.rs @@ -50,10 +50,7 @@ pub fn download_bioformats(gpl_formats: bool) -> Result<(), Error> { let path = crate::py::ndbioimage_file(); #[cfg(not(feature = "python"))] - let path = std::env::current_exe()? - .parent() - .unwrap() - .to_path_buf(); + let path = std::env::current_exe()?.parent().unwrap().to_path_buf(); let class_path = path.parent().unwrap(); let jassets = class_path.join("jassets"); diff --git a/src/lib.rs b/src/lib.rs index 66d2d3f..da7c4f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ mod tests { use crate::reader::{Frame, Reader}; use crate::stats::MinMax; use crate::view::Item; + use downloader::{Download, Downloader}; use ndarray::{Array, Array4, Array5, NewAxis}; use ndarray::{Array2, s}; use rayon::prelude::*; @@ -38,6 +39,46 @@ mod tests { Reader::new(&path, 0) } + #[test] + fn read_ome() -> Result<(), Box> { + let path = std::env::current_dir()?.join("tests/files/ome"); + std::fs::create_dir_all(&path)?; + let url = + "https://downloads.openmicroscopy.org/images/OME-TIFF/2016-06/bioformats-artificial/"; + let page = reqwest::blocking::get(url)?.text()?; + let pat = regex::Regex::new( + r#"]+)">[^<>]+\s+\d{2}-\w{3}-\d{4}\s+\d{2}:\d{2}\s+(\d+)"#, + )?; + let mut downloads = Vec::new(); + let mut files = Vec::new(); + for line in page.lines() { + if let Some(cap) = pat.captures(line) { + let link = cap[1].trim().to_string(); + let size = cap[2].trim().parse::()?; + if size < 10 * 1024usize.pow(2) { + if !path.join(&link).exists() { + downloads.push(Download::new(&format!("{}{}", url, link))); + } + files.push(path.join(link)); + } + } + } + if !downloads.is_empty() { + let mut downloader = Downloader::builder().download_folder(&path).build()?; + downloader.download(&downloads)?; + } + let mut count = 0; + for file in files { + if let Ok(reader) = Reader::new(&file, 0) { + let _ome = reader.get_ome()?; + count += 1; + } + } + println!("count: {}", count); + assert!(count > 30); + Ok(()) + } + fn get_pixel_type(file: &str) -> Result { let reader = open(file)?; Ok(format!(