use anyhow::ensure;
use clap::Args;
use log::info;
use serde::Serialize;
use std::path::PathBuf;
use crate::cli::core::{check_optional_filename, check_required_filename, AFTER_HELP, FULL_VERSION};
use crate::parsing::noodles_helper::get_vcf_sample_name;
#[derive(Args, Clone, Default, Serialize)]
#[clap(author, about,
after_help = &**AFTER_HELP
)]
pub struct CompareSettings {
#[clap(default_value = "")]
#[clap(hide = true)]
aardvark_version: String,
#[clap(required = true)]
#[clap(short = 'r')]
#[clap(long = "reference")]
#[clap(value_name = "FASTA")]
#[clap(help_heading = Some("Input/Output"))]
pub reference_fn: PathBuf,
#[clap(required = true)]
#[clap(short = 't')]
#[clap(long = "truth-vcf")]
#[clap(value_name = "VCF")]
#[clap(help_heading = Some("Input/Output"))]
pub truth_vcf_filename: PathBuf,
#[clap(required = true)]
#[clap(short = 'q')]
#[clap(long = "query-vcf")]
#[clap(value_name = "VCF")]
#[clap(help_heading = Some("Input/Output"))]
pub query_vcf_filename: PathBuf,
#[clap(short = 'b')]
#[clap(long = "regions")]
#[clap(value_name = "BED")]
#[clap(help_heading = Some("Input/Output"))]
pub regions: Option<PathBuf>,
#[clap(short = 's')]
#[clap(long = "stratification")]
#[clap(value_name = "TSV")]
#[clap(help_heading = Some("Input/Output"))]
pub stratifications: Option<PathBuf>,
#[clap(required = true)]
#[clap(short = 'o')]
#[clap(long = "output-dir")]
#[clap(value_name = "DIR")]
#[clap(help_heading = Some("Input/Output"))]
pub output_folder: PathBuf,
#[clap(long = "output-debug")]
#[clap(value_name = "DIR")]
#[clap(help_heading = Some("Input/Output"))]
pub debug_folder: Option<PathBuf>,
#[clap(long = "compare-label")]
#[clap(value_name = "LABEL")]
#[clap(help_heading = Some("Input/Output"))]
#[clap(default_value = "compare")]
pub compare_label: String,
#[clap(long = "truth-sample")]
#[clap(value_name = "SAMPLE")]
#[clap(help_heading = Some("Input/Output"))]
#[clap(default_value = "", hide_default_value = true)]
pub truth_sample: String,
#[clap(long = "query-sample")]
#[clap(value_name = "SAMPLE")]
#[clap(help_heading = Some("Input/Output"))]
#[clap(default_value = "", hide_default_value = true)]
pub query_sample: String,
#[clap(long = "min-variant-gap")]
#[clap(value_name = "BP")]
#[clap(help_heading = Some("Region generation"))]
#[clap(default_value = "50")]
pub min_variant_gap: usize,
#[clap(long = "disable-variant-trimming")]
#[clap(help_heading = Some("Region generation"))]
pub disable_variant_trimming: bool,
#[clap(long = "max-edit-distance")]
#[clap(value_name = "INT")]
#[clap(help_heading = Some("Compare parameters"))]
#[clap(default_value = "5000")]
#[clap(hide = true)] pub max_edit_distance: usize,
#[clap(long = "max-branch-factor")]
#[clap(value_name = "INT")]
#[clap(help_heading = Some("Compare parameters"))]
#[clap(default_value = "50")]
pub max_branch_factor: usize,
#[clap(long = "enable-exact-shortcut")]
#[clap(help_heading = Some("Compare parameters"))]
#[clap(hide = true)] pub enable_exact_shortcut: bool,
#[clap(long = "enable-haplotype-metrics")]
#[clap(help_heading = Some("Optional metrics"))]
#[clap(default_value = "false")]
pub enable_haplotype_scoring: bool,
#[clap(long = "enable-weighted-haplotype-metrics")]
#[clap(help_heading = Some("Optional metrics"))]
#[clap(default_value = "false")]
pub enable_weighted_haplotype_scoring: bool,
#[clap(long = "enable-record-basepair-metrics")]
#[clap(help_heading = Some("Optional metrics"))]
#[clap(default_value = "false")]
pub enable_record_basepair_scoring: bool,
#[clap(long = "threads")]
#[clap(value_name = "THREADS")]
#[clap(default_value = "1")]
pub threads: usize,
#[clap(short = 'v')]
#[clap(long = "verbose")]
#[clap(action = clap::ArgAction::Count)]
pub verbosity: u8,
#[clap(hide = true)]
#[clap(long = "skip")]
#[clap(default_value = "0")]
pub skip_blocks: usize,
#[clap(hide = true)]
#[clap(long = "take")]
#[clap(default_value = "0")]
pub take_blocks: usize,
}
pub fn check_compare_settings(mut settings: CompareSettings) -> anyhow::Result<CompareSettings> {
settings.aardvark_version = FULL_VERSION.clone();
info!("Aardvark version: {:?}", &settings.aardvark_version);
info!("Sub-command: compare");
info!("Inputs:");
check_required_filename(&settings.reference_fn, "Reference FASTA")?;
check_required_filename(&settings.truth_vcf_filename, "Truth VCF")?;
check_required_filename(&settings.query_vcf_filename, "Query VCF")?;
check_optional_filename(settings.regions.as_deref(), "Regions")?;
check_optional_filename(settings.stratifications.as_deref(), "Stratifications")?;
info!("\tReference: {:?}", &settings.reference_fn);
info!("\tTruth VCF: {:?}", &settings.truth_vcf_filename);
if settings.truth_sample.is_empty() {
settings.truth_sample = get_vcf_sample_name(&settings.truth_vcf_filename, 0)?;
}
info!("\tTruth sample: {:?}", &settings.truth_sample);
info!("\tQuery VCF: {:?}", &settings.query_vcf_filename);
if settings.query_sample.is_empty() {
settings.query_sample = get_vcf_sample_name(&settings.query_vcf_filename, 0)?;
}
info!("\tQuery sample: {:?}", &settings.query_sample);
if let Some(hcr_fn) = settings.regions.as_deref() {
info!("\tRegions: {hcr_fn:?}");
} else {
info!("\tRegions: None");
}
if let Some(filename) = settings.stratifications.as_deref() {
info!("\tStratifications: {filename:?}");
} else {
info!("\tStratifications: None");
}
if settings.enable_haplotype_scoring || settings.enable_weighted_haplotype_scoring || settings.enable_record_basepair_scoring {
info!("Optional metrics:");
info!("\tHaplotype scoring: {}", if settings.enable_haplotype_scoring { "ENABLED" } else { "DISABLED" });
info!("\tWeighted haplotype scoring: {}", if settings.enable_weighted_haplotype_scoring { "ENABLED" } else { "DISABLED" });
info!("\tRecord-basepair scoring: {}", if settings.enable_record_basepair_scoring { "ENABLED" } else { "DISABLED" });
}
if settings.take_blocks == 0 {
settings.take_blocks = usize::MAX;
}
info!("Outputs:");
info!("\tCompare label: {:?}", &settings.compare_label);
info!("\tOutput folder: {:?}", &settings.output_folder);
if let Some(debug_folder) = settings.debug_folder.as_ref() {
info!("\tDebug folder: {debug_folder:?}");
}
info!("Region generation parameters:");
ensure!(settings.min_variant_gap > 0, "--min-variant-gap must be >0");
info!("\tMinimum variant gap: {}", settings.min_variant_gap);
info!("\tVariant trimming: {}", if settings.disable_variant_trimming { "DISABLED "} else { "ENABLED" });
info!("Compare parameters:");
ensure!(settings.max_branch_factor > 0, "--max-branch-factor must be >0");
info!("\tMax branch factor: {}", settings.max_branch_factor);
if settings.enable_exact_shortcut {
info!("\tExact match shortcut: {}", if settings.enable_exact_shortcut { "ENABLED" } else { "DISABLED" });
}
if settings.threads == 0 {
settings.threads = 1;
}
info!("Processing threads: {}", settings.threads);
Ok(settings)
}