piscem 0.16.1

Fast, space-efficient k-mer-based read mapper for bulk RNA-seq, scRNA-seq, and scATAC-seq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
use anyhow::{Result, anyhow, bail};
use clap::{ArgGroup, Args};
use std::path::PathBuf;

trait DefaultMappingParams {
    const MAX_EC_CARD: u32;
    const MAX_HIT_OCC: u32;
    const MAX_HIT_OCC_RECOVER: u32;
    const MAX_READ_OCC: u32;
    const SKIPPING_STRATEGY: &'static str;
    const THRESHOLD: f32;
    const BIN_SIZE: u32;
    const BIN_OVERLAP: u32;
    const BCLEN: u16;
    const END_CACHE_CAPACITY: usize;
}

struct DefaultParams;

impl DefaultMappingParams for DefaultParams {
    const MAX_EC_CARD: u32 = 4096;
    const MAX_HIT_OCC: u32 = 256;
    const MAX_HIT_OCC_RECOVER: u32 = 1024;
    const MAX_READ_OCC: u32 = 2500;
    const SKIPPING_STRATEGY: &'static str = "permissive";
    const THRESHOLD: f32 = 0.7;
    const BIN_SIZE: u32 = 1000;
    const BIN_OVERLAP: u32 = 300;
    const BCLEN: u16 = 16;
    const END_CACHE_CAPACITY: usize = 5_000_000;
}

fn klen_is_good(s: &str) -> Result<usize> {
    let k: usize = s
        .parse()
        .map_err(|_| anyhow!("`{s}` can't be parsed as a number"))?;
    if k > 31 {
        bail!("klen = {k} must be <= 31");
    } else if (k & 1) == 0 {
        bail!("klen = {k} must be odd");
    } else {
        Ok(k)
    }
}

#[derive(Args, Clone, Debug)]
#[command(arg_required_else_help = true)]
#[command(group(
    ArgGroup::new("ref-input")
    .required(true)
    .args(&["ref_seqs", "ref_lists", "ref_dirs"]),
))]
pub(crate) struct BuildOpts {
    /// ',' separated list of reference FASTA files
    #[arg(short = 's', long, help_heading = "Input", value_delimiter = ',')]
    pub ref_seqs: Option<Vec<String>>,

    /// ',' separated list of files (each listing input FASTA files)
    #[arg(short = 'l', long, help_heading = "Input", value_delimiter = ',')]
    pub ref_lists: Option<Vec<String>>,

    /// ',' separated list of directories (all FASTA files in each directory will be indexed,
    /// but not recursively).
    #[arg(short = 'd', long, help_heading = "Input", value_delimiter = ',')]
    pub ref_dirs: Option<Vec<String>>,

    /// length of k-mer to use, must be <= 31 and odd
    #[arg(short, long, help_heading = "Index Construction Parameters", default_value_t = 31, value_parser = klen_is_good)]
    pub klen: usize,

    /// length of minimizer to use; must be < `klen`
    #[arg(
        short,
        long,
        help_heading = "Index Construction Parameters",
        default_value_t = 19
    )]
    pub mlen: usize,

    /// number of threads to use
    #[arg(short, long, help_heading = "Index Construction Parameters")]
    pub threads: usize,

    /// output file stem
    #[arg(short, long)]
    pub output: PathBuf,

    /// retain the reduced format GFA files produced by cuttlefish that
    /// describe the reference cDBG (the default is to remove these).
    #[arg(long, help_heading = "Indexing Details")]
    pub keep_intermediate_dbg: bool,

    /// working directory where temporary files should be placed.
    #[arg(short = 'w', long, help_heading = "Indexing Details", default_value_os_t = PathBuf::from("./workdir.noindex"))]
    pub work_dir: PathBuf,

    /// overwite an existing index if the output path is the same.
    #[arg(long, help_heading = "Indexing Details")]
    pub overwrite: bool,

    /// skip the construction of the equivalence class lookup table
    /// when building the index (not recommended).
    #[arg(long, help_heading = "Index Construction Parameters")]
    pub no_ec_table: bool,

    /// If provided (default is not to clip polyA), then reference sequences
    /// ending with polyA tails of length greater than or equal to this value
    /// will be clipped.
    #[arg(long, help_heading = "Index Construction Parameters")]
    pub polya_clip_length: Option<usize>,

    /// path to (optional) ',' sparated list of decoy sequences used to insert poison
    /// k-mer information into the index.
    #[arg(long, value_delimiter = ',')]
    pub decoy_paths: Option<Vec<PathBuf>>,

    /// index construction seed (seed value passed to SSHash index construction; useful if empty
    /// buckets occur).
    #[arg(
        long = "seed",
        help_heading = "Index Construction Parameters",
        default_value_t = 1
    )]
    pub seed: u64,
}

