]> git.donarmstrong.com Git - mothur.git/blobdiff - formatphylip.cpp
1.10.0
[mothur.git] / formatphylip.cpp
index 4a7878a54a19fb6a63ad32c00d359c7b490e5216..206df7edfbd915f00947c46d6de07f44fc021c38 100644 (file)
@@ -16,7 +16,7 @@ FormatPhylipMatrix::FormatPhylipMatrix(string df) : filename(df) {
 }
 /***********************************************************************/
 //not using nameMap
-void FormatPhylipMatrix::read(NameAssignment* nameMap){
+int FormatPhylipMatrix::read(NameAssignment* nameMap){
        try {
         
                        float distance;
@@ -63,11 +63,15 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                 
                                //convert to square column matrix
                                for(int i=1;i<nseqs;i++){
+                               
                                        fileHandle >> name;
                                        
                                        list->set(i, name);
                                        
                                        for(int j=0;j<i;j++){
+                                       
+                                               if (m->control_pressed) { outTemp.close(); remove(tempFile.c_str()); fileHandle.close();  delete reading; return 0; }
+                                                                                       
                                                fileHandle >> distance;
                                                
                                                if (distance == -1) { distance = 1000000; }
@@ -95,6 +99,7 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                                        system(command.c_str());
                                #endif
                                
+                               if (m->control_pressed) { remove(tempFile.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;
@@ -118,6 +123,8 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                                for(int k = 0; k < firstString.length(); k++)  {   in.putback(firstString[k]);  }
                                
                                while(!in.eof()) {
+                                       if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); remove(distFile.c_str()); remove(outfile.c_str());  delete reading; return 0; }
+
                                        in >> first >> second >> dist; gobble(in);
                                        
                                        if (first != currentRow) {
@@ -160,21 +167,26 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                                
                                remove(tempFile.c_str());
                                remove(outfile.c_str());
+                               
+                               if (m->control_pressed) {  remove(distFile.c_str());   delete reading; return 0; }
+
                        }
                        else{ //square matrix convert directly to formatted row file
                                int index = nseqs;
                                map<int, float> rowMap;
                                map<int, float>::iterator itRow;
-
+                               rowPos.resize(nseqs, -1);
                 
                                for(int i=0;i<nseqs;i++){
                                        fileHandle >> name;                
-                                                                               
+                                                                       
                                        list->set(i, name);
                                        
                                        for(int j=0;j<nseqs;j++){
-                                               fileHandle >> distance;
+                                               if (m->control_pressed) {  fileHandle.close(); out.close(); remove(distFile.c_str());   delete reading; return 0; }
                                                
+                                               fileHandle >> distance;
+                                       
                                                if (distance == -1) { distance = 1000000; }
                                                
                                                if((distance < cutoff) && (j != i)){
@@ -184,6 +196,8 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                                                reading->update(index);
                                        }
                                        
+                                       gobble(fileHandle);
+                       
                                        //save position in file of each new row
                                        rowPos[i] = out.tellp();
 
@@ -200,14 +214,19 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                        }
                        reading->finish();
                        delete reading;
-                       
-                       list->setLabel("0");
                        fileHandle.close();
                        out.close();
                        
+                       if (m->control_pressed) { remove(distFile.c_str());  return 0; }
+                       
+                       list->setLabel("0");
+                       
+                       return 1;
+                       
+                       
        }
        catch(exception& e) {
-               errorOut(e, "FormatPhylipMatrix", "read");
+               m->errorOut(e, "FormatPhylipMatrix", "read");
                 exit(1);
        }
 }