Skip to content

Commit

Permalink
fix for #52
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Jan 10, 2025
1 parent ce0967a commit 91f2171
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
12 changes: 10 additions & 2 deletions gtars/src/uniwig/writing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ndarray::Array;
use ndarray_npy::write_npy;
use std::fs::{create_dir_all, remove_file, File, OpenOptions};
use std::io::{BufWriter, Write};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::{fs, io};

/// Write output to npy files
Expand Down Expand Up @@ -165,7 +165,15 @@ pub fn write_bw_files(location: &str, chrom_sizes: &str, num_threads: i32, zoom_
//Collect all bedGraph files in the given location/directory
let mut bed_graph_files = Vec::new();

for entry in fs::read_dir(location).unwrap() {
let mut location_path = location;

if !location_path.ends_with("/"){
let mut temp_path = Path::new(location_path);
let parent_location_path = temp_path.parent().unwrap();
location_path = parent_location_path.to_str().unwrap();
}

for entry in fs::read_dir( location_path).unwrap() {
let entry = entry.unwrap();
let path = entry.path();

Expand Down
47 changes: 47 additions & 0 deletions gtars/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,4 +1069,51 @@ mod tests {

Ok(())
}

#[rstest]
fn test_process_bed_to_bw(
_path_to_dummy_bed_file: &str,
) -> Result<(), Box<(dyn std::error::Error + 'static)>> {
let path_to_crate = env!("CARGO_MANIFEST_DIR");
let chromsizerefpath: String = format!("{}{}", path_to_crate, "/tests/hg38.chrom.sizes");
let chromsizerefpath = chromsizerefpath.as_str();
let combinedbedpath = _path_to_dummy_bed_file;


let tempdir = tempfile::tempdir().unwrap();
let path = PathBuf::from(&tempdir.path());

let mut bwfileheader_path = path.into_os_string().into_string().unwrap();
bwfileheader_path.push_str("/final/");
let bwfileheader = bwfileheader_path.as_str();

let smoothsize: i32 = 1;
let output_type = "bw";
let filetype = "bed";
let num_threads = 2;
let score = true;
let stepsize = 1;
let zoom = 1;
let vec_count_type = vec!["start", "end", "core"];

uniwig_main(
vec_count_type,
smoothsize,
combinedbedpath,
chromsizerefpath,
bwfileheader,
output_type,
filetype,
num_threads,
score,
stepsize,
zoom,
false,
true,
1.0,
)
.expect("Uniwig main failed!");

Ok(())
}
}

0 comments on commit 91f2171

Please sign in to comment.