From 7240bddb4c4db4da8f88a81ad39cfcf17b94076a Mon Sep 17 00:00:00 2001 From: Donald Campbell <125581724+donaldcampbelljr@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:20:30 -0400 Subject: [PATCH] add remaining workflow for converting final product to bw --- gtars/src/uniwig/mod.rs | 22 ++++++++++++---------- gtars/src/uniwig/writing.rs | 22 +++++----------------- gtars/tests/test.rs | 2 +- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/gtars/src/uniwig/mod.rs b/gtars/src/uniwig/mod.rs index 2cb9fa79..2ea9ddd2 100644 --- a/gtars/src/uniwig/mod.rs +++ b/gtars/src/uniwig/mod.rs @@ -144,9 +144,10 @@ pub fn uniwig_main( let ft = FileType::from_str(filetype.to_lowercase().as_str()); // Set up output file names + let og_output_type = output_type; // need this later for conversion let mut output_type = output_type; - if output_type == "bedgraph" { - output_type = "bedGraph" + if output_type == "bedgraph" || output_type == "bw" || output_type == "bigwig" { + output_type = "bedGraph" // we must create bedgraphs first before creating bigwig files } let mut meta_data_file_names: [String; 3] = [ @@ -535,18 +536,19 @@ pub fn uniwig_main( write_combined_files(*location, output_type, bwfileheader, &final_chromosomes); } } - "bw" => { - //Ensure bedGraphs files are made and combined before proceeding with bw writing - for location in vec_strings.iter() { - bar.inc(1); - write_combined_files(*location, "bedGraph", bwfileheader, &final_chromosomes); - } + _ => {} + } + bar.finish(); - write_bw_files(bwfileheader, chromsizerefpath, num_threads) + match og_output_type { + "bw" | "bigWig" => { + println!("Writing bigWig files"); + write_bw_files(bwfileheader, chromsizerefpath, num_threads); } + _ => {} } - bar.finish(); + println!("FINISHED"); Ok(()) diff --git a/gtars/src/uniwig/writing.rs b/gtars/src/uniwig/writing.rs index 47693fb6..b8a33858 100644 --- a/gtars/src/uniwig/writing.rs +++ b/gtars/src/uniwig/writing.rs @@ -159,11 +159,6 @@ pub fn write_to_bed_graph_file( /// Converts uniwig generated bedGraphs to bigWig files pub fn write_bw_files(location: &str, chrom_sizes: &str, num_threads: i32) { - // // Create HashMap to store chromosome information - // // Then - // let mut chrom_map = HashMap::new(); - // chrom_map.insert("chr17".to_string(), 83257441); - //Collect all bedGraph files in the given location/directory let mut bed_graph_files = Vec::new(); @@ -190,28 +185,21 @@ pub fn write_bw_files(location: &str, chrom_sizes: &str, num_threads: i32) { println!("bedgraph files {:?}", bed_graph_files); for file in bed_graph_files.iter() { - // let mut path = PathBuf::from(file); - // let infile = File::open(file.clone()).unwrap(); - // let mut vals_iter = BedFileStream::from_bedgraph_file(infile); - // //vals_iter. - // let test1= vals_iter.next().unwrap().unwrap().1; //this gives a bbi value - // println!("done with: {}", file); - - // Just use the built in arg struct and functionbedgraphtobigwig - - let output_name = location.clone(); // TODO + let file_path = PathBuf::from(file); + let new_file_path = file_path.with_extension("bw"); + let new_file_path = new_file_path.to_str().unwrap(); let current_arg_struct = BedGraphToBigWigArgs { bedgraph: file.to_string(), chromsizes: chrom_sizes.to_string(), - output: output_name.to_string(), + output: new_file_path.to_string(), parallel: "".to_string(), single_pass: false, write_args: BBIWriteArgs { nthreads: num_threads as usize, nzooms: 0, uncompressed: false, - sorted: "".to_string(), + sorted: "start".to_string(), //TODO CHECK THIS!!!!!!!!!! block_size: 0, items_per_slot: 0, inmemory: false, diff --git a/gtars/tests/test.rs b/gtars/tests/test.rs index 135247ee..b7d841fb 100644 --- a/gtars/tests/test.rs +++ b/gtars/tests/test.rs @@ -505,7 +505,7 @@ mod tests { } #[rstest] - fn test_uniwig_bed_graphs(_path_to_bed_file: &str) { + fn test_uniwig_write_bw(_path_to_bed_file: &str) { let path_to_crate = env!("CARGO_MANIFEST_DIR"); // Read from sizes file