From 00b69ef91a74e7b210bacaca006f92e73b5d1a08 Mon Sep 17 00:00:00 2001 From: Seth Stadick Date: Fri, 5 Aug 2022 12:23:18 -0600 Subject: [PATCH] feat(progress-logger): added a progress logger --- Cargo.lock | 14 ++++++++++++-- Cargo.toml | 1 + src/main.rs | 13 +++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 94f2b1f..280d086 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -340,6 +340,7 @@ dependencies = [ "mimalloc", "num_cpus", "parking_lot", + "proglog", "rayon", "regex", "seq_io", @@ -564,9 +565,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] @@ -720,6 +721,15 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "proglog" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0907d41e1427d25a0b6376a803c9cb15d2e46586cca3a9560391c56661186aa3" +dependencies = [ + "log", +] + [[package]] name = "quote" version = "1.0.10" diff --git a/Cargo.toml b/Cargo.toml index 0de025f..eb0e030 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ log = "0.4.14" mimalloc = {version = "0.1.26", default-features = false} num_cpus = "1.13.0" parking_lot = "0.11.2" +proglog = "0.2.0" rayon = "1.5.1" regex = "1.5.4" seq_io = "0.3.1" diff --git a/src/main.rs b/src/main.rs index b2c6387..045717e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ use itertools::{self, izip, Itertools}; use lazy_static::lazy_static; use log::info; use parking_lot::Mutex; +use proglog::ProgLogBuilder; use rayon::prelude::*; use regex::{Regex, RegexBuilder}; use seq_io::fastq::{self, OwnedRecord}; @@ -333,6 +334,13 @@ struct Barcode<'a>(&'a [u8], &'a [u8]); #[allow(clippy::too_many_lines)] fn main() -> Result<()> { let opts = setup(); + let progress_logger = ProgLogBuilder::new() + .name("fqgrep-progress") + .noun("reads") + .verb("Searched") + .unit(50_000_000) + .build(); + let ref_sample = Sample::from_r1_path(&opts.r1_fastq, REF_PREFIX)?; let alt_sample = Sample::from_r1_path(&opts.r1_fastq, ALT_PREFIX)?; let both_sample = Sample::from_r1_path(&opts.r1_fastq, BOTH_PREFIX)?; @@ -379,6 +387,7 @@ fn main() -> Result<()> { (false, true) => Matches::Alt, (false, false) => Matches::None, }; + progress_logger.record(); (m, (r1, r2)) }) .filter(|(m, _)| *m != Matches::None) @@ -406,7 +415,7 @@ fn main() -> Result<()> { ) .for_each( |(ref_reads, alt_reads, both_reads): MatchedReads| { - // Aquire lock to ensure R1 and R2 are enqueued at the same time + // Acquire lock to ensure R1 and R2 are enqueued at the same time { let _lock = ref_writer.lock.lock(); ref_writer.r1.tx.as_ref().unwrap().send(ref_reads.0).expect("Failed to send R1s"); @@ -475,7 +484,7 @@ fn main() -> Result<()> { .handle .join() .expect("Error joining r2 handle"); - + drop(progress_logger); info!( "{} reads matched input ref sequence", ref_r1_stats.reads_written