From a5f9aee552a1a27a7b529f9e9f1abaa17c21100a Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:48:15 -0400 Subject: [PATCH] add runtime and bigwigwrite #1 --- genimtools/Cargo.toml | 1 + genimtools/src/uniwig/mod.rs | 32 +++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/genimtools/Cargo.toml b/genimtools/Cargo.toml index 01b205f0..18680559 100644 --- a/genimtools/Cargo.toml +++ b/genimtools/Cargo.toml @@ -16,6 +16,7 @@ polars = { version = "0.35.4", features = ["decompress", "decompress-fast"] } rust-lapper = "1.1.0" walkdir = "2.4.0" bigtools = "0.4.2" +tokio = "1.36.0" [dev-dependencies] rstest = "0.18.2" diff --git a/genimtools/src/uniwig/mod.rs b/genimtools/src/uniwig/mod.rs index ddf256e8..20a7402a 100644 --- a/genimtools/src/uniwig/mod.rs +++ b/genimtools/src/uniwig/mod.rs @@ -3,8 +3,12 @@ use std::io::{BufRead, BufReader, Read}; use std::path::Path; use std::fs::{File}; use std::error::Error; +use bigtools::BBIFile::BigWig; use clap::builder::OsStr; use flate2::read::GzDecoder; +use bigtools::BigWigWrite; +use bigtools::bedchromdata::BedParserStreamingIterator; +use bigtools::bed::bedparser::BedParser; pub mod cli; @@ -183,9 +187,31 @@ pub fn uniwig_main(sorted: bool, _smoothsize:i32, _writesize:i32, combinedbedpat for chromosome in chromosomes.iter(){ let chrom_name = chromosome.chrom.clone(); chroms.push(chrom_name); - chr_lens.push(chrom_sizes[&chromosome.chrom]); // retrieve size from hashmap + chr_lens.push(chrom_sizes[&chromosome.chrom] as i32); // retrieve size from hashmap } + // Original Steps + // Create bigwig file + // Create header from chroms and chr lens + // write to bigwig file with smoothing IF smoothsize is set + // original code skips this if smoothsize is not set + // Close bigwig file + + // Using BigTools + let runtime = tokio::runtime::Builder::new_multi_thread() + .worker_threads(6) + .build() + .expect("Unable to create runtime."); + + // let vals_iter = BedParser::from_bed_file(combinedbedpath); + // let vals = BedParserStreamingIterator::new(vals_iter, false); + + let out = BigWigWrite::create_file(file_names[0].clone()); + + //out.options.block_size = 5; + // out.write(chrom_sizes, vals, runtime).unwrap(); + + @@ -201,7 +227,7 @@ pub fn uniwig_main(sorted: bool, _smoothsize:i32, _writesize:i32, combinedbedpat } -fn read_chromosome_sizes(chrom_size_path: &str) -> Result, Box> { +fn read_chromosome_sizes(chrom_size_path: &str) -> Result, Box> { let chrom_size_file = File::open(Path::new(chrom_size_path))?; let mut chrom_sizes = std::collections::HashMap::new(); let reader = BufReader::new(chrom_size_file); @@ -211,7 +237,7 @@ fn read_chromosome_sizes(chrom_size_path: &str) -> Result()?; + let size = size_str.parse::()?; chrom_sizes.insert(chrom_name, size); }