+}*/
+//***************************************************************************************************************
+vector< vector<string> > MakeContigsCommand::readFileNames(string filename){
+ try {
+ vector< vector<string> > files;
+ string forward, reverse;
+
+ ifstream in;
+ m->openInputFile(filename, in);
+
+ while(!in.eof()) {
+
+ if (m->control_pressed) { return files; }
+
+ in >> forward; m->gobble(in);
+ in >> reverse; m->gobble(in);
+
+ //check to make sure both are able to be opened
+ ifstream in2;
+ int openForward = m->openInputFile(forward, in2, "noerror");
+
+ //if you can't open it, try default location
+ if (openForward == 1) {
+ if (m->getDefaultPath() != "") { //default path is set
+ string tryPath = m->getDefaultPath() + m->getSimpleName(forward);
+ m->mothurOut("Unable to open " + forward + ". Trying default " + tryPath); m->mothurOutEndLine();
+ ifstream in3;
+ openForward = m->openInputFile(tryPath, in3, "noerror");
+ in3.close();
+ forward = tryPath;
+ }
+ }
+
+ //if you can't open it, try output location
+ if (openForward == 1) {
+ if (m->getOutputDir() != "") { //default path is set
+ string tryPath = m->getOutputDir() + m->getSimpleName(forward);
+ m->mothurOut("Unable to open " + forward + ". Trying output directory " + tryPath); m->mothurOutEndLine();
+ ifstream in4;
+ openForward = m->openInputFile(tryPath, in4, "noerror");
+ forward = tryPath;
+ in4.close();
+ }
+ }
+
+ if (openForward == 1) { //can't find it
+ m->mothurOut("[WARNING]: can't find " + forward + ", ignoring pair.\n");
+ }else{ in2.close(); }
+
+ ifstream in3;
+ int openReverse = m->openInputFile(reverse, in3, "noerror");
+
+ //if you can't open it, try default location
+ if (openReverse == 1) {
+ if (m->getDefaultPath() != "") { //default path is set
+ string tryPath = m->getDefaultPath() + m->getSimpleName(reverse);
+ m->mothurOut("Unable to open " + reverse + ". Trying default " + tryPath); m->mothurOutEndLine();
+ ifstream in3;
+ openReverse = m->openInputFile(tryPath, in3, "noerror");
+ in3.close();
+ reverse = tryPath;
+ }
+ }
+
+ //if you can't open it, try output location
+ if (openReverse == 1) {
+ if (m->getOutputDir() != "") { //default path is set
+ string tryPath = m->getOutputDir() + m->getSimpleName(reverse);
+ m->mothurOut("Unable to open " + reverse + ". Trying output directory " + tryPath); m->mothurOutEndLine();
+ ifstream in4;
+ openReverse = m->openInputFile(tryPath, in4, "noerror");
+ reverse = tryPath;
+ in4.close();
+ }
+ }
+
+ if (openReverse == 1) { //can't find it
+ m->mothurOut("[WARNING]: can't find " + reverse + ", ignoring pair.\n");
+ }else{ in3.close(); }
+
+ if ((openForward != 1) && (openReverse != 1)) { //good pair
+ vector<string> pair;
+ pair.push_back(forward);
+ pair.push_back(reverse);
+ files.push_back(pair);
+ }
+
+ }
+ in.close();
+
+ return files;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "MakeContigsCommand", "checkReads");
+ exit(1);
+ }
+}
+//***************************************************************************************************************
+//illumina data requires paired forward and reverse data
+//BARCODE atgcatgc atgcatgc groupName
+//PRIMER atgcatgc atgcatgc groupName
+//PRIMER atgcatgc atgcatgc
+bool MakeContigsCommand::getOligos(vector<vector<string> >& fastaFileNames, string rootname){
+ try {
+ ifstream in;
+ m->openInputFile(oligosfile, in);
+
+ ofstream test;
+
+ string type, foligo, roligo, group;
+
+ int indexPrimer = 0;
+ int indexBarcode = 0;
+ set<string> uniquePrimers;
+ set<string> uniqueBarcodes;
+
+ while(!in.eof()){
+
+ in >> type;
+
+ if (m->debug) { m->mothurOut("[DEBUG]: reading type - " + type + ".\n"); }
+
+ if(type[0] == '#'){
+ while (!in.eof()) { char c = in.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there
+ m->gobble(in);
+ }
+ else{
+ m->gobble(in);
+ //make type case insensitive
+ for(int i=0;i<type.length();i++){ type[i] = toupper(type[i]); }
+
+ in >> foligo;
+
+ if (m->debug) { m->mothurOut("[DEBUG]: reading - " + foligo + ".\n"); }
+
+ for(int i=0;i<foligo.length();i++){
+ foligo[i] = toupper(foligo[i]);
+ if(foligo[i] == 'U') { foligo[i] = 'T'; }
+ }
+
+ if(type == "FORWARD"){
+ m->gobble(in);
+
+ in >> roligo;
+
+ for(int i=0;i<roligo.length();i++){
+ roligo[i] = toupper(roligo[i]);
+ if(roligo[i] == 'U') { roligo[i] = 'T'; }
+ }
+ //roligo = reverseOligo(roligo);
+
+ group = "";
+
+ // get rest of line in case there is a primer name
+ while (!in.eof()) {
+ char c = in.get();
+ if (c == 10 || c == 13){ break; }
+ else if (c == 32 || c == 9){;} //space or tab
+ else { group += c; }
+ }
+
+ oligosPair newPrimer(foligo, roligo);
+
+ //check for repeat barcodes
+ string tempPair = foligo+roligo;
+ if (uniquePrimers.count(tempPair) != 0) { m->mothurOut("primer pair " + newPrimer.forward + " " + newPrimer.reverse + " is in your oligos file already."); m->mothurOutEndLine(); }
+ else { uniquePrimers.insert(tempPair); }
+
+ if (m->debug) { if (group != "") { m->mothurOut("[DEBUG]: reading group " + group + ".\n"); }else{ m->mothurOut("[DEBUG]: no group for primer pair " + newPrimer.forward + " " + newPrimer.reverse + ".\n"); } }
+
+ primers[indexPrimer]=newPrimer; indexPrimer++;
+ primerNameVector.push_back(group);
+ }else if(type == "BARCODE"){
+ m->gobble(in);
+
+ in >> roligo;
+
+ for(int i=0;i<roligo.length();i++){
+ roligo[i] = toupper(roligo[i]);
+ if(roligo[i] == 'U') { roligo[i] = 'T'; }
+ }
+ //roligo = reverseOligo(roligo);
+
+ oligosPair newPair(foligo, roligo);
+
+ group = "";
+ while (!in.eof()) {
+ char c = in.get();
+ if (c == 10 || c == 13){ break; }
+ else if (c == 32 || c == 9){;} //space or tab
+ else { group += c; }
+ }
+
+ if (m->debug) { m->mothurOut("[DEBUG]: barcode pair " + newPair.forward + " " + newPair.reverse + ", and group = " + group + ".\n"); }
+
+ //check for repeat barcodes
+ string tempPair = foligo+roligo;
+ if (uniqueBarcodes.count(tempPair) != 0) { m->mothurOut("barcode pair " + newPair.forward + " " + newPair.reverse + " is in your oligos file already, disregarding."); m->mothurOutEndLine(); }
+ else { uniqueBarcodes.insert(tempPair); }
+
+ barcodes[indexBarcode]=newPair; indexBarcode++;
+ barcodeNameVector.push_back(group);
+ }else if(type == "LINKER"){
+ linker.push_back(foligo);
+ m->mothurOut("[WARNING]: make.contigs is not setup to remove linkers, ignoring.\n");
+ }else if(type == "SPACER"){
+ spacer.push_back(foligo);
+ m->mothurOut("[WARNING]: make.contigs is not setup to remove spacers, ignoring.\n");
+ }
+ else{ m->mothurOut("[WARNING]: " + type + " is not recognized as a valid type. Choices are primer, barcode, linker and spacer. Ignoring " + foligo + "."); m->mothurOutEndLine(); }
+ }
+ m->gobble(in);
+ }
+ in.close();
+
+ if(barcodeNameVector.size() == 0 && primerNameVector[0] == ""){ allFiles = 0; }
+
+ //add in potential combos
+ if(barcodeNameVector.size() == 0){
+ oligosPair temp("", "");
+ barcodes[0] = temp;
+ barcodeNameVector.push_back("");
+ }
+
+ if(primerNameVector.size() == 0){
+ oligosPair temp("", "");
+ primers[0] = temp;
+ primerNameVector.push_back("");
+ }
+
+ fastaFileNames.resize(barcodeNameVector.size());
+ for(int i=0;i<fastaFileNames.size();i++){
+ fastaFileNames[i].assign(primerNameVector.size(), "");
+ }
+
+ if(allFiles){
+ set<string> uniqueNames; //used to cleanup outputFileNames
+ for(map<int, oligosPair>::iterator itBar = barcodes.begin();itBar != barcodes.end();itBar++){
+ for(map<int, oligosPair>::iterator itPrimer = primers.begin();itPrimer != primers.end(); itPrimer++){
+
+ string primerName = primerNameVector[itPrimer->first];
+ string barcodeName = barcodeNameVector[itBar->first];
+
+ if ((primerName == "ignore") || (barcodeName == "ignore")) { } //do nothing
+ else {
+ string comboGroupName = "";
+ string fastaFileName = "";
+ string qualFileName = "";
+ string nameFileName = "";
+ string countFileName = "";
+
+ if(primerName == ""){
+ comboGroupName = barcodeNameVector[itBar->first];
+ }
+ else{
+ if(barcodeName == ""){
+ comboGroupName = primerNameVector[itPrimer->first];
+ }
+ else{
+ comboGroupName = barcodeNameVector[itBar->first] + "." + primerNameVector[itPrimer->first];
+ }
+ }
+
+
+ ofstream temp;
+ fastaFileName = rootname + comboGroupName + ".fasta";
+ if (uniqueNames.count(fastaFileName) == 0) {
+ outputNames.push_back(fastaFileName);
+ outputTypes["fasta"].push_back(fastaFileName);
+ uniqueNames.insert(fastaFileName);
+ }
+
+ fastaFileNames[itBar->first][itPrimer->first] = fastaFileName;
+ m->openOutputFile(fastaFileName, temp); temp.close();
+ }
+ }
+ }
+ }
+
+ bool allBlank = true;
+ for (int i = 0; i < barcodeNameVector.size(); i++) {
+ if (barcodeNameVector[i] != "") {
+ allBlank = false;
+ break;
+ }
+ }
+ for (int i = 0; i < primerNameVector.size(); i++) {
+ if (primerNameVector[i] != "") {
+ allBlank = false;
+ break;
+ }
+ }
+
+ if (allBlank) {
+ m->mothurOut("[WARNING]: your oligos file does not contain any group names. mothur will not create a groupfile."); m->mothurOutEndLine();
+ allFiles = false;
+ return false;
+ }
+
+ return true;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "MakeContigsCommand", "getOligos");
+ exit(1);
+ }