File: fastq_defline_matcher.hpp

package info (click to toggle)
sra-sdk 3.2.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296,076 kB
  • sloc: ansic: 532,876; cpp: 243,000; perl: 9,649; python: 8,978; sh: 7,888; java: 6,253; makefile: 1,148; yacc: 703; xml: 310; lex: 236
file content (1264 lines) | stat: -rw-r--r-- 42,442 bytes parent folder | download
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
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
#ifndef __CFASTQ_DEFLINE_MATCHER_HPP__
#define __CFASTQ_DEFLINE_MATCHER_HPP__

/**
 * @file fastq_defline_matcher.hpp
 * @brief Defline matcher classes
 *
 */

#include "fastq_read.hpp"
#include "regexpr.hpp"
#include <absl/strings/match.h>
#include <insdc/sra.h>

using namespace std;

/* platform id
#define sra_platform_id_t "INSDC:SRA:platform_id"
typedef uint8_t INSDC_SRA_platform_id;
enum
{
    SRA_PLATFORM_UNDEFINED         = 0,
    SRA_PLATFORM_454               = 1,
    SRA_PLATFORM_ILLUMINA          = 2,
    SRA_PLATFORM_ABSOLID           = 3,
    SRA_PLATFORM_COMPLETE_GENOMICS = 4,
    SRA_PLATFORM_HELICOS           = 5,
    SRA_PLATFORM_PACBIO_SMRT       = 6,
    SRA_PLATFORM_ION_TORRENT       = 7,
    SRA_PLATFORM_CAPILLARY         = 8,
    SRA_PLATFORM_OXFORD_NANOPORE   = 9
};
*/
class CDefLineMatcher
/// Base class for all defline matchers
{
public:
    /**
     * @brief Construct a new CDefLineMatcher object
     *
     * @param defLineName defline description
     * @param pattern defline regex pattern
     *
     * @throws runtime error on invalid pattern
     */
    CDefLineMatcher(
        const string& defLineName,
        const string& pattern)
    :   mDefLineName( defLineName ),
        re( pattern )
    {
    }

    virtual ~CDefLineMatcher() {}

    /**
     * @brief Check if matcher recrogizes defline
     *
     * @param[in] defline string_view de fline to check
     * @return true if defline matches
     * @return false if defline does not match
     */
    virtual bool Matches(const re2::StringPiece& defline)
    {
        return re.Matches(defline);
    }

    /**
     * @brief retrun Defline description
     *
     * @return const string&
     */
    const string& Defline() const { return mDefLineName;}

    /**
     * @brief Return matcher's pattern
    */
    const string& GetPattern() const { return re.GetPattern();}

    /**
     * @brief Fill CFastqRead with the data from matched defline
     *
     * @param read
     */
    virtual void GetMatch(CFastqRead& read) = 0;

    /**
     * @brief Return matcher's platform code
     *
     * @return uint8_t
     */
    virtual uint8_t GetPlatform() const = 0;


protected:
    string mDefLineName;             ///< Defline description
    CRegExprMatcher re;              ///< regexpr matcher
    string m_tmp_spot;               ///< variable for spot name assembly 

};

class CDefLineMatcher_NoMatch : public CDefLineMatcher
/// Matcher that matches nothing
{
public:
    CDefLineMatcher_NoMatch():
        CDefLineMatcher("NoMatch", "a^")
    {
    }

    bool Matches(const re2::StringPiece& defline) override {return false;}
    virtual void GetMatch(CFastqRead& read) override  {}
    virtual uint8_t GetPlatform() const override { return 0;}

protected:
};

class CDefLineMatcher_AllMatch : public CDefLineMatcher
/// Matcher that matches everything similar to defline
{
public:
    CDefLineMatcher_AllMatch():
        CDefLineMatcher("undefined", R"([@>+]([!-~]+)(\s+|$))")
    {
    }

    //bool Matches(const string_view& defline) override { return true;}
    virtual void GetMatch(CFastqRead& read) override  {
        read.SetSpot(re.GetMatch()[0]);
    }
    virtual uint8_t GetPlatform() const override { return 0;}
protected:
};

class CDefLineMatcherIlluminaNewDataGroup : public CDefLineMatcher
/// illuminaNewDataGroup matcher
{
public:
    CDefLineMatcherIlluminaNewDataGroup() :
        CDefLineMatcher(
            "illuminaNewDataGroup",
            R"(^[@>+]([!-~]+?)(\s+|[_|])([12345]|):([NY]):(\d+|O):?([!-~]*?)(\s+|$))")
    {
    }

    uint8_t GetPlatform() const override {
        return SRA_PLATFORM_ILLUMINA;
    };

    virtual void GetMatch(CFastqRead& read) override
    {
        read.SetSpot(re.GetMatch()[0]);
        read.SetReadNum(re.GetMatch()[2]);
        read.SetReadFilter(re.GetMatch()[3] == "Y" ? 1 : 0);
        read.SetSpotGroup(re.GetMatch()[5]);
    }

private:
};

static inline
void s_add_sep(string& s, re2::StringPiece& sep)
{
    if (!sep.empty())
        s.append(1, (sep[0] == '-') ? ':' : sep[0]);
}

class CDefLineMatcherIlluminaNewBase : public CDefLineMatcher
/// Base class for IlluminaNew matchers
{
public:
    CDefLineMatcherIlluminaNewBase(
        const string& displayName,
        const string& pattern): CDefLineMatcher(displayName, pattern)
    {
    }

    uint8_t GetPlatform() const override {
        return SRA_PLATFORM_ILLUMINA;
    };

    virtual void GetMatch(CFastqRead& read) override
    {
        m_tmp_spot.clear();
        if (!re.GetMatch()[0].empty()) {
            m_tmp_spot.assign(re.GetMatch()[0].data(), re.GetMatch()[0].size());
            s_add_sep(m_tmp_spot, re.GetMatch()[1]);
        }
        m_tmp_spot.append(re.GetMatch()[2].data(), re.GetMatch()[2].size()); //lane
        s_add_sep(m_tmp_spot, re.GetMatch()[3]);
        m_tmp_spot.append(re.GetMatch()[4].data(), re.GetMatch()[4].size()); //tile
        s_add_sep(m_tmp_spot, re.GetMatch()[5]);
        m_tmp_spot.append(re.GetMatch()[6].data(), re.GetMatch()[6].size()); //x
        s_add_sep(m_tmp_spot, re.GetMatch()[7]);
        m_tmp_spot.append(re.GetMatch()[8].data(), re.GetMatch()[8].size()); //y
        read.MoveSpot(std::move(m_tmp_spot));

        read.SetReadNum(re.GetMatch()[10]);

        read.SetReadFilter(re.GetMatch()[11] == "Y" ? 1 : 0);

        read.SetSpotGroup(re.GetMatch()[13]);
    }
private:

};


