Skip to main content

rustalign_cli/
build.rs

1//! rustalign-build - Build FM-index from reference
2
3use anyhow::Result;
4use clap::Parser;
5use rustalign_io::FastaReader;
6
7/// RustAlign index building options
8#[derive(Debug, Parser)]
9pub struct BuildOptions {
10    /// Input reference FASTA file(s)
11    #[clap(required = true, num_args = 1..)]
12    pub references: Vec<String>,
13
14    /// Output index basename
15    #[clap(required = true)]
16    pub index_base: String,
17
18    /// Build large index (for references > 4 billion nucleotides)
19    #[clap(short = 'l', long)]
20    pub large: bool,
21
22    /// Number of threads
23    #[clap(short = 'p', long, default_value = "1")]
24    pub threads: usize,
25}
26
27/// Run the rustalign-build tool
28pub fn run_with_options(opts: BuildOptions) -> Result<()> {
29    run_with_opts(opts)
30}
31
32/// Run the rustalign-build tool (legacy - parses args)
33pub fn run() -> Result<()> {
34    let opts = BuildOptions::parse();
35    run_with_options(opts)
36}
37
38#[allow(dead_code)]
39fn main() -> Result<()> {
40    run()
41}
42
43fn run_with_opts(opts: BuildOptions) -> Result<()> {
44    eprintln!("Building index from {:?}", opts.references);
45    eprintln!("Output: {}", opts.index_base);
46
47    // Read reference sequences
48    let mut total_length = 0u64;
49    for ref_file in &opts.references {
50        let reader = FastaReader::from_path(ref_file)?;
51        for record in reader {
52            let record = record?;
53            total_length += record.len() as u64;
54            eprintln!("  Loaded: {} ({} bp)", record.id, record.len());
55        }
56    }
57
58    eprintln!("Total reference length: {} bp", total_length);
59    eprintln!("Building FM-index...");
60
61    // TODO: Build FM-index
62    eprintln!("Index building not yet implemented");
63
64    Ok(())
65}