Skip to content

Commit

Permalink
add remaining workflow for converting final product to bw
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Oct 21, 2024
1 parent b8ba499 commit 7240bdd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
22 changes: 12 additions & 10 deletions gtars/src/uniwig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Expand Down Expand Up @@ -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(())
Expand Down
22 changes: 5 additions & 17 deletions gtars/src/uniwig/writing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion gtars/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7240bdd

Please sign in to comment.