static 
bool s_is_number(const string_view& s)
{
    return !s.empty() && find_if(s.begin(), s.end(), [](unsigned char c) { return !isdigit(c); }) == s.end();
}


class CDefLineMatcherIlluminaOldBase : public CDefLineMatcher
/// Base class for IlluminaNew matchers
{
    CRegExprMatcher sub_re1;              ///< additional regex to support numDiscards matching 
    CRegExprMatcher sub_re2;              ///< additional regex to support numDiscards matching
    CRegExprMatcher sub_re3;              ///< additional regex to support numDiscards matching
    CRegExprMatcher illuminaOldSuffix2;   ///< additional regex for suffix matching 
    CRegExprMatcher illuminaOldSuffix;    ///< additional regex for suffix matching

public:
    CDefLineMatcherIlluminaOldBase(
        const string& displayName,
        const string& pattern): CDefLineMatcher(displayName, pattern),
        sub_re1(R"(([!-~]*?)(:)(\d+)$)"),
        sub_re2(R"(([!-~]*?)(:)(\d+)(:)(\d+)(\s+|$))"),
        sub_re3(R"((\d+)(:)(\d+)(\s+|$))"),
        illuminaOldSuffix2(R"((-?\d+\.\d+|-?\d+)([^\d\s.][!-~]+))"),
        illuminaOldSuffix(R"((/[12345])([^\d\s][!-~]+))")
    {
        
    }

    uint8_t GetPlatform() const override {
        return SRA_PLATFORM_ILLUMINA;
    };

    //prefix, sep1, lane, sep2, tile, sep3, x, sep4, y, spotGroup, readNum, endSep
    //0       1     2     3     4     5     6  7     8  9          10       11 

    virtual void GetMatch(CFastqRead& read) override
    {
        re2::StringPiece prefix{re.GetMatch()[0]};
        auto& lane = re.GetMatch()[2];
        auto& tile = re.GetMatch()[4];
        auto& x = re.GetMatch()[6];
        auto& y = re.GetMatch()[8];

        auto& readNum = re.GetMatch()[10];

        m_tmp_suffix = re2::StringPiece();
        if (illuminaOldSuffix2.Matches(y)) {
            y = illuminaOldSuffix2.GetMatch()[0];
            auto& suffix = illuminaOldSuffix2.GetMatch()[1];
            if (suffix.size() >= 3) {
                if (absl::StartsWith(suffix, "/1") || absl::StartsWith(suffix, "/2"))
                    suffix.remove_prefix(2);
                m_tmp_suffix = suffix;                    
            }         
        } else if (!readNum.empty() && illuminaOldSuffix.Matches(readNum)) {
            readNum = illuminaOldSuffix.GetMatch()[0];    
            if (illuminaOldSuffix.GetMatch()[1].size() >= 3) 
                m_tmp_suffix = illuminaOldSuffix.GetMatch()[1];
        }

        if (!m_tmp_suffix.empty())
            read.SetSuffix(m_tmp_suffix);

        int numDiscards = 0;
        if (!prefix.empty()) {
            numDiscards = countExtraNumbersInIllumina(prefix, re.GetMatch()[7], x, y);
            if (numDiscards == 2 && x.find('.') != re2::StringPiece::npos) {
                string new_suffix;
                new_suffix.append(re.GetMatch()[5].data(), re.GetMatch()[5].size()); // sep3
		new_suffix.append(x.data(), x.size()); //x
                new_suffix.append(re.GetMatch()[7].data(), re.GetMatch()[7].size()); // sep4
		new_suffix.append(y.data(), y.size()); //y
                new_suffix.append(read.Suffix());
                read.SetSuffix(new_suffix);
            } else if (numDiscards == 1 && y.find('.') != re2::StringPiece::npos) {
                string new_suffix;
                new_suffix.append(re.GetMatch()[7].data(), re.GetMatch()[7].size()); // sep4
		new_suffix.append(y.data(), y.size()); //y
                new_suffix.append(read.Suffix());
                read.SetSuffix(new_suffix);
            }
        }

        m_tmp_spot.clear();
        if (numDiscards == 1) {
            assert(!prefix.empty());
            if (sub_re1.Matches(prefix)) {
                m_tmp_spot.append(sub_re1.GetMatch()[0].data(),
				  sub_re1.GetMatch()[0].size());
                m_tmp_spot.append(sub_re1.GetMatch()[1].data(),
				  sub_re1.GetMatch()[1].size());
                m_tmp_spot.append(sub_re1.GetMatch()[2].data(),
				  sub_re1.GetMatch()[2].size());
            } else {
                m_tmp_spot.append(prefix.data(), prefix.size());
            }
            s_add_sep(m_tmp_spot, re.GetMatch()[1]);
            m_tmp_spot.append(lane.data(), lane.size());
            s_add_sep(m_tmp_spot, re.GetMatch()[3]);
            m_tmp_spot.append(tile.data(), tile.size());
            s_add_sep(m_tmp_spot, re.GetMatch()[5]);
            m_tmp_spot.append(x.data(), x.size());

        } else if (numDiscards == 2) {
            assert(!prefix.empty());
            if (sub_re2.Matches(prefix)) {
                m_tmp_spot.append(sub_re2.GetMatch()[0].data(),
				  sub_re2.GetMatch()[0].size());
                m_tmp_spot.append(sub_re2.GetMatch()[1].data(),
				  sub_re2.GetMatch()[1].size());
                m_tmp_spot.append(sub_re2.GetMatch()[2].data(),
				  sub_re2.GetMatch()[2].size());
                m_tmp_spot.append(sub_re2.GetMatch()[3].data(),
				  sub_re2.GetMatch()[3].size());
                m_tmp_spot.append(sub_re2.GetMatch()[4].data(),
				  sub_re2.GetMatch()[4].size());
            } else if (sub_re3.Matches(prefix)) {
                m_tmp_spot.append(sub_re3.GetMatch()[0].data(),
				  sub_re3.GetMatch()[0].size());
                m_tmp_spot.append(sub_re3.GetMatch()[1].data(),
				  sub_re3.GetMatch()[1].size());
                m_tmp_spot.append(sub_re3.GetMatch()[2].data(),
				  sub_re3.GetMatch()[2].size());
            } else {
                assert(false);
                throw fastq_error(101, "Unexpected IlluminaOld Defline");
            }
            s_add_sep(m_tmp_spot, re.GetMatch()[1]);
            m_tmp_spot.append(lane.data(), lane.size());
            s_add_sep(m_tmp_spot, re.GetMatch()[3]);
            m_tmp_spot.append(tile.data(), tile.size());

        } else {
            if (!prefix.empty()) {
		m_tmp_spot.assign(prefix.data(), prefix.size());
                s_add_sep(m_tmp_spot, re.GetMatch()[1]);
            }
            m_tmp_spot.append(lane.data(), lane.size()); //lane
            s_add_sep(m_tmp_spot, re.GetMatch()[3]); // sep2
            m_tmp_spot.append(tile.data(), tile.size()); //tile
            s_add_sep(m_tmp_spot, re.GetMatch()[5]); // sep3
            m_tmp_spot.append(x.data(), x.size()); //x
            s_add_sep(m_tmp_spot, re.GetMatch()[7]); //sep 4
            m_tmp_spot.append(y.data(), y.size()); //y
        }
        read.MoveSpot(std::move(m_tmp_spot));

        if (!readNum.empty()) { // readNum
            readNum.remove_prefix(1);
            read.SetReadNum(readNum);
        }

        if (!re.GetMatch()[9].empty()) {
            re.GetMatch()[9].remove_prefix(1); // spotGroup
            read.SetSpotGroup(re.GetMatch()[9]);
        }

    }

    int countExtraNumbersInIllumina(re2::StringPiece& prefix, re2::StringPiece& sep_str, re2::StringPiece& x, re2::StringPiece& y)
    {
        if (sep_str.empty())
            return 0;
        const char sep = (sep_str[0] == '-') ? ':' : sep_str[0];
        // Determine how many numbers at the end of prefix
        // separated by sep 
        sharq::split(prefix, m_tmp_strlist, sep);
        int numCount = 0;

        // Determine if prefix ends in one or two digits
        // delineated with 'sep'
        auto sz = m_tmp_strlist.size();
        if (sz == 0)
            return 0;

        if (s_is_number(m_tmp_strlist[sz - 1]))
            ++numCount;
        if (sz > 1 && s_is_number(m_tmp_strlist[sz - 2]))
            ++numCount;

        // Determine how many numbers to discard (capping at 2 based on what we have seen in the data)
        int discardCount = 0;
        if (numCount) {
            sharq::split(y, m_tmp_strlist, '.');
            if (!m_tmp_strlist.empty() && atoi(m_tmp_strlist.front().data()) < 4) {
                discardCount += 1;
                if (numCount == 2) {
                    sharq::split(x, m_tmp_strlist, '.');
                    if (!m_tmp_strlist.empty() && atoi(m_tmp_strlist.front().data()) < 4) 
                        discardCount += 1;
                }
            }
        }
        return discardCount;
    }

private:
    vector<string_view> m_tmp_strlist;
    re2::StringPiece m_tmp_suffix;

};


