Skip to main content

jam_rs/
lib.rs

1pub mod bias;
2pub mod cli;
3pub mod core_utils;
4pub mod format;
5pub mod io;
6pub mod query;
7pub mod reader;
8pub mod sketch;
9pub mod writer;
10pub use cli::handlers::{
11    handle_bias_create_command, handle_bias_stats_command, handle_distance_command,
12    handle_sketch_command, handle_stats_command,
13};
14pub use io::{expand_input_paths, is_sequence_file};
15pub use jamhash::jamhash_u64;
16
17use anyhow::Result;
18use clap::Parser;
19use cli::{BiasCommands, Cli, Commands};
20
21pub fn run() -> Result<()> {
22    let cli = Cli::parse();
23
24    if let Some(threads) = cli.threads {
25        rayon::ThreadPoolBuilder::new()
26            .num_threads(threads)
27            .stack_size(8 * 1024 * 1024)
28            .build_global()?;
29    }
30
31    match cli.command {
32        Commands::Sketch {
33            input,
34            output,
35            kmer_size,
36            fscale,
37            complexity,
38            singleton,
39            temp_dir,
40            bias_table,
41        } => {
42            let expanded_inputs = expand_input_paths(&input)?;
43            handle_sketch_command(
44                expanded_inputs,
45                output,
46                kmer_size,
47                fscale,
48                singleton,
49                cli.threads.unwrap_or(1),
50                cli.memory.unwrap_or(2),
51                cli.force,
52                cli.silent,
53                complexity,
54                temp_dir,
55                bias_table,
56            )
57        }
58
59        Commands::Bias { command } => match command {
60            BiasCommands::Create {
61                positive,
62                negative,
63                output,
64                kmer_size,
65                fscale,
66                cms_width,
67                cms_depth,
68                alpha,
69                fold_enrichment,
70                threads,
71            } => handle_bias_create_command(
72                positive,
73                negative,
74                output,
75                kmer_size,
76                fscale,
77                cms_width,
78                cms_depth,
79                alpha,
80                fold_enrichment,
81                threads.or(cli.threads),
82                cli.force,
83                cli.silent,
84            ),
85            BiasCommands::Stats { input, output } => {
86                handle_bias_stats_command(input, output, cli.silent)
87            }
88        },
89
90        Commands::Dist {
91            input,
92            database,
93            output,
94            cutoff,
95            singleton,
96        } => handle_distance_command(input, database, output, cutoff, singleton, cli.silent),
97
98        Commands::Stats { input, short, full } => {
99            handle_stats_command(input, short, full, cli.silent)
100        }
101    }
102}