#[derive(Args, Clone, Debug)]
pub(crate) struct MapSCOpts {
    /// input index prefix
    #[arg(short, long, help_heading = "Input")]
    pub index: String,

    /// geometry of barcode, umi and read
    #[arg(short, long)]
    pub geometry: String,

    /// path to a ',' separated list of read 1 files
    #[arg(
        short = '1',
        long,
        help_heading = "Input",
        value_delimiter = ',',
        required = true
    )]
    pub read1: Vec<String>,

    /// path to a ',' separated list of read 2 files
    #[arg(
        short = '2',
        long,
        help_heading = "Input",
        value_delimiter = ',',
        required = true
    )]
    pub read2: Vec<String>,

    /// number of threads to use
    #[arg(short, long, default_value_t = 16)]
    pub threads: usize,

    /// path to output directory
    #[arg(short, long)]
    pub output: PathBuf,

    /// do not consider poison k-mers, even if the underlying index contains them.
    /// In this case, the mapping results will be identical to those obtained as if
    /// no poison table was added to the index.
    #[arg(long)]
    pub no_poison: bool,

    /// apply structural constraints when performing mapping.
    #[arg(short = 'c', long)]
    pub struct_constraints: bool,

    /// the skipping strategy to use for k-mer collection
    #[arg(long, default_value = &DefaultParams::SKIPPING_STRATEGY, value_parser = clap::builder::PossibleValuesParser::new(["permissive", "strict"]))]
    pub skipping_strategy: String,

    /// skip checking of the equivalence classes of k-mers that were too
    /// ambiguous to be otherwise considered (passing this flag can speed up
    /// mapping slightly, but may reduce specificity).
    #[arg(long)]
    pub ignore_ambig_hits: bool,

    /// includes the positions of each mapped read in the resulting RAD file.
    #[arg(long)]
    pub with_position: bool,

    /// determines the maximum cardinality equivalence class
    /// (number of (txp, orientation status) pairs) to examine (cannot be used with
    /// --ignore-ambig-hits).
    #[arg(
        long,
        short,
        default_value_t = DefaultParams::MAX_EC_CARD,
        conflicts_with = "ignore_ambig_hits",
        help_heading = "Advanced options"
    )]
    pub max_ec_card: u32,

    /// in the first pass, consider only k-mers having <= --max-hit-occ hits.
    #[arg(long, default_value_t = DefaultParams::MAX_HIT_OCC, help_heading = "Advanced options")]
    pub max_hit_occ: u32,

    /// if all k-mers have > --max-hit-occ hits, then make a second pass and consider k-mers
    /// having <= --max-hit-occ-recover hits.
    #[arg(long, default_value_t = DefaultParams::MAX_HIT_OCC_RECOVER, help_heading = "Advanced options")]
    pub max_hit_occ_recover: u32,

    /// reads with more than this number of mappings will not have
    /// their mappings reported.
    #[arg(long, default_value_t = DefaultParams::MAX_READ_OCC, help_heading = "Advanced options")]
    pub max_read_occ: u32,
}

#[derive(Args, Clone, Debug)]
#[command(group(
        ArgGroup::new("read_source")
        .required(true)
        .args(["read1", "reads"])
))]
pub(crate) struct MapBulkOpts {
    /// input index prefix
    #[arg(short, long, help_heading = "Input")]
    pub index: String,

