Skip to main content

fibertools_rs/cli/
pg_pansn_opts.rs

1use crate::utils::input_bam::InputBam;
2use clap::Args;
3use std::fmt::Debug;
4
5#[derive(Args, Debug, Clone)]
6pub struct PansnParameters {
7    /// panSN-spec prefix to add to contig names (e.g., "HG002#1#")
8    /// If provided, adds the prefix. Mutually exclusive with --strip
9    #[clap(short, long, conflicts_with = "strip")]
10    pub prefix: Option<String>,
11    /// Strip panSN-spec information from contig names
12    /// Mutually exclusive with --prefix
13    #[clap(long, conflicts_with = "prefix")]
14    pub strip: bool,
15    /// Delimiter character to use when stripping panSN-spec (default: '#')
16    #[clap(short, long, default_value = "#", requires = "strip")]
17    pub delimiter: char,
18    /// Tag to identify haplotype 1 contigs (e.g., "haplotype1")
19    /// If both hap1-tag and hap2-tag are provided, reads will be tagged with HP based on contig names
20    #[clap(short = '1', long = "hap1-tag")]
21    pub hap1_tag: Option<String>,
22    /// Tag to identify haplotype 2 contigs (e.g., "haplotype2")
23    /// If both hap1-tag and hap2-tag are provided, reads will be tagged with HP based on contig names
24    #[clap(short = '2', long = "hap2-tag")]
25    pub hap2_tag: Option<String>,
26    /// The mapping quality must be greater than or equal to this value for haplotag assignment
27    #[clap(short = 'q', long = "min-mapq", default_value = "0")]
28    pub min_mapq: u8,
29    /// BAM file to copy header from (excluding SQ and HD tags)
30    #[clap(short = 'c', long = "copy-header")]
31    pub copy_header: Option<String>,
32}
33
34impl Default for PansnParameters {
35    fn default() -> Self {
36        Self {
37            prefix: None,
38            strip: false,
39            delimiter: '#',
40            hap1_tag: None,
41            hap2_tag: None,
42            min_mapq: 0,
43            copy_header: None,
44        }
45    }
46}
47
48impl PansnParameters {
49    /// Check if any panSN operation is specified in the parameters
50    pub fn has_operations(&self) -> bool {
51        let has_panspec_operation = self.prefix.is_some() || self.strip;
52        let has_haplotag_operation = self.hap1_tag.is_some() && self.hap2_tag.is_some();
53        let has_copy_header_operation = self.copy_header.is_some();
54
55        has_panspec_operation || has_haplotag_operation || has_copy_header_operation
56    }
57}
58
59#[derive(Args, Debug)]
60pub struct PgPansnOptions {
61    #[clap(flatten)]
62    pub input: InputBam,
63    /// Output BAM file
64    #[clap(default_value = "-")]
65    pub out: String,
66    /// Additionally write the output BAM header to this file
67    #[clap(long)]
68    pub header_out: Option<String>,
69    #[clap(flatten)]
70    pub pansn: PansnParameters,
71}