+/**************************************************************************************************/
+map<string, int> ChimeraSlayerCommand::sortFastaFile(string fastaFile, string nameFile) {
+ try {
+ map<string, int> nameAbund;
+
+ //read through fastafile and store info
+ map<string, string> seqs;
+ ifstream in;
+ m->openInputFile(fastaFile, in);
+
+ while (!in.eof()) {
+
+ if (m->control_pressed) { in.close(); return nameAbund; }
+
+ Sequence seq(in); m->gobble(in);
+ seqs[seq.getName()] = seq.getAligned();
+ }
+
+ in.close();
+
+ //read namefile
+ vector<seqPriorityNode> nameMapCount;
+ int error = m->readNames(nameFile, nameMapCount, seqs);
+
+ if (m->control_pressed) { return nameAbund; }
+
+ if (error == 1) { m->control_pressed = true; return nameAbund; }
+ if (seqs.size() != nameMapCount.size()) { m->mothurOut( "The number of sequences in your fastafile does not match the number of sequences in your namefile, aborting."); m->mothurOutEndLine(); m->control_pressed = true; return nameAbund; }
+
+ sort(nameMapCount.begin(), nameMapCount.end(), compareSeqPriorityNodes);
+
+ string newFasta = fastaFile + ".temp";
+ ofstream out;
+ m->openOutputFile(newFasta, out);
+
+ //print new file in order of
+ for (int i = 0; i < nameMapCount.size(); i++) {
+ out << ">" << nameMapCount[i].name << endl << nameMapCount[i].seq << endl;
+ nameAbund[nameMapCount[i].name] = nameMapCount[i].numIdentical;
+ }
+ out.close();
+
+ rename(newFasta.c_str(), fastaFile.c_str());
+
+ return nameAbund;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ChimeraSlayerCommand", "sortFastaFile");
+ exit(1);
+ }
+}