File: oligos.cpp

package info (click to toggle)
mothur 1.48.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,692 kB
  • sloc: cpp: 161,866; makefile: 122; sh: 31
file content (899 lines) | stat: -rwxr-xr-x 39,479 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
//
//  oligos.cpp
//  Mothur
//
//  Created by Sarah Westcott on 4/4/14.
//  Copyright (c) 2014 Schloss Lab. All rights reserved.
//

#include "oligos.h"
#include "utils.hpp"

/**************************************************************************************************/

Oligos::Oligos(string o){
	try {
		m = MothurOut::getInstance();
        hasPPrimers = false; hasPBarcodes = false; pairedOligos = false; reversePairs = true;
        indexBarcode = 0; indexPairedBarcode = 0; indexPrimer = 0; indexPairedPrimer = 0;
		oligosfile = o;
        reversePairs = true;
        readOligos();
		if (pairedOligos) {
            numBarcodes = pairedBarcodes.size();
            numFPrimers = pairedPrimers.size();
        }else {
            numBarcodes = barcodes.size();
            numFPrimers = primers.size();
        }
	}
	catch(exception& e) {
		m->errorOut(e, "Oligos", "Oligos");
		exit(1);
	}
}
/**************************************************************************************************/

Oligos::Oligos(){
	try {
		m = MothurOut::getInstance();
        hasPPrimers = false; hasPBarcodes = false; pairedOligos = false; reversePairs = true;
        indexBarcode = 0; indexPairedBarcode = 0; indexPrimer = 0; indexPairedPrimer = 0;
        numFPrimers = 0; numBarcodes = 0;
	}
	catch(exception& e) {
		m->errorOut(e, "Oligos", "Oligos");
		exit(1);
	}
}
/**************************************************************************************************/
int Oligos::read(string o){
	try {
		oligosfile = o;
        readOligos();
        if (pairedOligos) {
            numBarcodes = pairedBarcodes.size();
            numFPrimers = pairedPrimers.size();
        }else {
            numBarcodes = barcodes.size();
            numFPrimers = primers.size();
        }
        return 0;
	}
	catch(exception& e) {
		m->errorOut(e, "Oligos", "read");
		exit(1);
	}
}
/**************************************************************************************************/
int Oligos::read(string o, bool reverse){
	try {
		oligosfile = o;
        reversePairs = reverse;
        readOligos();
        if (pairedOligos) {
            numBarcodes = pairedBarcodes.size();
            numFPrimers = pairedPrimers.size();
        }else {
            numBarcodes = barcodes.size();
            numFPrimers = primers.size();
        }
        return 0;
	}
	catch(exception& e) {
		m->errorOut(e, "Oligos", "read");
		exit(1);
	}
}
/**************************************************************************************************/
vector<string> Oligos::getSRAGroupNames(){
    try {
        vector<string> sraGroupNames;
        set<string> uniqueNames;
        
        if (pairedOligos) {
            for(map<int, oligosPair>::iterator itBar = pairedBarcodes.begin();itBar != pairedBarcodes.end();itBar++){
                for(map<int, oligosPair>::iterator itPrimer = pairedPrimers.begin();itPrimer != pairedPrimers.end(); itPrimer++){
                    
                    if (m->getControl_pressed()) { return sraGroupNames; }
                    
                    string primerName = getPrimerName(itPrimer->first);
                    string barcodeName = getBarcodeName(itBar->first);
                    
                    if ((primerName == "ignore") || (barcodeName == "ignore")) { } //do nothing
                    else if ((primerName == "") && (barcodeName == "")) { } //do nothing
                    else {
                        string comboGroupName = "";
                        string comboName = "";
                        
                        if(primerName == ""){
                            comboGroupName = barcodeName;
                        }else{
                            if(barcodeName == ""){
                                comboGroupName = primerName;
                            }
                            else{
                                comboGroupName = barcodeName + "." + primerName;
                            }
                        }
                        
                        if(((itPrimer->second).forward+(itPrimer->second).reverse) == ""){
                            if ((itBar->second).forward != "NONE") { comboName += (itBar->second).forward; }
                            if ((itBar->second).reverse != "NONE") {
                                if (comboName == "") {  comboName += (itBar->second).reverse; }
                                else {  comboName += ("."+(itBar->second).reverse);  }
                            }
                        }else{
                            if(((itBar->second).forward+(itBar->second).reverse) == ""){
                                if ((itPrimer->second).forward != "NONE") { comboName += (itPrimer->second).forward; }
                                if ((itPrimer->second).reverse != "NONE") {
                                    if (comboName == "") {  comboName += (itPrimer->second).reverse; }
                                    else {  comboName += ("."+(itPrimer->second).reverse);  }
                                }
                            }
                            else{
                                if ((itBar->second).forward != "NONE") { comboName += (itBar->second).forward; }
                                if ((itBar->second).reverse != "NONE") {
                                    if (comboName == "") {  comboName += (itBar->second).reverse; }
                                    else {  comboName += ("."+(itBar->second).reverse);  }
                                }
                                if ((itPrimer->second).forward != "NONE") {
                                    if (comboName == "") {  comboName += (itPrimer->second).forward; }
                                    else {  comboName += ("."+(itPrimer->second).forward);  }
                                }
                                if ((itPrimer->second).reverse != "NONE") {
                                    if (comboName == "") {  comboName += (itPrimer->second).reverse; }
                                    else {  comboName += ("."+(itPrimer->second).reverse);  }
                                }
                            }
                        }
                        
                        if (comboName != "") {  comboGroupName +=  "_" + comboName;  }
                        uniqueNames.insert(comboGroupName);
                    }
                }
            }
        }else {
            
            for(map<string, int>::iterator itBar = barcodes.begin();itBar != barcodes.end();itBar++){
                for(map<string, int>::iterator itPrimer = primers.begin();itPrimer != primers.end(); itPrimer++){
                    
                    string primerName = getPrimerName(itPrimer->second);
                    string barcodeName = getBarcodeName(itBar->second);
                    
                    if ((primerName == "ignore") || (barcodeName == "ignore")) { } //do nothing
                    else if ((primerName == "") && (barcodeName == "")) { } //do nothing
                    else {
                        string comboGroupName = "";
                        string comboName = "";
                        
                        if(primerName == ""){
                            comboGroupName = barcodeName;
                        }else{
                            if(barcodeName == ""){
                                comboGroupName = primerName;
                            }
                            else{
                                comboGroupName = barcodeName + "." + primerName;
                            }
                        }
                        
                        if(itPrimer->first == ""){
                            comboName = itBar->first;
                        }else{
                            if(itBar->first == ""){
                                comboName = itPrimer->first;
                            }
                            else{
                                comboName = itBar->first + "." + itPrimer->first;
                            }
                        }
                        
                        if (comboName != "") {  comboGroupName +=  "_" + comboName;  }
                        uniqueNames.insert(comboGroupName);
                    }
                }
            }
        }
        
        if (uniqueNames.size() == 0) {
            m->mothurOut("[ERROR]: your oligos file does not contain any group names.\n");  m->setControl_pressed(true);
        }else {
            if (m->getDebug()) { int count = 0; for (set<string>::iterator it = uniqueNames.begin(); it != uniqueNames.end(); it++) { m->mothurOut("[DEBUG]: " + toString(count) + " groupName = " + *it + "\n"); count++; } }
            for (set<string>::iterator it = uniqueNames.begin(); it != uniqueNames.end(); it++) {  sraGroupNames.push_back(*it); }
        }

    
        return sraGroupNames;
    }
    catch(exception& e) {
        m->errorOut(e, "Oligos", "getSRAGroupNames");
        exit(1);
    }
}
//***************************************************************************************************************

