Skip to content

Commit 91f2171

Browse files
fix for #52
1 parent ce0967a commit 91f2171

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

gtars/src/uniwig/writing.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use ndarray::Array;
66
use ndarray_npy::write_npy;
77
use std::fs::{create_dir_all, remove_file, File, OpenOptions};
88
use std::io::{BufWriter, Write};
9-
use std::path::PathBuf;
9+
use std::path::{Path, PathBuf};
1010
use std::{fs, io};
1111

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

168-
for entry in fs::read_dir(location).unwrap() {
168+
let mut location_path = location;
169+
170+
if !location_path.ends_with("/"){
171+
let mut temp_path = Path::new(location_path);
172+
let parent_location_path = temp_path.parent().unwrap();
173+
location_path = parent_location_path.to_str().unwrap();
174+
}
175+
176+
for entry in fs::read_dir( location_path).unwrap() {
169177
let entry = entry.unwrap();
170178
let path = entry.path();
171179

gtars/tests/test.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,4 +1069,51 @@ mod tests {
10691069

10701070
Ok(())
10711071
}
1072+
1073+
#[rstest]
1074+
fn test_process_bed_to_bw(
1075+
_path_to_dummy_bed_file: &str,
1076+
) -> Result<(), Box<(dyn std::error::Error + 'static)>> {
1077+
let path_to_crate = env!("CARGO_MANIFEST_DIR");
1078+
let chromsizerefpath: String = format!("{}{}", path_to_crate, "/tests/hg38.chrom.sizes");
1079+
let chromsizerefpath = chromsizerefpath.as_str();
1080+
let combinedbedpath = _path_to_dummy_bed_file;
1081+
1082+
1083+
let tempdir = tempfile::tempdir().unwrap();
1084+
let path = PathBuf::from(&tempdir.path());
1085+
1086+
let mut bwfileheader_path = path.into_os_string().into_string().unwrap();
1087+
bwfileheader_path.push_str("/final/");
1088+
let bwfileheader = bwfileheader_path.as_str();
1089+
1090+
let smoothsize: i32 = 1;
1091+
let output_type = "bw";
1092+
let filetype = "bed";
1093+
let num_threads = 2;
1094+
let score = true;
1095+
let stepsize = 1;
1096+
let zoom = 1;
1097+
let vec_count_type = vec!["start", "end", "core"];
1098+
1099+
uniwig_main(
1100+
vec_count_type,
1101+
smoothsize,
1102+
combinedbedpath,
1103+
chromsizerefpath,
1104+
bwfileheader,
1105+
output_type,
1106+
filetype,
1107+
num_threads,
1108+
score,
1109+
stepsize,
1110+
zoom,
1111+
false,
1112+
true,
1113+
1.0,
1114+
)
1115+
.expect("Uniwig main failed!");
1116+
1117+
Ok(())
1118+
}
10721119
}

0 commit comments

Comments
 (0)