use clap::{Parser, crate_version};
use std::path::{Path, PathBuf};
#[derive(Parser, Debug)]
#[clap(name = "bedpull",
version = concat!("v", crate_version!()),
arg_required_else_help = true,
about = "bedpull - Pull the query sequence from bam or fasta references using a bed file\nhttps://github.com/Psy-Fer/bedpull",
before_help = concat!(r#" __ __ ____"#, "\n",
r#" / /_ ___ ____/ /___ __ __/ / /"#, "\n",
r#" / __ \/ _ \/ __ / __ \/ / / / / / "#, "\n",
r#" / /_/ / __/ /_/ / /_/ / /_/ / / / "#, "\n",
r#" /_.___/\___/\__,_/ .___/\__,_/_/_/ "#, "\n",
r#" /_/ "#, "\n",)
)
]
pub struct Opts {
#[clap(short = 'b', long = "bam", parse(from_os_str), default_value = "None", display_order = 1)]
pub bam: PathBuf,
#[clap(short = 'f', long = "reference", parse(from_os_str), default_value = "None", display_order = 2)]
pub reference: PathBuf,
#[clap(short = 'r', long = "bed", parse(from_os_str), required=true, display_order = 3)]
pub bed: PathBuf,
#[clap(long = "paf", parse(from_os_str), default_value = "None", display_order = 3)]
pub paf: PathBuf,
#[clap(long = "query_ref", parse(from_os_str), default_value = "None", display_order = 3)]
pub query_ref: PathBuf,
#[clap(short = 'o', long = "output", required=true, display_order = 4)]
pub output: PathBuf,
#[clap(long = "use_paf_index", default_value="true", display_order = 8)]
pub use_paf_index: bool,
#[clap(long = "fastq", display_order = 8)]
pub fastq: bool,
}
fn quit_with_error(text: &str) {
eprintln!("\n\nError: {}", text);
std::process::exit(1);
}
fn check_if_file_exists(filename: &PathBuf) {
if !Path::new(filename).exists() {
let error_msg = format!("The file: {:?} does not exist", filename);
quit_with_error(&error_msg);
}
}
pub fn check_inputs_exist(opts: &Opts) {
if opts.bam.to_str() != Some("None") {
check_if_file_exists(&opts.bam);
}
if opts.reference.to_str() != Some("None") {
check_if_file_exists(&opts.reference);
}
if opts.bam.to_str() != Some("None") {
let mut bai = opts.bam.clone();
bai.set_extension("bam.bai");
check_if_file_exists(&bai);
}
if opts.bed.to_str() != Some("None") {
check_if_file_exists(&opts.bed);
}
}
pub fn check_option_values(_opts: &Opts) {
}