]> git.donarmstrong.com Git - mothur.git/blobdiff - getlineagecommand.cpp
added load.logfile command. changed summary.single output for subsample=t.
[mothur.git] / getlineagecommand.cpp
index 0d836130d31124298a13c3a388267144cf5538ff..1aba0fed4e6e772de07718a544335b6e6bb58db9 100644 (file)
@@ -57,7 +57,31 @@ string GetLineageCommand::getHelpString(){
                exit(1);
        }
 }
-
+//**********************************************************************************************************************
+string GetLineageCommand::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 == "fasta")            {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "taxonomy")    {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "name")        {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "group")       {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "list")        {   outputFileName =  "pick" + m->getExtension(inputName);   }
+            else if (type == "alignreport") {   outputFileName =  "pick.align.report";   }
+            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, "GetLineageCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 GetLineageCommand::GetLineageCommand(){        
        try {
@@ -168,12 +192,12 @@ GetLineageCommand::GetLineageCommand(string option)  {
                        
                        //check for required parameters                 
                        fastafile = validParameter.validFile(parameters, "fasta", true);
-                       if (fastafile == "not open") { abort = true; }
+                       if (fastafile == "not open") { fastafile = ""; abort = true; }
                        else if (fastafile == "not found") {  fastafile = "";  }
                        else { m->setFastaFile(fastafile); }
                        
                        namefile = validParameter.validFile(parameters, "name", true);
-                       if (namefile == "not open") { abort = true; }
+                       if (namefile == "not open") { namefile = ""; abort = true; }
                        else if (namefile == "not found") {  namefile = "";  }  
                        else { m->setNameFile(namefile); }
                        
@@ -192,7 +216,7 @@ GetLineageCommand::GetLineageCommand(string option)  {
                        else { m->setListFile(listfile); }
                        
                        taxfile = validParameter.validFile(parameters, "taxonomy", true);
-                       if (taxfile == "not open") { abort = true; }
+                       if (taxfile == "not open") { taxfile = ""; abort = true; }
                        else if (taxfile == "not found") {                              
                                taxfile = m->getTaxonomyFile(); 
                                if (taxfile != "") { m->mothurOut("Using " + taxfile + " as input file for the taxonomy parameter."); m->mothurOutEndLine(); }
@@ -217,6 +241,11 @@ GetLineageCommand::GetLineageCommand(string option)  {
                        m->splitAtChar(taxons, listOfTaxons, '-');
                        
                        if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == ""))  { m->mothurOut("You must provide one of the following: fasta, name, group, alignreport, taxonomy or listfile."); m->mothurOutEndLine(); abort = true; }
+               
+                       if ((namefile == "") && ((fastafile != "") || (taxfile != ""))){
+                               vector<string> files; files.push_back(fastafile); files.push_back(taxfile);
+                               parser.getNameFile(files);
+                       }
                }
 
        }
@@ -243,7 +272,7 @@ int GetLineageCommand::execute(){
                if (listfile != "")                     {               readList();             }
                
                
-               if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) {   remove(outputNames[i].c_str());  } return 0; }
+               if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) {   m->mothurRemove(outputNames[i]);  } return 0; }
                
                if (outputNames.size() != 0) {
                        m->mothurOutEndLine();
@@ -293,7 +322,7 @@ int GetLineageCommand::readFasta(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(fastafile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" +  m->getExtension(fastafile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -306,7 +335,7 @@ int GetLineageCommand::readFasta(){
                
                while(!in.eof()){
                
-                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+                       if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName);  return 0; }
                        
                        Sequence currSeq(in);
                        name = currSeq.getName();
@@ -340,7 +369,7 @@ int GetLineageCommand::readList(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" +  m->getExtension(listfile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -351,7 +380,7 @@ int GetLineageCommand::readList(){
                
                while(!in.eof()){
                        
-                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+                       if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName);  return 0; }
 
                        //read in list vector
                        ListVector list(in);
@@ -412,7 +441,7 @@ int GetLineageCommand::readName(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(namefile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" +  m->getExtension(namefile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -426,7 +455,7 @@ int GetLineageCommand::readName(){
                
                while(!in.eof()){
                
-                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+                       if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName);  return 0; }
 
                        in >> firstCol;                         
                        in >> secondCol;
@@ -498,7 +527,7 @@ int GetLineageCommand::readGroup(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(groupfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -511,7 +540,7 @@ int GetLineageCommand::readGroup(){
                
                while(!in.eof()){
 
-                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+                       if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName);  return 0; }
 
 
                        in >> name;                             //read from first column
@@ -545,7 +574,7 @@ int GetLineageCommand::readTax(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(taxfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile);
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -564,14 +593,15 @@ int GetLineageCommand::readTax(){
                        if (hasConPos != string::npos) {  
                                taxonsHasConfidence[i] = true; 
                                searchTaxons[i] = getTaxons(listOfTaxons[i]); 
-                               noConfidenceTaxons[i] = removeConfidences(listOfTaxons[i]);
+                               noConfidenceTaxons[i] = listOfTaxons[i];
+                               m->removeConfidences(noConfidenceTaxons[i]);
                        }
                }
                
                
                while(!in.eof()){
 
-                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+                       if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName);  return 0; }
 
                        in >> name;                             //read from first column
                        in >> tax;                      //read from second column
@@ -584,7 +614,8 @@ int GetLineageCommand::readTax(){
                                if (!taxonsHasConfidence[j]) {
                                        int hasConfidences = tax.find_first_of('(');
                                        if (hasConfidences != string::npos) { 
-                                               newtax = removeConfidences(tax);
+                                               newtax = tax;
+                                               m->removeConfidences(newtax);
                                        }
                                
                                        int pos = newtax.find(noConfidenceTaxons[j]);
@@ -613,7 +644,8 @@ int GetLineageCommand::readTax(){
                                                string noNewTax = tax;
                                                int hasConfidences = tax.find_first_of('(');
                                                if (hasConfidences != string::npos) { 
-                                                       noNewTax = removeConfidences(tax);
+                                                       noNewTax = tax;
+                                                       m->removeConfidences(noNewTax);
                                                }
                                        
                                                int pos = noNewTax.find(noConfidenceTaxons[j]);
@@ -725,36 +757,13 @@ vector< map<string, float> > GetLineageCommand::getTaxons(string tax) {
                exit(1);
        }
 }
-/**************************************************************************************************/
-string GetLineageCommand::removeConfidences(string tax) {
-       try {
-               
-               string taxon = "";
-               int taxLength = tax.length();
-               for(int i=0;i<taxLength;i++){
-                       if(tax[i] == ';'){
-                               taxon = taxon.substr(0, taxon.find_first_of('(')); //rip off confidence
-                               taxon += ";";
-                       }
-                       else{
-                               taxon += tax[i];
-                       }
-               }
-                               
-               return taxon;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetLineageCommand", "removeConfidences");
-               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
 int GetLineageCommand::readAlign(){
        try {
                string thisOutputDir = outputDir;
                if (outputDir == "") {  thisOutputDir += m->hasPath(alignfile);  }
-               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report";
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport");
                ofstream out;
                m->openOutputFile(outputFileName, out);
                
@@ -774,7 +783,7 @@ int GetLineageCommand::readAlign(){
                
                while(!in.eof()){
                
-                       if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
+                       if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName);  return 0; }
 
 
                        in >> name;                             //read from first column