diff --git a/bigtools/src/utils/cli/bigwigtobedgraph.rs b/bigtools/src/utils/cli/bigwigtobedgraph.rs index 883020d..743153f 100644 --- a/bigtools/src/utils/cli/bigwigtobedgraph.rs +++ b/bigtools/src/utils/cli/bigwigtobedgraph.rs @@ -156,7 +156,7 @@ pub async fn write_bg( let end = chrom.as_ref().and_then(|_| end); let chroms: Vec = bigwig.chroms().to_vec(); - let chrom_files: Vec, String)>> = chroms + let chrom_files: Vec)>> = chroms .into_iter() .filter(|c| chrom.as_ref().map_or(true, |chrom| &c.name == chrom)) .map(|chrom| { @@ -191,16 +191,15 @@ pub async fn write_bg( } let start = start.unwrap_or(0); let end = end.unwrap_or(chrom.length); - let name = chrom.name.clone(); let handle = runtime .spawn(file_future(bigwig, chrom, writer, start, end)) .map(|f| f.unwrap()); - Ok((handle, buf, name)) + Ok((handle, buf)) }) .collect::>(); for res in chrom_files { - let (f, mut buf, name) = res?; + let (f, mut buf) = res?; buf.switch(out_file); f.await?; while !buf.is_real_file_ready() { diff --git a/bigtools/tests/bigwigwrite.rs b/bigtools/tests/bigwigwrite.rs index 5bb5acc..c69f02d 100644 --- a/bigtools/tests/bigwigwrite.rs +++ b/bigtools/tests/bigwigwrite.rs @@ -9,7 +9,7 @@ use tempfile; use bigtools::bed::bedparser::BedParser; use bigtools::bedchromdata::BedParserStreamingIterator; use bigtools::utils::chromvalues::ChromValues; -use bigtools::{BigWigRead, BigWigWrite}; +use bigtools::{BigWigRead, BigWigWrite, Value}; use tokio::runtime; #[test] @@ -159,3 +159,40 @@ fn test_multi_chrom() -> io::Result<()> { Ok(()) } + +#[test] +fn test_iter() { + let chroms = vec![ + "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", "chrY", + ]; + let starts: Vec = vec![530, 538, 584, 713, 751, 860, 865, 873, 879, 902]; + let ends: Vec = vec![538, 584, 713, 751, 860, 865, 873, 879, 902, 923]; + + let iter = chroms + .into_iter() + .zip(starts.into_iter().zip(ends.into_iter())); + let iter = iter.map(|(chrom, (start, end))| { + Ok::<(String, Value), std::io::Error>(( + chrom.to_string(), + Value { + start, + end, + value: 0.0, + }, + )) + }); + + let vals_iter = BedParserStreamingIterator::new(BedParser::wrap_iter(iter), true); + + let chrom_map = HashMap::from([ + ("chrY".to_string(), 57_227_415) + ]); + + let runtime = tokio::runtime::Builder::new_current_thread() + .build() + .expect("Unable to create runtime."); + + let tempfile = tempfile::NamedTempFile::new().unwrap(); + let outb = BigWigWrite::create_file(tempfile.path().to_string_lossy().to_string()); + outb.write_singlethreaded(chrom_map, vals_iter, runtime).unwrap(); +} \ No newline at end of file