use std::path::PathBuf;
use structopt::StructOpt;
#[derive(Debug, Clone, StructOpt)]
#[structopt(name = "bam2mtx", about = "Convert BAM files to single-cell matrices")]
pub struct Bam2MtxArgs {
#[structopt(short, long, parse(from_os_str))]
pub bam: PathBuf,
#[structopt(long, parse(from_os_str))]
pub tsv: Option<PathBuf>,
#[structopt(long, parse(from_os_str))]
pub barcodes: PathBuf,
#[structopt(long)]
pub two_pass: bool,
#[structopt(short, long, parse(from_os_str))]
pub output: PathBuf,
#[structopt(short, long, default_value = "20")]
pub threads: usize,
#[structopt(long, default_value = "255", short = "q")]
pub min_mapq: u8,
#[structopt(long, default_value = "30", short = "Q")]
pub min_baseq: u8,
#[structopt(long, short = "S")]
pub stranded: bool,
#[structopt(long = "max-depth", default_value = "65536", short = "D")]
pub max_depth: u32,
#[structopt(long, default_value = "UB")]
pub umi_tag: String,
#[structopt(long, default_value = "CB")]
pub cb_tag: String,
#[structopt(long, parse(from_os_str), short = "r")]
pub reference: Option<PathBuf>,
#[structopt(long, default_value = "100000", short = "c")]
pub chunksize: u32,
#[structopt(long = "chunk-size-max-depth", default_value = "2")]
pub chunk_size_max_depth: u32,
#[structopt(long, default_value = "0.005")]
pub matrix_density: f64,
#[structopt(long = "allcontigs", short = "A")]
pub all_contigs: bool,
}
impl Bam2MtxArgs {
#[inline]
pub fn chunk_size(&self) -> usize {
usize::max(self.chunksize as usize, 1)
}
#[inline]
pub fn chunk_size_max_depth(&self) -> usize {
usize::max(self.chunk_size_max_depth as usize, 1)
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;
#[test]
fn parses_minimal_arguments() {
let args = Bam2MtxArgs::from_iter_safe(&[
"bam2mtx",
"--bam",
"test.bam",
"--tsv",
"test.tsv",
"--barcodes",
"barcodes.tsv",
"--output",
"output.h5ad",
])
.unwrap();
assert_eq!(args.bam, PathBuf::from("test.bam"));
assert_eq!(args.tsv, Some(PathBuf::from("test.tsv")));
assert_eq!(args.barcodes, PathBuf::from("barcodes.tsv"));
assert_eq!(args.output, PathBuf::from("output.h5ad"));
assert_eq!(args.max_depth, 655_36);
assert_eq!(args.chunk_size_max_depth, 2);
assert!(!args.two_pass);
}
}