class CDefLineMatcherIlluminaNew : public CDefLineMatcherIlluminaNewBase
/// illuminaNew matcher
{
public:
    CDefLineMatcherIlluminaNew() :
        CDefLineMatcherIlluminaNewBase(
            "illuminaNew",
            R"(^[@>+]([!-~]+?)([:_])(\d+)([:_])(\d+)([:_])(-?\d+\.?\d*)([:_])(-?\d+\.\d+|\d+)(\s+|[:_|-])([12345]|):([NY]):(\d+|O):?([!-~]*?)(\s+|$))")
    {}
};


class CDefLineMatcherIlluminaNewNoPrefix : public CDefLineMatcherIlluminaNewBase
/// illuminaNewNoPrefix matcher
{
public:
    CDefLineMatcherIlluminaNewNoPrefix() :
        CDefLineMatcherIlluminaNewBase(
            "illuminaNewNoPrefix",
            R"(^[@>+]([!-~]*?)(:?)(\d+)([:_])(\d+)([:_])(\d+)([:_])(\d+)(\s+|_)([12345]|):([NY]):(\d+|O):?([!-~]*?)(\s+|$))")
    {}

};


class CDefLineMatcherIlluminaNewWithSuffix : public CDefLineMatcherIlluminaNewBase
/// IlluminaNewWithSuffix (aka IlluminaNewWithJunk in fastq-load.py) matcher
{
public:
    CDefLineMatcherIlluminaNewWithSuffix() :
        CDefLineMatcherIlluminaNewBase(
            "illuminaNewWithSuffix",
            R"(^[@>+]([!-~]+)([:_])(\d+)([:_])(\d+)([:_])(-?\d+\.?\d*)([:_])(-?\d+\.\d+|\d+)([!-/:-~][!-~]*?\s+|[!-/:-~][!-~]*?[:_|-])([12345]|):([NY]):(\d+|O):?([!-~]*?)(\s+|$))"),
        mSuffixPattern("(#[!-~]*?|)(/[12345]|\\[12345])?([!-~]*?)(#[!-~]*?|)(/[12345]|\\[12345])?([:_|]?)(\\s+|$)")
    {
    }
    virtual void GetMatch(CFastqRead& read) override
    {
        CDefLineMatcherIlluminaNewBase::GetMatch(read);
        const auto &m9 = re.GetMatch()[9];
        if ( m9.size() > 2 ) {
            if ( mSuffixPattern.Matches( m9 ) ) {
                read.SetSuffix( mSuffixPattern.GetMatch()[2] );
            }
        }
    }

private:
    CRegExprMatcher mSuffixPattern;
};

    //         if (re2::RE2::PartialMatchN(re.GetMatch()[9], mSuffixPattern, &mSuffixArgs[0], (int)mSuffixArgs.size())) {
    //             read.SetSuffix(mSuffixMatch[2]);
    //         }
    //     }
    // }

    // re2::RE2 mSuffixPattern{"(#[!-~]*?|)(/[12345]|\\[12345])?([!-~]*?)(#[!-~]*?|)(/[12345]|\\[12345])?([:_|]?)(\\s+|$)"};
    // vector<re2::RE2::Arg> mSuffixArgv;
    // vector<re2::RE2::Arg*> mSuffixArgs;
    // vector<re2::StringPiece> mSuffixMatch;


class CDefLineMatcherIlluminaNewWithPeriods : public CDefLineMatcherIlluminaNewBase
/// illuminaNewWithPeriods matcher
{
public:
    CDefLineMatcherIlluminaNewWithPeriods() :
        CDefLineMatcherIlluminaNewBase(
            "illuminaNewWithPeriods",
            "^[@>+]([!-~]+?)(\\.)(\\d+)(\\.)(\\d+)(\\.)(\\d+)(\\.)(\\d+)(\\s+|_)([12345]|)\\.([NY])\\.(\\d+|O)\\.?([!-~]*?)(\\s+|$)")
    {}
};


