Skip to content

Commit

Permalink
add simple test for read_bed_vec, check if bed file is gzipped #1
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Mar 15, 2024
1 parent 3a03747 commit e01a648
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions genimtools/src/uniwig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::io::{BufRead, BufReader, Read};
use std::path::Path;
use std::fs::{File};
use std::error::Error;
use clap::builder::OsStr;
use flate2::read::GzDecoder;


pub mod cli;
Expand Down Expand Up @@ -37,6 +39,23 @@ pub fn read_bed_map(combinedbedpath: &str){

pub fn read_bed_vec(combinedbedpath: &str) -> Vec<Chromosome> {

let path = Path::new(combinedbedpath);

let file = File::open(path).unwrap();

let is_gzipped = path.extension().unwrap_or(&OsStr::from("bed")) == "gz";

if is_gzipped {
let decoder = GzDecoder::new(file);
let reader = BufReader::new(decoder);
} else {
let reader = BufReader::new(file);
}






let chr1 = Chromosome{
chrom: "".to_string(),
Expand Down
9 changes: 9 additions & 0 deletions genimtools/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn path_to_tokenize_bed_file() -> &'static str {

mod tests {
use genimtools::common::utils::extract_regions_from_bed_file;
use genimtools::uniwig::read_bed_vec;

use super::*;

Expand Down Expand Up @@ -155,4 +156,12 @@ mod tests {
}

}

#[rstest]
fn test_read_bed_vec(path_to_bed_file: &str, path_to_bed_file_gzipped: &str) {

read_bed_vec(path_to_bed_file);
read_bed_vec(path_to_bed_file_gzipped);

}
}

0 comments on commit e01a648

Please sign in to comment.