File: barcodes_test.cpp

package info (click to toggle)
adapterremoval 2.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,864 kB
  • sloc: cpp: 24,110; python: 427; makefile: 207; sh: 16
file content (655 lines) | stat: -rw-r--r-- 26,957 bytes parent folder | download | duplicates (3)
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
/*************************************************************************\
 * AdapterRemoval - cleaning next-generation sequencing reads            *
 *                                                                       *
 * Copyright (C) 2011 by Stinus Lindgreen - stinus@binf.ku.dk            *
 * Copyright (C) 2014 by Mikkel Schubert - mikkelsch@gmail.com           *
 *                                                                       *
 * If you use the program, please cite the paper:                        *
 * S. Lindgreen (2012): AdapterRemoval: Easy Cleaning of Next Generation *
 * Sequencing Reads, BMC Research Notes, 5:337                           *
 * http://www.biomedcentral.com/1756-0500/5/337/                         *
 *                                                                       *
 * This program is free software: you can redistribute it and/or modify  *
 * it under the terms of the GNU General Public License as published by  *
 * the Free Software Foundation, either version 3 of the License, or     *
 * (at your option) any later version.                                   *
 *                                                                       *
 * This program is distributed in the hope that it will be useful,       *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 * GNU General Public License for more details.                          *
 *                                                                       *
 * You should have received a copy of the GNU General Public License     *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. *
\*************************************************************************/
#include <limits>
#include <sstream>
#include <vector>

#include "barcode_table.hpp"
#include "debug.hpp"
#include "fastq.hpp"
#include "testing.hpp"


namespace ar
{

TEST_CASE("what()", "[barcodes::errors]")
{
    barcode_error err("test error");

    REQUIRE(std::string(err.what()) == "test error");
}


TEST_CASE("copy constructor", "[barcodes::errors]")
{
    barcode_error err("test error");
    barcode_error copy(err);

    REQUIRE(std::string(copy.what()) == "test error");
}


TEST_CASE("Empty barcode-table is OK", "[barcodes::constuctor]")
{
    const fastq_pair_vec barcodes;

    barcode_table table(barcodes, 0, 0, 0);
}


TEST_CASE("Overlapping SE barcodes fail", "[barcodes::constuctor]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACGT"), fastq()));
    barcodes.push_back(fastq_pair(fastq("2", "ACGT"), fastq()));

    REQUIRE_THROWS_AS(barcode_table(barcodes, 0, 0, 0), barcode_error);
}


TEST_CASE("Overlapping PE barcodes fail", "[barcodes::constuctor]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACGT"), fastq("3", "CGTG")));
    barcodes.push_back(fastq_pair(fastq("2", "ACGT"), fastq("4", "CGTG")));

    REQUIRE_THROWS_AS(barcode_table(barcodes, 0, 0, 0), barcode_error);
}


TEST_CASE("Partially overlapping PE barcodes are OK", "[barcodes::constuctor]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACGT"), fastq("3", "CGTG")));
    barcodes.push_back(fastq_pair(fastq("2", "CGTG"), fastq("4", "ACGT")));

    barcode_table table(barcodes, 0, 0, 0);
}


TEST_CASE("Variable length SE barcodes fail #1", "[barcodes::construction]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACGT"), fastq()));
    barcodes.push_back(fastq_pair(fastq("2", "TGCTA"), fastq()));

    REQUIRE_THROWS_AS(barcode_table(barcodes, 0, 0, 0), barcode_error);
}


TEST_CASE("Variable length SE barcodes fail #2", "[barcodes::construction]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACGT"), fastq()));
    barcodes.push_back(fastq_pair(fastq("2", "TGCTA"), fastq()));

    REQUIRE_THROWS_AS(barcode_table(barcodes, 0, 0, 0), barcode_error);
}


TEST_CASE("Variable length PE barcodes fail #1", "[barcodes::construction]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACGTT"), fastq("3", "CGTG")));
    barcodes.push_back(fastq_pair(fastq("2", "CGTG"), fastq("4", "ACGT")));

    REQUIRE_THROWS_AS(barcode_table(barcodes, 0, 0, 0), barcode_error);
}