class CDefLineMatcherIlluminaNewWithUnderscores : public CDefLineMatcherIlluminaNewBase
/// illuminaNewWithUnderscores matcher
{
public:
    CDefLineMatcherIlluminaNewWithUnderscores() :
        CDefLineMatcherIlluminaNewBase(
            "illuminaNewWithUnderscores",
            "^[@>+]([!-~]+?)(_)(\\d+)(_)(\\d+)(_)(\\d+)(_)(\\d+)(\\s+|_)([12345]|)_([NY])_(\\d+|O)_?([!-~]*?)(\\s+|$)")
    {}
};

class CDefLineMatcherIlluminaOldColon : public CDefLineMatcherIlluminaOldBase
/// illuminaOldColon
{
public:
    CDefLineMatcherIlluminaOldColon() :
        CDefLineMatcherIlluminaOldBase(
            "IlluminaOldColon",
            R"(^[@>+]?([!-~]+?)(:)(\d+)(:)(\d+)(:)(-?\d+\.?\d*)([-:])(-?\d+\.\d+|-?\d+)_?[012]?(#[!-~]*?|)\s?(/[12345]|\\[12345])?(\s+|$))")
    {}

};

class CDefLineMatcherIlluminaOldUnderscore : public CDefLineMatcherIlluminaOldBase
/// IlluminaOldUnderscore
{
public:
    CDefLineMatcherIlluminaOldUnderscore() :
        CDefLineMatcherIlluminaOldBase(
            "IlluminaOldUnderscore",
            R"(^[@>+]?([!-~]+?)(_)(\d+)(_)(\d+)(_)(-?\d+\.?\d*)(_)(-?\d+\.\d+|-?\d+)(#[!-~]*?|)\s?(/[12345]|\\[12345])?(\s+|$))")
    {}

};

class CDefLineMatcherIlluminaOldNoPrefix : public CDefLineMatcherIlluminaOldBase
/// IlluminaOldUnderscore
{
public:
    CDefLineMatcherIlluminaOldNoPrefix() :
        CDefLineMatcherIlluminaOldBase(
            "IlluminaOldNoPrefix",
            R"(^[@>+]?([!-~]*?)(:?)(\d+)(:)(\d+)(:)(-?\d+\.?\d*)(:)(-?\d+\.\d+|-?\d+)(#[!-~]*?|)\s?(/[12345]|\\[12345])?(\s+|$))")
    {}

};


class CDefLineMatcherIlluminaOldWithSuffix : public CDefLineMatcherIlluminaOldBase
/// IlluminaOldUnderscore
{
public:
    CDefLineMatcherIlluminaOldWithSuffix() :
        CDefLineMatcherIlluminaOldBase(
            "IlluminaOldWithSuffix",
            R"(^[@>+]?([!-~]+?)(:)(\d+)(:)(\d+)(:)(-?\d+\.?\d*)(:)(-?\d+\.\d+|-?\d+)(#[!-~]*?|)(/[12345][!-~]+)(\s+|$))")
    {}
};

class CDefLineMatcherIlluminaOldWithSuffix2 : public CDefLineMatcherIlluminaOldBase
/// IlluminaOldUnderscore
{
public:
    CDefLineMatcherIlluminaOldWithSuffix2() :
        CDefLineMatcherIlluminaOldBase(
            "IlluminaOldWithSuffix2",
            R"(^[@>+]?([!-~]+?)(:)(\d+)(:)(\d+)(:)(-?\d+\.?\d*)(:)(-?\d+\.?\d*[!-~]+?)(#[!-~]*?|)\s?(/[12345]|\\[12345])?(\s+|$))")
    {}

};


class CDefLineMatcherBgiOld : public CDefLineMatcher
/// BgiOld matcher
{
public:
    CDefLineMatcherBgiOld() :
        CDefLineMatcher(
            "BgiOld",
            R"(^[@>+](\S{1,3}\d{9}\S{0,3})(L\d)(C\d{3})(R\d{3})([_]?\d{1,8})(#[!-~]*?|)(/[1234]\S*|)(\s+|$))")
    {
    }
    uint8_t GetPlatform() const override {
        return 0;//SRA_PLATFORM_UNDEFINED
    };

    virtual void GetMatch(CFastqRead& read) override
    {

        // flowcell, lane, column, row, readNo, spotGroup, readNum, endSep
        m_tmp_spot.clear();
        m_tmp_spot.append(re.GetMatch()[0].data(), re.GetMatch()[0].size()); //flowcell
        m_tmp_spot.append(re.GetMatch()[1].data(), re.GetMatch()[1].size()); //lane
        m_tmp_spot.append(re.GetMatch()[2].data(), re.GetMatch()[2].size()); //column
        m_tmp_spot.append(re.GetMatch()[3].data(), re.GetMatch()[3].size()); //row
        m_tmp_spot.append(re.GetMatch()[4].data(), re.GetMatch()[4].size()); // readNo
        read.MoveSpot(std::move(m_tmp_spot));

        if (!re.GetMatch()[6].empty() && absl::StartsWith(re.GetMatch()[6], "/"))
            re.GetMatch()[6].remove_prefix(1);
        read.SetReadNum(re.GetMatch()[6]);

        if (!re.GetMatch()[5].empty())
            re.GetMatch()[5].remove_prefix(1); // spotGroup
        read.SetSpotGroup(re.GetMatch()[5]);
    }

};

class CDefLineMatcherBgiNew : public CDefLineMatcher
/// BgiNew matcher
{
public:
    CDefLineMatcherBgiNew() :
        CDefLineMatcher(
            "BgiNew",
            R"(^[@>+](\S{1,3}\d{9}\S{0,3})(L\d)(C\d{3})(R\d{3})([_]?\d{1,8})(\S*)(\s+|[_|-])([12345]|):([NY]):(\d+|O):?([!-~]*?)(\s+|$))")

    {}

    uint8_t GetPlatform() const override {
        return 0;//SRA_PLATFORM_UNDEFINED
    };

    virtual void GetMatch(CFastqRead& read) override
    {
        //  0         1     2       3    4       5       6     7        8           9         10         11
        //  flowcell, lane, column, row, readNo, suffix, sep1, readNum, filterRead, reserved, spotGroup, endSep
        m_tmp_spot.clear();
        m_tmp_spot.append(re.GetMatch()[0].data(), re.GetMatch()[0].size()); //flowcell
        m_tmp_spot.append(re.GetMatch()[1].data(), re.GetMatch()[1].size()); //lane
        m_tmp_spot.append(re.GetMatch()[2].data(), re.GetMatch()[2].size()); //column
        m_tmp_spot.append(re.GetMatch()[3].data(), re.GetMatch()[3].size()); //row
        m_tmp_spot.append(re.GetMatch()[4].data(), re.GetMatch()[4].size()); // readNo
        read.MoveSpot(std::move(m_tmp_spot));

        read.SetSuffix(re.GetMatch()[5]);

        read.SetReadNum(re.GetMatch()[7]);

        read.SetSpotGroup(re.GetMatch()[10]);

        read.SetReadFilter(re.GetMatch()[8] == "Y" ? 1 : 0);
    }
};

