Skip to content

Commit

Permalink
update workflows file and add some test
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkLoc committed May 20, 2024
1 parent e0e91e2 commit 3b30036
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Build

name: Build
- run: echo "start run cargo build"
- run: cargo build --verbose
- name: Run tests

name: Run tests
- run: echo "start run cargo test"
- run: cargo test --verbose
- run: echo "This job's status is ${{ job.status }}."
37 changes: 30 additions & 7 deletions src/cli/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,8 @@ pub fn flatten_fq(
std::process::exit(1);
}

let fields = get_flag(flag);
let mut out_writer = file_writer(out, compression_level)?;
let flags = format!("{:b}", flag).chars().rev().collect::<Vec<char>>();
let mut fields = vec![];
for (i, k) in flags.iter().enumerate() {
if k == &'1' {
fields.push(i);
}
}

for rec in fq_reader.records().flatten() {
let read = [rec.id().as_bytes(), rec.seq(), "+".as_bytes(), rec.qual()];
Expand Down Expand Up @@ -70,3 +64,32 @@ pub fn flatten_fq(
info!("time elapsed is: {:?}", start.elapsed());
Ok(())
}

fn get_flag(num: u8) -> Vec<usize> {
let flags = format!("{:b}", num).chars().rev().collect::<Vec<char>>();

let mut fields = vec![];
for (i, k) in flags.iter().enumerate() {
if k == &'1' {
fields.push(i);
}
}
fields
}

#[cfg(test)]
mod tests {
use super::*;

// 1, 2, 4, 8
#[test]
fn flag3() {
// 3 = 1 + 2, index: [0,1]
assert_eq!(get_flag(3), vec![0, 1]);
}

#[test]
fn flag7() {
assert_eq!(get_flag(7), vec![0, 1, 2]);
}
}
20 changes: 20 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,23 @@ where
Ok(Box::new(BufWriter::with_capacity(BUFF_SIZE, fp)))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn gz_or_not() {
assert_eq!(is_gzipped("example/mini2k.fq.gz").unwrap(), true);
}

#[test]
fn xz_or_not() {
assert_eq!(is_xz("example/mini2k.fq.xz").unwrap(), true);
}

#[test]
fn bzip2_or_not() {
assert_eq!(is_bzipped("example/mini2k.fq.bz2").unwrap(), true);
}
}

0 comments on commit 3b30036

Please sign in to comment.