TEST_CASE("Variable length PE barcodes fail #2", "[barcodes::construction]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACGT"), fastq("3", "CGTGT")));
    barcodes.push_back(fastq_pair(fastq("2", "CGTG"), fastq("4", "ACGT")));

    REQUIRE_THROWS_AS(barcode_table(barcodes, 0, 0, 0), barcode_error);
}


TEST_CASE("Variable length PE barcodes fail #3", "[barcodes::construction]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACGT"), fastq("3", "CGTG")));
    barcodes.push_back(fastq_pair(fastq("2", "CGTGA"), fastq("4", "ACGT")));

    REQUIRE_THROWS_AS(barcode_table(barcodes, 0, 0, 0), barcode_error);
}


TEST_CASE("Variable length PE barcodes fail #4", "[barcodes::construction]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACGT"), fastq("3", "CGTG")));
    barcodes.push_back(fastq_pair(fastq("2", "CGTGA"), fastq("4", "ACGTA")));

    REQUIRE_THROWS_AS(barcode_table(barcodes, 0, 0, 0), barcode_error);
}


///////////////////////////////////////////////////////////////////////////////
// Exact matches for SE reads, when using a table containing SE barcodes

TEST_CASE("Exact match among different SE barcodes for SE reads", "[barcodes::exact]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));
    barcodes.push_back(fastq_pair(fastq("2", "CACAC"), fastq()));
    barcodes.push_back(fastq_pair(fastq("3", "AATTC"), fastq()));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq()) == 0);
    REQUIRE(table.identify(fastq("B", "CACAC"), fastq()) == 1);
    REQUIRE(table.identify(fastq("C", "AATTC"), fastq()) == 2);
}


TEST_CASE("Exact match among similar SE barcodes for SE reads - differs at 5p", "[barcodes::exact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));
    barcodes.push_back(fastq_pair(fastq("2", "TCCCA"), fastq()));
    barcodes.push_back(fastq_pair(fastq("3", "AGCCA"), fastq()));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("B", "TCCCA")) == 1);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("C", "AGCCA")) == 2);
}


TEST_CASE("Exact match among similar SE barcodes for SE reads - differs at 3p", "[barcodes::exact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));
    barcodes.push_back(fastq_pair(fastq("2", "ACCCT"), fastq()));
    barcodes.push_back(fastq_pair(fastq("3", "ACCTA"), fastq()));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("C", "ACCTA")) == 2);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("B", "ACCCT")) == 1);
}


TEST_CASE("Shorter and longer reads for SE barcodes and SE reads", "[barcodes::exact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));
    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCAG")) == 0);
}


///////////////////////////////////////////////////////////////////////////////
// Exact matches for SE reads, when using a table containing PE barcodes

TEST_CASE("Exact match among different PE barcodes for SE reads", "[barcodes::exact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("4", "GTTTC")));
    barcodes.push_back(fastq_pair(fastq("2", "CACAC"), fastq("5", "GATGC")));
    barcodes.push_back(fastq_pair(fastq("3", "AATTC"), fastq("6", "TGCGG")));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("C", "AATTC")) == 2);
    REQUIRE(table.identify(fastq("B", "CACAC")) == 1);
}


TEST_CASE("Exact match among similar PE barcodes for SE reads - differs at 5p", "[barcodes::exact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("4", "GTTTC")));
    barcodes.push_back(fastq_pair(fastq("2", "TCCCA"), fastq("5", "GTTTC")));
    barcodes.push_back(fastq_pair(fastq("3", "AGCCA"), fastq("6", "ATTTC")));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("B", "TCCCA")) == 1);
    REQUIRE(table.identify(fastq("C", "AGCCA")) == 2);
}


TEST_CASE("Exact match among similar PE barcodes for SE reads - differs at 3p", "[barcodes::exact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("4", "GTTTC")));
    barcodes.push_back(fastq_pair(fastq("2", "ACCCT"), fastq("5", "GTTTC")));
    barcodes.push_back(fastq_pair(fastq("3", "AGCCA"), fastq("6", "GTTTA")));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("C", "AGCCA")) == 2);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("B", "ACCCT")) == 1);
}


