+ m->errorOut(e, "DistanceCommand", "driver");
+ exit(1);
+ }
+}
+#ifdef USE_MPI
+/**************************************************************************************************/
+/////// need to fix to work with calcs and sequencedb
+int DistanceCommand::driverMPI(int startLine, int endLine, MPI_File& outMPI, float cutoff){
+ try {
+ MPI_Status status;
+ int startTime = time(NULL);
+
+ string outputString = "";
+
+ for(int i=startLine;i<endLine;i++){
+
+ for(int j=0;j<i;j++){
+
+ if (m->control_pressed) { return 0; }
+
+ distCalculator->calcDist(alignDB.get(i), alignDB.get(j));
+ double dist = distCalculator->getDist();
+
+ if(dist <= cutoff){
+ if (output == "column") { outputString += (alignDB.get(i).getName() + ' ' + alignDB.get(j).getName() + ' ' + toString(dist) + '\n'); }
+ }
+
+ if ((output == "square") || (output == "lt")){ //make a square column you can convert to square phylip
+ outputString += (alignDB.get(i).getName() + ' ' + alignDB.get(j).getName() + ' ' + toString(dist) + '\n');
+ outputString += (alignDB.get(j).getName() + ' ' + alignDB.get(i).getName() + ' ' + toString(dist) + '\n');
+ }
+
+ }
+
+ if(i % 100 == 0){
+ m->mothurOut(toString(i) + "\t" + toString(time(NULL) - startTime)); m->mothurOutEndLine();
+ }
+
+ if(i % 10 == 0){ //output to file
+ //send results to parent
+ int length = outputString.length();
+ char buf[length];
+ strcpy(buf, outputString.c_str());
+
+ MPI_File_write_shared(outMPI, buf, length, MPI_CHAR, &status);
+ outputString = "";
+ }
+
+ }
+
+ m->mothurOut(toString(endLine-1) + "\t" + toString(time(NULL) - startTime)); m->mothurOutEndLine();
+ if(outputString != ""){ //output to file
+ //send results to parent
+ int length = outputString.length();
+ char buf[length];
+ strcpy(buf, outputString.c_str());
+
+ MPI_File_write_shared(outMPI, buf, length, MPI_CHAR, &status);
+ outputString = "";
+ }
+
+ return 1;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "DistanceCommand", "driverMPI");
+ exit(1);
+ }
+}
+#endif
+/**************************************************************************************************/
+int DistanceCommand::convertMatrix(string outputFile) {
+ try{
+
+ //sort file by first column so the distances for each row are together
+ string outfile = getRootName(outputFile) + "sorted.dist.temp";
+
+ //use the unix sort
+ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ string command = "sort -n " + outputFile + " -o " + outfile;
+ system(command.c_str());
+ #else //sort using windows sort
+ string command = "sort " + outputFile + " /O " + outfile;
+ system(command.c_str());
+ #endif
+
+
+ //output to new file distance for each row and save positions in file where new row begins
+ ifstream in;
+ openInputFile(outfile, in);
+
+ ofstream out;
+ openOutputFile(outputFile, out);
+
+ out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint);
+
+ out << alignDB.getNumSeqs() << endl;
+
+ //get first currentRow
+ string first, currentRow, second;
+ float dist;
+ map<string, float> rowDists; //take advantage of the fact that maps are already sorted by key
+ map<string, float>::iterator it;
+
+ in >> first;
+ currentRow = first;
+
+ rowDists[first] = 0.00; //distance to yourself is 0.0
+
+ in.seekg(0);
+ //openInputFile(outfile, in);
+
+ while(!in.eof()) {
+ if (m->control_pressed) { in.close(); remove(outfile.c_str()); out.close(); return 0; }
+
+ in >> first >> second >> dist; gobble(in);
+
+ if (first != currentRow) {
+ //print out last row
+ out << currentRow << '\t'; //print name
+
+ //print dists
+ for (it = rowDists.begin(); it != rowDists.end(); it++) {
+ out << it->second << '\t';
+ }
+ out << endl;
+
+ //start new row
+ currentRow = first;
+ rowDists.clear();
+ rowDists[first] = 0.00;
+ rowDists[second] = dist;
+ }else{
+ rowDists[second] = dist;
+ }
+ }
+ //print out last row
+ out << currentRow << '\t'; //print name
+
+ //print dists
+ for (it = rowDists.begin(); it != rowDists.end(); it++) {
+ out << it->second << '\t';
+ }
+ out << endl;
+
+ in.close();
+ out.close();
+
+ remove(outfile.c_str());
+
+ return 1;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "DistanceCommand", "convertMatrix");