// NANOPORE

class CDefLineMatcherNanoporeBase : public CDefLineMatcher
{
public:
    CDefLineMatcherNanoporeBase( const string& defLineName, const string& pattern )
    :   CDefLineMatcher( defLineName, pattern ),
        getPorePass( R"(pass[/\\])" ),
        getPoreFail( R"(fail[/\\])" ),
        getPoreBarcode2( R"((NB\d{2}|BC\d{2}|barcode\d{2})([/\\]))" )
    {
    }

    uint8_t GetPlatform() const override {
        return SRA_PLATFORM_OXFORD_NANOPORE;
    };

    void PostProcess( CFastqRead& read )
    {   // Common Nanopore processing (done after parsing the defline)

        if ( read.Channel().empty() )
        {
            read.SetChannel( "0" );
        }
        if ( read.NanoporeReadNo().empty() )
        {
            read.SetNanoporeReadNo( "0" );
        }

        // Set readNum to None if actually a file number or missing
        if ( poreMid == "_file" ||
             read.NanoporeReadNo().empty() )
        {
            read.SetNanoporeReadNo( "0" );
        }

        // Process poreFile if present
        if ( ! poreFile.empty() )
        {
            // Check for 'pass' or 'fail'
            if ( getPorePass.Matches( poreFile ) )
            {
                read.SetReadFilter( 0 );
            }
            else if ( getPoreFail.Matches( poreFile ) )
            {
                read.SetReadFilter( 1 );
            }

            // Check for barcode
            if ( getPoreBarcode2.Matches( poreFile ) )
            {
                re2::StringPiece barcode = getPoreBarcode2.GetMatch()[0];
                const string Barcode = "barcode";
                if ( barcode.find( Barcode ) == 0 )
                {   // self.spotGroup = re.sub(r'barcode(\d+)$',r'BC\1',self.spotGroup,1)
                    read.SetSpotGroup( string( "BC" )
				       + string(barcode.data() + Barcode.size(),
						barcode.size() - Barcode.size()) );
                }
                else
                {
                    read.SetSpotGroup( barcode );
                }
            }
        }

    //     # Split poreFile on '/' or '\' if present

    //     poreFileChunks = re.split(r'[/\\]',self.poreFile)
    //     if len ( poreFileChunks) > 1:
    //         self.poreFile = poreFileChunks.pop()
    //TODO: ... and then self.poreFile does not seem to be used anywhere (ask Bob)

    //TODO: where does appendPoreReadToName come from? (ask Bob)
    // if self.poreRead and self.appendPoreReadToName:
    //     self.name += self.suffix + self.poreRead

    // # Check for missing poreRead (from R-based poRe fastq dump) and normalize read type

    // if ( poreRead.empty() )
    // {
    //TODO: where does filename come from? (ask Bob)
        //     if self.filename:
        //         if self.pore2Dpresent.search(self.filename):
        //             self.poreRead = "2D"
        //         elif self.poreTemplatePresent.search(self.filename):
        //             self.poreRead = "template"
        //         elif self.poreComplementPresent.search(self.filename):
        //             self.poreRead = "complement"
        //         else:
        //             self.poreRead = ""

        //         if self.poreRead and self.appendPoreReadToName:
        //             self.name += self.suffix + "_" + self.poreRead //AB: this might happen twice
        //     else:
        //         self.poreRead = ""

    }
    // elif ( self.poreRead == "_twodirections" or
    //        self.poreRead[1:] == "2D" or
    //        self.poreRead[0:3] == "_2d" ):
    //     self.poreRead = "2D"
    // elif ( self.poreRead[0:9] == "_template" or
    //        self.poreRead == "-1D" or
    //        self.poreRead == ".1T" ):
    //     self.poreRead = "template"
    // else:
    //     self.poreRead = "complement"

    // if ( not self.deflineType and
    //      self.saveDeflineType ):
    //     self.deflineType = self.NANOPORE
    // }
    //TODO: ... and then self.poreRead does not seem to be used anywhere (ask Bob)

    re2::StringPiece poreMid;
    string poreFile;
    re2::StringPiece poreRead;
    CRegExprMatcher getPorePass;
    CRegExprMatcher getPoreFail;
    CRegExprMatcher getPoreBarcode2;
};

class CDefLineMatcherNanopore_Basic : public CDefLineMatcherNanoporeBase
{
public:
    CDefLineMatcherNanopore_Basic( const string& defLineName, const string& pattern )
        : CDefLineMatcherNanoporeBase( defLineName, pattern ), getPoreReadNo2( R"(read_?(\d+))" )
    {
    }

    virtual void GetMatch(CFastqRead& read) override
    {
//re.DumpMatch();
        // 0 poreStart
        // 1 self.channel
        // 2 poreMid
        // 3 self.readNo
        // 4 poreEnd
        // 5 self.poreRead
        // 6 self.poreFile
        // 7 endSep

        m_tmp_spot.clear();
        if ( !re.GetMatch()[3].empty() )
        {   // self.name = poreStart + self.channel + poreMid + self.readNo + poreEnd
            m_tmp_spot.append(re.GetMatch()[0].data(), re.GetMatch()[0].size()); //poreStart
            m_tmp_spot.append(re.GetMatch()[1].data(), re.GetMatch()[1].size()); //channel
            m_tmp_spot.append(re.GetMatch()[2].data(), re.GetMatch()[2].size()); //poreMid
            m_tmp_spot.append(re.GetMatch()[3].data(), re.GetMatch()[3].size()); //readNo
            m_tmp_spot.append(re.GetMatch()[4].data(), re.GetMatch()[4].size()); //poreEnd

            read.SetNanoporeReadNo( re.GetMatch()[3] );
        }
        else
        {   // self.name = poreStart + self.channel + poreEnd
            m_tmp_spot.append(re.GetMatch()[0].data(), re.GetMatch()[0].size()); //poreStart
            m_tmp_spot.append(re.GetMatch()[1].data(), re.GetMatch()[1].size()); //channel
            m_tmp_spot.append(re.GetMatch()[4].data(), re.GetMatch()[4].size()); //poreEnd

            if ( getPoreReadNo2.Matches(re.GetLastInput()) )
            {
                read.SetNanoporeReadNo( getPoreReadNo2.GetMatch()[0] );
            }
        }
        read.MoveSpot(std::move(m_tmp_spot));

        read.SetChannel( re.GetMatch()[1] );

        poreMid = re.GetMatch()[2];
        poreRead = re.GetMatch()[5];
        poreFile.append(re.GetMatch()[6].data(), re.GetMatch()[6].size());
        PostProcess( read );
    }