TEST_CASE("Shorter and longer reads for PE barcodes and SE reads", "[barcodes::exact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("2", "TGATA")));
    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCAG")) == 0);
}


TEST_CASE("Exact match among different PE barcodes for SE reads with ambigous results", "[barcodes::exact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("4", "GTTTC")));
    barcodes.push_back(fastq_pair(fastq("2", "AATTC"), fastq("5", "GATGC")));
    barcodes.push_back(fastq_pair(fastq("3", "AATTC"), fastq("6", "TGCGG")));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("C", "AATTC")) == -2);
}

///////////////////////////////////////////////////////////////////////////////
// Exact matches for PE reads, when using a table containing SE barcodes


TEST_CASE("Exact match among different SE barcodes for PE reads", "[barcodes::exact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));
    barcodes.push_back(fastq_pair(fastq("2", "CACAC"), fastq()));
    barcodes.push_back(fastq_pair(fastq("3", "AATTC"), fastq()));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("D", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("B", "CACAC"), fastq("E", "GATGC")) == 1);
    REQUIRE(table.identify(fastq("C", "AATTC"), fastq("F", "TGCGG")) == 2);
}


TEST_CASE("Exact match among similar SE barcodes for PE reads - differs at 5p", "[barcodes::exact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));
    barcodes.push_back(fastq_pair(fastq("2", "TCCCA"), fastq()));
    barcodes.push_back(fastq_pair(fastq("3", "ATCCA"), fastq()));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("D", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("B", "TCCCA"), fastq("E", "GTTTC")) == 1);
    REQUIRE(table.identify(fastq("C", "ATCCA"), fastq("F", "ATTTC")) == 2);
}


TEST_CASE("Exact match among similar SE barcodes for PE reads - differs at 3p", "[barcodes::exact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));
    barcodes.push_back(fastq_pair(fastq("2", "ACCCT"), fastq()));
    barcodes.push_back(fastq_pair(fastq("3", "ACCGA"), fastq()));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("D", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("B", "ACCCT"), fastq("E", "GTTTC")) == 1);
    REQUIRE(table.identify(fastq("C", "ACCGA"), fastq("F", "GTTTA")) == 2);
}


TEST_CASE("Shorter and longer reads for SE barcodes and PE reads", "[barcodes::exact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));
    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCC"), fastq("B", "TGATGA")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "TGATGA")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCAG"), fastq("B", "TGATGA")) == 0);
}


///////////////////////////////////////////////////////////////////////////////
// Exact matches for PE reads, when using a table containing PE barcodes


TEST_CASE("Exact match among different PE barcodes for PE reads", "[barcodes::exact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("4", "GTTTC")));
    barcodes.push_back(fastq_pair(fastq("2", "CACAC"), fastq("5", "GATGC")));
    barcodes.push_back(fastq_pair(fastq("3", "AATTC"), fastq("6", "TGCGG")));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("D", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("B", "CACAC"), fastq("E", "GATGC")) == 1);
    REQUIRE(table.identify(fastq("C", "AATTC"), fastq("F", "TGCGG")) == 2);
}


TEST_CASE("Exact match among similar PE barcodes for PE reads - differs at 5p", "[barcodes::exact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("4", "GTTTC")));
    barcodes.push_back(fastq_pair(fastq("2", "TCCCA"), fastq("5", "GTTTC")));
    barcodes.push_back(fastq_pair(fastq("3", "ACCCA"), fastq("6", "ATTTC")));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("D", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("B", "TCCCA"), fastq("E", "GTTTC")) == 1);
    REQUIRE(table.identify(fastq("C", "ACCCA"), fastq("F", "ATTTC")) == 2);
}


