]> git.donarmstrong.com Git - mothur.git/blobdiff - readcluster.cpp
added chop.seqs command
[mothur.git] / readcluster.cpp
index 11b8d012a22e592d99bb71e3063c0c89a710252a..c8a8bc7b5074bf91ea46e2c30f2364a509d2c5ff 100644 (file)
 
 /***********************************************************************/
 
-ReadCluster::ReadCluster(string distfile, float c){
+ReadCluster::ReadCluster(string distfile, float c, string o){
                globaldata = GlobalData::getInstance();
+               m = MothurOut::getInstance();
         distFile = distfile;
                cutoff = c;
+               outputDir = o;
 }
 
 /***********************************************************************/
 
-void ReadCluster::read(NameAssignment* nameMap){
+int ReadCluster::read(NameAssignment* nameMap){
        try {
         
                if (format == "phylip") { convertPhylip2Column(nameMap); }
                else { list = new ListVector(nameMap->getListVector());  }
                
-               OutPutFile = sortFile(distFile);
+               if (m->control_pressed) { return 0; }
+               
+               OutPutFile = sortFile(distFile, outputDir);
+               
+               return 0;
                        
        }
        catch(exception& e) {
-               errorOut(e, "ReadCluster", "read");
+               m->errorOut(e, "ReadCluster", "read");
                exit(1);
        }
 }
 /***********************************************************************/
 
-void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
+int ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
        try {   
                //convert phylip file to column file
                map<int, string> rowToName;
@@ -63,7 +69,7 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                }
                else{
                        list = new ListVector(nameMap->getListVector());
-                       if(nameMap->count(name)==0){        mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); }
+                       if(nameMap->count(name)==0){        m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); }
                }
         
                char d;
@@ -95,6 +101,9 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                                        list->set(i, name);
                                        
                                        for(int j=0;j<i;j++){
+                                       
+                                               if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+                                               
                                                in >> distance;
                                                
                                                if (distance == -1) { distance = 1000000; }
@@ -106,9 +115,12 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                                        
                                }
                                else{
-                                       if(nameMap->count(name)==0){        mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); }
+                                       if(nameMap->count(name)==0){        m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); }
                                        
                                        for(int j=0;j<i;j++){
+                                               
+                                               if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+                                               
                                                in >> distance;
                                                
                                                if (distance == -1) { distance = 1000000; }
@@ -129,6 +141,8 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                                if(nameMap == NULL){
                                        list->set(i, name);
                                        for(int j=0;j<nseqs;j++){
+                                               if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+                                               
                                                in >> distance;
                                        
                                                if (distance == -1) { distance = 1000000; }
@@ -139,9 +153,11 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                                        }
                                }
                                else{
-                                       if(nameMap->count(name)==0){        mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); }
+                                       if(nameMap->count(name)==0){        m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); }
                                        
                                        for(int j=0;j<nseqs;j++){
+                                               if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+                                               
                                                in >> distance;
                         
                                                if (distance == -1) { distance = 1000000; }
@@ -179,6 +195,8 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                float dist;
                
                while (in2) {
+                       if (m->control_pressed) { in2.close(); out2.close(); remove(tempFile.c_str()); remove(outputFile.c_str()); return 0; }
+                       
                        in2 >> first >> second >> dist;
                        out2 << rowToName[first] << '\t' << rowToName[second] << '\t' << dist << endl;
                        gobble(in2);
@@ -188,9 +206,13 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
                
                remove(tempFile.c_str());
                distFile = outputFile;
+               
+               if (m->control_pressed) {  remove(outputFile.c_str());  }
+
+               return 0;
        }
        catch(exception& e) {
-               errorOut(e, "ReadCluster", "convertPhylip2Column");
+               m->errorOut(e, "ReadCluster", "convertPhylip2Column");
                exit(1);
        }
 }