    CRegExprMatcher getPoreReadNo2;
};

class CDefLineMatcherNanopore1 : public CDefLineMatcherNanopore_Basic
{
public:
    CDefLineMatcherNanopore1() : CDefLineMatcherNanopore_Basic(
            "Nanopore1",
            R"([@>+]+?(channel_)(\d+)(_read_)?(\d+)?([!-~]*?)(_twodirections|_2d|-2D|_template|-1D|_complement|-complement|\.1C|\.1T|\.2D)?(:[!-~ ]+?_ch\d+_file\d+_strand.fast5)?(\s+|$))"
        ) {}
};

class CDefLineMatcherNanopore2 : public CDefLineMatcherNanopore_Basic
{
public:
    CDefLineMatcherNanopore2() : CDefLineMatcherNanopore_Basic(
            "Nanopore2",
            R"([@>+]([!-~]*?ch)(\d+)(_file)(\d+)([!-~]*?)(_twodirections|_2d|-2D|_template|-1D|_complement|-complement|\.1C|\.1T|\.2D)(:[!-~ ]+?_ch\d+_file\d+_strand.fast5)?(\s+|$))"
        ) {}
};

class CDefLineMatcherNanopore3 : public CDefLineMatcherNanoporeBase
{
public:
    CDefLineMatcherNanopore3() :
        CDefLineMatcherNanoporeBase(
            "Nanopore3",
            R"([@>+]([!-~]*?)[: ]?([!-~]+?Basecall)(_[12]D[_0]*?|_Alignment[_0]*?|_Barcoding[_0]*?|)(_twodirections|_2d|-2D|_template|-1D|_complement|-complement|\.1C|\.1T|\.2D|)[: ]([!-~]*?)[: ]?([!-~ ]+?_ch)_?(\d+)(_read|_file)_?(\d+)(_strand\d*.fast5|_strand\d*.*|)(\s+|$))"
        )
    {}

    virtual void GetMatch(CFastqRead& read) override
    {
//re.DumpMatch();
        // 0 prefix
        // 1 self.name
        // 2 self.suffix
        // 3 self.poreRead
        // 4 discard
        // 5 poreStart
        // 6 self.channel
        // 7 poreMid
        // 8 self.readNo
        // 9 poreEnd
        // 10 endSep

        read.SetSpot( re.GetMatch()[1] );
        read.SetSuffix( re.GetMatch()[2] );
        // For now, poreRead is expected to be "_template", other variants will be passed to the regular fastq-load.py
        read.SetChannel( re.GetMatch()[6] );
        read.SetNanoporeReadNo( re.GetMatch()[8] );

        poreMid = re.GetMatch()[7];
        //self.poreFile = poreStart + self.channel + poreMid + self.readNo + poreEnd
        poreFile.append(re.GetMatch()[5].data(), re.GetMatch()[5].size()); //poreStart
        poreFile.append(re.GetMatch()[6].data(), re.GetMatch()[6].size()); //channel
        poreFile.append(re.GetMatch()[7].data(), re.GetMatch()[7].size()); //poreMid
        poreFile.append(re.GetMatch()[8].data(), re.GetMatch()[8].size()); //readNo
        poreFile.append(re.GetMatch()[9].data(), re.GetMatch()[9].size()); //poreEnd

        poreRead = re.GetMatch()[3];
        PostProcess( read );
    }
};

class CDefLineMatcherNanopore3_1 : public CDefLineMatcherNanoporeBase
{
public:
    CDefLineMatcherNanopore3_1() :
        CDefLineMatcherNanoporeBase(
            "Nanopore3_1",
            R"([@>+]([!-~]+?)[: ]?([!-~]+?Basecall)(_[12]D[_0]*?|_Alignment[_0]*?|_Barcoding[_0]*?|)(_twodirections|_2d|-2D|_template|-1D|_complement|-complement|\.1C|\.1T|\.2D|)[: ]([!-~]*?)[: ]?([!-~ ]+?_read_)(\d+)(_ch_)(\d+)(_strand\d*.fast5|_strand\d*.*)(\s+|$))"
        )
    {}

    virtual void GetMatch(CFastqRead& read) override
    {
//re.DumpMatch();
        // 0 prefix
        // 1 self.name
        // 2 self.suffix
        // 3 self.poreRead
        // 4 discard
        // 5 poreStart
        // 6 self.readNo
        // 7 poreMid
        // 8 self.channel
        // 9 poreEnd
        // 10 endSep

        read.SetSpot( re.GetMatch()[1] );
        read.SetSuffix( re.GetMatch()[2] );
        // For now, poreRead is expected to be "_template", other variants will be passed to the regular fastq-load.py
        read.SetNanoporeReadNo( re.GetMatch()[6] );
        read.SetChannel( re.GetMatch()[8] );

        poreMid = re.GetMatch()[7];
        // poreFile = poreStart + self.readNo + poreMid + self.channel + poreEnd
        poreFile.append(re.GetMatch()[5].data(), re.GetMatch()[5].size()); //poreStart
        poreFile.append(re.GetMatch()[6].data(), re.GetMatch()[6].size()); //readNo
        poreFile.append(re.GetMatch()[7].data(), re.GetMatch()[7].size()); //poreMid
        poreFile.append(re.GetMatch()[8].data(), re.GetMatch()[8].size()); //channel
        poreFile.append(re.GetMatch()[9].data(), re.GetMatch()[9].size()); //poreEnd

        poreRead = re.GetMatch()[3];
        PostProcess( read );
    }
};

class CDefLineMatcherNanopore4 : public CDefLineMatcherNanoporeBase
{
public:
    CDefLineMatcherNanopore4() :
        CDefLineMatcherNanoporeBase(
            "Nanopore4",
            R"([@>+]([!-~]*?\S{8}-\S{4}-\S{4}-\S{4}-\S{12}\S*[_]?\d?)[\s+[!-~ ]*?|]$)"
        ),
        getPoreReadNo( R"(read[=_]?(\d+))" ),
        getPoreChannel( R"(ch[=_]?(\d+))" ),
        getPoreBarcode( R"(barcode=(\S+))" )
    {}