    /// path to a comma-separated list of read 1 files
    #[arg(
        short = '1',
        long,
        help_heading = "Input",
        value_delimiter = ',',
        requires = "read2"
    )]
    pub read1: Option<Vec<String>>,

    /// path to a ',' separated list of read 2 files
    #[arg(
        short = '2',
        long,
        help_heading = "Input",
        value_delimiter = ',',
        requires = "read1"
    )]
    pub read2: Option<Vec<String>>,

    /// path to a ',' separated list of read unpaired read files
    #[arg(short = 'r', long, help_heading = "Input", value_delimiter = ',', conflicts_with_all = ["read1", "read2"])]
    pub reads: Option<Vec<String>>,

    /// number of threads to use
    #[arg(short, long, default_value_t = 16)]
    pub threads: usize,

    /// path to output directory
    #[arg(short, long)]
    pub output: PathBuf,

    /// do not consider poison k-mers, even if the underlying index contains them.
    /// In this case, the mapping results will be identical to those obtained as if
    /// no poison table was added to the index.
    #[arg(long)]
    pub no_poison: bool,

    /// apply structural constraints when performing mapping.
    #[arg(short = 'c', long)]
    pub struct_constraints: bool,

    /// skipping strategy to use for k-mer collection
    #[arg(long, default_value = &DefaultParams::SKIPPING_STRATEGY, value_parser = clap::builder::PossibleValuesParser::new(["permissive", "strict"]))]
    pub skipping_strategy: String,

    /// skip checking of the equivalence classes of k-mers that were too
    /// ambiguous to be otherwise considered (passing this flag can speed up
    /// mapping slightly, but may reduce specificity).
    #[arg(long)]
    pub ignore_ambig_hits: bool,

    /// determines the maximum cardinality equivalence class
    /// (number of (txp, orientation status) pairs) to examine (cannot be used with
    /// --ignore-ambig-hits).
    #[arg(
        long,
        short,
        default_value_t = DefaultParams::MAX_EC_CARD,
        conflicts_with = "ignore_ambig_hits",
        help_heading = "Advanced options"
    )]
    pub max_ec_card: u32,

    /// in the first pass, consider only k-mers having <= --max-hit-occ hits.
    #[arg(long, default_value_t = DefaultParams::MAX_HIT_OCC, help_heading = "Advanced options")]
    pub max_hit_occ: u32,

    /// if all k-mers have > --max-hit-occ hits, then make a second pass and consider k-mers
    /// having <= --max-hit-occ-recover hits.
    #[arg(long, default_value_t = DefaultParams::MAX_HIT_OCC_RECOVER, help_heading = "Advanced options")]
    pub max_hit_occ_recover: u32,

    /// reads with more than this number of mappings will not have
    /// their mappings reported.
    #[arg(long, default_value_t = DefaultParams::MAX_READ_OCC, help_heading = "Advanced options")]
    pub max_read_occ: u32,
}


#[derive(Args, Clone, Debug)]
pub(crate) struct MapSCAtacOpts {
    /// input index prefix
    #[arg(short, long, help_heading = "Input")]
    pub index: String,