int Oligos::readOligos(){
	try {
		ifstream inOligos;
        Utils util; util.openInputFile(oligosfile, inOligos);
		
		string type, oligo, roligo, group;
        bool pfUsesNone = false; bool prUsesNone = false; bool bfUsesNone = false; bool brUsesNone = false;
        set<string> uniqueBarcodes;
        set<string> uniquePrimers;
		
		while(!inOligos.eof()){
            
            string line = util.getline(inOligos); gobble(inOligos);
        
			if(line[0] == '#'){} //ignore
			else{
                vector<string> pieces = util.splitWhiteSpace(line);
                
                toUpper(pieces[0]); type = pieces[0];//make type case insensitive
                
                oligo = pieces[1]; formatOligo(oligo);
                
                if (m->getDebug()) { m->mothurOut("[DEBUG]: reading type - " + type + ".\n"); m->mothurOut("[DEBUG]: reading - " + oligo + ".\n"); }
				
				if(type == "FORWARD"){
					group = "";
                    
                    if (pieces.size() > 2) { group = pieces[2]; }
					
					//check for repeat primers
					map<string, int>::iterator itPrime = primers.find(oligo);
					if (itPrime != primers.end()) { m->mothurOut("[WARNING]: primer " + oligo + " is in your oligos file already, disregarding.\n");   }
                    else {
                        if (m->getDebug()) {  if (group != "") { m->mothurOut("[DEBUG]: reading group " + group + ".\n"); }else{ m->mothurOut("[DEBUG]: no group for primer " + oligo + ".\n"); }  }
                    
                        primers[oligo]=indexPrimer; indexPrimer++;
                        primerNameVector.push_back(group);
                    }
				}
                else if (type == "PRIMER"){
                    
                    roligo = pieces[2]; formatOligo(roligo);
                    
                    if (oligo == "NONE")        {  pfUsesNone = true; }
                    else if (roligo == "NONE")  { prUsesNone = true;  }
                   
                    if (roligo != "NONE") {
                        if (reversePairs) {  roligo = reverseOligo(roligo); }
                    }
                    group = "";
                    
                    if (pieces.size() > 3) { group = pieces[3]; }
                    
                    oligosPair newPrimer(oligo, roligo);
                    
                    if (m->getDebug()) { m->mothurOut("[DEBUG]: primer pair " + newPrimer.forward + " " + newPrimer.reverse + ", and group = " + group + ".\n"); }
					
					//check for repeat barcodes
                    string tempPair = oligo+roligo;
                    if (uniquePrimers.count(tempPair) != 0) { m->mothurOut("[WARNING]: primer pair " + newPrimer.forward + " " + newPrimer.reverse + " is in your oligos file already, disregarding.\n");   }
                    else { uniquePrimers.insert(tempPair);
					
                        if (m->getDebug()) {  if (group != "") { m->mothurOut("[DEBUG]: reading group " + group + ".\n"); }else{ m->mothurOut("[DEBUG]: no group for primer pair " + newPrimer.forward + " " + newPrimer.reverse + ".\n"); }  }
                
                        pairedPrimers[indexPairedPrimer]=newPrimer; indexPairedPrimer++;
                        primerNameVector.push_back(group);
                        hasPPrimers = true;
                    }
                }
				else if(type == "REVERSE"){
                    string oligoRC = reverseOligo(oligo);
					revPrimer.push_back(oligoRC);
				}
				else if(type == "BARCODE"){
                    //barcode lines can look like   BARCODE   atgcatgc   groupName  - for 454 seqs
                    //or                            BARCODE   atgcatgc   atgcatgc    groupName  - for illumina data that has forward and reverse info
                    group = "";
                    
                    if (pieces.size() == 3) {
                        group = pieces[2];
                        
                        //check for repeat barcodes
                        map<string, int>::iterator itBar = barcodes.find(oligo);
                        if (itBar != barcodes.end()) { m->mothurOut("[WARNING]: barcode " + oligo + " is in your oligos file already, disregarding.\n");   }
                        else {
                            barcodes[oligo]=indexBarcode; indexBarcode++;
                            barcodeNameVector.push_back(group);
                        }
                    }
                    else if (pieces.size() == 4) {
                        
                        hasPBarcodes = true;
                        string reverseBarcode = pieces[2]; formatOligo(reverseBarcode);
                        group = pieces[3];
                        
                        if (oligo == "NONE")                {  bfUsesNone = true; }
                        else if (reverseBarcode == "NONE")  { brUsesNone = true;  }
                        
                        if (reverseBarcode != "NONE") {
                            if (reversePairs) {   reverseBarcode = reverseOligo(reverseBarcode); }
                        }
                        oligosPair newPair(oligo, reverseBarcode);
                        
                        if (m->getDebug()) { m->mothurOut("[DEBUG]: barcode pair " + newPair.forward + " " + newPair.reverse + ", and group = " + group + ".\n"); }
                        
                        //check for repeat barcodes
                        string tempPair = oligo+reverseBarcode;
                        if (uniqueBarcodes.count(tempPair) != 0) { m->mothurOut("barcode pair " + newPair.forward + " " + newPair.reverse +  " is in your oligos file already, disregarding.\n");  }
                        else {
                            uniqueBarcodes.insert(tempPair);
                            pairedBarcodes[indexPairedBarcode]=newPair; indexPairedBarcode++;
                            barcodeNameVector.push_back(group);
                        }
                        
                    }
				}else if(type == "LINKER"){
					linker.push_back(oligo);
				}else if(type == "SPACER"){
					spacer.push_back(oligo);
				}
				else{	m->mothurOut("[WARNING]: " + type + " is not recognized as a valid type. Choices are primer, forward, reverse, and barcode. Ignoring " + oligo + ".\n");  }
			}
		}
		inOligos.close();
		
        if ((linker.size() == 0) && (spacer.size() == 0) && (pairedBarcodes.size() == 0) && (barcodes.size() == 0) && (pairedPrimers.size() == 0) && (primers.size() == 0) && (revPrimer.size() == 0)) { m->mothurOut("[ERROR]: invalid oligos file, quitting.\n"); m->setControl_pressed(true); return 0; }
        
        if (hasPBarcodes || hasPPrimers) {
            pairedOligos = true;
            if ((primers.size() != 0) || (barcodes.size() != 0) || (linker.size() != 0) || (spacer.size() != 0) || (revPrimer.size() != 0)) { m->setControl_pressed(true);  m->mothurOut("[ERROR]: cannot mix paired primers and barcodes with non paired or linkers and spacers, quitting.\n");  return 0; }
            
            //check for "NONE" to make sure if none is used then all primers in that position are NONE
            //ex. Can't have: PRIMER NONE reversePrimer and PRIMER fowardPrimer reversePrimer in same file
            if (bfUsesNone) {
                bool allNONE = true;
                for(map<int, oligosPair>::iterator itBar = pairedBarcodes.begin();itBar != pairedBarcodes.end();itBar++){
                    if ((itBar->second).forward != "NONE") {
                        allNONE = false;
                        break;
                    }
                }
                if (!allNONE) {
                    m->setControl_pressed(true);  m->mothurOut("[ERROR]: cannot mix forwardBarcode=NONE and forwardBarcode=barcodeString in same file. Mothur assumes all sequences have forward barcodes or all do not, quitting.\n");   return 0;
                }
            }
            
            if (brUsesNone) {
                bool allNONE = true;
                for(map<int, oligosPair>::iterator itBar = pairedBarcodes.begin();itBar != pairedBarcodes.end();itBar++){
                    if ((itBar->second).reverse != "NONE") {
                        allNONE = false;
                        break;
                    }
                }
                if (!allNONE) {
                    m->setControl_pressed(true);  m->mothurOut("[ERROR]: cannot mix reverseBarcode=NONE and reverseBarcode=barcodeString in same file. Mothur assumes all sequences have reverse barcodes or all do not, quitting.\n");   return 0;
                }
            }
            
            if (pfUsesNone) {
                bool allNONE = true;
                for(map<int, oligosPair>::iterator itPrimer = pairedPrimers.begin();itPrimer != pairedPrimers.end(); itPrimer++){
                    if ((itPrimer->second).forward != "NONE") {
                        allNONE = false;
                        break;
                    }
                }
                if (!allNONE) {
                    m->setControl_pressed(true);  m->mothurOut("[ERROR]: cannot mix forwardPrimer=NONE and forwardPrimer=primerString in same file. Mothur assumes all sequences have forward primers or all do not, quitting.\n");   return 0;
                }
            }
            
            if (prUsesNone) {
                bool allNONE = true;
                for(map<int, oligosPair>::iterator itPrimer = pairedPrimers.begin();itPrimer != pairedPrimers.end(); itPrimer++){
                    if ((itPrimer->second).reverse != "NONE") {
                        allNONE = false;
                        break;
                    }
                }
                if (!allNONE) {
                    m->setControl_pressed(true);  m->mothurOut("[ERROR]: cannot mix reversePrimer=NONE and reversePrimer=primerString in same file. Mothur assumes all sequences have reverse primers or all do not, quitting.\n");   return 0;
                }
            }
        }
        
        
		//add in potential combos
		if(barcodeNameVector.size() == 0){
            if (pairedOligos) {
                oligosPair newPair("", "");
                pairedBarcodes[0] = newPair;
            }else {
                barcodes[""] = 0;
            }
			barcodeNameVector.push_back("");
		}
		
		if(primerNameVector.size() == 0){
            if (pairedOligos) {
                oligosPair newPair("", "");
                pairedPrimers[0] = newPair;
            }else {
                primers[""] = 0;
            }
			primerNameVector.push_back("");
		}
		
		
        if (pairedOligos) {
            for(map<int, oligosPair>::iterator itBar = pairedBarcodes.begin();itBar != pairedBarcodes.end();itBar++){
                for(map<int, oligosPair>::iterator itPrimer = pairedPrimers.begin();itPrimer != pairedPrimers.end(); itPrimer++){
                    
                    string primerName = primerNameVector[itPrimer->first];
                    string barcodeName = barcodeNameVector[itBar->first];
                    
                    if (m->getDebug()) {  m->mothurOut("[DEBUG]: primerName = " + primerName + " barcodeName = " + barcodeName + "\n");  }
                    
                    if ((primerName == "ignore") || (barcodeName == "ignore")) { if (m->getDebug()) {  m->mothurOut("[DEBUG]: in ignore. \n");  }  } //do nothing
                    else if ((primerName == "") && (barcodeName == "")) { if (m->getDebug()) {  m->mothurOut("[DEBUG]: in blank. \n");  }  } //do nothing
                    else {
                        string comboGroupName = "";
                        string fastqFileName = "";
                        
                        if(primerName == ""){
                            comboGroupName = barcodeNameVector[itBar->first];
                        }else{
                            if(barcodeName == ""){
                                comboGroupName = primerNameVector[itPrimer->first];
                            }
                            else{
                                comboGroupName = barcodeNameVector[itBar->first] + "." + primerNameVector[itPrimer->first];
                            }
                        }
                        
                        if (m->getDebug()) {  m->mothurOut("[DEBUG]: comboGroupName = " + comboGroupName +  "\n");  }
                        
                        uniqueNames.insert(comboGroupName);
                        
                        map<string, vector<string> >::iterator itGroup2Barcode = Group2Barcode.find(comboGroupName);
                        if (itGroup2Barcode == Group2Barcode.end()) {
                            vector<string> tempBarcodes; tempBarcodes.push_back((itBar->second).forward+"."+(itBar->second).reverse);
                            Group2Barcode[comboGroupName] = tempBarcodes;
                        }else {
                            Group2Barcode[comboGroupName].push_back((itBar->second).forward+"."+(itBar->second).reverse);
                        }
                        
                        itGroup2Barcode = Group2Primer.find(comboGroupName);
                        if (itGroup2Barcode == Group2Primer.end()) {
                            vector<string> tempPrimers; tempPrimers.push_back((itPrimer->second).forward+"."+(itPrimer->second).reverse);
                            Group2Primer[comboGroupName] = tempPrimers;
                        }else {
                            Group2Primer[comboGroupName].push_back((itPrimer->second).forward+"."+(itPrimer->second).reverse);
                        }
                    }
                }
            }
        }else {
            for(map<string, int>::iterator itBar = barcodes.begin();itBar != barcodes.end();itBar++){
                for(map<string, int>::iterator itPrimer = primers.begin();itPrimer != primers.end(); itPrimer++){
                    
                    string primerName = primerNameVector[itPrimer->second];
                    string barcodeName = barcodeNameVector[itBar->second];
                    
                    if ((primerName == "ignore") || (barcodeName == "ignore")) { } //do nothing
                    else if ((primerName == "") && (barcodeName == "")) { } //do nothing
                    else {
                        string comboGroupName = "";
                        string fastqFileName = "";
                        
                        if(primerName == ""){
                            comboGroupName = barcodeNameVector[itBar->second];
                        }
                        else{
                            if(barcodeName == ""){
                                comboGroupName = primerNameVector[itPrimer->second];
                            }
                            else{
                                comboGroupName = barcodeNameVector[itBar->second] + "." + primerNameVector[itPrimer->second];
                            }
                        }
                        uniqueNames.insert(comboGroupName);
                        
                        map<string, vector<string> >::iterator itGroup2Barcode = Group2Barcode.find(comboGroupName);
                        if (itGroup2Barcode == Group2Barcode.end()) {
                            vector<string> tempBarcodes; tempBarcodes.push_back(itBar->first);
                            Group2Barcode[comboGroupName] = tempBarcodes;
                        }else {
                            Group2Barcode[comboGroupName].push_back(itBar->first);
                        }
                        
                        itGroup2Barcode = Group2Primer.find(comboGroupName);
                        if (itGroup2Barcode == Group2Primer.end()) {
                            vector<string> tempPrimers; tempPrimers.push_back(itPrimer->first);
                            Group2Primer[comboGroupName] = tempPrimers;
                        }else {
                            Group2Primer[comboGroupName].push_back(itPrimer->first);
                        }
                    }
                }
            }
        }
        
        
        if (m->getDebug()) { int count = 0; for (set<string>::iterator it = uniqueNames.begin(); it != uniqueNames.end(); it++) { m->mothurOut("[DEBUG]: " + toString(count) + " groupName = " + *it + "\n"); count++; } }
        
        Groups.clear();
        for (set<string>::iterator it = uniqueNames.begin(); it != uniqueNames.end(); it++) {  Groups.push_back(*it); }
        
        return 0;
	}
	catch(exception& e) {
		m->errorOut(e, "Oligos", "readOligos");
		exit(1);
	}
}
//********************************************************************/
vector<string> Oligos::getBarcodes(string groupName){
	try {
        vector<string> thisGroupsBarcodes;
        
        map<string, vector<string> >::iterator it = Group2Barcode.find(groupName);
        
        if (it == Group2Barcode.end()) {  m->mothurOut("[ERROR]: no barcodes found for group " + groupName + ".\n"); m->setControl_pressed(true);
        }else { thisGroupsBarcodes = it->second; }
        
        return thisGroupsBarcodes;
    }
	catch(exception& e) {
		m->errorOut(e, "Oligos", "getBarcodes");
		exit(1);
	}
}
//********************************************************************/
vector<string> Oligos::getPrimers(string groupName){
	try {
        vector<string> thisGroupsPrimers;
        
        map<string, vector<string> >::iterator it = Group2Primer.find(groupName);
        
        if (it == Group2Primer.end()) {  m->mothurOut("[ERROR]: no primers found for group " + groupName + ".\n"); m->setControl_pressed(true);
        }else { thisGroupsPrimers = it->second; }
        
        return thisGroupsPrimers;
    }
	catch(exception& e) {
		m->errorOut(e, "Oligos", "getPrimers");
		exit(1);
	}
}
//********************************************************************/
//can't have paired and unpaired so this function will either run the paired map or the unpaired
map<int, oligosPair> Oligos::getReversedPairedPrimers(){
    try {
        map<int, oligosPair> rpairedPrimers;
        set<string> uniquePrimers;
        
        for (map<int, oligosPair>::iterator it = pairedPrimers.begin(); it != pairedPrimers.end(); it++) {
            //add reverse compliment barcodes
            string forward = reverseOligo((it->second).forward);
            string reverse = reverseOligo((it->second).reverse);
            
            string temp = forward+reverse;
            if (uniquePrimers.count(temp) != 0) { } //already have this pair assigned to a sample, ignore reversed version
            else {
                uniquePrimers.insert(temp);
                oligosPair tempPair(forward, reverse); //reverseforward, reverseReverse
                rpairedPrimers[it->first] = tempPair;
            }
        }
        
        for (map<string, int>::iterator it = primers.begin(); it != primers.end(); it++) {
            //add reverse compliment barcodes
            string forward = reverseOligo(it->first);
            string reverse = "";
            
            string temp = forward+reverse;
            if (uniquePrimers.count(temp) != 0) { } //already have this pair assigned to a sample, ignore reversed version
            else {
                uniquePrimers.insert(temp);
                oligosPair tempPair(forward, reverse); //reverseforward, reverseReverse
                rpairedPrimers[it->second] = tempPair;
            }
        }

        return rpairedPrimers;
    }
    catch(exception& e) {
        m->errorOut(e, "Oligos", "getReversedPairedPrimers");
        exit(1);
    }
}
//********************************************************************/
//can't have paired and unpaired so this function will either run the paired map or the unpaired
map<int, oligosPair> Oligos::getReorientedPairedPrimers(){
	try {
        map<int, oligosPair> rpairedPrimers;
        set<string> uniquePrimers;
        
        for (map<int, oligosPair>::iterator it = pairedPrimers.begin(); it != pairedPrimers.end(); it++) {
            string forward = (it->second).reverse;
            if (reversePairs) { forward = reverseOligo(forward); }
            string reverse = (it->second).forward;
            if (reversePairs) { reverse = reverseOligo(reverse); }
            oligosPair tempPair(forward, reverse); //reversePrimer, rc ForwardPrimer
            rpairedPrimers[it->first] = tempPair;
        }
        
        
        for (map<string, int>::iterator it = primers.begin(); it != primers.end(); it++) {
            oligosPair tempPair("", reverseOligo((it->first))); //reverseBarcode, rc ForwardBarcode
            rpairedPrimers[it->second] = tempPair;
        }
        
        return rpairedPrimers;
    }
	catch(exception& e) {
		m->errorOut(e, "Oligos", "getReorientedPairedPrimers");
		exit(1);
	}
}
//********************************************************************/
vector<string> Oligos::getReorientedReversePrimers(){
    try {
        vector<string> revReorientedPrimers;
        
        for (map<string, int>::iterator it = primers.begin(); it != primers.end(); it++) {
            string reverse = reverseOligo((it->first)); //rc ForwardPrimer
            revReorientedPrimers.push_back(reverse);
        }
        
        return revReorientedPrimers;
    }
    catch(exception& e) {
        m->errorOut(e, "Oligos", "getReorientedPairedPrimers");
        exit(1);
    }
}
//********************************************************************/
map<string, int> Oligos::getReorientedPrimers(){
    try {
        map<string, int> reorientedPrimers;
        
        for (int i = 0; i < revPrimer.size(); i++) {
            string primer = reverseOligo(revPrimer[i]);
            reorientedPrimers[primer] = -1; //ignore value
        }
        
        return reorientedPrimers;
    }
    catch(exception& e) {
        m->errorOut(e, "Oligos", "getReorientedPrimers");
        exit(1);
    }
}
//********************************************************************/
vector<string> Oligos::getReversedReversePrimers(){
    try {
        vector<string> revReversedPrimers;
        
        for (int i = 0; i < revPrimer.size(); i++) {
            string primer = reverseOligo(revPrimer[i]);
            revReversedPrimers.push_back(primer);
        }
    
        return revReversedPrimers;
    }
    catch(exception& e) {
        m->errorOut(e, "Oligos", "getReorientedPairedPrimers");
        exit(1);
    }
}
//********************************************************************/
map<string, int> Oligos::getReversedPrimers(){
    try {
        map<string, int> revReversedPrimers;
        
        for (map<string, int>::iterator it = primers.begin(); it != primers.end(); it++) {
            string reverse = reverseOligo((it->first)); //rc ForwardPrimer
            revReversedPrimers[reverse] = it->second;
        }
        
        return revReversedPrimers;
    }
    catch(exception& e) {
        m->errorOut(e, "Oligos", "getReorientedPrimers");
        exit(1);
    }
}
//********************************************************************/
//can't have paired and unpaired so this function will either run the paired map or the unpaired
map<int, oligosPair> Oligos::getReversedPairedBarcodes(){
    try {
        map<int, oligosPair> rpairedBarcodes;
        set<string> uniqueBarcodes;
        
        for (map<int, oligosPair>::iterator it = pairedBarcodes.begin(); it != pairedBarcodes.end(); it++) {
            //add reverse compliment barcodes
            string forward = reverseOligo((it->second).forward);
            string reverse = reverseOligo((it->second).reverse);
            
            string temp = forward+reverse;
            if (uniqueBarcodes.count(temp) != 0) { } //already have this pair assigned to a sample, ignore reversed version
            else {
                uniqueBarcodes.insert(temp);
                oligosPair tempPair(forward, reverse); //reverseforward, reverseReverse
                rpairedBarcodes[it->first] = tempPair;
            }
        }
        
        for (map<string, int>::iterator it = barcodes.begin(); it != barcodes.end(); it++) {
            //add reverse compliment barcodes
            string forward = reverseOligo(it->first);
            string reverse = "";
            
            string temp = forward+reverse;
            if (uniqueBarcodes.count(temp) != 0) { } //already have this pair assigned to a sample, ignore reversed version
            else {
                uniqueBarcodes.insert(temp);
                oligosPair tempPair(forward, reverse); //reverseforward, reverseReverse
                rpairedBarcodes[it->second] = tempPair;
            }
        }

        return rpairedBarcodes;
    }
    catch(exception& e) {
        m->errorOut(e, "Oligos", "getReversedPairedBarcodes");
        exit(1);
    }
}
//********************************************************************/
//can't have paired and unpaired so this function will either run the paired map or the unpaired
map<int, oligosPair> Oligos::getReorientedPairedBarcodes(){
	try {
        map<int, oligosPair> rpairedBarcodes;
        set<string> uniqueBarcodes;
        
        for (map<int, oligosPair>::iterator it = pairedBarcodes.begin(); it != pairedBarcodes.end(); it++) {
            string forward = (it->second).reverse;
            if (reversePairs) { forward = reverseOligo(forward); } //forward is now the reverse of reverse
            string reverse = (it->second).forward;
            if (reversePairs) { reverse = reverseOligo(reverse); } //reverse is now the reverse of forward
            
            //check for repeat barcodes
            string temp = forward+reverse;
            if (uniqueBarcodes.count(temp) != 0) { } //already have this pair assigned to a sample, ignore reoriented version
            else {
                uniqueBarcodes.insert(temp);
                oligosPair tempPair(forward, reverse); //(reverse, forward) or if reversePairs (rc_reverse, rc_forward)
                rpairedBarcodes[it->first] = tempPair;
            }
        }
       
        for (map<string, int>::iterator it = barcodes.begin(); it != barcodes.end(); it++) {
            string forward = ""; string reverse = reverseOligo((it->first));
            string temp = forward+reverse;
            
            if (uniqueBarcodes.count(temp) != 0) { } //already have this pair assigned to a sample, ignore reoriented version
            else { uniqueBarcodes.insert(temp);
                oligosPair tempPair(forward, reverse); //reversePrimer, rc ForwardPrimer
                rpairedBarcodes[it->second] = tempPair;
            }
        }

        return rpairedBarcodes;
    }
	catch(exception& e) {
		m->errorOut(e, "Oligos", "getReorientedPairedBarcodes");
		exit(1);
	}
}
//********************************************************************/
string Oligos::reverseOligo(string oligo){
	try {
        
        if (oligo == "NONE") { return "NONE"; }
        
        string reverse = "";
        
        for(int i=oligo.length()-1;i>=0;i--){
            
            if(oligo[i] == 'A')		{	reverse += 'T';	}
            else if(oligo[i] == 'T'){	reverse += 'A';	}
            else if(oligo[i] == 'U'){	reverse += 'A';	}
            
            else if(oligo[i] == 'G'){	reverse += 'C';	}
            else if(oligo[i] == 'C'){	reverse += 'G';	}
            
            else if(oligo[i] == 'R'){	reverse += 'Y';	}
            else if(oligo[i] == 'Y'){	reverse += 'R';	}
            
            else if(oligo[i] == 'M'){	reverse += 'K';	}
            else if(oligo[i] == 'K'){	reverse += 'M';	}
            
            else if(oligo[i] == 'W'){	reverse += 'W';	}
            else if(oligo[i] == 'S'){	reverse += 'S';	}
            
            else if(oligo[i] == 'B'){	reverse += 'V';	}
            else if(oligo[i] == 'V'){	reverse += 'B';	}
            
            else if(oligo[i] == 'D'){	reverse += 'H';	}
            else if(oligo[i] == 'H'){	reverse += 'D';	}
            
            else						{	reverse += 'N';	}
        }
        
        
        return reverse;
    }
	catch(exception& e) {
		m->errorOut(e, "Oligos", "reverseOligo");
		exit(1);
	}
}
//********************************************************************/
void Oligos::formatOligo(string& oligo){
    try {
        for(int i=0;i<oligo.length();i++){
            oligo[i] = toupper(oligo[i]);
            if(oligo[i] == 'U')    {    oligo[i] = 'T';    }
        }
    }
    catch(exception& e) {
        m->errorOut(e, "Oligos", "formatOligo");
        exit(1);
    }
}
//********************************************************************/
string Oligos::getBarcodeName(int index){
	try {
        string name = "";
        
        if ((index >= 0) && (index < barcodeNameVector.size())) { name = barcodeNameVector[index]; }
            
        return name;
    }
	catch(exception& e) {
		m->errorOut(e, "Oligos", "getBarcodeName");
		exit(1);
	}
}
//********************************************************************/
string Oligos::getPrimerName(int index){
    try {
        string name = "";
        
        if ((index >= 0) && (index < primerNameVector.size())) { name = primerNameVector[index]; }
        
        return name;
    }
    catch(exception& e) {
        m->errorOut(e, "Oligos", "getPrimerName");
        exit(1);
    }
}
//********************************************************************/
string Oligos::getGroupName(int barcodeIndex, int primerIndex){
    try {
        
        string thisGroup = "";
            if(numBarcodes != 0){
                thisGroup = getBarcodeName(barcodeIndex);
                if (numFPrimers != 0) {
                    if (getPrimerName(primerIndex) != "") {
                        if(thisGroup != "") {
                            thisGroup += "." + getPrimerName(primerIndex);
                        }else {
                            thisGroup = getPrimerName(primerIndex);
                        }
                    } 
                }
            }
        
        return thisGroup;
    }
    catch(exception& e) {
        m->errorOut(e, "Oligos", "getGroupName");
        exit(1);
    }
}

/**************************************************************************************************/