TEST_CASE("Exact match among similar PE barcodes for PE reads - differs at 3p", "[barcodes::exact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("4", "GTTTC")));
    barcodes.push_back(fastq_pair(fastq("2", "ACCCT"), fastq("5", "GTTTC")));
    barcodes.push_back(fastq_pair(fastq("3", "ACCCA"), fastq("6", "GTTTA")));

    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("D", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("B", "ACCCT"), fastq("E", "GTTTC")) == 1);
    REQUIRE(table.identify(fastq("C", "ACCCA"), fastq("F", "GTTTA")) == 2);
}


TEST_CASE("Shorter and longer reads for PE barcodes and PE reads", "[barcodes::exact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("2", "TGATGA")));
    const barcode_table table(barcodes, 0, 0, 0);

    REQUIRE(table.identify(fastq("A", "ACCC"), fastq("B", "TGATG")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCC"), fastq("B", "TGATGA")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCC"), fastq("B", "TGATGAT")) == -1);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "TGATG")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "TGATGA")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "TGATGAG")) == 0);

    REQUIRE(table.identify(fastq("A", "ACCCAT"), fastq("B", "TGATG")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCAT"), fastq("B", "TGATGA")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCAT"), fastq("B", "TGATGAG")) == 0);
}

///////////////////////////////////////////////////////////////////////////////
// Exact matches for SE reads, when reads have mismatches

TEST_CASE("Exact matching reads with mismatches for SE barcodes", "[barcodes::exact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));

    const barcode_table table(barcodes, 0, 0, 0);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCCA")) == -1);
    REQUIRE(table.identify(fastq("A", "AGCCA")) == -1);
    REQUIRE(table.identify(fastq("A", "ACACA")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCTA")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCTT")) == -1);
    REQUIRE(table.identify(fastq("A", "NCCCA")) == -1);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCCA"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "AGCCA"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACACA"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCTA"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCTT"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ANCCA"), fastq("B", "GTTTC")) == -1);
}


TEST_CASE("Exact matching reads with mismatches for PE barcodes", "[barcodes::exact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("B", "GTTTC")));

    const barcode_table table(barcodes, 0, 0, 0);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCCA")) == -1);
    REQUIRE(table.identify(fastq("A", "AGCCA")) == -1);
    REQUIRE(table.identify(fastq("A", "ACACA")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCTA")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCTT")) == -1);
    REQUIRE(table.identify(fastq("A", "NCCCA")) == -1);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACTCA"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTA")) == -1);
    REQUIRE(table.identify(fastq("A", "GCCCA"), fastq("B", "GATTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ANCCA"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTN")) == -1);
}


///////////////////////////////////////////////////////////////////////////////
// Inexact matching with global limits

TEST_CASE("Global limits override local limits for SE barcodes", "[barcodes::inexact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));

    const barcode_table table(barcodes, 0, 1, 1);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCCA")) == -1);
    REQUIRE(table.identify(fastq("A", "NCCCA")) == -1);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACACA"), fastq("B", "GTTTC")) == -1);
}


TEST_CASE("Global limits override local limits for PE barcodes", "[barcodes::inexact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("2", "GTTTC")));

    const barcode_table table(barcodes, 0, 1, 1);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCCA")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCNA")) == -1);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACACA"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTAG")) == -1);
    REQUIRE(table.identify(fastq("A", "ANCCA"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "NTTTC")) == -1);
}


TEST_CASE("Mismatches in R1 only with SE table", "[barcodes::inexact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));

    const barcode_table table(barcodes, 1, 1, 0);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCCT")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCN")) == 0);
    REQUIRE(table.identify(fastq("A", "ANCCN")) == -1);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACTCA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "GCTCA"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCT"), fastq("B", "GTTTG")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCNA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "NCCNA"), fastq("B", "GTTTC")) == -1);
}


TEST_CASE("Mismatches in R1 only with PE table", "[barcodes::inexact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("2", "GTTTC")));

    const barcode_table table(barcodes, 1, 1, 0);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCCT")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCN")) == 0);
    REQUIRE(table.identify(fastq("A", "ANCCN")) == -1);

    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACTCA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "GCTCA"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTG")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCN"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "NTTTC")) == -1);
}


