X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getseqscommand.cpp;h=ae242b6f56946c544aff5f389b026c2c93a50bee;hb=c53c53b0280452e1c3a087fbf807b2e508cd66c4;hp=e58cc883b26a33d2dec9526bb52bcbfb7de7741e;hpb=b9456b1087ade74251792e039f4e5021dbf32349;p=mothur.git diff --git a/getseqscommand.cpp b/getseqscommand.cpp index e58cc88..ae242b6 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -119,19 +119,30 @@ void GetSeqsCommand::readFasta(){ openInputFile(fastafile, in); string name; + bool wroteSomething = false; + while(!in.eof()){ Sequence currSeq(in); name = currSeq.getName(); //if this name is in the accnos file if (names.count(name) == 1) { + wroteSomething = true; + currSeq.printSequence(out); + + names.erase(name); } gobble(in); } in.close(); - out.close(); + out.close(); + + if (wroteSomething == false) { + mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine(); + remove(outputFileName.c_str()); + } } catch(exception& e) { @@ -152,6 +163,8 @@ void GetSeqsCommand::readName(){ openInputFile(namefile, in); string name, firstCol, secondCol; + bool wroteSomething = false; + while(!in.eof()){ @@ -173,22 +186,31 @@ void GetSeqsCommand::readName(){ for (int i = 0; i < parsedNames.size(); i++) { if (names.count(parsedNames[i]) == 1) { validSecond.push_back(parsedNames[i]); + names.erase(parsedNames[i]); } } //if the name in the first column is in the set then print it and any other names in second column also in set if (names.count(firstCol) == 1) { + + wroteSomething = true; + out << firstCol << '\t'; //you know you have at least one valid second since first column is valid for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; } out << validSecond[validSecond.size()-1] << endl; + + names.erase(firstCol); //make first name in set you come to first column and then add the remaining names to second column }else { //you want part of this row if (validSecond.size() != 0) { + + wroteSomething = true; + out << validSecond[0] << '\t'; //you know you have at least one valid second since first column is valid @@ -202,6 +224,11 @@ void GetSeqsCommand::readName(){ in.close(); out.close(); + if (wroteSomething == false) { + mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine(); + remove(outputFileName.c_str()); + } + } catch(exception& e) { errorOut(e, "GetSeqsCommand", "readName"); @@ -221,6 +248,8 @@ void GetSeqsCommand::readGroup(){ openInputFile(groupfile, in); string name, group; + bool wroteSomething = false; + while(!in.eof()){ in >> name; //read from first column @@ -228,13 +257,22 @@ void GetSeqsCommand::readGroup(){ //if this name is in the accnos file if (names.count(name) == 1) { + wroteSomething = true; + out << name << '\t' << group << endl; + + names.erase(name); } gobble(in); } in.close(); out.close(); + + if (wroteSomething == false) { + mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine(); + remove(outputFileName.c_str()); + } } catch(exception& e) { @@ -255,6 +293,8 @@ void GetSeqsCommand::readAlign(){ openInputFile(alignfile, in); string name, junk; + bool wroteSomething = false; + //read column headers for (int i = 0; i < 16; i++) { if (!in.eof()) { in >> junk; out << junk << '\t'; } @@ -268,7 +308,8 @@ void GetSeqsCommand::readAlign(){ //if this name is in the accnos file if (names.count(name) == 1) { - + wroteSomething = true; + out << name << '\t'; //read rest @@ -278,6 +319,8 @@ void GetSeqsCommand::readAlign(){ } out << endl; + names.erase(name); + }else {//still read just don't do anything with it //read rest for (int i = 0; i < 15; i++) { @@ -290,7 +333,11 @@ void GetSeqsCommand::readAlign(){ } in.close(); out.close(); - + + if (wroteSomething == false) { + mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine(); + remove(outputFileName.c_str()); + } } catch(exception& e) {