#include "needlemanoverlap.hpp"
#include "blastalign.hpp"
#include "noalign.hpp"
-#include "nast.hpp"
#include "ignoregaps.h"
#include "eachgapdist.h"
//**********************************************************************************************************************
PairwiseSeqsCommand::PairwiseSeqsCommand(){
try {
- //initialize outputTypes
+ abort = true; calledHelp = true;
vector<string> tempOutNames;
outputTypes["phylip"] = tempOutNames;
outputTypes["column"] = tempOutNames;
//**********************************************************************************************************************
PairwiseSeqsCommand::PairwiseSeqsCommand(string option) {
try {
- abort = false;
+ abort = false; calledHelp = false;
//allow user to run help
- if(option == "help") { help(); abort = true; }
+ if(option == "help") { help(); abort = true; calledHelp = true; }
else {
int PairwiseSeqsCommand::execute(){
try {
- if (abort == true) { return 0; }
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
int longestBase = 2000; //will need to update this in driver if we find sequences with more bases. hardcoded so we don't have the pre-read user fasta file.
}else{ //you have multiple processors
for (int i = 0; i < processors; i++) {
- lines.push_back(new linePair());
+ distlinePair tempLine;
+ lines.push_back(tempLine);
if (output != "square") {
- lines[i]->start = int (sqrt(float(i)/float(processors)) * numSeqs);
- lines[i]->end = int (sqrt(float(i+1)/float(processors)) * numSeqs);
+ lines[i].start = int (sqrt(float(i)/float(processors)) * numSeqs);
+ lines[i].end = int (sqrt(float(i+1)/float(processors)) * numSeqs);
}else{
- lines[i]->start = int ((float(i)/float(processors)) * numSeqs);
- lines[i]->end = int ((float(i+1)/float(processors)) * numSeqs);
+ lines[i].start = int ((float(i)/float(processors)) * numSeqs);
+ lines[i].end = int ((float(i+1)/float(processors)) * numSeqs);
}
}
-
- createProcesses(outputFile);
-
- map<int, int>::iterator it = processIDS.begin();
- rename((outputFile + toString(it->second) + ".temp").c_str(), outputFile.c_str());
- it++;
- //append and remove temp files
- for (; it != processIDS.end(); it++) {
- m->appendFiles((outputFile + toString(it->second) + ".temp"), outputFile);
- remove((outputFile + toString(it->second) + ".temp").c_str());
- }
+ createProcesses(outputFile);
}
#else
//ifstream inFASTA;
delete distCalculator;
+ //set phylip file as new current phylipfile
+ string current = "";
+ itTypes = outputTypes.find("phylip");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setPhylipFile(current); }
+ }
+
+ //set column file as new current columnfile
+ itTypes = outputTypes.find("column");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setColumnFile(current); }
+ }
+
m->mothurOutEndLine();
m->mothurOut("Output File Name: "); m->mothurOutEndLine();
for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
void PairwiseSeqsCommand::createProcesses(string filename) {
try {
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
- int process = 0;
+ int process = 1;
processIDS.clear();
//loop through and create all the processes you want
int pid = fork();
if (pid > 0) {
- processIDS[lines[process]->end] = pid; //create map from line number to pid so you can append files in correct order later
+ processIDS.push_back(pid);
process++;
}else if (pid == 0){
- if (output != "square") { driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", cutoff); }
- else { driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", "square"); }
+ if (output != "square") { driver(lines[process].start, lines[process].end, filename + toString(getpid()) + ".temp", cutoff); }
+ else { driver(lines[process].start, lines[process].end, filename + toString(getpid()) + ".temp", "square"); }
+ exit(0);
+ }else {
+ m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
+ for (int i=0;i<processIDS.size();i++) { int temp = processIDS[i]; kill (temp, SIGINT); }
exit(0);
- }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
+ }
}
-
+
+ //parent do my part
+ if (output != "square") { driver(lines[0].start, lines[0].end, filename, cutoff); }
+ else { driver(lines[0].start, lines[0].end, filename, "square"); }
+
+
//force parent to wait until all the processes are done
- for (map<int, int>::iterator it = processIDS.begin(); it != processIDS.end(); it++) {
- int temp = it->second;
+ for (int i=0;i<processIDS.size();i++) {
+ int temp = processIDS[i];
wait(&temp);
}
+
+ //append and remove temp files
+ for (int i=0;i<processIDS.size();i++) {
+ m->appendFiles((filename + toString(processIDS[i]) + ".temp"), filename);
+ remove((filename + toString(processIDS[i]) + ".temp").c_str());
+ }
#endif
}
catch(exception& e) {
alignment->resize(alignDB.get(j).getUnaligned().length()+1);
}
- Sequence* seqI = new Sequence(alignDB.get(i).getName(), alignDB.get(i).getAligned());
- Sequence* seqJ = new Sequence(alignDB.get(j).getName(), alignDB.get(j).getAligned());
+ Sequence seqI(alignDB.get(i).getName(), alignDB.get(i).getAligned());
+ Sequence seqJ(alignDB.get(j).getName(), alignDB.get(j).getAligned());
- Nast(alignment, seqI, seqJ);
+ alignment->align(seqI.getUnaligned(), seqJ.getUnaligned());
+ seqI.setAligned(alignment->getSeqAAln());
+ seqJ.setAligned(alignment->getSeqBAln());
- distCalculator->calcDist(*seqI, *seqJ);
+ distCalculator->calcDist(seqI, seqJ);
double dist = distCalculator->getDist();
- delete seqI; delete seqJ;
-
if(dist <= cutoff){
if (output == "column") { outFile << alignDB.get(i).getName() << ' ' << alignDB.get(j).getName() << ' ' << dist << endl; }
}
alignment->resize(alignDB.get(j).getUnaligned().length()+1);
}
- Sequence* seqI = new Sequence(alignDB.get(i).getName(), alignDB.get(i).getAligned());
- Sequence* seqJ = new Sequence(alignDB.get(j).getName(), alignDB.get(j).getAligned());
+ Sequence seqI(alignDB.get(i).getName(), alignDB.get(i).getAligned());
+ Sequence seqJ(alignDB.get(j).getName(), alignDB.get(j).getAligned());
- Nast(alignment, seqI, seqJ);
+ alignment->align(seqI.getUnaligned(), seqJ.getUnaligned());
+ seqI.setAligned(alignment->getSeqAAln());
+ seqJ.setAligned(alignment->getSeqBAln());
- distCalculator->calcDist(*seqI, *seqJ);
+ distCalculator->calcDist(seqI, seqJ);
double dist = distCalculator->getDist();
-
- delete seqI; delete seqJ;
outFile << dist << '\t';
}
alignment->resize(alignDB.get(j).getUnaligned().length()+1);
}
- Sequence* seqI = new Sequence(alignDB.get(i).getName(), alignDB.get(i).getAligned());
- Sequence* seqJ = new Sequence(alignDB.get(j).getName(), alignDB.get(j).getAligned());
+ Sequence seqI(alignDB.get(i).getName(), alignDB.get(i).getAligned());
+ Sequence seqJ(alignDB.get(j).getName(), alignDB.get(j).getAligned());
- Nast(alignment, seqI, seqJ);
+ alignment->align(seqI.getUnaligned(), seqJ.getUnaligned());
+ seqI.setAligned(alignment->getSeqAAln());
+ seqJ.setAligned(alignment->getSeqBAln());
- distCalculator->calcDist(*seqI, *seqJ);
+ distCalculator->calcDist(seqI, seqJ);
double dist = distCalculator->getDist();
- delete seqI; delete seqJ;
-
if(dist <= cutoff){
outputString += (alignDB.get(i).getName() + ' ' + alignDB.get(j).getName() + ' ' + toString(dist) + '\n');
}
MPI_File_open(MPI_COMM_SELF, filename, amode, MPI_INFO_NULL, &outMPI);
- int startTime = time(NULL);
+
string outputString = "";
size = 0;
alignment->resize(alignDB.get(j).getUnaligned().length()+1);
}
- Sequence* seqI = new Sequence(alignDB.get(i).getName(), alignDB.get(i).getAligned());
- Sequence* seqJ = new Sequence(alignDB.get(j).getName(), alignDB.get(j).getAligned());
+ Sequence seqI(alignDB.get(i).getName(), alignDB.get(i).getAligned());
+ Sequence seqJ(alignDB.get(j).getName(), alignDB.get(j).getAligned());
- Nast(alignment, seqI, seqJ);
+ alignment->align(seqI.getUnaligned(), seqJ.getUnaligned());
+ seqI.setAligned(alignment->getSeqAAln());
+ seqJ.setAligned(alignment->getSeqBAln());
- distCalculator->calcDist(*seqI, *seqJ);
+ distCalculator->calcDist(seqI, seqJ);
double dist = distCalculator->getDist();
- delete seqI; delete seqJ;
-
outputString += toString(dist) + "\t";
}
MPI_File_open(MPI_COMM_SELF, filename, amode, MPI_INFO_NULL, &outMPI);
- int startTime = time(NULL);
+
string outputString = "";
size = 0;
alignment->resize(alignDB.get(j).getUnaligned().length()+1);
}
- Sequence* seqI = new Sequence(alignDB.get(i).getName(), alignDB.get(i).getAligned());
- Sequence* seqJ = new Sequence(alignDB.get(j).getName(), alignDB.get(j).getAligned());
+ Sequence seqI(alignDB.get(i).getName(), alignDB.get(i).getAligned());
+ Sequence seqJ(alignDB.get(j).getName(), alignDB.get(j).getAligned());
- Nast(alignment, seqI, seqJ);
+ alignment->align(seqI.getUnaligned(), seqJ.getUnaligned());
+ seqI.setAligned(alignment->getSeqAAln());
+ seqJ.setAligned(alignment->getSeqBAln());
- distCalculator->calcDist(*seqI, *seqJ);
+ distCalculator->calcDist(seqI, seqJ);
double dist = distCalculator->getDist();
- delete seqI; delete seqJ;
-
outputString += toString(dist) + "\t";
}