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)]
58#[allow(clippy::large_enum_variant)]
59pub enum Commands {
60 /// Identify the reference genome used in a BAM/SAM file
61 Identify(identify::IdentifyArgs),
62
63 /// Compare two headers or references
64 Compare(compare::CompareArgs),
65
66 /// Score a query file against a reference file directly (no catalog).
67 /// By default, scoring is asymmetric: it measures how well the query
68 /// matches the reference. Use --symmetric to compute both directions.
69 Score(score::ScoreArgs),
70
71 /// Manage the reference catalog
72 Catalog(catalog::CatalogArgs),
73
74 /// Start the web server
75 Serve(ServeArgs),
76}
77
78#[derive(clap::Args)]
79pub struct ServeArgs {
80 /// Port to listen on
81 #[arg(short, long, default_value = "8080")]
82 pub port: u16,
83
84 /// Address to bind to
85 #[arg(short, long, default_value = "127.0.0.1")]
86 pub address: String,
87
88 /// Open browser automatically
89 #[arg(long)]
90 pub open: bool,
91
92 /// Refget server URL for looking up unknown contigs.
93 /// Defaults to EBI's ENA CRAM endpoint. Use --no-refget to disable.
94 #[arg(long, default_value = crate::refget::DEFAULT_REFGET_SERVER)]
95 pub refget_server: String,
96
97 /// Disable refget lookups for unmatched contigs
98 #[arg(long)]
99 pub no_refget: bool,
100}
101
102#[derive(Clone, Copy, Debug, clap::ValueEnum)]
103pub enum OutputFormat {
104 Text,
105 Json,
106 Tsv,
107}