+ m->errorOut(e, "GetMIMarksPackageCommand", "execute");
+ exit(1);
+ }
+}
+//***************************************************************************************************************
+int GetMIMarksPackageCommand::readOligos(){
+ try {
+ ifstream inOligos;
+ m->openInputFile(oligosfile, inOligos);
+
+ string type, oligo, roligo, group;
+ vector<string> primerNameVector, barcodeNameVector;
+ set<string> uniquePrimers;
+ set<string> uniqueBarcodes;
+
+ while(!inOligos.eof()){
+
+ inOligos >> type;
+
+ if (m->debug) { m->mothurOut("[DEBUG]: reading type - " + type + ".\n"); }
+
+ if(type[0] == '#'){
+ while (!inOligos.eof()) { char c = inOligos.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there
+ m->gobble(inOligos);
+ }
+ else{
+ m->gobble(inOligos);
+ //make type case insensitive
+ for(int i=0;i<type.length();i++){ type[i] = toupper(type[i]); }
+
+ inOligos >> oligo;
+
+ if (m->debug) { m->mothurOut("[DEBUG]: reading - " + oligo + ".\n"); }
+
+ for(int i=0;i<oligo.length();i++){
+ oligo[i] = toupper(oligo[i]);
+ if(oligo[i] == 'U') { oligo[i] = 'T'; }
+ }
+
+ if(type == "FORWARD"){
+ group = "";
+
+ // get rest of line in case there is a primer name
+ while (!inOligos.eof()) {
+ char c = inOligos.get();
+ if (c == 10 || c == 13 || c == -1){ break; }
+ else if (c == 32 || c == 9){;} //space or tab
+ else { group += c; }
+ }
+
+ primerNameVector.push_back(group);
+ }
+ else if (type == "PRIMER"){
+ m->gobble(inOligos);
+
+ inOligos >> roligo;
+
+ for(int i=0;i<roligo.length();i++){
+ roligo[i] = toupper(roligo[i]);
+ if(roligo[i] == 'U') { roligo[i] = 'T'; }
+ }
+
+ group = "";
+
+ // get rest of line in case there is a primer name
+ while (!inOligos.eof()) {
+ char c = inOligos.get();
+ if (c == 10 || c == 13 || c == -1){ break; }
+ else if (c == 32 || c == 9){;} //space or tab
+ else { group += c; }
+ }
+
+ primerNameVector.push_back(group);
+ }else if(type == "BARCODE"){
+ inOligos >> group;
+
+ //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
+
+ string temp = "";
+ while (!inOligos.eof()) {
+ char c = inOligos.get();
+ if (c == 10 || c == 13 || c == -1){ break; }
+ else if (c == 32 || c == 9){;} //space or tab
+ else { temp += c; }
+ }
+
+ //then this is illumina data with 4 columns
+ if (temp != "") {
+
+ string reverseBarcode = group; //reverseOligo(group); //reverse barcode
+ group = temp;
+
+ barcodeNameVector.push_back(group);
+ }else {
+ barcodeNameVector.push_back(group);
+ }
+ }
+ }
+ m->gobble(inOligos);
+ }
+ inOligos.close();
+
+ //add in potential combos
+ if(barcodeNameVector.size() == 0){
+ barcodeNameVector.push_back("");
+ }
+
+ if(primerNameVector.size() == 0){
+ primerNameVector.push_back("");
+ }
+
+ set<string> uniqueNames;
+ for(int i = 0; i < barcodeNameVector.size(); i++){
+ for(int j = 0; j < primerNameVector.size(); j++){
+
+ string primerName = primerNameVector[j];
+ string barcodeName = barcodeNameVector[i];
+
+ if ((primerName == "ignore") || (barcodeName == "ignore")) { } //do nothing
+ else if ((primerName == "") && (barcodeName == "")) { }
+ else {
+ string comboGroupName = "";
+
+ if(primerName == ""){
+ comboGroupName = barcodeNameVector[i];
+ }
+ else{
+ if(barcodeName == ""){
+ comboGroupName = primerNameVector[j];
+ }
+ else{
+ comboGroupName = barcodeNameVector[i] + "." + primerNameVector[j];
+ }
+ }
+ uniqueNames.insert(comboGroupName);
+ }
+ }
+ }
+
+
+
+ if (m->debug) { 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++) { Groups.push_back(*it); }
+
+ return true;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetMIMarksPackageCommand", "readOligos");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+// going to have to rework this to allow for other options --
+/*
+ file option 1
+
+ sfffile1 oligosfile1
+ sfffile2 oligosfile2
+ ...
+
+ file option 2
+
+ fastqfile1 oligosfile1
+ fastqfile2 oligosfile2
+ ...
+
+ file option 3
+
+ fastqfile fastqfile group
+ fastqfile fastqfile group
+ fastqfile fastqfile group
+ ...
+
+ */
+
+int GetMIMarksPackageCommand::readFile(){
+ try {
+ //vector<string> theseFiles;
+ inputfile = file;
+
+ ifstream in;
+ m->openInputFile(file, in);
+
+ while(!in.eof()) {
+
+ if (m->control_pressed) { return 0; }
+
+ string line = m->getline(in); m->gobble(in);
+ vector<string> pieces = m->splitWhiteSpace(line);
+
+ string group = "";
+ string thisFileName1, thisFileName2; thisFileName1 = ""; thisFileName2 = "";
+ if (pieces.size() == 2) {
+ thisFileName1 = pieces[0];
+ thisFileName2 = pieces[1];
+ }else if (pieces.size() == 3) {
+ thisFileName1 = pieces[1];
+ thisFileName2 = pieces[2];
+ string group = pieces[0];
+ }else {
+ m->mothurOut("[ERROR]: file lines can be 2 or 3 columns. The 2 column files are sff file then oligos or fastqfile then oligos. You may have multiple lines in the file. The 3 column files are for paired read libraries. The format is groupName, forwardFastqFile reverseFastqFile. \n"); m->control_pressed = true;
+ }
+
+ if (m->debug) { m->mothurOut("[DEBUG]: group = " + group + ", thisFileName1 = " + thisFileName1 + ", thisFileName2 = " + thisFileName2 + ".\n"); }
+
+ //check to make sure both are able to be opened
+ ifstream in2;
+ int openForward = m->openInputFile(thisFileName1, 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(thisFileName1);
+ m->mothurOut("Unable to open " + thisFileName1 + ". Trying default " + tryPath); m->mothurOutEndLine();
+ ifstream in3;
+ openForward = m->openInputFile(tryPath, in3, "noerror");
+ in3.close();
+ thisFileName1 = 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(thisFileName1);
+ m->mothurOut("Unable to open " + thisFileName1 + ". Trying output directory " + tryPath); m->mothurOutEndLine();
+ ifstream in4;
+ openForward = m->openInputFile(tryPath, in4, "noerror");
+ thisFileName1 = tryPath;
+ in4.close();
+ }
+ }
+
+ if (openForward == 1) { //can't find it
+ m->mothurOut("[WARNING]: can't find " + thisFileName1 + ", ignoring.\n");
+ }else{ in2.close(); }
+
+ int openReverse = 1;
+
+ ifstream in3;
+ openReverse = m->openInputFile(thisFileName2, 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(thisFileName2);
+ m->mothurOut("Unable to open " + thisFileName2 + ". Trying default " + tryPath); m->mothurOutEndLine();
+ ifstream in3;
+ openReverse = m->openInputFile(tryPath, in3, "noerror");
+ in3.close();
+ thisFileName2 = 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(thisFileName2);
+ m->mothurOut("Unable to open " + thisFileName2 + ". Trying output directory " + tryPath); m->mothurOutEndLine();
+ ifstream in4;
+ openReverse = m->openInputFile(tryPath, in4, "noerror");
+ thisFileName2 = tryPath;
+ in4.close();
+ }
+ }
+
+ if (openReverse == 1) { //can't find it
+ m->mothurOut("[WARNING]: can't find " + thisFileName2 + ", ignoring pair.\n");
+ }else{ in3.close(); }
+
+
+ if ((pieces.size() == 2) && (openForward != 1) && (openReverse != 1)) { //good pair and sff or fastq and oligos
+ oligosfile = thisFileName2;
+ if (m->debug) { m->mothurOut("[DEBUG]: about to read oligos\n"); }
+ readOligos();
+ }else if((pieces.size() == 3) && (openForward != 1) && (openReverse != 1)) { //good pair and paired read
+ Groups.push_back(group);
+ }
+ }
+ in.close();
+
+ inputfile = file;
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetMIMarksPackageCommand", "readFile");