int numSeqs = seqDB->getNumSeqs();
cutoff += 0.005;
- string phylipFile = "";
- string distFile = getRootName(globaldata->getFastaFile()) + "dist";
- remove(distFile.c_str());
+ string outputFile;
//doses the user want the phylip formatted file as well
if (isTrue(phylip) == true) {
- phylipFile = getRootName(globaldata->getFastaFile()) + "phylip.dist";
- remove(phylipFile.c_str());
+ outputFile = getRootName(globaldata->getFastaFile()) + "phylip.dist";
+ remove(outputFile.c_str());
//output numSeqs to phylip formatted dist file
- openOutputFile(phylipFile, phylipOut);
- phylipOut << numSeqs << endl;
- phylipOut.close();
+ openOutputFile(outputFile, outFile);
+ outFile << numSeqs << endl;
+ outFile.close();
+ }else { //user wants column format
+ outputFile = getRootName(globaldata->getFastaFile()) + "dist";
+ remove(outputFile.c_str());
}
-
//# if defined (_WIN32)
//figure out how to implement the fork and wait commands in windows
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
//if you don't need to fork anything
if(processors == 1){
- driver(distCalculator, seqDB, 0, numSeqs, distFile, phylipFile + "tempPhylipA", cutoff);
-
- if (isTrue(phylip) == true) {
- appendFiles((phylipFile + "tempPhylipA"), phylipFile);
- remove((phylipFile + "tempPhylipA").c_str());
- }
+ driver(distCalculator, seqDB, 0, numSeqs, outputFile + ".temp", cutoff);
+ appendFiles((outputFile + ".temp"), outputFile);
+ remove((outputFile + ".temp").c_str());
}else{ //you have multiple processors
for (int i = 0; i < processors; i++) {
cout << lines[0]->start << '\t' << lines[0]->end << endl;
cout << lines[1]->start << '\t' << lines[1]->end << endl;
- createProcesses(distFile, phylipFile);
+ createProcesses(outputFile);
//append and remove temp files
for (it = processIDS.begin(); it != processIDS.end(); it++) {
- appendFiles((distFile + toString(it->second) + ".temp"), distFile);
- remove((distFile + toString(it->second) + ".temp").c_str());
-
- if (isTrue(phylip) == true) {
- appendFiles((phylipFile + toString(it->second) + ".temp"), phylipFile);
- remove((phylipFile + toString(it->second) + ".temp").c_str());
- }
+ appendFiles((outputFile + toString(it->second) + ".temp"), outputFile);
+ remove((outputFile + toString(it->second) + ".temp").c_str());
}
}
#else
- driver(distCalculator, seqDB, 0, numSeqs, distFile, phylipFile + "tempPhylipA", cutoff);
-
- if (isTrue(phylip) = true) {
- appendFiles((phylipFile + "tempPhylipA"), phylipFile);
- remove((phylipFile + "tempPhylipA").c_str());
- }
+ driver(distCalculator, seqDB, 0, numSeqs, outputFile + ".temp", cutoff);
+ appendFiles((outputFile + ".temp"), outputFile);
+ remove((outputFile + ".temp").c_str());
#endif
delete distCalculator;
}
}
/**************************************************************************************************/
-void DistanceCommand::createProcesses(string column, string phylip) {
+void DistanceCommand::createProcesses(string filename) {
try {
int process = 0;
processIDS.clear();
processIDS[lines[process]->end] = pid; //create map from line number to pid so you can append files in correct order later
process++;
}else if (pid == 0){
- driver(distCalculator, seqDB, lines[process]->start, lines[process]->end, column + toString(getpid()) + ".temp", phylip + toString(getpid()) + ".temp", cutoff);
+ driver(distCalculator, seqDB, lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", cutoff);
exit(0);
}else { cout << "unable to spawn the necessary processes." << endl; exit(0); }
}
/**************************************************************************************************/
/////// need to fix to work with calcs and sequencedb
-int DistanceCommand::driver(Dist* distCalculator, SequenceDB* align, int startLine, int endLine, string dFileName, string pFilename, float cutoff){
+int DistanceCommand::driver(Dist* distCalculator, SequenceDB* align, int startLine, int endLine, string dFileName, float cutoff){
try {
int startTime = time(NULL);
//column file
- ofstream distFile(dFileName.c_str(), ios::trunc);
- distFile.setf(ios::fixed, ios::showpoint);
- distFile << setprecision(4);
-
- ofstream philFile(pFilename.c_str(), ios::trunc);
- philFile.setf(ios::fixed, ios::showpoint);
- philFile << setprecision(4);
+ ofstream outFile(dFileName.c_str(), ios::trunc);
+ outFile.setf(ios::fixed, ios::showpoint);
+ outFile << setprecision(4);
for(int i=startLine;i<endLine;i++){
double dist = distCalculator->getDist();
if(dist <= cutoff){
- distFile << align->get(i)->getName() << ' ' << align->get(j)->getName() << ' ' << dist << endl;
+ if (isTrue(phylip) != true) { outFile << align->get(i)->getName() << ' ' << align->get(j)->getName() << ' ' << dist << endl; }
}
- if (isTrue(phylip) == true) { philFile << dist << '\t'; }
+ if (isTrue(phylip) == true) { outFile << dist << '\t'; }
}
- if (isTrue(phylip) == true) { philFile << endl; }
+ if (isTrue(phylip) == true) { outFile << endl; }
if(i % 100 == 0){
cout << i << '\t' << time(NULL) - startTime << endl;
}
cout << endLine-1 << '\t' << time(NULL) - startTime << endl;
- if (isTrue(phylip) != true) { remove(pFilename.c_str()); }
-
//philFile.close();
//distFile.close();