use anyhow::{bail, Result};
use redicat_lib::engine::par_granges;
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(Debug, Clone, StructOpt)]
#[structopt(author, name = "bulk")]
pub struct BulkArgs {
pub reads: PathBuf,
#[structopt(long, short = "o")]
pub output: PathBuf,
#[structopt(long, short = "t", default_value = "10")]
pub threads: usize,
#[structopt(long, short = "c", default_value = par_granges::CHUNKSIZE_STR.as_str())]
pub chunksize: u32,
#[structopt(long, short = "Q")]
pub min_baseq: Option<u8>,
#[structopt(long, default_value = "255", short = "q")]
pub mapquality: u8,
#[structopt(long, short = "z")]
pub zero_base: bool,
#[structopt(long, short = "D", default_value = "10000")]
pub max_depth: u32,
#[structopt(long, short = "d", default_value = "5")]
pub min_depth: u32,
#[structopt(long, short = "n", default_value = "10")]
pub max_n_fraction: u32,
#[structopt(long, short = "a")]
pub all: bool,
#[structopt(long = "editing-threshold", short = "et", default_value = "10000")]
pub editing_threshold: u32,
#[structopt(long = "allcontigs", short = "A")]
pub all_contigs: bool,
}
#[derive(Debug, Clone)]
pub struct BulkConfig {
pub reads: PathBuf,
pub output: PathBuf,
pub threads: usize,
pub chunksize: u32,
pub min_baseq: Option<u8>,
pub mapquality: u8,
pub coord_offset: u32,
pub max_depth: u32,
pub min_depth: u32,
pub max_n_fraction: u32,
pub report_all: bool,
pub editing_threshold: u32,
pub all_contigs: bool,
}
impl From<BulkArgs> for BulkConfig {
fn from(args: BulkArgs) -> BulkConfig {
BulkConfig {
reads: args.reads,
output: args.output,
threads: args.threads,
chunksize: args.chunksize,
min_baseq: args.min_baseq,
mapquality: args.mapquality,
coord_offset: if args.zero_base { 0 } else { 1 },
max_depth: args.max_depth,
min_depth: args.min_depth,
max_n_fraction: args.max_n_fraction,
report_all: args.all,
editing_threshold: args.editing_threshold,
all_contigs: args.all_contigs,
}
}
}
impl BulkConfig {
#[inline]
pub fn editing_mode(&self) -> bool {
!self.report_all
}
pub fn validate(&self) -> Result<()> {
if self.editing_threshold == 0 {
bail!("--editing-threshold must be greater than 0");
}
if self.max_n_fraction == 0 {
bail!("--max-n-fraction must be greater than 0");
}
Ok(())
}
}