X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=formatcolumn.cpp;h=2bbcf518b864aa5a5656a271f2922c531e74af11;hb=df905918ace8537273616b4120d404ebd29dc9cc;hp=a11601b74004d2429b985a1aa1e6fe4114457855;hpb=832d53a9dfac6b1795735eec643d8cf627b0d8e3;p=mothur.git diff --git a/formatcolumn.cpp b/formatcolumn.cpp index a11601b..2bbcf51 100644 --- a/formatcolumn.cpp +++ b/formatcolumn.cpp @@ -12,11 +12,11 @@ /***********************************************************************/ FormatColumnMatrix::FormatColumnMatrix(string df) : filename(df){ - openInputFile(filename, fileHandle); + m->openInputFile(filename, fileHandle); } /***********************************************************************/ -void FormatColumnMatrix::read(NameAssignment* nameMap){ +int FormatColumnMatrix::read(NameAssignment* nameMap){ try { string firstName, secondName; @@ -35,10 +35,12 @@ void FormatColumnMatrix::read(NameAssignment* nameMap){ ofstream out; string tempOutFile = filename + ".temp"; - openOutputFile(tempOutFile, out); + m->openOutputFile(tempOutFile, out); while(fileHandle && lt == 1){ //let's assume it's a triangular matrix... + if (m->control_pressed) { out.close(); remove(tempOutFile.c_str()); fileHandle.close(); delete reading; return 0; } + fileHandle >> firstName >> secondName >> distance; // get the row and column names and distance map::iterator itA = nameMap->find(firstName); @@ -66,7 +68,7 @@ void FormatColumnMatrix::read(NameAssignment* nameMap){ reading->update(itA->second * nseqs / 2); } - gobble(fileHandle); + m->gobble(fileHandle); } out.close(); fileHandle.close(); @@ -77,7 +79,7 @@ void FormatColumnMatrix::read(NameAssignment* nameMap){ }else{ squareFile = tempOutFile; } //sort file by first column so the distances for each row are together - string outfile = getRootName(squareFile) + "sorted.dist.temp"; + string outfile = m->getRootName(squareFile) + "sorted.dist.temp"; //use the unix sort #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) @@ -88,13 +90,14 @@ void FormatColumnMatrix::read(NameAssignment* nameMap){ system(command.c_str()); #endif + if (m->control_pressed) { remove(tempOutFile.c_str()); remove(outfile.c_str()); delete reading; return 0; } //output to new file distance for each row and save positions in file where new row begins ifstream in; - openInputFile(outfile, in); + m->openInputFile(outfile, in); distFile = outfile + ".rowFormatted"; - openOutputFile(distFile, out); + m->openOutputFile(distFile, out); rowPos.resize(nseqs, -1); int currentRow; @@ -111,7 +114,10 @@ void FormatColumnMatrix::read(NameAssignment* nameMap){ for(int k = 0; k < firstString.length(); k++) { in.putback(firstString[k]); } while(!in.eof()) { - in >> first >> second >> dist; gobble(in); + + if (m->control_pressed) { in.close(); out.close(); remove(distFile.c_str()); remove(tempOutFile.c_str()); remove(outfile.c_str()); delete reading; return 0; } + + in >> first >> second >> dist; m->gobble(in); if (first != currentRow) { //save position in file of each new row @@ -153,16 +159,23 @@ void FormatColumnMatrix::read(NameAssignment* nameMap){ in.close(); out.close(); + if (m->control_pressed) { remove(distFile.c_str()); remove(tempOutFile.c_str()); remove(outfile.c_str()); delete reading; return 0; } remove(tempOutFile.c_str()); remove(outfile.c_str()); reading->finish(); + + delete reading; list->setLabel("0"); + + if (m->control_pressed) { remove(distFile.c_str()); return 0; } + + return 1; } catch(exception& e) { - errorOut(e, "FormatColumnMatrix", "read"); + m->errorOut(e, "FormatColumnMatrix", "read"); exit(1); } }