Skip to main content

cyto_cli/map/
options.rs

1use clap::Parser;
2
3use crate::map::{GEOMETRY_CRISPR_FLEX_V2, GEOMETRY_GEX_FLEX_V2};
4
5use super::{GEOMETRY_CRISPR_FLEX_V1, GEOMETRY_CRISPR_PROPERSEQ, GEOMETRY_GEX_FLEX_V1};
6
7#[derive(Parser, Debug)]
8#[clap(next_help_heading = "Mapping Options")]
9pub struct MapOptions {
10    /// Custom Geometry DSL string
11    ///
12    /// If unsure, try a preset first.
13    #[clap(short = 'g', long)]
14    pub geometry: Option<String>,
15
16    /// Geometry Preset
17    ///
18    /// Required unless a custom geometry is provided.
19    #[clap(long)]
20    pub preset: Option<GeometryPreset>,
21
22    /// Remap window size for position adjustment (0 to disable)
23    ///
24    /// This is the position window size for remapping an element (+/-) on failed match
25    ///
26    /// If preset to a v2 condition this is ignored and set to 5
27    #[clap(long, default_value = "1", conflicts_with = "preset")]
28    remap_window: usize,
29
30    /// Use exact matching (no hamming distance correction)
31    #[clap(short = 'x', long)]
32    pub exact: bool,
33
34    /// Skip UMI quality check
35    #[clap(long)]
36    pub no_umi_qual_check: bool,
37
38    #[clap(flatten)]
39    whitelist: WhitelistOptions,
40
41    #[clap(flatten)]
42    probe: ProbeOptions,
43}
44impl MapOptions {
45    pub fn remap_window(&self) -> usize {
46        match self.preset {
47            Some(GeometryPreset::GexV2 | GeometryPreset::CrisprV2) => 5,
48            _ => self.remap_window,
49        }
50    }
51
52    pub fn probe_regex(&self) -> Option<&str> {
53        self.probe.probe_regex.as_deref()
54    }
55
56    pub fn probe_path(&self) -> Option<&str> {
57        self.probe.probes.as_deref()
58    }
59
60    pub fn whitelist_path(&self) -> &str {
61        &self.whitelist.whitelist
62    }
63}
64
65#[derive(Parser, Debug)]
66#[clap(next_help_heading = "Probe Options")]
67pub struct ProbeOptions {
68    /// Path to probe file
69    #[clap(short = 'p', long)]
70    pub probes: Option<String>,
71
72    /// Regex pattern for probe alias
73    ///
74    /// Used to select/filter probes that are known to be in the dataset
75    #[clap(long)]
76    pub probe_regex: Option<String>,
77}
78
79#[derive(Parser, Debug)]
80#[clap(next_help_heading = "Whitelist Options")]
81pub struct WhitelistOptions {
82    /// Path to whitelist file
83    #[clap(short = 'w', long)]
84    pub whitelist: String,
85}
86
87#[derive(clap::ValueEnum, Clone, Copy, Debug)]
88pub enum GeometryPreset {
89    /// [barcode][umi:12]|[gex][:18][probe]
90    GexV1,
91    /// [barcode][umi:12][:10][probe]|[gex]
92    GexV2,
93    /// [barcode][umi:12]|[probe][anchor][protospacer]
94    CrisprV1,
95    /// [barcode][umi:12][:10][probe]|[:14][anchor][protospacer]
96    CrisprV2,
97    /// [barcode][umi:12]|[:18][probe][anchor][protospacer]
98    CrisprProper,
99}
100impl GeometryPreset {
101    pub fn into_geometry_str(&self) -> &str {
102        match self {
103            Self::GexV1 => GEOMETRY_GEX_FLEX_V1,
104            Self::GexV2 => GEOMETRY_GEX_FLEX_V2,
105            Self::CrisprV1 => GEOMETRY_CRISPR_FLEX_V1,
106            Self::CrisprV2 => GEOMETRY_CRISPR_FLEX_V2,
107            Self::CrisprProper => GEOMETRY_CRISPR_PROPERSEQ,
108        }
109    }
110}