]> git.donarmstrong.com Git - mothur.git/blobdiff - listseqscommand.cpp
optimizing classify.seqs calculating of template probabilities.
[mothur.git] / listseqscommand.cpp
index 902ac87286e302977d2fe555754a632487e6e43b..bfbb0788c5092382f22bea643c5405674361dd67 100644 (file)
@@ -49,7 +49,26 @@ string ListSeqsCommand::getHelpString(){
                exit(1);
        }
 }
-
+//**********************************************************************************************************************
+string ListSeqsCommand::getOutputFileNameTag(string type, string inputName=""){        
+       try {
+        string outputFileName = "";
+               map<string, vector<string> >::iterator it;
+        
+        //is this a type this command creates
+        it = outputTypes.find(type);
+        if (it == outputTypes.end()) {  m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
+        else {
+            if (type == "accnos")             {   outputFileName =  "accnos";       }
+            else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true;  }
+        }
+        return outputFileName;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ListSeqsCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 ListSeqsCommand::ListSeqsCommand(){    
        try {
@@ -150,15 +169,18 @@ ListSeqsCommand::ListSeqsCommand(string option)  {
                        //check for required parameters
                        fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not open") { abort = true; }
-                       else if (fastafile == "not found") {  fastafile = "";  }        
+                       else if (fastafile == "not found") {  fastafile = "";  }
+                       else { m->setFastaFile(fastafile); }
                        
                        namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not open") { abort = true; }
                        else if (namefile == "not found") {  namefile = "";  }  
+                       else { m->setNameFile(namefile); }
                        
                        groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }
                        else if (groupfile == "not found") {  groupfile = "";  }        
+                       else { m->setGroupFile(groupfile); }
                        
                        alignfile = validParameter.validFile(parameters, "alignreport", true);
                        if (alignfile == "not open") { abort = true; }
@@ -167,10 +189,12 @@ ListSeqsCommand::ListSeqsCommand(string option)  {
                        listfile = validParameter.validFile(parameters, "list", true);
                        if (listfile == "not open") { abort = true; }
                        else if (listfile == "not found") {  listfile = "";  }
-
+                       else { m->setListFile(listfile); }
+                       
                        taxfile = validParameter.validFile(parameters, "taxonomy", true);
                        if (taxfile == "not open") { abort = true; }
                        else if (taxfile == "not found") {  taxfile = "";  }
+                       else { m->setTaxonomyFile(taxfile); }
                        
                        if ((fastafile == "") && (namefile == "") && (listfile == "") && (groupfile == "") && (alignfile == "") && (taxfile == ""))  { m->mothurOut("You must provide a file."); m->mothurOutEndLine(); abort = true; }
                        
@@ -209,7 +233,7 @@ int ListSeqsCommand::execute(){
                
                if (outputDir == "") {  outputDir += m->hasPath(inputFileName);  }
                
-               string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + "accnos";
+               string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + getOutputFileNameTag("accnos");
 
                ofstream out;
                m->openOutputFile(outputFileName, out);
@@ -218,13 +242,13 @@ int ListSeqsCommand::execute(){
                //output to .accnos file
                for (int i = 0; i < names.size(); i++) {
                        
-                       if (m->control_pressed) { outputTypes.clear(); out.close(); remove(outputFileName.c_str()); return 0; }
+                       if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(outputFileName); return 0; }
                        
                        out << names[i] << endl;
                }
                out.close();
                
-               if (m->control_pressed) { outputTypes.clear();  remove(outputFileName.c_str()); return 0; }
+               if (m->control_pressed) { outputTypes.clear();  m->mothurRemove(outputFileName); return 0; }
                
                m->setAccnosFile(outputFileName);
                
@@ -308,13 +332,7 @@ int ListSeqsCommand::readList(){
                                
                                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());
-                                       names.push_back(name);
-                               }
-                       
-                               names.push_back(binnames);
+                               m->splitAtComma(binnames, names);
                        }
                }
                in.close();     
@@ -344,14 +362,7 @@ int ListSeqsCommand::readName(){
                        in >> secondCol;                        
                        
                        //parse second column saving each name
-                       while (secondCol.find_first_of(',') != -1) { 
-                               name = secondCol.substr(0,secondCol.find_first_of(','));
-                               secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
-                               names.push_back(name);
-                       }
-                       
-                       //get name after last ,
-                       names.push_back(secondCol);
+                       m->splitAtComma(secondCol, names);
                        
                        m->gobble(in);
                }
@@ -408,14 +419,14 @@ int ListSeqsCommand::readAlign(){
                        if (!in.eof())  {       in >> junk;             }
                        else                    {       break;                  }
                }
-               
+               //m->getline(in);
                
                while(!in.eof()){
                
                        if (m->control_pressed) { in.close(); return 0; }
 
                        in >> name;                             //read from first column
-                       
+                       //m->getline(in);
                        //read rest
                        for (int i = 0; i < 15; i++) {  
                                if (!in.eof())  {       in >> junk;             }