]> git.donarmstrong.com Git - mothur.git/blobdiff - getseqscommand.cpp
testing mpi
[mothur.git] / getseqscommand.cpp
index ec0539093be68f0581b12f24170f07f726b1ee29..f40c89b3fb3eff837729bc203055d11ef1a3c5a5 100644 (file)
@@ -160,6 +160,8 @@ int GetSeqsCommand::execute(){
                //get names you want to keep
                readAccnos();
                
+               if (m->control_pressed) { return 0; }
+               
                //read through the correct file and output lines you want to keep
                if (fastafile != "")            {               readFasta();    }
                else if (namefile != "")        {               readName();             }
@@ -167,6 +169,8 @@ int GetSeqsCommand::execute(){
                else if (alignfile != "")       {               readAlign();    }
                else if (listfile != "")        {               readList();             }
                
+               if (m->control_pressed) { return 0; }
+               
                if (outputNames.size() != 0) {
                        m->mothurOutEndLine();
                        m->mothurOut("Output File Names: "); m->mothurOutEndLine();
@@ -184,7 +188,7 @@ int GetSeqsCommand::execute(){
 }
 
 //**********************************************************************************************************************
-void GetSeqsCommand::readFasta(){
+int GetSeqsCommand::readFasta(){
        try {
                if (outputDir == "") { outputDir += hasPath(fastafile); }
                string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + "pick" +  getExtension(fastafile);
@@ -199,6 +203,9 @@ void GetSeqsCommand::readFasta(){
                bool wroteSomething = false;
                
                while(!in.eof()){
+               
+                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+                       
                        Sequence currSeq(in);
                        name = currSeq.getName();
                        
@@ -221,6 +228,8 @@ void GetSeqsCommand::readFasta(){
                        m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();
                        remove(outputFileName.c_str()); 
                }else {  outputNames.push_back(outputFileName); }
+               
+               return 0;
 
        }
        catch(exception& e) {
@@ -229,7 +238,7 @@ void GetSeqsCommand::readFasta(){
        }
 }
 //**********************************************************************************************************************
-void GetSeqsCommand::readList(){
+int GetSeqsCommand::readList(){
        try {
                if (outputDir == "") { outputDir += hasPath(listfile); }
                string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + "pick" +  getExtension(listfile);
@@ -242,6 +251,9 @@ void GetSeqsCommand::readList(){
                bool wroteSomething = false;
                
                while(!in.eof()){
+                       
+                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+
                        //read in list vector
                        ListVector list(in);
                        
@@ -265,10 +277,13 @@ void GetSeqsCommand::readList(){
                                }
                        
                                //get last name
-                               if (names.count(binnames) == 1) {  newNames += binnames;  }
+                               if (names.count(binnames) == 1) {  newNames += binnames + ",";  }
 
                                //if there are names in this bin add to new list
-                               if (newNames != "") {  newList.push_back(newNames);     }
+                               if (newNames != "") { 
+                                       newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
+                                       newList.push_back(newNames);    
+                               }
                        }
                                
                        //print new listvector
@@ -286,6 +301,8 @@ void GetSeqsCommand::readList(){
                        m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();
                        remove(outputFileName.c_str()); 
                }else {  outputNames.push_back(outputFileName); }
+               
+               return 0;
 
        }
        catch(exception& e) {
@@ -294,7 +311,7 @@ void GetSeqsCommand::readList(){
        }
 }
 //**********************************************************************************************************************
-void GetSeqsCommand::readName(){
+int GetSeqsCommand::readName(){
        try {
                if (outputDir == "") { outputDir += hasPath(namefile); }
                string outputFileName = outputDir + getRootName(getSimpleName(namefile)) + "pick" +  getExtension(namefile);
@@ -310,6 +327,8 @@ void GetSeqsCommand::readName(){
                
                
                while(!in.eof()){
+               
+                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
 
                        in >> firstCol;                         
                        in >> secondCol;                        
@@ -370,6 +389,8 @@ void GetSeqsCommand::readName(){
                        remove(outputFileName.c_str()); 
                }else {  outputNames.push_back(outputFileName); }
                
+               return 0;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "GetSeqsCommand", "readName");
@@ -378,7 +399,7 @@ void GetSeqsCommand::readName(){
 }
 
 //**********************************************************************************************************************
-void GetSeqsCommand::readGroup(){
+int GetSeqsCommand::readGroup(){
        try {
                if (outputDir == "") { outputDir += hasPath(groupfile); }
                string outputFileName = outputDir + getRootName(getSimpleName(groupfile)) + "pick" + getExtension(groupfile);
@@ -394,6 +415,9 @@ void GetSeqsCommand::readGroup(){
                
                while(!in.eof()){
 
+                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+
+
                        in >> name;                             //read from first column
                        in >> group;                    //read from second column
                        
@@ -415,6 +439,8 @@ void GetSeqsCommand::readGroup(){
                        m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();
                        remove(outputFileName.c_str()); 
                }else {  outputNames.push_back(outputFileName); }
+               
+               return 0;
 
        }
        catch(exception& e) {
@@ -425,7 +451,7 @@ void GetSeqsCommand::readGroup(){
 
 //**********************************************************************************************************************
 //alignreport file has a column header line then all other lines contain 16 columns.  we just want the first column since that contains the name
-void GetSeqsCommand::readAlign(){
+int GetSeqsCommand::readAlign(){
        try {
                if (outputDir == "") { outputDir += hasPath(alignfile); }
                string outputFileName = outputDir + getRootName(getSimpleName(alignfile)) + "pick.align.report";
@@ -447,6 +473,9 @@ void GetSeqsCommand::readAlign(){
                out << endl;
                
                while(!in.eof()){
+               
+                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+
 
                        in >> name;                             //read from first column
                        
@@ -483,6 +512,8 @@ void GetSeqsCommand::readAlign(){
                        remove(outputFileName.c_str()); 
                }else {  outputNames.push_back(outputFileName); }
                
+               return 0;
+               
        }
        catch(exception& e) {
                m->errorOut(e, "GetSeqsCommand", "readAlign");
@@ -491,7 +522,7 @@ void GetSeqsCommand::readAlign(){
 }
 //**********************************************************************************************************************
 
-void GetSeqsCommand::readAccnos(){
+int GetSeqsCommand::readAccnos(){
        try {
                
                ifstream in;
@@ -505,7 +536,9 @@ void GetSeqsCommand::readAccnos(){
                        
                        gobble(in);
                }
-               in.close();             
+               in.close();     
+               
+               return 0;
 
        }
        catch(exception& e) {