    /// path to a ',' separated list of read 1 files
    #[arg(
        short = '1',
        long,
        help_heading = "Input",
        value_delimiter = ',',
        requires = "read2"
    )]
    pub read1: Option<Vec<String>>,

    /// path to a ',' separated list of read 2 files
    #[arg(
        short = '2',
        long,
        help_heading = "Input",
        value_delimiter = ',',
        requires = "read1"
    )]
    pub read2: Option<Vec<String>>,

    #[arg(short = 'r', long, help_heading = "Input", value_delimiter = ',', conflicts_with_all = ["read1", "read2"])]
    pub reads: Option<Vec<String>>,

    /// path to a ',' separated list of barcode files
    #[arg(
        short = 'b',
        long,
        help_heading = "Input",
        value_delimiter = ','
    )]
    pub barcode: Option<Vec<String>>,

    /// number of threads to use
    #[arg(short, long, default_value_t = 16)]
    pub threads: usize,

    /// path to output directory
    #[arg(short, long)]
    pub output: PathBuf,

    /// skip checking of the equivalence classes of k-mers that were too
    /// ambiguous to be otherwise considered (passing this flag can speed up
    /// mapping slightly, but may reduce specificity).
    #[arg(long)]
    pub ignore_ambig_hits: bool,

    /// do not consider poison k-mers, even if the underlying index contains them.
    /// In this case, the mapping results will be identical to those obtained as if
    /// no poison table was added to the index.
    #[arg(long)]
    pub no_poison: bool,

    /// [DEPRECATED] apply structural constraints when performing mapping.
    /// This option is no longer supported and will be ignored.
    #[arg(short = 'c', long, hide = true)]
    pub struct_constraints: bool,

    /// the skipping strategy to use for k-mer collection
    #[arg(long, default_value = &DefaultParams::SKIPPING_STRATEGY, value_parser = clap::builder::PossibleValuesParser::new(["permissive", "strict"]))]
    pub skipping_strategy: String,

    /// [DEPRECATED] output mappings in sam format.
    /// This option is no longer supported and will be ignored.
    #[arg(long, hide = true)]
    pub sam_format: bool,

    /// [DEPRECATED] output mappings in bed format.
    /// This option is no longer supported and will be ignored.
    #[arg(long, hide = true)]
    pub bed_format: bool,

    /// [DEPRECATED] use chromosomes as color.
    /// This option is no longer supported and will be ignored.
    #[arg(long, hide = true)]
    pub use_chr: bool,

    /// threshold to be considered for pseudoalignment, default set to 0.7
    #[arg(long, default_value_t = DefaultParams::THRESHOLD)]
    pub thr: f32,

    /// size of virtual color, default set to 1000
    #[arg(long, default_value_t = DefaultParams::BIN_SIZE)]
    pub bin_size: u32,

    /// size for bin overlap, default set to 300
    #[arg(long, default_value_t = DefaultParams::BIN_OVERLAP)]
    pub bin_overlap: u32,

    /// do not apply Tn5 shift to mapped positions
    #[arg(long)]
    pub no_tn5_shift: bool,

    /// [DEPRECATED] Check if any mapping kmer exist for a mate which is not mapped,
    /// but there exists mapping for the other read.
    /// This option is no longer supported and will be ignored.
    #[arg(long, hide = true)]
    pub check_kmer_orphan: bool,

    /// determines the maximum cardinality equivalence class
    /// (number of (txp, orientation status) pairs) to examine (cannot be used with
    /// --ignore-ambig-hits).
    #[arg(
        long,
        short,
        default_value_t = DefaultParams::MAX_EC_CARD,
        conflicts_with = "ignore_ambig_hits",
        help_heading = "Advanced options"
    )]
    pub max_ec_card: u32,

    /// in the first pass, consider only k-mers having <= --max-hit-occ hits.
    #[arg(long, default_value_t = DefaultParams::MAX_HIT_OCC, help_heading = "Advanced options")]
    pub max_hit_occ: u32,

    /// if all k-mers have > --max-hit-occ hits, then make a second pass and consider k-mers
    /// having <= --max-hit-occ-recover hits.
    #[arg(long, default_value_t = DefaultParams::MAX_HIT_OCC_RECOVER, help_heading = "Advanced options")]
    pub max_hit_occ_recover: u32,

    /// reads with more than this number of mappings will not have
    /// their mappings reported.
    #[arg(long, default_value_t = DefaultParams::MAX_READ_OCC, help_heading = "Advanced options")]
    pub max_read_occ: u32,

    /// the length of the barcode sequence
    #[arg(long, default_value_t = DefaultParams::BCLEN, help_heading = "Advanced options")]
    pub bclen: u16,

    /// the capacity of the cache used to provide fast lookup for k-mers at the ends of unitigs
    #[arg(long, default_value_t = DefaultParams::END_CACHE_CAPACITY, help_heading = "Advanced options")]
    pub end_cache_capacity: usize,
}