Skip to content

Commit

Permalink
add Qx output, bump to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
angelovangel committed Jan 23, 2024
1 parent b1ee762 commit d0615c2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ readme = "README.md"
homepage = "https://github.com/angelovangel/faster"
repository = "https://github.com/angelovangel/faster"
keywords = ["fastq", "bio"]
version = "0.1.5"
version = "0.2.0"
authors = ["Angel Angelov <aangeloo@gmail.com>"]
edition = "2018"

Expand Down
44 changes: 39 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn samplefq(path: &String, n: usize) {

fn main() {
let matches = App::new("faster")
.version("0.1.5")
.version("0.2.0")
.author("Angel Angelov <aangeloo@gmail.com>")
.about("fast statistics and more for 1 fastq file")

Expand Down Expand Up @@ -75,7 +75,10 @@ fn main() {
.long("nx")
.takes_value(true)
.help("Output NX value, provide the desired NX value as 0.5 for e.g. N50 [numeric]"))

.arg(Arg::with_name("qyield")
.long("qyield")
.takes_value(true)
.help("Percent bases with Q score of x or higher (use range 8..60)"))
.arg(Arg::with_name("sample")
//.short("s")
.long("sample")
Expand Down Expand Up @@ -114,7 +117,7 @@ fn main() {

// this group makes one and only one arg from the set required, avoid defining conflicts_with
.group(ArgGroup::with_name("group")
.required(true).args(&["table", "len", "gc", "qscore", "filter", "sample", "trim_front", "trim_tail", "regex_string", "regex_file", "nx"]))
.required(true).args(&["table", "len", "gc", "qscore", "filter", "sample", "trim_front", "trim_tail", "regex_string", "regex_file", "nx", "qyield"]))
.get_matches();
//println!("Working on {}", matches.value_of("INPUT").unwrap());
// read file
Expand Down Expand Up @@ -206,8 +209,8 @@ fn main() {

// case nx
} else if matches.is_present("nx") {
let nxvalue: f32 = matches.
value_of("nx")
let nxvalue: f32 = matches
.value_of("nx")
.unwrap()
.trim()
.parse::<f32>()
Expand Down Expand Up @@ -238,7 +241,38 @@ fn main() {
process::exit(0)
}
}
} else if matches.is_present("qyield") {
let qvalue = matches
.value_of("qyield")
.unwrap()
.trim()
.parse::<u8>()
.expect("Failed to parse desired QX value");

match qvalue {
x if (8..=60).contains(&x) => {
let mut bases: i64 = 0;
let mut qualx: i64 = 0;
// do work
while !record.is_empty() {
let len = record.seq().len() as i64;
bases += len;
qualx += modules::get_qual_bases(record.qual(), 33 + qvalue); // 33 offset

reader
.read(&mut record)
.expect("Failed to parse fastq record!")
}
let qx = qualx as f64 / bases as f64 * 100.0;
println!("Q{}\t{:.2}", qvalue, qx);
process::exit(0)
}
_ => {
eprintln!("The qyield value should be between 10 and 60");
process::exit(0)
}
}

} else if matches.is_present("sample") {
// parse fraction
let fraction = matches
Expand Down

0 comments on commit d0615c2

Please sign in to comment.