Skip to content

Commit

Permalink
Adds sorting to pcr.seqs to force order
Browse files Browse the repository at this point in the history
  • Loading branch information
mothur-westcott committed Oct 5, 2021
1 parent f597278 commit 60cc15c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
58 changes: 56 additions & 2 deletions source/commands/pcrseqscommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#include "pcrseqscommand.h"
#include "sortseqscommand.h"

//**********************************************************************************************************************
vector<string> PcrSeqsCommand::setParameters(){
Expand Down Expand Up @@ -216,8 +217,7 @@ int PcrSeqsCommand::execute(){

if (abort) { if (calledHelp) { return 0; } return 2; }

long start = time(NULL);
fileAligned = true; pairedOligos = false;
long start = time(NULL); fileAligned = true; pairedOligos = false;

string thisOutputDir = outputdir;
if (outputdir == "") { thisOutputDir += util.hasPath(fastafile); }
Expand Down Expand Up @@ -317,6 +317,11 @@ int PcrSeqsCommand::execute(){
}
if (m->getControl_pressed()) { for (int i = 0; i < outputNames.size(); i++) { util.mothurRemove(outputNames[i]); } return 0; }

itTypes = outputTypes.find("fasta");
if (itTypes != outputTypes.end()) {
if ((itTypes->second).size() != 0) { preserveOrder((itTypes->second)[0]); }
}

m->mothurOut("It took " + toString(time(NULL) - start) + " secs to screen " + toString(numFastaSeqs) + " sequences.\n");

m->mothurOut("\nOutput File Names: \n");
Expand Down Expand Up @@ -1020,6 +1025,55 @@ int PcrSeqsCommand::adjustDots(string goodFasta, map<string, vector<int> > locat
}
}
//***************************************************************************************************************
void PcrSeqsCommand::preserveOrder(string outputfile){
try {
string thisOutputDir = outputdir;
if (outputdir == "") { thisOutputDir += util.hasPath(fastafile); }
string orderAccnosFile = thisOutputDir + util.getRootName(util.getSimpleName(fastafile)) + "order.accnos";

ofstream out; util.openOutputFile(orderAccnosFile, out);
ifstream in; util.openInputFile(fastafile, in);

while (!in.eof()) {
if (m->getControl_pressed()) { break; }

Sequence seq(in); util.gobble(in);

if (seq.getName() != "") {
out << seq.getName() << endl;
}
}
in.close();
out.close();

//run sort.seqs
string inputString = "fasta=" + outputfile + ", accnos=" + orderAccnosFile;

m->mothurOut("/******************************************/\n");
m->mothurOut("\nRunning command: sort.seqs(" + inputString + ")\n");
current->setMothurCalling(true);

Command* sortSeqsCommand = new SortSeqsCommand(inputString);
sortSeqsCommand->execute();

string tempFastafile = sortSeqsCommand->getOutputFiles()["fasta"][0];
util.mothurRemove(outputfile);
util.renameFile(tempFastafile, outputfile);
util.mothurRemove(orderAccnosFile);

delete sortSeqsCommand;
current->setMothurCalling(false);

m->mothurOut("/******************************************/\n");

}
catch(exception& e) {
m->errorOut(e, "PcrSeqsCommand", "preserveOrder");
exit(1);
}

}
//***************************************************************************************************************
Sequence PcrSeqsCommand::readEcoli(){
try {
ifstream in; util.openInputFile(ecolifile, in);
Expand Down
1 change: 1 addition & 0 deletions source/commands/pcrseqscommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class PcrSeqsCommand : public Command {
int writeAccnos(set<string>, string);
Sequence readEcoli();
long long createProcesses(string, string, string, set<string>&);
void preserveOrder(string);
int adjustDots(string goodFasta, map<string, vector<int> > locations, int pstart, int pend, bool, bool);
};

Expand Down
2 changes: 1 addition & 1 deletion source/commands/sortseqscommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int SortSeqsCommand::execute(){
vector<string> temp;
util.readAccnos(accnosfile, temp);
for (int i = 0; i < temp.size(); i++) { names[temp[i]] = i; }
m->mothurOut("\nUsing " + accnosfile + " to determine the order. It contains " + toString(temp.size()) + " representative sequences.\n");
m->mothurOut("\nUsing " + accnosfile + " to determine the order. It contains " + toString(temp.size()) + " sequences.\n");
}

if (fastafile != "") { readFasta(); }
Expand Down
2 changes: 1 addition & 1 deletion source/datastructures/counttable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int CountTable::createTable(map<string, string>& g) {
groups.insert(it->second);
}

createTable(names, g, groups);
return (createTable(names, g, groups));

}
catch(exception& e) {
Expand Down

0 comments on commit 60cc15c

Please sign in to comment.