bigsig 0.1.0

Large-scale Sequence Search with BItsliced Genomic Signature Index (BIGSIG)
Documentation
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
extern crate bigsig;
extern crate rayon;
#[macro_use]
extern crate clap;
extern crate env_logger;

use clap::{App, AppSettings, Arg, SubCommand};
use bigsig::bigsi;
use bigsig::build;
use bigsig::read_id_mt_pe::false_prob;
use std::alloc::System;
use std::time::SystemTime;
use rayon::ThreadPoolBuilder;
use env_logger::Builder;

pub fn init_log() -> u64 {
    Builder::from_default_env().init();
    println!("\n ************** initializing logger *****************\n");
    1
}

#[global_allocator]
static GLOBAL: System = System;

fn main() -> std::io::Result<()> {
    let _ = init_log();
    let matches = App::new("bigsig")
        .version("0.1.0")
        .about("Large-scale Sequence Search with BItsliced Genomic Signature Index (BIGSIG)")
        .setting(AppSettings::ArgRequiredElseHelp)
        .subcommand(
            SubCommand::with_name("construct")
                .about("Construct a BIGSIG")
                .version("0.1.0")
                .setting(AppSettings::ArgRequiredElseHelp)
                .arg(
                    Arg::with_name("bigsi")
                        .short("b")
                        .long("bigsi")
                        .required(true)
                        .takes_value(true),
                )
                .arg(
                    Arg::with_name("ref_file")
                        .help("Sets the input file to use")
                        .required(true)
                        .short("r")
                        .takes_value(true)
                        .long("refs"),
                )
                .arg(
                    Arg::with_name("k-mer_size")
                        .help("Sets k-mer size")
                        .required(true)
                        .short("k")
                        .takes_value(true)
                        .long("kmer"),
                )
                .arg(
                    Arg::with_name("num_hashes")
                        .help("Sets number of hashes for bloom filter")
                        .required(true)
                        .short("n")
                        .takes_value(true)
                        .long("num_hashes"),
                )
                .arg(
                    Arg::with_name("length_bloom")
                        .help("Sets the length of the bloom filter")
                        .required(true)
                        .short("s")
                        .takes_value(true)
                        .long("bloom"),
                )
                .arg(
                    Arg::with_name("minimizer")
                        .help("build index with minimizers, default length minimizer is 15, unless indicated otherwise")
                        .required(false)
                        .short("m")
                        .takes_value(false)
                        .long("minimizer"),
                )
                .arg(
                    Arg::with_name("value")
                        .help("sets length minimizer (default 15)")
                        .required(false)
                        .short("v")
                        .default_value("15")
                        .takes_value(true)
                        .long("value"),
                )
                .arg(
                    Arg::with_name("threads")
                        .help("number of threads to use, if not set one thread will be used")
                        .required(false)
                        .short("t")
                        .takes_value(true)
                        .long("threads"),
                )
                .arg(
                    Arg::with_name("quality")
                        .help("minimum phred score to keep basepairs within read (default 15)")
                        .required(false)
                        .short("Q")
                        .takes_value(true)
                        .long("quality"),
                )
                .arg(
                    Arg::with_name("filter")
                        .help("minimum coverage kmer threshold (default automatically detected)")
                        .required(false)
                        .short("f")
                        .takes_value(true)
                        .long("filter"),
                        ),
        )
        .subcommand(
            SubCommand::with_name("query")
                .about("query a bigsig on one or more fasta/fastq.gz files")
                .version("0.1.0")
                .setting(AppSettings::ArgRequiredElseHelp)
                .arg(
                    Arg::with_name("bigsi")
                        .help("Sets the name of the index file for search")
                        .short("b")
                        .long("bigsi")
                        .required(true)
                        .takes_value(true),
                )

                .arg(
                    Arg::with_name("query")
                        .help("query file(-s)fastq.gz")
                        .required(true)
                        .min_values(1)
                        .short("q")
                        .takes_value(true)
                        .long("query"),
                )
                .arg(
                    Arg::with_name("reverse")
                        .help("reverse file(-s)fastq.gz")
                        .required(false)
                        .min_values(1)
                        .default_value("none")
                        .short("r")
                        .takes_value(true)
                        .long("reverse"),
                )
                .arg(
                    Arg::with_name("filter")
                        .help("set minimum k-mer frequency ")
                        .required(false)
                        .short("f")
                        .takes_value(true)
                        .long("filter"),
                )
                .arg(
                    Arg::with_name("shared_kmers")
                        .help("set minimum proportion of shared k-mers with a reference")
                        .required(false)
                        .short("p")
                        .takes_value(true)
                        .long("p_shared"),
                )
                .arg(
                    Arg::with_name("gene_search")
                        .help("If set('-g'), the proportion of kmers from the query matching the entries in the index will be reported")
                        .required(false)
                        .short("g")
                        .takes_value(false)
                        .long("gene_search"),
                )
                .arg(
                    Arg::with_name("perfect_search")
                        .help("If ('-s') is set, the fast 'perfect match' algorithm will be used")
                        .required(false)
                        .short("s")
                        .takes_value(false)
                        .long("perfect_search"),
                )
                .arg(
                    Arg::with_name("multi_fasta")
                        .help("If set('-m'), each accession in a multifasta will betreated as a separate query, currently only with the -s option")
                        .required(false)
                        .short("m")
                        .takes_value(false)
                        .long("multi_fasta"),
                )
                .arg(
                    Arg::with_name("quality")
                        .help("minimum phred score to keep basepairs within read (default 15)")
                        .required(false)
                        .short("Q")
                        .takes_value(true)
                        .long("quality"),
                ),
        )
        .subcommand(
            SubCommand::with_name("show")
                .about("show index parameters")
                .version("0.1")
                .setting(AppSettings::ArgRequiredElseHelp)
                .arg(
                    Arg::with_name("bigsi")
                        .short("b")
                        .long("bigsi")
                        .required(true)
                        .takes_value(true)
                        .help("index for which info is requested"),
                        )
                .arg(
                    Arg::with_name("compressed")
                        .help("If set to 'true', it is assumed a gz compressed index is used")
                        .required(false)
                        .short("c")
                        .takes_value(true)
                        .long("compressed"),
                ),
        )
        .subcommand(
            SubCommand::with_name("identify")
                .about("identify reads based on probability")
                .version("0.1.0")
                .setting(AppSettings::ArgRequiredElseHelp)
                .arg(
                    Arg::with_name("bigsi")
                        .short("b")
                        .long("bigsi")
                        .required(true)
                        .takes_value(true)
                        .help("index to be used for search"),
                        )
                .arg(
                    Arg::with_name("query")
                        .help("query file(-s)fastq.gz")
                        .required(true)
                        .min_values(1)
                        .short("q")
                        .takes_value(true)
                        .long("query"),
                )
                .arg(
                    Arg::with_name("batch")
                        .help("Sets size of batch of reads to be processed in parallel (default 50,000)")
                        .required(false)
                        .short("c")
                        .takes_value(true)
                        .long("batch"),
                )
                .arg(
                    Arg::with_name("threads")
                        .help("number of threads to use, if not set the maximum available number threads will be used")
                        .required(false)
                        .short("t")
                        .takes_value(true)
                        .long("threads"),
                )
                .arg(
                    Arg::with_name("prefix")
                        .help("prefix for output file(-s)")
                        .required(true)
                        .short("n") //running out of options here!
                        .takes_value(true)
                        .long("prefix"),
                )
                .arg(
                    Arg::with_name("down_sample")
                        .help("down-sample k-mers used for read classification, default 1; increases speed at cost of decreased sensitivity ")
                        .required(false)
                        .short("d")
                        .takes_value(true)
                        .long("down_sample"),
                )
                .arg(
                    Arg::with_name("high_mem_load")
                        .help("When this flag is set, a faster, but less memory efficient method to load the index is used. Loading the index requires approximately 2X the size of the index of RAM. ")
                        .required(false)
                        .short("H")
                        .takes_value(false)
                        .long("high_mem_load"),
                )
                .arg(
                    Arg::with_name("fp_correct")
                        .help("Parameter to correct for false positives, default 3 (= 0.001), maybe increased for larger searches. Adjust for larger datasets")
                        .required(false)
                        .short("p")
                        .takes_value(true)
                        .long("fp_correct"),
                )
                .arg(
                    Arg::with_name("quality")
                        .help("kmers with nucleotides below this minimum phred score will be excluded from the analyses (default 15)")
                        .required(false)
                        .short("Q")
                        .takes_value(true)
                        .long("quality"),
                )
                .arg(
                    Arg::with_name("bitvector_sample")
                        .help("Collects matches for subset of kmers indicated (default=3), using this subset to more rapidly find hits for the remainder of the kmers")
                        .required(false)
                        .short("B")
                        .takes_value(true)
                        .long("bitvector_sample"),
                        ),
        )
        .subcommand(
            SubCommand::with_name("batch_identify")
                .about("Identify batch of samples reads")
                .version("0.1.0")
                .setting(AppSettings::ArgRequiredElseHelp)
                .arg(
                    Arg::with_name("bigsi")
                        .short("b")
                        .long("bigsi")
                        .required(true)
                        .takes_value(true)
                        .help("index to be used for search"),
                        )
                .arg(
                    Arg::with_name("query")
                        .help("tab-delimiteed file with samples to be classified [sample_name reads1 reads2 (optional)]")
                        .required(true)
                        .min_values(1)
                        .short("q")
                        .takes_value(true)
                        .long("query"),
                )
                .arg(
                    Arg::with_name("tag")
                        .help("tag to be include in output file names ")
                        .required(true)
                        .short("T") //
                        .takes_value(true)
                        .long("tag"),
                )
                .arg(
                    Arg::with_name("batch")
                        .help("Sets size of batch of reads to be processed in parallel (default 50,000)")
                        .required(false)
                        .short("c")
                        .takes_value(true)
                        .long("batch"),
                )
                .arg(
                    Arg::with_name("threads")
                        .help("number of threads to use, if not set the maximum available number threads will be used")
                        .required(false)
                        .short("t")
                        .takes_value(true)
                        .long("threads"),
                )
                .arg(
                    Arg::with_name("down_sample")
                        .help("down-sample k-mers used for read classification, default 1; increases speed at cost of decreased sensitivity ")
                        .required(false)
                        .short("d")
                        .takes_value(true)
                        .long("down_sample"),
                )
                .arg(
                    Arg::with_name("high_mem_load")
                        .help("When this flag is set, a faster, but less memory efficient method to load the index is used. Loading the index requires approximately 2X the size of the index of RAM. ")
                        .required(false)
                        .short("H")
                        .takes_value(false)
                        .long("high_mem_load"),
                )
                .arg(
                    Arg::with_name("fp_correct")
                        .help("Parameter to correct for false positives, default 3 (= 0.001), maybe increased for larger searches. Adjust for larger datasets")
                        .required(false)
                        .short("p")
                        .takes_value(true)
                        .long("fp_correct"),
                )
                .arg(
                    Arg::with_name("quality")
                        .help("kmers with nucleotides below this minimum phred score will be excluded from the analyses (default 15)")
                        .required(false)
                        .short("Q")
                        .takes_value(true)
                        .long("quality"),
                )
                .arg(
                    Arg::with_name("bitvector_sample")
                        .help("Collects matches for subset of kmers indicated (default=3), using this subset to more rapidly find hits for the remainder of the kmers")
                        .required(false)
                        .short("B")
                        .takes_value(true)
                        .long("bitvector_sample"),
                        ),
        )
        .subcommand(
            SubCommand::with_name("filter")
                .about("filters reads")
                .version("0.1.0")
                .setting(AppSettings::ArgRequiredElseHelp)
                .arg(
                    Arg::with_name("classification")
                        .short("c")
                        .long("classification")
                        .required(true)
                        .takes_value(true)
                        .help("tab delimited read classification file generated with the read_id subcommand"),
                        )
                .arg(
                    Arg::with_name("files")
                        .help("query file(-s)fastq.gz")
                        .required(true)
                        .min_values(1)
                        .short("f")
                        .takes_value(true)
                        .long("files"),
                )
                .arg(
                    Arg::with_name("taxon")
                        .help("taxon to be in- or excluded from the read file(-s)")
                        .required(true)
                        .short("t")
                        .takes_value(true)
                        .long("taxon"),
                        )
                .arg(
                    Arg::with_name("prefix")
                        .help("prefix for output file(-s)")
                        .required(true)
                        .short("p")
                        .takes_value(true)
                        .long("prefix"),
                        )
                .arg(
                    Arg::with_name("exclude")
                        .help("If set('-e or --exclude'), reads for which the classification contains the taxon name will be excluded")
                        .required(false)
                        .short("e")
                        .takes_value(false)
                        .long("exclude"),
                ),
          )
              .get_matches();
    if let Some(matches) = matches.subcommand_matches("construct") {
        println!(" Ref_file : {}", matches.value_of("ref_file").unwrap());
        println!(" Bigsi file : {}", matches.value_of("bigsi").unwrap());
        println!("K-mer size: {}", matches.value_of("k-mer_size").unwrap());
        println!(
            "Bloom filter parameters: num hashes {}, filter size {}",
            matches.value_of("num_hashes").unwrap(),
            matches.value_of("length_bloom").unwrap()
        );
        let kmer = value_t!(matches, "k-mer_size", usize).unwrap_or(31);
        let bloom = value_t!(matches, "length_bloom", usize).unwrap_or(50_000_000);
        let hashes = value_t!(matches, "num_hashes", usize).unwrap_or(4);
        let threads = value_t!(matches, "threads", usize).unwrap_or(1);
        let quality = value_t!(matches, "quality", u8).unwrap_or(15);
        let minimizer = matches.is_present("minimizer");
        //hack to work around current clap bug with default values only being &str
        let minimizer_value: usize = matches.value_of("value").unwrap().parse::<usize>().unwrap();
        let map = build::tab_to_map(matches.value_of("ref_file").unwrap().to_string());
        let filter = value_t!(matches, "filter", isize).unwrap_or(-1);
        if minimizer {
            println!("Build with minimizers, minimizer size: {}", minimizer_value);
            let (bigsi_map, colors_accession, n_ref_kmers) = if threads == 1 {
                build::build_single_mini(
                    &map,
                    bloom,
                    hashes,
                    kmer,
                    minimizer_value,
                    quality,
                    filter,
                )
            } else {
                build::build_multi_mini(
                    &map,
                    bloom,
                    hashes,
                    kmer,
                    minimizer_value,
                    threads,
                    quality,
                    filter,
                )
            };
            println!("Saving BIGSI to file.");
            let index = bigsi::BigsyMapMiniNew {
                map: bigsi_map,
                colors: colors_accession,
                n_ref_kmers: n_ref_kmers,
                bloom_size: bloom,
                num_hash: hashes,
                k_size: kmer,
                m_size: minimizer_value,
            };
            bigsi::save_bigsi_mini(
                &(matches.value_of("bigsi").unwrap().to_owned() + ".mxi"),
                &index,
            );
        /*
        bigsi::save_bigsi_mini(
            bigsi_map.to_owned(),
            colors_accession.to_owned(),
            n_ref_kmers.to_owned(),
            bloom,
            hashes,
            kmer,
            minimizer_value,
            &(matches.value_of("bigsi").unwrap().to_owned() + ".mxi"),
        );*/
        } else {
            let (bigsi_map, colors_accession, n_ref_kmers) = if threads == 1 {
                build::build_single(&map, bloom, hashes, kmer, quality, filter)
            } else {
                build::build_multi(&map, bloom, hashes, kmer, threads, quality, filter)
            };
            let index = bigsi::BigsyMapNew {
                map: bigsi_map,
                colors: colors_accession,
                n_ref_kmers: n_ref_kmers,
                bloom_size: bloom,
                num_hash: hashes,
                k_size: kmer,
            };
            println!("Saving BIGSI to file.");
            bigsi::save_bigsi(
                &(matches.value_of("bigsi").unwrap().to_owned() + ".bxi"),
                &index,
            );
        }
    }
    if let Some(matches) = matches.subcommand_matches("query") {
        let files1: Vec<_> = matches.values_of("query").unwrap().collect();
        let files2 = if matches.value_of("reverse").unwrap() == "none" {
            vec![]
        } else {
            matches.values_of("reverse").unwrap().collect()
        };
        //let files2: Vec<_> = matches.values_of("reverse").unwrap().collect();
        let filter = value_t!(matches, "filter", isize).unwrap_or(-1);
        let cov = value_t!(matches, "shared_kmers", f64).unwrap_or(0.35);
        let gene_search = matches.is_present("gene_search");
        let perfect_search = matches.is_present("perfect_search");
        let multi_fasta = matches.is_present("multi_fasta");
        let quality = value_t!(matches, "quality", u8).unwrap_or(15);
        if matches.value_of("bigsi").unwrap().ends_with(".mxi") {
            eprintln!(
                "Error: An index with minimizers (.mxi) is used, but not available for this function"
            );
        } else {
            let bigsi_time = SystemTime::now();
            eprintln!("Loading index");
            let index = bigsi::read_bigsi(matches.value_of("bigsi").unwrap());
            match bigsi_time.elapsed() {
                Ok(elapsed) => {
                    eprintln!("Index loaded in {} seconds", elapsed.as_secs());
                }
                Err(e) => {
                    // an error occurred!
                    eprintln!("Error: {:?}", e);
                }
            }
            if perfect_search {
                if multi_fasta {
                    //make 'perfect' batch....
                    bigsig::perfect_search::batch_search_mf(
                        files1,
                        &index.map,
                        &index.colors,
                        &index.n_ref_kmers,
                        index.bloom_size,
                        index.num_hash,
                        index.k_size,
                        cov,
                    )
                } else {
                    bigsig::perfect_search::batch_search(
                        files1,
                        &index.map,
                        &index.colors,
                        &index.n_ref_kmers,
                        index.bloom_size,
                        index.num_hash,
                        index.k_size,
                        cov,
                    )
                }
            } else {
                bigsig::batch_search_pe::batch_search(
                    files1,
                    files2,
                    &index.map,
                    &index.colors,
                    &index.n_ref_kmers,
                    index.bloom_size,
                    index.num_hash,
                    index.k_size,
                    filter,
                    cov,
                    gene_search,
                    quality,
                )
            }
        }
    }

    if let Some(matches) = matches.subcommand_matches("show") {
        let bigsi_time = SystemTime::now();
        eprintln!("Loading index");
        let index = matches.value_of("bigsi").unwrap();
        if index.ends_with(".mxi") {
            let bigsi = bigsi::read_bigsi_mini(index);
            match bigsi_time.elapsed() {
                Ok(elapsed) => {
                    eprintln!("Index loaded in {} seconds", elapsed.as_secs());
                }
                Err(e) => {
                    // an error occurred!
                    eprintln!("Error: {:?}", e);
                }
            }
            println!(
            "BIGSI parameters:\nBloomfilter-size: {}\nNumber of hashes: {}\nK-mer size: {}\n minimizer size: {}\n",
            bigsi.bloom_size, bigsi.num_hash, bigsi.k_size, bigsi.m_size
        );
            println!("Number of accessions in index: {}", bigsi.colors.len());
            let mut accessions = Vec::new();
            for (_k, v) in bigsi.colors {
                accessions.push(v);
            }
            accessions.sort_by(|a, b| a.cmp(b));
            for a in accessions {
                let k_size = bigsi.n_ref_kmers.get(&a).unwrap();
                println!(
                    "{} {} {:.3}",
                    a,
                    k_size,
                    false_prob(
                        bigsi.bloom_size as f64,
                        bigsi.num_hash as f64,
                        *k_size as f64
                    )
                );
            }
        } else {
            let bigsi = bigsi::read_bigsi(index);
            match bigsi_time.elapsed() {
                Ok(elapsed) => {
                    eprintln!("Index loaded in {} seconds", elapsed.as_secs());
                }
                Err(e) => {
                    // an error occurred!
                    eprintln!("Error: {:?}", e);
                }
            }
            println!(
                "BIGSI parameters:\nBloomfilter-size: {}\nNumber of hashes: {}\nK-mer size: {}",
                bigsi.bloom_size, bigsi.num_hash, bigsi.k_size
            );
            println!("Number of accessions in index: {}", bigsi.colors.len());
            let mut accessions = Vec::new();
            for (_k, v) in bigsi.colors {
                accessions.push(v);
            }
            accessions.sort_by(|a, b| a.cmp(b));
            for a in accessions {
                let k_size = bigsi.n_ref_kmers.get(&a).unwrap();
                println!(
                    "{} {} {:.3}",
                    a,
                    k_size,
                    false_prob(
                        bigsi.bloom_size as f64,
                        bigsi.num_hash as f64,
                        *k_size as f64
                    )
                );
            }
        }
    }
    if let Some(matches) = matches.subcommand_matches("identify") {
        let bigsi_time = SystemTime::now();
        //let fq = matches.value_of("query").unwrap();
        let fq: Vec<_> = matches.values_of("query").unwrap().collect();
        let threads = value_t!(matches, "threads", usize).unwrap_or(0);
        let down_sample = value_t!(matches, "down_sample", usize).unwrap_or(1);
        let correct = value_t!(matches, "fp_correct", f64).unwrap_or(3.0);
        let fp_correct = 10f64.powf(-correct);
        let index = matches.value_of("bigsi").unwrap();
        let prefix = matches.value_of("prefix").unwrap();
        let quality = value_t!(matches, "quality", u8).unwrap_or(15);
        let batch = value_t!(matches, "batch", usize).unwrap_or(50000);
        let high_mem_load = matches.is_present("high_mem_load");
        let bitvector_sample = value_t!(matches, "bitvector_sample", usize).unwrap_or(3);
        ThreadPoolBuilder::new()
        .num_threads(threads)
        .build_global()
        .expect("Can't initialize ThreadPoolBuilder");

        if index.ends_with(".mxi") {
            //let metadata = fs::metadata(&index).expect("Can't read metadata index!");
            let bigsi = if high_mem_load {
                bigsi::read_bigsi_mini_highmem(index)
            } else {
                bigsi::read_bigsi_mini(index)
            };
            match bigsi_time.elapsed() {
                Ok(elapsed) => {
                    eprintln!("Index loaded in {} seconds", elapsed.as_secs());
                }
                Err(e) => {
                    // an error occurred!
                    eprintln!("Error: {:?}", e);
                }
            }
            if fq[0].ends_with(".gz") {
                if fq.len() > 1 {
                    bigsig::read_id_mt_pe::per_read_stream_pe(
                        fq,
                        &bigsi.map,
                        &bigsi.colors,
                        &bigsi.n_ref_kmers,
                        bigsi.bloom_size,
                        bigsi.num_hash,
                        bigsi.k_size,
                        bigsi.m_size,
                        threads,
                        down_sample,
                        fp_correct,
                        batch,
                        prefix,
                        quality,
                        bitvector_sample,
                    )
                } else {
                    bigsig::read_id_mt_pe::per_read_stream_se(
                        fq,
                        &bigsi.map,
                        &bigsi.colors,
                        &bigsi.n_ref_kmers,
                        bigsi.bloom_size,
                        bigsi.num_hash,
                        bigsi.k_size,
                        bigsi.m_size,
                        threads,
                        down_sample,
                        fp_correct,
                        batch,
                        prefix,
                        quality,
                        bitvector_sample,
                    )
                };
            } else {
                bigsig::read_id_mt_pe::stream_fasta(
                    fq,
                    &bigsi.map,
                    &bigsi.colors,
                    &bigsi.n_ref_kmers,
                    bigsi.bloom_size,
                    bigsi.num_hash,
                    bigsi.k_size,
                    bigsi.m_size,
                    threads,
                    down_sample,
                    fp_correct,
                    batch,
                    prefix,
                    bitvector_sample,
                );
            }
        } else {
            let bigsi = if high_mem_load {
                bigsi::read_bigsi_highmem(index)
            } else {
                bigsi::read_bigsi(index)
            };
            match bigsi_time.elapsed() {
                Ok(elapsed) => {
                    eprintln!("Index loaded in {} seconds", elapsed.as_secs());
                }
                Err(e) => {
                    // an error occurred!
                    eprintln!("Error: {:?}", e);
                }
            }
            if fq[0].ends_with(".gz") {
                if fq.len() > 1 {
                    bigsig::read_id_mt_pe::per_read_stream_pe(
                        fq,
                        &bigsi.map,
                        &bigsi.colors,
                        &bigsi.n_ref_kmers,
                        bigsi.bloom_size,
                        bigsi.num_hash,
                        bigsi.k_size,
                        0,
                        threads,
                        down_sample,
                        fp_correct,
                        batch,
                        prefix,
                        quality,
                        bitvector_sample,
                    )
                } else {
                    bigsig::read_id_mt_pe::per_read_stream_se(
                        fq,
                        &bigsi.map,
                        &bigsi.colors,
                        &bigsi.n_ref_kmers,
                        bigsi.bloom_size,
                        bigsi.num_hash,
                        bigsi.k_size,
                        0,
                        threads,
                        down_sample,
                        fp_correct,
                        batch,
                        prefix,
                        quality,
                        bitvector_sample,
                    )
                };
            } else {
                bigsig::read_id_mt_pe::stream_fasta(
                    fq,
                    &bigsi.map,
                    &bigsi.colors,
                    &bigsi.n_ref_kmers,
                    bigsi.bloom_size,
                    bigsi.num_hash,
                    bigsi.k_size,
                    0,
                    threads,
                    down_sample,
                    fp_correct,
                    batch,
                    prefix,
                    bitvector_sample,
                );
            }
        }
        bigsig::reports::read_counts_five_fields(prefix.to_owned() + "_reads.txt", prefix);
    }
    if let Some(matches) = matches.subcommand_matches("batch_identify") {
        let  batch_samples = matches.value_of("query").unwrap();
        //let fq: Vec<_> = matches.values_of("query").unwrap().collect();
        let threads = value_t!(matches, "threads", usize).unwrap_or(0);
        ThreadPoolBuilder::new()
        .num_threads(threads)
        .build_global()
        .expect("Can't initialize ThreadPoolBuilder");
        let down_sample = value_t!(matches, "down_sample", usize).unwrap_or(1);
        let correct = value_t!(matches, "fp_correct", f64).unwrap_or(3.0);
        let fp_correct = 10f64.powf(-correct);
        let index = matches.value_of("bigsi").unwrap();
        let quality = value_t!(matches, "quality", u8).unwrap_or(15);
        let batch = value_t!(matches, "batch", usize).unwrap_or(50000);
        let high_mem_load = matches.is_present("high_mem_load");
        let bitvector_sample = value_t!(matches, "bitvector_sample", usize).unwrap_or(3);
        let tag = matches.value_of("tag").unwrap();

        bigsig::read_id_batch::read_id_batch(batch_samples, index, threads, down_sample, fp_correct, batch, quality, bitvector_sample, high_mem_load, tag);
    }
    if let Some(matches) = matches.subcommand_matches("filter") {
        let classification = matches.value_of("classification").unwrap();
        let files: Vec<_> = matches.values_of("files").unwrap().collect();
        let taxon = matches.value_of("taxon").unwrap();
        let prefix = matches.value_of("prefix").unwrap();
        let exclude = matches.is_present("exclude");
        let map = bigsig::read_filter::tab_to_map(classification.to_string(), taxon, "accept");
        if files.len() == 1 {
            bigsig::read_filter::read_filter_se(map, files, taxon, prefix, exclude);
        } else {
            bigsig::read_filter::read_filter_pe(map, files, taxon, prefix, exclude);
        }
    }
    Ok(())
}