]> git.donarmstrong.com Git - mothur.git/blobdiff - listseqscommand.cpp
fixed problem with class.fy.seqs where group totals did not add up. added constructo...
[mothur.git] / listseqscommand.cpp
index d0b00bd3061d2a14365ee43ef96db1bc04ac1cb0..d23949f497e65b262e3067d74d566d4665124412 100644 (file)
@@ -13,7 +13,7 @@
 
 //**********************************************************************************************************************
 
-ListSeqsCommand::ListSeqsCommand(string option){
+ListSeqsCommand::ListSeqsCommand(string option)  {
        try {
                abort = false;
                
@@ -107,17 +107,17 @@ ListSeqsCommand::ListSeqsCommand(string option){
                        else if (listfile == "not found") {  listfile = "";  }
 
                        
-                       if ((fastafile == "") && (namefile == "") && (listfile == "") && (groupfile == "") && (alignfile == ""))  { mothurOut("You must provide a file."); mothurOutEndLine(); abort = true; }
+                       if ((fastafile == "") && (namefile == "") && (listfile == "") && (groupfile == "") && (alignfile == ""))  { m->mothurOut("You must provide a file."); m->mothurOutEndLine(); abort = true; }
                        
                        int okay = 1;
                        if (outputDir != "") { okay++; }
                        
-                       if (parameters.size() > okay) { mothurOut("You may only enter one file."); mothurOutEndLine(); abort = true;  }
+                       if (parameters.size() > okay) { m->mothurOut("You may only enter one file."); m->mothurOutEndLine(); abort = true;  }
                }
 
        }
        catch(exception& e) {
-               errorOut(e, "ListSeqsCommand", "ListSeqsCommand");
+               m->errorOut(e, "ListSeqsCommand", "ListSeqsCommand");
                exit(1);
        }
 }
@@ -125,14 +125,14 @@ ListSeqsCommand::ListSeqsCommand(string option){
 
 void ListSeqsCommand::help(){
        try {
-               mothurOut("The list.seqs command reads a fasta, name, group, list or alignreport file and outputs a .accnos file containing sequence names.\n");
-               mothurOut("The list.seqs command parameters are fasta, name, group and alignreport.  You must provide one of these parameters.\n");
-               mothurOut("The list.seqs command should be in the following format: list.seqs(fasta=yourFasta).\n");
-               mothurOut("Example list.seqs(fasta=amazon.fasta).\n");
-               mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
+               m->mothurOut("The list.seqs command reads a fasta, name, group, list or alignreport file and outputs a .accnos file containing sequence names.\n");
+               m->mothurOut("The list.seqs command parameters are fasta, name, group and alignreport.  You must provide one of these parameters.\n");
+               m->mothurOut("The list.seqs command should be in the following format: list.seqs(fasta=yourFasta).\n");
+               m->mothurOut("Example list.seqs(fasta=amazon.fasta).\n");
+               m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
        }
        catch(exception& e) {
-               errorOut(e, "ListSeqsCommand", "help");
+               m->errorOut(e, "ListSeqsCommand", "help");
                exit(1);
        }
 }
@@ -151,6 +151,8 @@ int ListSeqsCommand::execute(){
                else if (alignfile != "")       {       inputFileName = alignfile;      readAlign();    }
                else if (listfile != "")        {       inputFileName = listfile;       readList();             }
                
+               if (m->control_pressed) { return 0; }
+               
                //sort in alphabetical order
                sort(names.begin(), names.end());
                
@@ -163,21 +165,31 @@ int ListSeqsCommand::execute(){
                
                //output to .accnos file
                for (int i = 0; i < names.size(); i++) {
+                       
+                       if (m->control_pressed) { out.close(); remove(outputFileName.c_str()); return 0; }
+                       
                        out << names[i] << endl;
                }
                out.close();
                
+               if (m->control_pressed) { remove(outputFileName.c_str()); return 0; }
+
+               m->mothurOutEndLine();
+               m->mothurOut("Output File Name: "); m->mothurOutEndLine();
+               m->mothurOut(outputFileName); m->mothurOutEndLine();    
+               m->mothurOutEndLine();
+               
                return 0;               
        }
 
        catch(exception& e) {
-               errorOut(e, "ListSeqsCommand", "execute");
+               m->errorOut(e, "ListSeqsCommand", "execute");
                exit(1);
        }
 }
 
 //**********************************************************************************************************************
-void ListSeqsCommand::readFasta(){
+int ListSeqsCommand::readFasta(){
        try {
                
                ifstream in;
@@ -185,6 +197,9 @@ void ListSeqsCommand::readFasta(){
                string name;
                
                while(!in.eof()){
+                       
+                       if (m->control_pressed) { in.close(); return 0; }
+                       
                        Sequence currSeq(in);
                        name = currSeq.getName();
                        
@@ -192,16 +207,18 @@ void ListSeqsCommand::readFasta(){
                        
                        gobble(in);
                }
-               in.close();             
+               in.close();     
+               
+               return 0;
 
        }
        catch(exception& e) {
-               errorOut(e, "ListSeqsCommand", "readFasta");
+               m->errorOut(e, "ListSeqsCommand", "readFasta");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-void ListSeqsCommand::readList(){
+int ListSeqsCommand::readList(){
        try {
                ifstream in;
                openInputFile(listfile, in);
@@ -214,6 +231,8 @@ void ListSeqsCommand::readList(){
                        for (int i = 0; i < list.getNumBins(); i++) {
                                string binnames = list.get(i);
                                
+                               if (m->control_pressed) { in.close(); return 0; }
+                               
                                while (binnames.find_first_of(',') != -1) { 
                                        string name = binnames.substr(0,binnames.find_first_of(','));
                                        binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
@@ -225,15 +244,17 @@ void ListSeqsCommand::readList(){
                }
                in.close();     
                
+               return 0;
+               
        }
        catch(exception& e) {
-               errorOut(e, "ListSeqsCommand", "readList");
+               m->errorOut(e, "ListSeqsCommand", "readList");
                exit(1);
        }
 }
 
 //**********************************************************************************************************************
-void ListSeqsCommand::readName(){
+int ListSeqsCommand::readName(){
        try {
                
                ifstream in;
@@ -241,6 +262,8 @@ void ListSeqsCommand::readName(){
                string name, firstCol, secondCol;
                
                while(!in.eof()){
+               
+                       if (m->control_pressed) { in.close(); return 0; }
 
                        in >> firstCol;                         
                        in >> secondCol;                        
@@ -258,16 +281,17 @@ void ListSeqsCommand::readName(){
                        gobble(in);
                }
                in.close();
+               return 0;
                
        }
        catch(exception& e) {
-               errorOut(e, "ListSeqsCommand", "readName");
+               m->errorOut(e, "ListSeqsCommand", "readName");
                exit(1);
        }
 }
 
 //**********************************************************************************************************************
-void ListSeqsCommand::readGroup(){
+int ListSeqsCommand::readGroup(){
        try {
        
                ifstream in;
@@ -275,7 +299,9 @@ void ListSeqsCommand::readGroup(){
                string name, group;
                
                while(!in.eof()){
-
+                       
+                       if (m->control_pressed) { in.close(); return 0; }
+                       
                        in >> name;                             //read from first column
                        in >> group;                    //read from second column
                        
@@ -284,17 +310,18 @@ void ListSeqsCommand::readGroup(){
                        gobble(in);
                }
                in.close();
+               return 0;
 
        }
        catch(exception& e) {
-               errorOut(e, "ListSeqsCommand", "readGroup");
+               m->errorOut(e, "ListSeqsCommand", "readGroup");
                exit(1);
        }
 }
 
 //**********************************************************************************************************************
 //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 ListSeqsCommand::readAlign(){
+int ListSeqsCommand::readAlign(){
        try {
        
                ifstream in;
@@ -309,6 +336,8 @@ void ListSeqsCommand::readAlign(){
                
                
                while(!in.eof()){
+               
+                       if (m->control_pressed) { in.close(); return 0; }
 
                        in >> name;                             //read from first column
                        
@@ -323,11 +352,13 @@ void ListSeqsCommand::readAlign(){
                        gobble(in);
                }
                in.close();
+               
+               return 0;
 
                
        }
        catch(exception& e) {
-               errorOut(e, "ListSeqsCommand", "readAlign");
+               m->errorOut(e, "ListSeqsCommand", "readAlign");
                exit(1);
        }
 }