    virtual void GetMatch(CFastqRead& read) override
    {
        // 0 self.name
        read.SetSpot( re.GetMatch()[0] );

        if ( getPoreReadNo.Matches(re.GetLastInput()) )
        {
            read.SetNanoporeReadNo( getPoreReadNo.GetMatch()[0] );
        }

        if ( getPoreChannel.Matches(re.GetLastInput()) )
        {
            read.SetChannel( getPoreChannel.GetMatch()[0] );
        }

        const string Unclassified = string("unclassified");
        if ( getPoreBarcode.Matches(re.GetLastInput()) &&
             getPoreBarcode.GetMatch()[0] != Unclassified )
        {
            read.SetSpotGroup( getPoreBarcode.GetMatch()[0] );
        }

        PostProcess( read );
    }

    CRegExprMatcher getPoreReadNo;
    CRegExprMatcher getPoreChannel;
    CRegExprMatcher getPoreBarcode;
};

class CDefLineMatcherNanopore5 : public CDefLineMatcherNanoporeBase
{
public:
    CDefLineMatcherNanopore5() :
        CDefLineMatcherNanoporeBase(
            "Nanopore5",
            R"([@>+]([!-~]*?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}_Basecall)(_[12]D[_0]*?|_Alignment[_0]*?|_Barcoding[_0]*?)(_twodirections|_2d|-2D|_template|-1D|_complement|-complement|\.1C|\.1T|\.2D)\S*?$)"
        )
    {}

    virtual void GetMatch(CFastqRead& read) override
    {
        // 0 self.name
        // 1 self.suffix
        // 2 self.poreRead    }
        read.SetSpot( re.GetMatch()[0] );
        read.SetSuffix( re.GetMatch()[1] );
        // For now, poreRead is expected to be "_template", other variants will be passed to the regular fastq-load.py

        PostProcess( read );
    }
};

// LS454
class CDefLineMatcherLS454 : public CDefLineMatcher
/// LS454 matcher
{
public:
    CDefLineMatcherLS454() :
        CDefLineMatcher(
            "LS454",
            R"(^[@>+]([!-~]+_|)([A-Z0-9]{7})(\d{2})([A-Z0-9]{5})(/[12345])?(\s+|$))")
    {
    }
    uint8_t GetPlatform() const override {
        return SRA_PLATFORM_454;
    };

    virtual void GetMatch(CFastqRead& read) override
    {
        // prefix, dateAndHash454, region454, xy454, readNum, endSep
        // 0       1               2          3      4        5
        m_tmp_spot.clear();
        m_tmp_spot.append(re.GetMatch()[0].data(), re.GetMatch()[0].size()); //prefix
        m_tmp_spot.append(re.GetMatch()[1].data(), re.GetMatch()[1].size()); //dateAndHash454
        m_tmp_spot.append(re.GetMatch()[2].data(), re.GetMatch()[2].size()); //region454
        m_tmp_spot.append(re.GetMatch()[3].data(), re.GetMatch()[3].size()); //xy454
        read.MoveSpot(std::move(m_tmp_spot));
        auto& readNo = re.GetMatch()[4];
        if (!readNo.empty()) {
            readNo.remove_prefix(1);
            read.SetReadNum(readNo);
        }
    }
};

/*
    self.ionTorrent = re.compile(r"[@>+]([A-Z0-9]{5})(:)(\d{1,5})(:)(\d{1,5})([^#/\s]*)(#[!-~]*?|)(/[12345]|\\[12345]|[LR])?(\s+|$)")
    self.ionTorrent2 = re.compile(r"[@>+]([A-Z0-9]{5})(:)(\d{1,5})(:)(\d{1,5})([!-~]*)(\s+|[_|])([12345]|):([NY]):(\d+):?([!-~]*?)(\s+|$)")
*/
class CDefLineMatcherIonTorrent : public CDefLineMatcher
/// ION_TORRENT
{
public:
    CDefLineMatcherIonTorrent() :
        CDefLineMatcher(
            "IonTorrent",
            R"(^[@>+]([A-Z0-9]{5})(:)(\d{1,5})(:)(\d{1,5})([^#/\s]*)(#[!-~]*?|)(/[12345]|\\[12345]|[LR])?(\s+|$))")
    {
    }
    uint8_t GetPlatform() const override {
        return SRA_PLATFORM_ION_TORRENT;
    };

    virtual void GetMatch(CFastqRead& read) override
    {
        // runId, sep1, row, sep2, column, readNum, endSep
        // runId, sep1, row, sep2, column, suffix, spotGroup, readNum, endSep
        // 0      1     2    3     4       5       6          7        8 
        m_tmp_spot.clear();

        m_tmp_spot.append(re.GetMatch()[0].data(), re.GetMatch()[0].size()); //runId
        m_tmp_spot.append(re.GetMatch()[1].data(), re.GetMatch()[1].size()); //sep1
        m_tmp_spot.append(re.GetMatch()[2].data(), re.GetMatch()[2].size()); //row
        m_tmp_spot.append(re.GetMatch()[3].data(), re.GetMatch()[3].size()); //sep2
        m_tmp_spot.append(re.GetMatch()[4].data(), re.GetMatch()[4].size()); //column
        read.MoveSpot(std::move(m_tmp_spot));
        auto& suffix = re.GetMatch()[5];

        auto& spotGroup = re.GetMatch()[6];
        if (!spotGroup.empty()) {
            spotGroup.remove_prefix(1);
            read.SetSpotGroup(spotGroup);            
        }

        auto& readNum = re.GetMatch()[7];
        static const re2::StringPiece readNum1{"1"};
        static const re2::StringPiece readNum2{"2"};

        if (readNum.empty() && !suffix.empty() && (suffix[0] == 'L' || suffix[0] == 'R')) {
            assert(suffix.size() == 1 && (suffix[0] == 'L' || suffix[0] == 'R'));
            read.SetReadNum( suffix == "L" ? readNum1 : readNum2 );
        } else {
            read.SetSuffix(suffix);
            if (absl::StartsWith(readNum, "/") || absl::StartsWith(readNum, "\\")) 
                readNum.remove_prefix(1);
            else if (readNum == "L")
                readNum = "1";
            else if (readNum == "R")
                readNum = "2";
            read.SetReadNum(readNum);
        }
    }
};


