Skip to content

Commit

Permalink
add runtime and bigwigwrite #1
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Mar 18, 2024
1 parent 56c6861 commit a5f9aee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions genimtools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 29 additions & 3 deletions genimtools/src/uniwig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();





Expand All @@ -201,7 +227,7 @@ pub fn uniwig_main(sorted: bool, _smoothsize:i32, _writesize:i32, combinedbedpat

}

fn read_chromosome_sizes(chrom_size_path: &str) -> Result<std::collections::HashMap<String, i32>, Box<dyn Error>> {
fn read_chromosome_sizes(chrom_size_path: &str) -> Result<std::collections::HashMap<String, u32>, Box<dyn Error>> {
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);
Expand All @@ -211,7 +237,7 @@ fn read_chromosome_sizes(chrom_size_path: &str) -> Result<std::collections::Hash
let mut iter = line.split('\t');
let chrom_name = iter.next().unwrap().to_owned();
let size_str = iter.next().unwrap();
let size = size_str.parse::<i32>()?;
let size = size_str.parse::<u32>()?;

chrom_sizes.insert(chrom_name, size);
}
Expand Down

0 comments on commit a5f9aee

Please sign in to comment.