+//**********************************************************************************************************************
+//just looking at common mistakes.
+int GetSeqsCommand::runSanityCheck(){
+ try {
+ string thisOutputDir = outputDir;
+ if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); }
+ string filename = outputDir + "get.seqs.debug.report";
+
+ ofstream out;
+ m->openOutputFile(filename, out);
+
+
+ //compare fasta, name, qual and taxonomy if given to make sure they contain the same seqs
+ if (fastafile != "") {
+ if (namefile != "") { //compare with fasta
+ if (sanity["fasta"] != sanity["name"]) { //create mismatch file
+ createMisMatchFile(out, fastafile, namefile, sanity["fasta"], sanity["name"]);
+ }
+ }
+ if (qualfile != "") {
+ if (sanity["fasta"] != sanity["qual"]) { //create mismatch file
+ createMisMatchFile(out, fastafile, qualfile, sanity["fasta"], sanity["qual"]);
+ }
+ }
+ if (taxfile != "") {
+ if (sanity["fasta"] != sanity["tax"]) { //create mismatch file
+ createMisMatchFile(out, fastafile, taxfile, sanity["fasta"], sanity["tax"]);
+ }
+ }
+ }
+
+ //compare dupnames, groups and list if given to make sure they match
+ if (namefile != "") {
+ if (groupfile != "") {
+ if (sanity["dupname"] != sanity["group"]) { //create mismatch file
+ createMisMatchFile(out, namefile, groupfile, sanity["dupname"], sanity["group"]);
+ }
+ }
+ if (listfile != "") {
+ if (sanity["dupname"] != sanity["list"]) { //create mismatch file
+ createMisMatchFile(out, namefile, listfile, sanity["dupname"], sanity["list"]);
+ }
+ }
+ }else{
+
+ if ((groupfile != "") && (fastafile != "")) {
+ if (sanity["fasta"] != sanity["group"]) { //create mismatch file
+ createMisMatchFile(out, fastafile, groupfile, sanity["fasta"], sanity["group"]);
+ }
+ }
+ }
+
+ out.close();
+
+ if (m->isBlank(filename)) { m->mothurRemove(filename); }
+ else { m->mothurOut("\n[DEBUG]: " + filename + " contains the file mismatches.\n");outputNames.push_back(filename); outputTypes["debug"].push_back(filename); }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSeqsCommand", "runSanityCheck");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+//just looking at common mistakes.
+int GetSeqsCommand::createMisMatchFile(ofstream& out, string filename1, string filename2, set<string> set1, set<string> set2){
+ try {
+ out << "****************************************" << endl << endl;
+ out << "Names unique to " << filename1 << ":\n";
+
+ //remove names in set1 that are also in set2
+ for (set<string>::iterator it = set1.begin(); it != set1.end();) {
+ string name = *it;
+
+ if (set2.count(name) == 0) { out << name << endl; } //name unique to set1
+ else { set2.erase(name); } //you are in both so erase
+ set1.erase(it++);
+ }
+
+ out << "\nNames unique to " << filename2 << ":\n";
+ //output results
+ for (set<string>::iterator it = set2.begin(); it != set2.end(); it++) { out << *it << endl; }
+
+ out << "****************************************" << endl << endl;
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSeqsCommand", "runSanityCheck");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+int GetSeqsCommand::compareAccnos(){
+ try {
+
+ string thisOutputDir = outputDir;
+ if (outputDir == "") { thisOutputDir += m->hasPath(accnosfile); }
+ string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(accnosfile)) + "accnos.report";
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+
+ ifstream in;
+ m->openInputFile(accnosfile2, in);
+ string name;
+
+ set<string> namesAccnos2;
+ set<string> namesDups;
+ set<string> namesAccnos = names;
+
+ map<string, int> nameCount;
+
+ if (namefile != "") {
+ ifstream inName;
+ m->openInputFile(namefile, inName);
+
+
+ while(!inName.eof()){
+
+ if (m->control_pressed) { inName.close(); return 0; }
+
+ string thisname, repnames;
+
+ inName >> thisname; m->gobble(inName); //read from first column
+ inName >> repnames; //read from second column
+
+ int num = m->getNumNames(repnames);
+ nameCount[thisname] = num;
+
+ m->gobble(inName);
+ }
+ inName.close();
+ }
+
+ while(!in.eof()){
+ in >> name;
+
+ if (namesAccnos.count(name) == 0){ //name unique to accnos2
+ int pos = name.find_last_of('_');
+ string tempName = name;
+ if (pos != string::npos) { tempName = tempName.substr(pos+1); cout << tempName << endl; }
+ if (namesAccnos.count(tempName) == 0){
+ namesAccnos2.insert(name);
+ }else { //you are in both so erase
+ namesAccnos.erase(name);
+ namesDups.insert(name);
+ }
+ }else { //you are in both so erase
+ namesAccnos.erase(name);
+ namesDups.insert(name);
+ }
+
+ m->gobble(in);
+ }
+ in.close();
+
+ out << "Names in both files : " + toString(namesDups.size()) << endl;
+ m->mothurOut("Names in both files : " + toString(namesDups.size())); m->mothurOutEndLine();
+
+ for (set<string>::iterator it = namesDups.begin(); it != namesDups.end(); it++) {
+ out << (*it);
+ if (namefile != "") { out << '\t' << nameCount[(*it)]; }
+ out << endl;
+ }
+
+ out << "Names unique to " + accnosfile + " : " + toString(namesAccnos.size()) << endl;
+ m->mothurOut("Names unique to " + accnosfile + " : " + toString(namesAccnos.size())); m->mothurOutEndLine();
+
+ for (set<string>::iterator it = namesAccnos.begin(); it != namesAccnos.end(); it++) {
+ out << (*it);
+ if (namefile != "") { out << '\t' << nameCount[(*it)]; }
+ out << endl;
+ }
+
+ out << "Names unique to " + accnosfile2 + " : " + toString(namesAccnos2.size()) << endl;
+ m->mothurOut("Names unique to " + accnosfile2 + " : " + toString(namesAccnos2.size())); m->mothurOutEndLine();
+
+ for (set<string>::iterator it = namesAccnos2.begin(); it != namesAccnos2.end(); it++) {
+ out << (*it);
+ if (namefile != "") { out << '\t' << nameCount[(*it)]; }
+ out << endl;
+ }
+
+ out.close();
+
+ outputNames.push_back(outputFileName); outputTypes["accnosreport"].push_back(outputFileName);
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSeqsCommand", "readAccnos");
+ exit(1);
+ }
+}
+