barkit/
lib.rs

1use clap::{command, ArgAction, Parser, Subcommand};
2
3#[derive(Parser, Debug)]
4#[command(version, about, long_about = None)]
5pub struct Args {
6    #[command(subcommand)]
7    pub command: Commands,
8
9    /// Max RAM usage in megabytes
10    #[arg(short = 'm', long)]
11    pub max_memory: Option<usize>,
12
13    /// The approximate number of threads to use.
14    #[arg(short = 't', long, default_value = "1", global = true)]
15    pub threads: usize,
16
17    /// Be quiet and do not show extra information
18    #[arg(long, action = ArgAction::SetTrue, global = true)]
19    pub quiet: bool,
20
21    /// Overwrite output files
22    #[arg(short = 'f', long, action = ArgAction::SetTrue, global = true)]
23    pub force: bool,
24}
25
26#[derive(Subcommand, Debug)]
27pub enum Commands {
28    /// Extract barcode nucleotide sequence according to a specified regex pattern
29    #[clap(arg_required_else_help = true)]
30    Extract {
31        #[clap(flatten)]
32        input_fastqs: InputsGroup,
33
34        #[clap(flatten)]
35        output_fastqs: OutputsGroup,
36
37        #[clap(flatten)]
38        patterns: PatternsGroup,
39
40        #[clap(flatten)]
41        compression: CompressionGroup,
42
43        #[clap(flatten)]
44        additional_params: AdditionalParamsGroup,
45    },
46}
47
48#[derive(Debug, clap::Args)]
49pub struct InputsGroup {
50    /// Input forward FASTQ file
51    #[arg(short = '1', long, value_name = "IN_FASTQ1", requires = "out_fq1")]
52    pub fq1: String,
53
54    /// Input reverse FASTQ file
55    #[arg(short = '2', long, value_name = "IN_FASTQ2", requires_all = ["fq1", "out_fq2"])]
56    pub fq2: Option<String>,
57}
58
59#[derive(Debug, clap::Args)]
60pub struct OutputsGroup {
61    /// Output forward FASTQ file
62    #[arg(short = 'o', long, value_name = "OUT_FASTQ1")]
63    pub out_fq1: String,
64
65    /// Output reverse FASTQ file
66    #[arg(short = 'O', long, value_name = "OUT_FASTQ2", requires = "out_fq1")]
67    pub out_fq2: Option<String>,
68}
69
70#[derive(Debug, clap::Args)]
71#[group(required = true, multiple = true)]
72pub struct PatternsGroup {
73    /// Barcode pattern of forward reads
74    #[arg(short = 'p', long, requires = "fq1")]
75    pub pattern1: Option<String>,
76
77    /// Barcode pattern of reverse reads
78    #[arg(short = 'P', long, requires = "fq2")]
79    pub pattern2: Option<String>,
80}
81
82#[derive(Debug, clap::Args)]
83pub struct CompressionGroup {
84    /// Compress outputs in gzip format
85    #[arg(long, action = ArgAction::SetTrue, conflicts_with_all = ["bgz", "mgz", "lz4"])]
86    pub gz: bool,
87
88    /// Compress outputs in bgzf (bgzip) format
89    #[arg(long, action = ArgAction::SetTrue, conflicts_with_all = ["gz", "mgz", "lz4"])]
90    pub bgz: bool,
91
92    /// Compress outputs in mgzip format
93    #[arg(long, action = ArgAction::SetTrue, conflicts_with_all = ["gz", "bgz", "lz4"])]
94    pub mgz: bool,
95
96    /// Compress outputs in lz4 format
97    #[arg(long, action = ArgAction::SetTrue, conflicts_with_all = ["gz", "bgz", "mgz"])]
98    pub lz4: bool,
99}
100
101#[derive(Debug, clap::Args)]
102pub struct AdditionalParamsGroup {
103    /// Searches for both barcode pattern in reverse complement
104    #[arg(short = 'r', long, action=ArgAction::SetTrue)]
105    pub rc_barcodes: bool,
106
107    /// Skip trimming the adapter sequence from the read
108    #[arg(short = 's', long, action=ArgAction::SetTrue)]
109    pub skip_trimming: bool,
110
111    /// Max error (mismatch) between provided pattern and read sequence
112    #[arg(short = 'e', long, default_value = "1")]
113    pub max_error: usize,
114}