serrf-cli 0.1.0

Command-line interface for SERRF metabolomics normalization
use clap::{Parser, Subcommand};
use std::path::PathBuf;

#[derive(Parser, Debug)]
#[command(name = "serrf", about = "SERRF metabolomics normalization")]
pub struct Args {
    #[command(subcommand)]
    pub command: Command,

    /// Verbosity: -v for info, -vv for debug
    #[arg(short, long, action = clap::ArgAction::Count, global = true)]
    pub verbose: u8,

    /// Suppress stderr summary
    #[arg(long, global = true)]
    pub quiet: bool,
}

#[derive(Subcommand, Debug)]
pub enum Command {
    /// Normalize an intensity matrix using SERRF
    Normalize(NormalizeArgs),
}

#[derive(clap::Args, Debug)]
pub struct NormalizeArgs {
    /// Path to intensity CSV (compounds as rows, samples as columns)
    #[arg(long)]
    pub intensities: PathBuf,

    /// Path to metadata CSV (sample_id, sample_type, batch, injection_order)
    #[arg(long)]
    pub metadata: PathBuf,

    /// Output path for normalized CSV
    #[arg(long)]
    pub output: PathBuf,

    /// Output path for JSON report
    #[arg(long)]
    pub report: PathBuf,

    /// Number of trees in each random forest
    #[arg(long, default_value = "500")]
    pub trees: usize,

    /// Maximum tree depth (omit for unlimited)
    #[arg(long)]
    pub max_depth: Option<usize>,

    /// Minimum samples per leaf node
    #[arg(long, default_value = "1")]
    pub min_samples_leaf: usize,

    /// Fraction of QC samples held out as validation (when no explicit validate samples)
    #[arg(long, default_value = "0.2")]
    pub qc_validation_fraction: f64,

    /// Random seed for reproducibility
    #[arg(long, default_value = "42")]
    pub seed: u64,

    /// Minimum fraction of QC samples that must be non-missing per compound
    #[arg(long, default_value = "0.6")]
    pub min_qc_non_missing_fraction: f64,

    /// Near-zero threshold for predictions and anchors
    #[arg(long, default_value = "1e-12")]
    pub epsilon: f64,

    /// Include other compound intensities as predictors (slower, opt-in)
    #[arg(long, default_value = "false")]
    pub use_correlated_compounds: bool,

    /// Train RF on log-transformed intensities (recommended for log-normal data)
    #[arg(long, default_value = "false")]
    pub log_space: bool,
}