TEST_CASE("Mismatches in R2 only with SE table", "[barcodes::inexact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));

    const barcode_table table(barcodes, 1, 0, 1);
    REQUIRE(table.identify(fastq("A", "ACCCT"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "ATTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTT")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "ATTTG")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "ANTTG")) == 0);
}


TEST_CASE("Mismatches in R2 only with PE table", "[barcodes::inexact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("2", "GTTTC")));

    const barcode_table table(barcodes, 1, 0, 1);
    REQUIRE(table.identify(fastq("A", "ACCCT"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "ATTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTT")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "ATTTG")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTN")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCN"), fastq("B", "GTTTT")) == -1);
    REQUIRE(table.identify(fastq("A", "ACTCA"), fastq("B", "GTNTT")) == -1);
}



TEST_CASE("Mismatches in R1/R2 with PE table", "[barcodes::inexact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("2", "GTTTC")));

    const barcode_table table(barcodes, 1, 1, 1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCT"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTAC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCT"), fastq("B", "GTTAC")) == -1);
    REQUIRE(table.identify(fastq("A", "TCCAA"), fastq("B", "GTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GGTGC")) == -1);
    REQUIRE(table.identify(fastq("A", "ANCCA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTNC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACTCA"), fastq("B", "GTNTC")) == -1);
}


TEST_CASE("Multiple mismatches in R1/R2 with PE table", "[barcodes::inexact::pe]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("2", "GTTTC")));

    const barcode_table table(barcodes, 2, 2, 2);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCT"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GTTAC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCT"), fastq("B", "GTTAC")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCAA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCA"), fastq("B", "GGTGC")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCCT"), fastq("B", "CTTTC")) == -1);
    REQUIRE(table.identify(fastq("A", "TCCNA"), fastq("B", "GTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCCT"), fastq("B", "NTTTC")) == 0);
    REQUIRE(table.identify(fastq("A", "NCCCN"), fastq("B", "GTTTA")) == -1);
}



TEST_CASE("Ambigious matches in R1 for SE table", "[barcodes::inexact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq()));
    barcodes.push_back(fastq_pair(fastq("2", "TCCCA"), fastq()));
    barcodes.push_back(fastq_pair(fastq("3", "ACCCG"), fastq()));

    const barcode_table table(barcodes, 1, 1, 1);
    REQUIRE(table.identify(fastq("A", "TCCCA")) == 1);
    REQUIRE(table.identify(fastq("A", "CCCCA")) == -2);
    REQUIRE(table.identify(fastq("A", "ACCCC")) == -2);
    REQUIRE(table.identify(fastq("A", "ACCCN")) == -2);
}


TEST_CASE("Ambigious matches in SE R1 for PE table", "[barcodes::inexact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("4", "TGCGT")));
    barcodes.push_back(fastq_pair(fastq("2", "TCCCA"), fastq("5", "AAGTT")));
    barcodes.push_back(fastq_pair(fastq("3", "ACCCG"), fastq("6", "CGGCA")));

    const barcode_table table(barcodes, 1, 1, 1);
    REQUIRE(table.identify(fastq("A", "TCCCA")) == 1);
    REQUIRE(table.identify(fastq("A", "CCCCA")) == -2);
    REQUIRE(table.identify(fastq("A", "ACCCC")) == -2);
    REQUIRE(table.identify(fastq("A", "ACCCN")) == -2);
}


TEST_CASE("Mismatch resulting in apparent match", "[barcodes::inexact::se]")
{
    fastq_pair_vec barcodes;
    barcodes.push_back(fastq_pair(fastq("1", "ACCCA"), fastq("4", "TGCGT")));
    barcodes.push_back(fastq_pair(fastq("2", "TCCTT"), fastq("5", "AAGTT")));

    const barcode_table table(barcodes, 1, 1, 1);
    REQUIRE(table.identify(fastq("A", "ACCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "TCCTT")) == 1);
    REQUIRE(table.identify(fastq("A", "TCCCA")) == 0);
    REQUIRE(table.identify(fastq("A", "ACCTT")) == 1);
}

} // namespace ar