class CDefLineMatcherIonTorrent2 : public CDefLineMatcher
/// ION_TORRENT
{
public:
    CDefLineMatcherIonTorrent2() :
        CDefLineMatcher(
            "IonTorrent2",
            R"(^[@>+]([A-Z0-9]{5})(:)(\d{1,5})(:)(\d{1,5})([!-~]*)(\s+|[_|])([12345]|):([NY]):(\d+|O):?([!-~]*?)(\s+|$))")
    {
    }
    uint8_t GetPlatform() const override {
        return SRA_PLATFORM_ION_TORRENT;
    };

    virtual void GetMatch(CFastqRead& read) override
    {

        // runId, sep1, row, sep2, column, suffix, sep3, readNum, filterRead, reserved, spotGroup, endSep
        // 0      1     2    3     4       5       6     7         8          9         10         11
        


        m_tmp_spot.clear();

        m_tmp_spot.append(re.GetMatch()[0].data(), re.GetMatch()[0].size()); //runId
        m_tmp_spot.append(re.GetMatch()[1].data(), re.GetMatch()[1].size()); //sep1
        m_tmp_spot.append(re.GetMatch()[2].data(), re.GetMatch()[2].size()); //row
        m_tmp_spot.append(re.GetMatch()[3].data(), re.GetMatch()[3].size()); //sep2
        m_tmp_spot.append(re.GetMatch()[4].data(), re.GetMatch()[4].size()); //column
        read.MoveSpot(std::move(m_tmp_spot));

        read.SetSuffix(re.GetMatch()[5]);

        read.SetReadNum(re.GetMatch()[7]);

        read.SetReadFilter(re.GetMatch()[8] == "Y" ? 1 : 0);

        read.SetSpotGroup(re.GetMatch()[10]);
    }
};


class CDefLineMatcherPacBio : public CDefLineMatcher
/// PacBio
{
public:
    CDefLineMatcherPacBio() :
        CDefLineMatcher(
            "PacBio",
            R"(^[@>+](m\d{5,6}_\d{6}_[!-~]+?_c\d{33}_s\d+_[pX]\d/\d+/?\d*_?\d*|m\d{6}_\d{6}_[!-~]+?_c\d{33}_s\d+_[pX]\d[|/]\d+[|/]ccs[!-~]*?)(\s+|$))")
    {
    }
    CDefLineMatcherPacBio(const string& defLineName, const string& pattern) :
        CDefLineMatcher(defLineName, pattern)
    {
    }

    uint8_t GetPlatform() const override {
        return SRA_PLATFORM_PACBIO_SMRT;
    };

    virtual void GetMatch(CFastqRead& read) override
    {
        // Name
        // 0   

        m_tmp_spot.clear();

        m_tmp_spot.append(re.GetMatch()[0].data(), re.GetMatch()[0].size()); // name
        read.MoveSpot(std::move(m_tmp_spot));
    }
};

class CDefLineMatcherPacBio2 : public CDefLineMatcherPacBio
/// PacBio2
{
public:
    CDefLineMatcherPacBio2() :
        CDefLineMatcherPacBio(
            "PacBio2",
            R"(^[@>+]([!-~]*?m\d{5,6}\S{0,3}_\d{6}_\d{6}\S*[/_]\d+[!-~]*?)(\s+|$))")
    {
    }
};


class CDefLineMatcherPacBio3 : public CDefLineMatcherPacBio
/// PacBio3
{
public:
    CDefLineMatcherPacBio3() :
        CDefLineMatcherPacBio(
            "PacBio3",
            R"(^[@>+]([!-~]*?m\d{5,6}\S{0,3}_\d{6}_\d{6}\S*[/_]\d+/ccs[!-~]*?)(\s+|$))")
    {
    }
};

class CDefLineMatcherPacBio4 : public CDefLineMatcherPacBio
/// PacBio4
{
public:
    CDefLineMatcherPacBio4() :
        CDefLineMatcherPacBio(
            "PacBio4",
            R"(^[@>+]([!-~]*?m\d{5,6}\S{0,3}_\d{6}_\d{6}\S*[/_]\d+/\d+_\d+[!-~]*?)(\s+|$))")
    {
    }
};


//self.illuminaOldBcRnOnly = re.compile(r"^[@>+]([!-~]+?)(#[!-~]+?)(/[12345]|\\[12345])(\s+|$)")

class CDefLineIlluminaOldBcRn : public CDefLineMatcher
/// IlluminaOld BarCode and ReadNum only 
{
public:
    CDefLineIlluminaOldBcRn() :
        CDefLineMatcher(
            "illuminaOldBcRnOnly",
            R"(^[@>+]([!-~]+?)(#[!-~]+?)(/[1234]|\\[1234])(\s+|$))")
    {
    }
    CDefLineIlluminaOldBcRn(const string& defLineName, const string& pattern) :
        CDefLineMatcher(defLineName, pattern)
    {
    }

    uint8_t GetPlatform() const override {
        return SRA_PLATFORM_UNDEFINED;
    };

    virtual void GetMatch(CFastqRead& read) override
    {
        // Name SpotGroup ReadNum endSep
        // 0    1         2       3

        m_tmp_spot.clear();

        m_tmp_spot.append(re.GetMatch()[0].data(), re.GetMatch()[0].size()); // name
        read.MoveSpot(std::move(m_tmp_spot));

        auto& spot_group = re.GetMatch()[1];
        if (absl::StartsWith(spot_group, "#")) {
            spot_group.remove_prefix(1);
            read.SetSpotGroup(spot_group);
            auto& read_num = re.GetMatch()[2];
            auto sz = read_num.size();
            if ((sz > 0 && read_num[0] == '/') || (sz > 1 && read_num[0] == '\\')) {
                read_num.remove_prefix(1);
                read.SetReadNum(read_num);
            }
        } else {
            spot_group.remove_prefix(1);
            read.SetReadNum(spot_group);
        }
    }
};

//self.illuminaOldBcOnly = re.compile(r"^[@>+]([!-~]+?)(#[!-~]+)(\s+|$)(.?)")
class CDefLineIlluminaOldBcOnly : public CDefLineIlluminaOldBcRn
/// IlluminaOld BarCode only 
{
public:
    CDefLineIlluminaOldBcOnly() :
        CDefLineIlluminaOldBcRn(
            "illuminaOldBcOnly",
            R"(^[@>+]([!-~]+?)(#[!-~]+)(\s+|$)(.?))")
    {
    }
};

//self.illuminaOldRnOnly = re.compile(r"^[@>+]([!-~]+?)(/[12345]|\\[12345])(\s+|$)(.?)")
class CDefLineIlluminaOldRnOnly : public CDefLineIlluminaOldBcRn
/// IlluminaOld ReadNum only 
{
public:
    CDefLineIlluminaOldRnOnly() :
        CDefLineIlluminaOldBcRn(
            "illuminaOldRnOnly",
            R"(^[@>+]([!-~]+?)(/[1234]|\\[1234])(\s+|$)(.?))")
    {
    }
};


#endif