Skip to content

Commit eadb5d6

Browse files
committed
Update the seq_files and kmer cli
1 parent 0baecf2 commit eadb5d6

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

src/cli.rs

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Command line interface, built using [`crate::clap` with `Derive`](https://docs.rs/clap/latest/clap/_derive/_tutorial/index.html)
2-
use clap::{ArgGroup, Parser, Subcommand};
2+
use clap::{ArgGroup, Args, Parser, Subcommand};
33

44
use super::hashing::{AaLevel, HashType, DEFAULT_LEVEL};
55

@@ -40,7 +40,7 @@ pub fn check_threads(threads: usize) {
4040
#[derive(Parser)]
4141
#[command(author, version, about, long_about = None)]
4242
#[command(propagate_version = true)]
43-
pub struct Args {
43+
pub struct MainArgs {
4444
#[doc(hidden)]
4545
#[command(subcommand)]
4646
pub command: Commands,
@@ -54,6 +54,18 @@ pub struct Args {
5454
pub quiet: bool,
5555
}
5656

57+
#[derive(Args)]
58+
#[group(required = true, multiple = false)]
59+
pub struct Kmers {
60+
/// K-mer list (comma separated k-mer values to sketch at)
61+
#[arg(short, long, required = true, value_delimiter = ',')]
62+
pub k_vals: Option<Vec<usize>>,
63+
64+
/// K-mer linear sequence (start,end,step)
65+
#[arg(long, required = true, value_delimiter = ',')]
66+
pub k_seq: Option<Vec<usize>>,
67+
}
68+
5769
/// Subcommands and their specific options
5870
#[derive(Subcommand)]
5971
pub enum Commands {
@@ -65,10 +77,10 @@ pub enum Commands {
6577
/// Create sketches from input data
6678
Sketch {
6779
/// List of input FASTA files
68-
#[arg(long, group = "input", num_args = 1.., value_delimiter = ',')]
80+
#[arg(group = "input")]
6981
seq_files: Option<Vec<String>>,
7082

71-
/// File listing input files (tab separated name, sequences)
83+
/// File listing input files (tab separated name, sequences, see README)
7284
#[arg(short, group = "input")]
7385
file_list: Option<String>,
7486

@@ -86,13 +98,8 @@ pub enum Commands {
8698
#[arg(short)]
8799
output: String,
88100

89-
/// K-mer list
90-
#[arg(short, long, group = "kmer", required = true, num_args = 1.., value_delimiter = ',')]
91-
k_vals: Option<Vec<usize>>,
92-
93-
/// K-mer sequence: start end step
94-
#[arg(long, group = "kmer", required = true, num_args = 3)]
95-
k_seq: Option<Vec<usize>>,
101+
#[command(flatten)]
102+
kmers: Kmers,
96103

97104
/// Sketch size
98105
#[arg(short, long, default_value_t = DEFAULT_SKETCHSIZE)]
@@ -240,7 +247,7 @@ pub enum Commands {
240247
},
241248
}
242249

243-
/// Function to parse command line args into [`Args`] struct
244-
pub fn cli_args() -> Args {
245-
Args::parse()
250+
/// Function to parse command line args into [`MainArgs`] struct
251+
pub fn cli_args() -> MainArgs {
252+
MainArgs::parse()
246253
}

src/io.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Functions to read input fasta/fastq files
2+
use crate::cli::Kmers;
3+
24
use std::fs::File;
35
use std::io::{stdout, BufRead, BufReader, BufWriter, Write};
46
use std::path::Path;
@@ -24,14 +26,14 @@ pub fn read_input_fastas(seq_files: &[String]) -> Vec<InputFastx> {
2426
input_files
2527
}
2628

27-
pub fn parse_kmers(k_list: &Option<Vec<usize>>, k_seq: &Option<Vec<usize>>) -> Vec<usize> {
28-
if k_list.is_some() && k_seq.is_some() {
29+
pub fn parse_kmers(k: &Kmers) -> Vec<usize> {
30+
if k.k_vals.is_some() && k.k_seq.is_some() {
2931
panic!("Only one of --k-vals or --k-seq should be specified");
3032
}
3133

32-
let mut kmers = if let Some(k) = k_list {
34+
let mut kmers = if let Some(k) = &k.k_vals {
3335
k.clone().to_vec()
34-
} else if let Some(k) = k_seq {
36+
} else if let Some(k) = &k.k_seq {
3537
(k[0]..=k[1]).step_by(k[2]).collect()
3638
} else {
3739
panic!("Must specify --k-vals or --k-seq");
@@ -85,7 +87,11 @@ pub fn get_input_list(
8587
let parsed_input = match fields.len() {
8688
1 => ((fields[0].to_string()), fields[0].to_string(), None),
8789
2 => ((fields[0].to_string()), fields[1].to_string(), None),
88-
3 => ((fields[0].to_string()), fields[0].to_string(), Some(fields[2].to_string())),
90+
3 => (
91+
(fields[0].to_string()),
92+
fields[0].to_string(),
93+
Some(fields[2].to_string()),
94+
),
8995
_ => {
9096
panic!("Unable to parse line in file_list")
9197
}

src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::time::Instant;
1616
extern crate arrayref;
1717
extern crate num_cpus;
1818
use anyhow::Error;
19-
use indicatif::{ParallelProgressIterator, ProgressStyle};
19+
use indicatif::ParallelProgressIterator;
2020
use rayon::prelude::*;
2121

2222
pub mod cli;
@@ -80,8 +80,7 @@ pub fn main() -> Result<(), Error> {
8080
#[cfg(feature = "3di")]
8181
convert_pdb,
8282
output,
83-
k_vals,
84-
k_seq,
83+
kmers,
8584
mut sketch_size,
8685
seq_type,
8786
level,
@@ -101,7 +100,7 @@ pub fn main() -> Result<(), Error> {
101100
log::info!("Getting input files");
102101
let input_files = get_input_list(file_list, seq_files);
103102
log::info!("Parsed {} samples in input list", input_files.len());
104-
let kmers = parse_kmers(k_vals, k_seq);
103+
let kmers = parse_kmers(kmers);
105104
// Build, merge
106105
let rc = !*single_strand;
107106
// Set expected sketchsize

0 commit comments

Comments
 (0)