Skip to content

Commit 2995d86

Browse files
committed
refactor: improve grep example
1 parent 416f1fc commit 2995d86

3 files changed

Lines changed: 20 additions & 356 deletions

File tree

examples/grep.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::sync::Arc;
22

33
use anyhow::Result;
44
use binseq::prelude::*;
5+
use clap::Parser;
56
use memchr::memmem::Finder;
67
use parking_lot::Mutex;
78

@@ -50,21 +51,26 @@ impl ParallelProcessor for GrepCounter {
5051
}
5152
}
5253

53-
fn main() -> Result<()> {
54-
let path = std::env::args()
55-
.nth(1)
56-
.unwrap_or("./data/subset.bq".to_string());
57-
let pattern = std::env::args()
58-
.nth(2)
59-
.unwrap_or("ACGT".to_string())
60-
.as_bytes()
61-
.to_vec();
62-
let n_threads = std::env::args().nth(3).unwrap_or("1".to_string()).parse()?;
54+
#[derive(Parser)]
55+
struct Args {
56+
/// Input BINSEQ path to grep
57+
#[clap(required = true)]
58+
input: String,
6359

64-
let reader = BinseqReader::new(&path)?;
65-
let counter = GrepCounter::new(&pattern);
66-
reader.process_parallel(counter.clone(), n_threads)?;
67-
counter.pprint();
60+
/// Pattern to search for (either sseq or xseq)
61+
#[clap(required = true)]
62+
pattern: String,
63+
64+
/// Threads to use [0: auto]
65+
#[clap(short = 'T', long, default_value_t = 0)]
66+
threads: usize,
67+
}
6868

69+
fn main() -> Result<()> {
70+
let args = Args::parse();
71+
let reader = BinseqReader::new(&args.input)?;
72+
let counter = GrepCounter::new(args.pattern.as_bytes());
73+
reader.process_parallel(counter.clone(), args.threads)?;
74+
counter.pprint();
6975
Ok(())
7076
}

examples/parallel_processing.rs

Lines changed: 0 additions & 157 deletions
This file was deleted.

examples/read_write.rs

Lines changed: 0 additions & 185 deletions
This file was deleted.

0 commit comments

Comments
 (0)