Skip to main content

ref_solver/cli/
mod.rs

1//! Command-line interface for ref-solver.
2//!
3//! This module implements the CLI using clap. Available commands:
4//!
5//! - **identify**: Identify the reference genome from a BAM/SAM/CRAM file
6//! - **compare**: Compare two headers or a header against a known reference
7//! - **catalog**: List, show, or export references from the catalog
8//! - **serve**: Start the interactive web interface
9//!
10//! ## Usage
11//!
12//! ```text
13//! # Identify reference from a BAM file
14//! ref-solver identify sample.bam
15//!
16//! # Pipe from samtools
17//! samtools view -H sample.bam | ref-solver identify -
18//!
19//! # JSON output for scripting
20//! ref-solver identify sample.bam --format json
21//!
22//! # Compare against a known reference
23//! ref-solver compare sample.bam hg38_ucsc --reference
24//!
25//! # Start web UI
26//! ref-solver serve --port 8080 --open
27//! ```
28
29use clap::{Parser, Subcommand};
30
31pub mod catalog;
32pub mod compare;
33pub mod identify;
34pub mod score;
35
36#[derive(Parser)]
37#[command(name = "ref-solver")]
38#[command(author = "Fulcrum Genomics")]
39#[command(version)]
40#[command(about = "Identify and match reference genomes from BAM/SAM headers")]
41#[command(
42    long_about = "ref-solver helps you identify which reference genome was used to align a BAM/SAM/CRAM file.\n\nIt matches the sequence dictionary from your file against a catalog of known human reference genomes and provides:\n- Exact matches when possible\n- Detailed diagnostics when differences exist\n- Actionable suggestions for fixing mismatches (renaming, reordering)"
43)]
44pub struct Cli {
45    #[command(subcommand)]
46    pub command: Commands,
47
48    /// Enable verbose output
49    #[arg(short, long, global = true)]
50    pub verbose: bool,
51
52    /// Output format
53    #[arg(short, long, global = true, default_value = "text")]
54    pub format: OutputFormat,
55}
56
57#[derive(Subcommand)]
58pub enum Commands {
59    /// Identify the reference genome used in a BAM/SAM file
60    Identify(identify::IdentifyArgs),
61
62    /// Compare two headers or references
63    Compare(compare::CompareArgs),
64
65    /// Score a query file against a reference file directly (no catalog).
66    /// By default, scoring is asymmetric: it measures how well the query
67    /// matches the reference. Use --symmetric to compute both directions.
68    Score(score::ScoreArgs),
69
70    /// Manage the reference catalog
71    Catalog(catalog::CatalogArgs),
72
73    /// Start the web server
74    Serve(ServeArgs),
75}
76
77#[derive(clap::Args)]
78pub struct ServeArgs {
79    /// Port to listen on
80    #[arg(short, long, default_value = "8080")]
81    pub port: u16,
82
83    /// Address to bind to
84    #[arg(short, long, default_value = "127.0.0.1")]
85    pub address: String,
86
87    /// Open browser automatically
88    #[arg(long)]
89    pub open: bool,
90}
91
92#[derive(Clone, Copy, Debug, clap::ValueEnum)]
93pub enum OutputFormat {
94    Text,
95    Json,
96    Tsv,
97}